OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/nacl/nacl_browsertest_util.h" | 5 #include "chrome/test/nacl/nacl_browsertest_util.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 static void AddPnaclParm(const base::FilePath::StringType& url, | 181 static void AddPnaclParm(const base::FilePath::StringType& url, |
182 base::FilePath::StringType* url_with_parm) { | 182 base::FilePath::StringType* url_with_parm) { |
183 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { | 183 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { |
184 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl=1"); | 184 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl=1"); |
185 } else { | 185 } else { |
186 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl=1"); | 186 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl=1"); |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
| 190 static void AddPnaclDisabledParm(const base::FilePath::StringType& url, |
| 191 base::FilePath::StringType* url_with_parm) { |
| 192 if (url.find(FILE_PATH_LITERAL("?")) == base::FilePath::StringType::npos) { |
| 193 *url_with_parm = url + FILE_PATH_LITERAL("?pnacl_disabled=1"); |
| 194 } else { |
| 195 *url_with_parm = url + FILE_PATH_LITERAL("&pnacl_disabled=1"); |
| 196 } |
| 197 } |
| 198 |
190 NaClBrowserTestBase::NaClBrowserTestBase() { | 199 NaClBrowserTestBase::NaClBrowserTestBase() { |
191 } | 200 } |
192 | 201 |
193 NaClBrowserTestBase::~NaClBrowserTestBase() { | 202 NaClBrowserTestBase::~NaClBrowserTestBase() { |
194 } | 203 } |
195 | 204 |
196 void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { | 205 void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { |
197 command_line->AppendSwitch(switches::kEnableNaCl); | 206 command_line->AppendSwitch(switches::kEnableNaCl); |
198 } | 207 } |
199 | 208 |
200 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { | 209 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { |
201 // Sanity check. | 210 // Sanity check. |
202 base::FilePath plugin_lib; | 211 base::FilePath plugin_lib; |
203 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); | 212 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
204 ASSERT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); | 213 ASSERT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); |
205 | 214 |
206 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; | 215 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; |
207 } | 216 } |
208 | 217 |
209 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { | 218 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { |
210 return GetNaClVariantRoot(Variant(), document_root); | 219 return GetNaClVariantRoot(Variant(), document_root); |
211 } | 220 } |
212 | 221 |
213 bool NaClBrowserTestBase::IsPnacl() { | 222 bool NaClBrowserTestBase::IsAPnaclTest() { |
214 return false; | 223 return false; |
215 } | 224 } |
216 | 225 |
| 226 bool NaClBrowserTestBase::IsPnaclDisabled() { |
| 227 return false; |
| 228 } |
| 229 |
217 GURL NaClBrowserTestBase::TestURL( | 230 GURL NaClBrowserTestBase::TestURL( |
218 const base::FilePath::StringType& url_fragment) { | 231 const base::FilePath::StringType& url_fragment) { |
219 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); | 232 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); |
220 expanded_url = expanded_url.Append(url_fragment); | 233 expanded_url = expanded_url.Append(url_fragment); |
221 return test_server_->GetURL(expanded_url.MaybeAsASCII()); | 234 return test_server_->GetURL(expanded_url.MaybeAsASCII()); |
222 } | 235 } |
223 | 236 |
224 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, | 237 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, |
225 TestMessageHandler* handler) { | 238 TestMessageHandler* handler) { |
226 JavascriptTestObserver observer( | 239 JavascriptTestObserver observer( |
227 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 240 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
228 handler); | 241 handler); |
229 ui_test_utils::NavigateToURL(browser(), url); | 242 ui_test_utils::NavigateToURL(browser(), url); |
230 return observer.Run(); | 243 return observer.Run(); |
231 } | 244 } |
232 | 245 |
233 void NaClBrowserTestBase::RunLoadTest( | 246 void NaClBrowserTestBase::RunLoadTest( |
234 const base::FilePath::StringType& test_file) { | 247 const base::FilePath::StringType& test_file) { |
235 LoadTestMessageHandler handler; | 248 LoadTestMessageHandler handler; |
236 base::FilePath::StringType test_file_with_parm = test_file; | 249 base::FilePath::StringType test_file_with_pnacl = test_file; |
237 if (IsPnacl()) { | 250 if (IsAPnaclTest()) { |
238 AddPnaclParm(test_file, &test_file_with_parm); | 251 AddPnaclParm(test_file, &test_file_with_pnacl); |
239 } | 252 } |
240 bool ok = RunJavascriptTest(TestURL(test_file_with_parm), &handler); | 253 base::FilePath::StringType test_file_with_both = test_file_with_pnacl; |
| 254 if (IsPnaclDisabled()) { |
| 255 AddPnaclDisabledParm(test_file_with_pnacl, &test_file_with_both); |
| 256 } |
| 257 bool ok = RunJavascriptTest(TestURL(test_file_with_both), &handler); |
241 ASSERT_TRUE(ok) << handler.error_message(); | 258 ASSERT_TRUE(ok) << handler.error_message(); |
242 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 259 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
243 } | 260 } |
244 | 261 |
245 void NaClBrowserTestBase::RunNaClIntegrationTest( | 262 void NaClBrowserTestBase::RunNaClIntegrationTest( |
246 const base::FilePath::StringType& url_fragment) { | 263 const base::FilePath::StringType& url_fragment) { |
247 NaClIntegrationMessageHandler handler; | 264 NaClIntegrationMessageHandler handler; |
248 base::FilePath::StringType url_fragment_with_parm = url_fragment; | 265 base::FilePath::StringType url_fragment_with_pnacl = url_fragment; |
249 if (IsPnacl()) { | 266 if (IsAPnaclTest()) { |
250 AddPnaclParm(url_fragment, &url_fragment_with_parm); | 267 AddPnaclParm(url_fragment, &url_fragment_with_pnacl); |
251 } | 268 } |
252 bool ok = RunJavascriptTest(TestURL(url_fragment_with_parm), &handler); | 269 base::FilePath::StringType url_fragment_with_both = url_fragment_with_pnacl; |
| 270 if (IsPnaclDisabled()) { |
| 271 AddPnaclDisabledParm(url_fragment_with_pnacl, &url_fragment_with_both); |
| 272 } |
| 273 bool ok = RunJavascriptTest(TestURL(url_fragment_with_both), &handler); |
253 ASSERT_TRUE(ok) << handler.error_message(); | 274 ASSERT_TRUE(ok) << handler.error_message(); |
254 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 275 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
255 } | 276 } |
256 | 277 |
257 bool NaClBrowserTestBase::StartTestServer() { | 278 bool NaClBrowserTestBase::StartTestServer() { |
258 // Launch the web server. | 279 // Launch the web server. |
259 base::FilePath document_root; | 280 base::FilePath document_root; |
260 if (!GetDocumentRoot(&document_root)) | 281 if (!GetDocumentRoot(&document_root)) |
261 return false; | 282 return false; |
262 test_server_.reset(new net::SpawnedTestServer( | 283 test_server_.reset(new net::SpawnedTestServer( |
263 net::SpawnedTestServer::TYPE_HTTP, | 284 net::SpawnedTestServer::TYPE_HTTP, |
264 net::SpawnedTestServer::kLocalhost, | 285 net::SpawnedTestServer::kLocalhost, |
265 document_root)); | 286 document_root)); |
266 return test_server_->Start(); | 287 return test_server_->Start(); |
267 } | 288 } |
268 | 289 |
269 base::FilePath::StringType NaClBrowserTestNewlib::Variant() { | 290 base::FilePath::StringType NaClBrowserTestNewlib::Variant() { |
270 return FILE_PATH_LITERAL("newlib"); | 291 return FILE_PATH_LITERAL("newlib"); |
271 } | 292 } |
272 | 293 |
273 base::FilePath::StringType NaClBrowserTestGLibc::Variant() { | 294 base::FilePath::StringType NaClBrowserTestGLibc::Variant() { |
274 return FILE_PATH_LITERAL("glibc"); | 295 return FILE_PATH_LITERAL("glibc"); |
275 } | 296 } |
276 | 297 |
277 base::FilePath::StringType NaClBrowserTestPnacl::Variant() { | 298 base::FilePath::StringType NaClBrowserTestPnacl::Variant() { |
278 return FILE_PATH_LITERAL("pnacl"); | 299 return FILE_PATH_LITERAL("pnacl"); |
279 } | 300 } |
280 | 301 |
281 bool NaClBrowserTestPnacl::IsPnacl() { | 302 bool NaClBrowserTestPnacl::IsAPnaclTest() { |
282 return true; | 303 return true; |
283 } | 304 } |
284 | 305 |
285 void NaClBrowserTestPnacl::SetUpCommandLine(CommandLine* command_line) { | 306 base::FilePath::StringType NaClBrowserTestPnaclDisabled::Variant() { |
| 307 return FILE_PATH_LITERAL("pnacl"); |
| 308 } |
| 309 |
| 310 bool NaClBrowserTestPnaclDisabled::IsAPnaclTest() { |
| 311 return true; |
| 312 } |
| 313 |
| 314 bool NaClBrowserTestPnaclDisabled::IsPnaclDisabled() { |
| 315 return true; |
| 316 } |
| 317 void NaClBrowserTestPnaclDisabled::SetUpCommandLine(CommandLine* command_line) { |
286 NaClBrowserTestBase::SetUpCommandLine(command_line); | 318 NaClBrowserTestBase::SetUpCommandLine(command_line); |
287 command_line->AppendSwitch(switches::kEnablePnacl); | 319 command_line->AppendSwitch(switches::kDisablePnacl); |
288 } | 320 } |
289 | 321 |
290 NaClBrowserTestPnaclWithOldCache::NaClBrowserTestPnaclWithOldCache() { | 322 NaClBrowserTestPnaclWithOldCache::NaClBrowserTestPnaclWithOldCache() { |
291 scoped_ptr<base::Environment> env(base::Environment::Create()); | 323 scoped_ptr<base::Environment> env(base::Environment::Create()); |
292 env->SetVar("PNACL_USE_OLD_CACHE", "true"); | 324 env->SetVar("PNACL_USE_OLD_CACHE", "true"); |
293 } | 325 } |
294 | 326 |
295 base::FilePath::StringType NaClBrowserTestStatic::Variant() { | 327 base::FilePath::StringType NaClBrowserTestStatic::Variant() { |
296 return FILE_PATH_LITERAL("static"); | 328 return FILE_PATH_LITERAL("static"); |
297 } | 329 } |
298 | 330 |
299 bool NaClBrowserTestStatic::GetDocumentRoot(base::FilePath* document_root) { | 331 bool NaClBrowserTestStatic::GetDocumentRoot(base::FilePath* document_root) { |
300 *document_root = base::FilePath(FILE_PATH_LITERAL("chrome/test/data/nacl")); | 332 *document_root = base::FilePath(FILE_PATH_LITERAL("chrome/test/data/nacl")); |
301 return true; | 333 return true; |
302 } | 334 } |
OLD | NEW |