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 "content/public/test/javascript_test_observer.h"
14 #include "net/test/spawned_test_server/spawned_test_server.h"
20 class PPAPITestMessageHandler
: public content::TestMessageHandler
{
22 PPAPITestMessageHandler();
24 MessageResponse
HandleMessage(const std::string
& json
) override
;
25 void Reset() override
;
27 const std::string
& message() const {
34 DISALLOW_COPY_AND_ASSIGN(PPAPITestMessageHandler
);
37 class PPAPITestBase
: public InProcessBrowserTest
{
41 // InProcessBrowserTest:
42 void SetUp() override
;
43 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
44 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 virtual void RunTest(const std::string
& test_case
);
52 virtual void RunTestViaHTTP(const std::string
& test_case
);
53 virtual void RunTestWithSSLServer(const std::string
& test_case
);
54 virtual void RunTestWithWebSocketServer(const std::string
& test_case
);
55 virtual void RunTestIfAudioOutputAvailable(const std::string
& test_case
);
56 virtual void RunTestViaHTTPIfAudioOutputAvailable(
57 const std::string
& test_case
);
60 class InfoBarObserver
: public content::NotificationObserver
{
62 explicit InfoBarObserver(PPAPITestBase
* test_base
);
65 void ExpectInfoBarAndAccept(bool should_accept
);
68 // content::NotificationObserver:
69 void Observe(int type
,
70 const content::NotificationSource
& source
,
71 const content::NotificationDetails
& details
) override
;
73 void VerifyInfoBarState();
75 content::NotificationRegistrar registrar_
;
76 PPAPITestBase
* test_base_
;
77 bool expecting_infobar_
;
81 // Runs the test for a tab given the tab that's already navigated to the
83 void RunTestURL(const GURL
& test_url
);
84 // Gets the URL of the the given |test_case| for the given HTTP test server.
85 // If |extra_params| is non-empty, it will be appended as URL parameters.
86 GURL
GetTestURL(const net::SpawnedTestServer
& http_server
,
87 const std::string
& test_case
,
88 const std::string
& extra_params
);
91 // In-process plugin test runner. See OutOfProcessPPAPITest below for the
92 // out-of-process version.
93 class PPAPITest
: public PPAPITestBase
{
97 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
99 std::string
BuildQuery(const std::string
& base
,
100 const std::string
& test_case
) override
;
103 bool in_process_
; // Controls the --ppapi-in-process switch.
106 class PPAPIPrivateTest
: public PPAPITest
{
108 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
111 // Variant of PPAPITest that runs plugins out-of-process to test proxy
113 class OutOfProcessPPAPITest
: public PPAPITest
{
115 OutOfProcessPPAPITest();
117 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
120 class OutOfProcessPPAPIPrivateTest
: public OutOfProcessPPAPITest
{
122 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
125 // NaCl plugin test runner for Newlib runtime.
126 class PPAPINaClTest
: public PPAPITestBase
{
128 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
129 void SetUpOnMainThread() override
;
130 // PPAPITestBase overrides.
131 void RunTest(const std::string
& test_case
) override
;
132 void RunTestViaHTTP(const std::string
& test_case
) override
;
133 void RunTestWithSSLServer(const std::string
& test_case
) override
;
134 void RunTestWithWebSocketServer(const std::string
& test_case
) override
;
135 void RunTestIfAudioOutputAvailable(const std::string
& test_case
) override
;
136 void RunTestViaHTTPIfAudioOutputAvailable(
137 const std::string
& test_case
) override
;
140 // NaCl plugin test runner for Newlib runtime.
141 class PPAPINaClNewlibTest
: public PPAPINaClTest
{
143 std::string
BuildQuery(const std::string
& base
,
144 const std::string
& test_case
) override
;
147 class PPAPIPrivateNaClNewlibTest
: public PPAPINaClNewlibTest
{
149 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
152 // NaCl plugin test runner for GNU-libc runtime.
153 class PPAPINaClGLibcTest
: public PPAPINaClTest
{
155 std::string
BuildQuery(const std::string
& base
,
156 const std::string
& test_case
) override
;
159 class PPAPIPrivateNaClGLibcTest
: public PPAPINaClGLibcTest
{
161 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
164 // NaCl plugin test runner for the PNaCl + Newlib runtime.
165 class PPAPINaClPNaClTest
: public PPAPINaClTest
{
167 std::string
BuildQuery(const std::string
& base
,
168 const std::string
& test_case
) override
;
171 class PPAPIPrivateNaClPNaClTest
: public PPAPINaClPNaClTest
{
173 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
176 // Test Non-SFI Mode, using PNaCl toolchain to produce nexes.
177 class PPAPINaClPNaClNonSfiTest
: public PPAPINaClTest
{
179 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
181 std::string
BuildQuery(const std::string
& base
,
182 const std::string
& test_case
) override
;
185 class PPAPIPrivateNaClPNaClNonSfiTest
: public PPAPINaClPNaClNonSfiTest
{
187 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
191 class PPAPINaClTestDisallowedSockets
: public PPAPITestBase
{
193 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
195 std::string
BuildQuery(const std::string
& base
,
196 const std::string
& test_case
) override
;
199 class PPAPIBrokerInfoBarTest
: public OutOfProcessPPAPITest
{
201 // PPAPITestBase override:
202 void SetUpOnMainThread() override
;
205 #endif // CHROME_TEST_PPAPI_PPAPI_TEST_H_