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_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/javascript_test_observer.h"
15 #include "net/test/spawned_test_server/spawned_test_server.h"
21 class PPAPITestMessageHandler : public TestMessageHandler {
23 PPAPITestMessageHandler();
25 MessageResponse HandleMessage(const std::string& json);
27 virtual void Reset() OVERRIDE;
29 const std::string& message() const {
36 DISALLOW_COPY_AND_ASSIGN(PPAPITestMessageHandler);
39 class PPAPITestBase : public InProcessBrowserTest {
43 // InProcessBrowserTest:
44 virtual void SetUpCommandLine(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 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 void RunTestAndReload(const std::string& test_case);
56 void RunTestViaHTTP(const std::string& test_case);
57 void RunTestWithSSLServer(const std::string& test_case);
58 void RunTestWithWebSocketServer(const std::string& test_case);
59 void RunTestIfAudioOutputAvailable(const std::string& test_case);
60 void RunTestViaHTTPIfAudioOutputAvailable(const std::string& test_case);
61 std::string StripPrefixes(const std::string& test_name);
64 class InfoBarObserver : public content::NotificationObserver {
69 virtual void Observe(int type,
70 const content::NotificationSource& source,
71 const content::NotificationDetails& details) OVERRIDE;
73 void ExpectInfoBarAndAccept(bool should_accept);
76 content::NotificationRegistrar registrar_;
77 std::list<bool> expected_infobars_;
80 // Runs the test for a tab given the tab that's already navigated to the
82 void RunTestURL(const GURL& test_url);
83 // Gets the URL of the the given |test_case| for the given HTTP test server.
84 // If |extra_params| is non-empty, it will be appended as URL parameters.
85 GURL GetTestURL(const net::SpawnedTestServer& http_server,
86 const std::string& test_case,
87 const std::string& extra_params);
89 // Return the document root for the HTTP server on which tests will be run.
90 // The result is placed in |document_root|. False is returned upon failure.
91 bool GetHTTPDocumentRoot(base::FilePath* document_root);
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 // Variant of PPAPITest that runs plugins out-of-process to test proxy
110 class OutOfProcessPPAPITest : public PPAPITest {
112 OutOfProcessPPAPITest();
114 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
117 // NaCl plugin test runner for Newlib runtime.
118 class PPAPINaClTest : public PPAPITestBase {
120 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
123 // NaCl plugin test runner for Newlib runtime.
124 class PPAPINaClNewlibTest : public PPAPINaClTest {
126 virtual std::string BuildQuery(const std::string& base,
127 const std::string& test_case) OVERRIDE;
130 // NaCl plugin test runner for GNU-libc runtime.
131 class PPAPINaClGLibcTest : public PPAPINaClTest {
133 virtual std::string BuildQuery(const std::string& base,
134 const std::string& test_case) OVERRIDE;
137 // NaCl plugin test runner for the PNaCl + Newlib runtime.
138 class PPAPINaClPNaClTest : public PPAPINaClTest {
140 virtual std::string BuildQuery(const std::string& base,
141 const std::string& test_case) OVERRIDE;
144 class PPAPINaClTestDisallowedSockets : public PPAPITestBase {
146 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
148 virtual std::string BuildQuery(const std::string& base,
149 const std::string& test_case) OVERRIDE;
152 class PPAPIBrokerInfoBarTest : public OutOfProcessPPAPITest {
154 // PPAPITestBase override:
155 virtual void SetUpOnMainThread() OVERRIDE;
158 #endif // CHROME_TEST_PPAPI_PPAPI_TEST_H_