1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CONTENT_TEST_PPAPI_PPAPI_TEST_H_ 6#define CONTENT_TEST_PPAPI_PPAPI_TEST_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/compiler_specific.h" 12#include "content/public/test/content_browser_test.h" 13#include "content/public/test/javascript_test_observer.h" 14#include "net/test/spawned_test_server/spawned_test_server.h" 15#include "url/gurl.h" 16 17// This file provides test classes for writing Pepper tests for 18// content_browsertests. The interfaces provided here should look similar to 19// what's available in chrome/test/ppapi. 20 21namespace base { 22class CommandLine; 23} 24 25namespace content { 26 27class PPAPITestMessageHandler : public content::TestMessageHandler { 28 public: 29 PPAPITestMessageHandler(); 30 31 virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE; 32 virtual void Reset() OVERRIDE; 33 34 const std::string& message() const { 35 return message_; 36 } 37 38 private: 39 std::string message_; 40 41 DISALLOW_COPY_AND_ASSIGN(PPAPITestMessageHandler); 42}; 43 44class PPAPITestBase : public ContentBrowserTest { 45 public: 46 PPAPITestBase(); 47 48 // ContentBrowserTest overrides. 49 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; 50 51 virtual std::string BuildQuery(const std::string& base, 52 const std::string& test_case) = 0; 53 54 // Returns the URL to load for file: tests. 55 GURL GetTestFileUrl(const std::string& test_case); 56 virtual void RunTest(const std::string& test_case); 57 58 // Run the test and reload. This can test for clean shutdown, including 59 // leaked instance object vars. 60 virtual void RunTestAndReload(const std::string& test_case); 61 62 protected: 63 // Runs the test for a tab given the tab that's already navigated to the 64 // given URL. 65 void RunTestURL(const GURL& test_url); 66}; 67 68// In-process plugin test runner. See OutOfProcessPPAPITest below for the 69// out-of-process version. 70class PPAPITest : public PPAPITestBase { 71 public: 72 PPAPITest(); 73 74 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; 75 76 virtual std::string BuildQuery(const std::string& base, 77 const std::string& test_case) OVERRIDE; 78 protected: 79 bool in_process_; // Controls the --ppapi-in-process switch. 80}; 81 82// Variant of PPAPITest that runs plugins out-of-process to test proxy 83// codepaths. 84class OutOfProcessPPAPITest : public PPAPITest { 85 public: 86 OutOfProcessPPAPITest(); 87 88 virtual void SetUp() OVERRIDE; 89 virtual void TearDown() OVERRIDE; 90}; 91 92} // namespace 93 94#endif // CONTENT_TEST_PPAPI_PPAPI_TEST_H_ 95