Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / ppapi / ppapi_test.h
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.
4
5 #ifndef CHROME_TEST_PPAPI_PPAPI_TEST_H_
6 #define CHROME_TEST_PPAPI_PPAPI_TEST_H_
7
8 #include <string>
9
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"
15
16 namespace content {
17 class RenderViewHost;
18 }
19
20 class PPAPITestMessageHandler : public TestMessageHandler {
21  public:
22   PPAPITestMessageHandler();
23
24   MessageResponse HandleMessage(const std::string& json);
25
26   virtual void Reset() OVERRIDE;
27
28   const std::string& message() const {
29     return message_;
30   }
31
32  private:
33   std::string message_;
34
35   DISALLOW_COPY_AND_ASSIGN(PPAPITestMessageHandler);
36 };
37
38 class PPAPITestBase : public InProcessBrowserTest {
39  public:
40   PPAPITestBase();
41
42   // InProcessBrowserTest:
43   virtual void SetUp() OVERRIDE;
44   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
45   virtual void SetUpOnMainThread() OVERRIDE;
46
47   virtual std::string BuildQuery(const std::string& base,
48                                  const std::string& test_case) = 0;
49
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);
63
64  protected:
65   class InfoBarObserver : public content::NotificationObserver {
66    public:
67     explicit InfoBarObserver(PPAPITestBase* test_base);
68     ~InfoBarObserver();
69
70     void ExpectInfoBarAndAccept(bool should_accept);
71
72    private:
73     // content::NotificationObserver:
74     virtual void Observe(int type,
75                          const content::NotificationSource& source,
76                          const content::NotificationDetails& details) OVERRIDE;
77
78     void VerifyInfoBarState();
79
80     content::NotificationRegistrar registrar_;
81     PPAPITestBase* test_base_;
82     bool expecting_infobar_;
83     bool should_accept_;
84   };
85
86   // Runs the test for a tab given the tab that's already navigated to the
87   // given URL.
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);
94 };
95
96 // In-process plugin test runner.  See OutOfProcessPPAPITest below for the
97 // out-of-process version.
98 class PPAPITest : public PPAPITestBase {
99  public:
100   PPAPITest();
101
102   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
103
104   virtual std::string BuildQuery(const std::string& base,
105                                  const std::string& test_case) OVERRIDE;
106  protected:
107   bool in_process_;  // Controls the --ppapi-in-process switch.
108 };
109
110 class PPAPIPrivateTest : public PPAPITest {
111  protected:
112   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
113 };
114
115 // Variant of PPAPITest that runs plugins out-of-process to test proxy
116 // codepaths.
117 class OutOfProcessPPAPITest : public PPAPITest {
118  public:
119   OutOfProcessPPAPITest();
120
121   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
122 };
123
124 class OutOfProcessPPAPIPrivateTest : public OutOfProcessPPAPITest {
125  protected:
126   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
127 };
128
129 // NaCl plugin test runner for Newlib runtime.
130 class PPAPINaClTest : public PPAPITestBase {
131  public:
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;
145 };
146
147 // NaCl plugin test runner for Newlib runtime.
148 class PPAPINaClNewlibTest : public PPAPINaClTest {
149  public:
150   virtual std::string BuildQuery(const std::string& base,
151                                  const std::string& test_case) OVERRIDE;
152 };
153
154 class PPAPIPrivateNaClNewlibTest : public PPAPINaClNewlibTest {
155  protected:
156   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
157 };
158
159 // NaCl plugin test runner for GNU-libc runtime.
160 class PPAPINaClGLibcTest : public PPAPINaClTest {
161  public:
162   virtual std::string BuildQuery(const std::string& base,
163                                  const std::string& test_case) OVERRIDE;
164 };
165
166 class PPAPIPrivateNaClGLibcTest : public PPAPINaClGLibcTest {
167  protected:
168   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
169 };
170
171 // NaCl plugin test runner for the PNaCl + Newlib runtime.
172 class PPAPINaClPNaClTest : public PPAPINaClTest {
173  public:
174   virtual std::string BuildQuery(const std::string& base,
175                                  const std::string& test_case) OVERRIDE;
176 };
177
178 class PPAPIPrivateNaClPNaClTest : public PPAPINaClPNaClTest {
179  protected:
180   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
181 };
182
183 // Test Non-SFI Mode, using PNaCl toolchain to produce nexes.
184 class PPAPINaClPNaClNonSfiTest : public PPAPINaClTest {
185  public:
186   virtual void SetUpCommandLine(base::CommandLine* command_line);
187
188   virtual std::string BuildQuery(const std::string& base,
189                                  const std::string& test_case) OVERRIDE;
190 };
191
192 class PPAPIPrivateNaClPNaClNonSfiTest : public PPAPINaClPNaClNonSfiTest {
193  protected:
194   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
195 };
196
197 class PPAPINaClTestDisallowedSockets : public PPAPITestBase {
198  public:
199   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
200
201   virtual std::string BuildQuery(const std::string& base,
202                                  const std::string& test_case) OVERRIDE;
203 };
204
205 class PPAPIBrokerInfoBarTest : public OutOfProcessPPAPITest {
206  public:
207   // PPAPITestBase override:
208   virtual void SetUpOnMainThread() OVERRIDE;
209 };
210
211 #endif  // CHROME_TEST_PPAPI_PPAPI_TEST_H_