1 // Copyright (c) 2012 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.
5 #ifndef CHROME_TEST_PPAPI_PPAPI_TEST_H_
6 #define CHROME_TEST_PPAPI_PPAPI_TEST_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/javascript_test_observer.h"
14 #include "net/test/spawned_test_server/spawned_test_server.h"
20 class PPAPITestMessageHandler
: public TestMessageHandler
{
22 PPAPITestMessageHandler();
24 MessageResponse
HandleMessage(const std::string
& json
);
26 virtual void Reset() OVERRIDE
;
28 const std::string
& message() const {
35 DISALLOW_COPY_AND_ASSIGN(PPAPITestMessageHandler
);
38 class PPAPITestBase
: public InProcessBrowserTest
{
42 // InProcessBrowserTest:
43 virtual void SetUp() OVERRIDE
;
44 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
45 virtual void SetUpOnMainThread() OVERRIDE
;
47 virtual std::string
BuildQuery(const std::string
& base
,
48 const std::string
& test_case
) = 0;
50 // Returns the URL to load for file: tests.
51 GURL
GetTestFileUrl(const std::string
& test_case
);
52 virtual void RunTest(const std::string
& test_case
);
53 // Run the test and reload. This can test for clean shutdown, including leaked
54 // instance object vars.
55 virtual void RunTestAndReload(const std::string
& test_case
);
56 virtual void RunTestViaHTTP(const std::string
& test_case
);
57 virtual void RunTestWithSSLServer(const std::string
& test_case
);
58 virtual void RunTestWithWebSocketServer(const std::string
& test_case
);
59 virtual void RunTestIfAudioOutputAvailable(const std::string
& test_case
);
60 virtual void RunTestViaHTTPIfAudioOutputAvailable(
61 const std::string
& test_case
);
62 std::string
StripPrefixes(const std::string
& test_name
);
65 class InfoBarObserver
: public content::NotificationObserver
{
67 explicit InfoBarObserver(PPAPITestBase
* test_base
);
70 void ExpectInfoBarAndAccept(bool should_accept
);
73 // content::NotificationObserver:
74 virtual void Observe(int type
,
75 const content::NotificationSource
& source
,
76 const content::NotificationDetails
& details
) OVERRIDE
;
78 void VerifyInfoBarState();
80 content::NotificationRegistrar registrar_
;
81 PPAPITestBase
* test_base_
;
82 bool expecting_infobar_
;
86 // Runs the test for a tab given the tab that's already navigated to the
88 void RunTestURL(const GURL
& test_url
);
89 // Gets the URL of the the given |test_case| for the given HTTP test server.
90 // If |extra_params| is non-empty, it will be appended as URL parameters.
91 GURL
GetTestURL(const net::SpawnedTestServer
& http_server
,
92 const std::string
& test_case
,
93 const std::string
& extra_params
);
96 // In-process plugin test runner. See OutOfProcessPPAPITest below for the
97 // out-of-process version.
98 class PPAPITest
: public PPAPITestBase
{
102 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
104 virtual std::string
BuildQuery(const std::string
& base
,
105 const std::string
& test_case
) OVERRIDE
;
107 bool in_process_
; // Controls the --ppapi-in-process switch.
110 class PPAPIPrivateTest
: public PPAPITest
{
112 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
115 // Variant of PPAPITest that runs plugins out-of-process to test proxy
117 class OutOfProcessPPAPITest
: public PPAPITest
{
119 OutOfProcessPPAPITest();
121 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
124 class OutOfProcessPPAPIPrivateTest
: public OutOfProcessPPAPITest
{
126 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
129 // NaCl plugin test runner for Newlib runtime.
130 class PPAPINaClTest
: public PPAPITestBase
{
132 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
133 virtual void SetUpOnMainThread() OVERRIDE
;
134 // PPAPITestBase overrides.
135 virtual void RunTest(const std::string
& test_case
) OVERRIDE
;
136 virtual void RunTestAndReload(const std::string
& test_case
) OVERRIDE
;
137 virtual void RunTestViaHTTP(const std::string
& test_case
) OVERRIDE
;
138 virtual void RunTestWithSSLServer(const std::string
& test_case
) OVERRIDE
;
139 virtual void RunTestWithWebSocketServer(
140 const std::string
& test_case
) OVERRIDE
;
141 virtual void RunTestIfAudioOutputAvailable(
142 const std::string
& test_case
) OVERRIDE
;
143 virtual void RunTestViaHTTPIfAudioOutputAvailable(
144 const std::string
& test_case
) OVERRIDE
;
147 // NaCl plugin test runner for Newlib runtime.
148 class PPAPINaClNewlibTest
: public PPAPINaClTest
{
150 virtual std::string
BuildQuery(const std::string
& base
,
151 const std::string
& test_case
) OVERRIDE
;
154 class PPAPIPrivateNaClNewlibTest
: public PPAPINaClNewlibTest
{
156 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
159 // NaCl plugin test runner for GNU-libc runtime.
160 class PPAPINaClGLibcTest
: public PPAPINaClTest
{
162 virtual std::string
BuildQuery(const std::string
& base
,
163 const std::string
& test_case
) OVERRIDE
;
166 class PPAPIPrivateNaClGLibcTest
: public PPAPINaClGLibcTest
{
168 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
171 // NaCl plugin test runner for the PNaCl + Newlib runtime.
172 class PPAPINaClPNaClTest
: public PPAPINaClTest
{
174 virtual std::string
BuildQuery(const std::string
& base
,
175 const std::string
& test_case
) OVERRIDE
;
178 class PPAPIPrivateNaClPNaClTest
: public PPAPINaClPNaClTest
{
180 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
183 // Test Non-SFI Mode, using PNaCl toolchain to produce nexes.
184 class PPAPINaClPNaClNonSfiTest
: public PPAPINaClTest
{
186 virtual void SetUpCommandLine(base::CommandLine
* command_line
);
188 virtual std::string
BuildQuery(const std::string
& base
,
189 const std::string
& test_case
) OVERRIDE
;
192 class PPAPIPrivateNaClPNaClNonSfiTest
: public PPAPINaClPNaClNonSfiTest
{
194 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
197 class PPAPINaClTestDisallowedSockets
: public PPAPITestBase
{
199 virtual void SetUpCommandLine(base::CommandLine
* command_line
) OVERRIDE
;
201 virtual std::string
BuildQuery(const std::string
& base
,
202 const std::string
& test_case
) OVERRIDE
;
205 class PPAPIBrokerInfoBarTest
: public OutOfProcessPPAPITest
{
207 // PPAPITestBase override:
208 virtual void SetUpOnMainThread() OVERRIDE
;
211 #endif // CHROME_TEST_PPAPI_PPAPI_TEST_H_