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 SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
44 virtual void SetUpOnMainThread() OVERRIDE
;
46 virtual std::string
BuildQuery(const std::string
& base
,
47 const std::string
& test_case
) = 0;
49 // Returns the URL to load for file: tests.
50 GURL
GetTestFileUrl(const std::string
& test_case
);
51 void RunTest(const std::string
& test_case
);
52 // Run the test and reload. This can test for clean shutdown, including leaked
53 // instance object vars.
54 void RunTestAndReload(const std::string
& test_case
);
55 void RunTestViaHTTP(const std::string
& test_case
);
56 void RunTestWithSSLServer(const std::string
& test_case
);
57 void RunTestWithWebSocketServer(const std::string
& test_case
);
58 void RunTestIfAudioOutputAvailable(const std::string
& test_case
);
59 void RunTestViaHTTPIfAudioOutputAvailable(const std::string
& test_case
);
60 std::string
StripPrefixes(const std::string
& test_name
);
63 class InfoBarObserver
: public content::NotificationObserver
{
65 explicit InfoBarObserver(PPAPITestBase
* test_base
);
68 void ExpectInfoBarAndAccept(bool should_accept
);
71 // content::NotificationObserver:
72 virtual void Observe(int type
,
73 const content::NotificationSource
& source
,
74 const content::NotificationDetails
& details
) OVERRIDE
;
76 void VerifyInfoBarState();
78 content::NotificationRegistrar registrar_
;
79 PPAPITestBase
* test_base_
;
80 bool expecting_infobar_
;
84 // Runs the test for a tab given the tab that's already navigated to the
86 void RunTestURL(const GURL
& test_url
);
87 // Gets the URL of the the given |test_case| for the given HTTP test server.
88 // If |extra_params| is non-empty, it will be appended as URL parameters.
89 GURL
GetTestURL(const net::SpawnedTestServer
& http_server
,
90 const std::string
& test_case
,
91 const std::string
& extra_params
);
94 // In-process plugin test runner. See OutOfProcessPPAPITest below for the
95 // out-of-process version.
96 class PPAPITest
: public PPAPITestBase
{
100 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
102 virtual std::string
BuildQuery(const std::string
& base
,
103 const std::string
& test_case
) OVERRIDE
;
105 bool in_process_
; // Controls the --ppapi-in-process switch.
108 class PPAPIPrivateTest
: public PPAPITest
{
110 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
113 // Variant of PPAPITest that runs plugins out-of-process to test proxy
115 class OutOfProcessPPAPITest
: public PPAPITest
{
117 OutOfProcessPPAPITest();
119 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
122 class OutOfProcessPPAPIPrivateTest
: public OutOfProcessPPAPITest
{
124 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
127 // NaCl plugin test runner for Newlib runtime.
128 class PPAPINaClTest
: public PPAPITestBase
{
130 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
133 // NaCl plugin test runner for Newlib runtime.
134 class PPAPINaClNewlibTest
: public PPAPINaClTest
{
136 virtual std::string
BuildQuery(const std::string
& base
,
137 const std::string
& test_case
) OVERRIDE
;
140 class PPAPIPrivateNaClNewlibTest
: public PPAPINaClNewlibTest
{
142 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
145 // NaCl plugin test runner for GNU-libc runtime.
146 class PPAPINaClGLibcTest
: public PPAPINaClTest
{
148 virtual std::string
BuildQuery(const std::string
& base
,
149 const std::string
& test_case
) OVERRIDE
;
152 class PPAPIPrivateNaClGLibcTest
: public PPAPINaClGLibcTest
{
154 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
157 // NaCl plugin test runner for the PNaCl + Newlib runtime.
158 class PPAPINaClPNaClTest
: public PPAPINaClTest
{
160 virtual std::string
BuildQuery(const std::string
& base
,
161 const std::string
& test_case
) OVERRIDE
;
164 class PPAPIPrivateNaClPNaClTest
: public PPAPINaClPNaClTest
{
166 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
169 class PPAPINaClTestDisallowedSockets
: public PPAPITestBase
{
171 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
;
173 virtual std::string
BuildQuery(const std::string
& base
,
174 const std::string
& test_case
) OVERRIDE
;
177 class PPAPIBrokerInfoBarTest
: public OutOfProcessPPAPITest
{
179 // PPAPITestBase override:
180 virtual void SetUpOnMainThread() OVERRIDE
;
183 #endif // CHROME_TEST_PPAPI_PPAPI_TEST_H_