| 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 | |
| 199 NaClBrowserTestBase::NaClBrowserTestBase() { | 190 NaClBrowserTestBase::NaClBrowserTestBase() { |
| 200 } | 191 } |
| 201 | 192 |
| 202 NaClBrowserTestBase::~NaClBrowserTestBase() { | 193 NaClBrowserTestBase::~NaClBrowserTestBase() { |
| 203 } | 194 } |
| 204 | 195 |
| 205 void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { | 196 void NaClBrowserTestBase::SetUpCommandLine(CommandLine* command_line) { |
| 206 command_line->AppendSwitch(switches::kEnableNaCl); | 197 command_line->AppendSwitch(switches::kEnableNaCl); |
| 207 } | 198 } |
| 208 | 199 |
| 209 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { | 200 void NaClBrowserTestBase::SetUpInProcessBrowserTestFixture() { |
| 210 // Sanity check. | 201 // Sanity check. |
| 211 base::FilePath plugin_lib; | 202 base::FilePath plugin_lib; |
| 212 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); | 203 ASSERT_TRUE(PathService::Get(chrome::FILE_NACL_PLUGIN, &plugin_lib)); |
| 213 ASSERT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); | 204 ASSERT_TRUE(base::PathExists(plugin_lib)) << plugin_lib.value(); |
| 214 | 205 |
| 215 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; | 206 ASSERT_TRUE(StartTestServer()) << "Cannot start test server."; |
| 216 } | 207 } |
| 217 | 208 |
| 218 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { | 209 bool NaClBrowserTestBase::GetDocumentRoot(base::FilePath* document_root) { |
| 219 return GetNaClVariantRoot(Variant(), document_root); | 210 return GetNaClVariantRoot(Variant(), document_root); |
| 220 } | 211 } |
| 221 | 212 |
| 222 bool NaClBrowserTestBase::IsAPnaclTest() { | 213 bool NaClBrowserTestBase::IsPnacl() { |
| 223 return false; | 214 return false; |
| 224 } | 215 } |
| 225 | 216 |
| 226 bool NaClBrowserTestBase::IsPnaclDisabled() { | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 230 GURL NaClBrowserTestBase::TestURL( | 217 GURL NaClBrowserTestBase::TestURL( |
| 231 const base::FilePath::StringType& url_fragment) { | 218 const base::FilePath::StringType& url_fragment) { |
| 232 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); | 219 base::FilePath expanded_url = base::FilePath(FILE_PATH_LITERAL("files")); |
| 233 expanded_url = expanded_url.Append(url_fragment); | 220 expanded_url = expanded_url.Append(url_fragment); |
| 234 return test_server_->GetURL(expanded_url.MaybeAsASCII()); | 221 return test_server_->GetURL(expanded_url.MaybeAsASCII()); |
| 235 } | 222 } |
| 236 | 223 |
| 237 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, | 224 bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, |
| 238 TestMessageHandler* handler) { | 225 TestMessageHandler* handler) { |
| 239 JavascriptTestObserver observer( | 226 JavascriptTestObserver observer( |
| 240 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 227 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| 241 handler); | 228 handler); |
| 242 ui_test_utils::NavigateToURL(browser(), url); | 229 ui_test_utils::NavigateToURL(browser(), url); |
| 243 return observer.Run(); | 230 return observer.Run(); |
| 244 } | 231 } |
| 245 | 232 |
| 246 void NaClBrowserTestBase::RunLoadTest( | 233 void NaClBrowserTestBase::RunLoadTest( |
| 247 const base::FilePath::StringType& test_file) { | 234 const base::FilePath::StringType& test_file) { |
| 248 LoadTestMessageHandler handler; | 235 LoadTestMessageHandler handler; |
| 249 base::FilePath::StringType test_file_with_pnacl = test_file; | 236 base::FilePath::StringType test_file_with_parm = test_file; |
| 250 if (IsAPnaclTest()) { | 237 if (IsPnacl()) { |
| 251 AddPnaclParm(test_file, &test_file_with_pnacl); | 238 AddPnaclParm(test_file, &test_file_with_parm); |
| 252 } | 239 } |
| 253 base::FilePath::StringType test_file_with_both = test_file_with_pnacl; | 240 bool ok = RunJavascriptTest(TestURL(test_file_with_parm), &handler); |
| 254 if (IsPnaclDisabled()) { | |
| 255 AddPnaclDisabledParm(test_file_with_pnacl, &test_file_with_both); | |
| 256 } | |
| 257 bool ok = RunJavascriptTest(TestURL(test_file_with_both), &handler); | |
| 258 ASSERT_TRUE(ok) << handler.error_message(); | 241 ASSERT_TRUE(ok) << handler.error_message(); |
| 259 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 242 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
| 260 } | 243 } |
| 261 | 244 |
| 262 void NaClBrowserTestBase::RunNaClIntegrationTest( | 245 void NaClBrowserTestBase::RunNaClIntegrationTest( |
| 263 const base::FilePath::StringType& url_fragment) { | 246 const base::FilePath::StringType& url_fragment) { |
| 264 NaClIntegrationMessageHandler handler; | 247 NaClIntegrationMessageHandler handler; |
| 265 base::FilePath::StringType url_fragment_with_pnacl = url_fragment; | 248 base::FilePath::StringType url_fragment_with_parm = url_fragment; |
| 266 if (IsAPnaclTest()) { | 249 if (IsPnacl()) { |
| 267 AddPnaclParm(url_fragment, &url_fragment_with_pnacl); | 250 AddPnaclParm(url_fragment, &url_fragment_with_parm); |
| 268 } | 251 } |
| 269 base::FilePath::StringType url_fragment_with_both = url_fragment_with_pnacl; | 252 bool ok = RunJavascriptTest(TestURL(url_fragment_with_parm), &handler); |
| 270 if (IsPnaclDisabled()) { | |
| 271 AddPnaclDisabledParm(url_fragment_with_pnacl, &url_fragment_with_both); | |
| 272 } | |
| 273 bool ok = RunJavascriptTest(TestURL(url_fragment_with_both), &handler); | |
| 274 ASSERT_TRUE(ok) << handler.error_message(); | 253 ASSERT_TRUE(ok) << handler.error_message(); |
| 275 ASSERT_TRUE(handler.test_passed()) << "Test failed."; | 254 ASSERT_TRUE(handler.test_passed()) << "Test failed."; |
| 276 } | 255 } |
| 277 | 256 |
| 278 bool NaClBrowserTestBase::StartTestServer() { | 257 bool NaClBrowserTestBase::StartTestServer() { |
| 279 // Launch the web server. | 258 // Launch the web server. |
| 280 base::FilePath document_root; | 259 base::FilePath document_root; |
| 281 if (!GetDocumentRoot(&document_root)) | 260 if (!GetDocumentRoot(&document_root)) |
| 282 return false; | 261 return false; |
| 283 test_server_.reset(new net::SpawnedTestServer( | 262 test_server_.reset(new net::SpawnedTestServer( |
| 284 net::SpawnedTestServer::TYPE_HTTP, | 263 net::SpawnedTestServer::TYPE_HTTP, |
| 285 net::SpawnedTestServer::kLocalhost, | 264 net::SpawnedTestServer::kLocalhost, |
| 286 document_root)); | 265 document_root)); |
| 287 return test_server_->Start(); | 266 return test_server_->Start(); |
| 288 } | 267 } |
| 289 | 268 |
| 290 base::FilePath::StringType NaClBrowserTestNewlib::Variant() { | 269 base::FilePath::StringType NaClBrowserTestNewlib::Variant() { |
| 291 return FILE_PATH_LITERAL("newlib"); | 270 return FILE_PATH_LITERAL("newlib"); |
| 292 } | 271 } |
| 293 | 272 |
| 294 base::FilePath::StringType NaClBrowserTestGLibc::Variant() { | 273 base::FilePath::StringType NaClBrowserTestGLibc::Variant() { |
| 295 return FILE_PATH_LITERAL("glibc"); | 274 return FILE_PATH_LITERAL("glibc"); |
| 296 } | 275 } |
| 297 | 276 |
| 298 base::FilePath::StringType NaClBrowserTestPnacl::Variant() { | 277 base::FilePath::StringType NaClBrowserTestPnacl::Variant() { |
| 299 return FILE_PATH_LITERAL("pnacl"); | 278 return FILE_PATH_LITERAL("pnacl"); |
| 300 } | 279 } |
| 301 | 280 |
| 302 bool NaClBrowserTestPnacl::IsAPnaclTest() { | 281 bool NaClBrowserTestPnacl::IsPnacl() { |
| 303 return true; | 282 return true; |
| 304 } | 283 } |
| 305 | 284 |
| 306 base::FilePath::StringType NaClBrowserTestPnaclDisabled::Variant() { | 285 void NaClBrowserTestPnacl::SetUpCommandLine(CommandLine* command_line) { |
| 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 | |
| 318 void NaClBrowserTestPnaclDisabled::SetUpCommandLine(CommandLine* command_line) { | |
| 319 NaClBrowserTestBase::SetUpCommandLine(command_line); | 286 NaClBrowserTestBase::SetUpCommandLine(command_line); |
| 320 command_line->AppendSwitch(switches::kDisablePnacl); | 287 command_line->AppendSwitch(switches::kEnablePnacl); |
| 321 } | 288 } |
| 322 | 289 |
| 323 NaClBrowserTestPnaclWithOldCache::NaClBrowserTestPnaclWithOldCache() { | 290 NaClBrowserTestPnaclWithOldCache::NaClBrowserTestPnaclWithOldCache() { |
| 324 scoped_ptr<base::Environment> env(base::Environment::Create()); | 291 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 325 env->SetVar("PNACL_USE_OLD_CACHE", "true"); | 292 env->SetVar("PNACL_USE_OLD_CACHE", "true"); |
| 326 } | 293 } |
| 327 | 294 |
| 328 base::FilePath::StringType NaClBrowserTestStatic::Variant() { | 295 base::FilePath::StringType NaClBrowserTestStatic::Variant() { |
| 329 return FILE_PATH_LITERAL("static"); | 296 return FILE_PATH_LITERAL("static"); |
| 330 } | 297 } |
| 331 | 298 |
| 332 bool NaClBrowserTestStatic::GetDocumentRoot(base::FilePath* document_root) { | 299 bool NaClBrowserTestStatic::GetDocumentRoot(base::FilePath* document_root) { |
| 333 *document_root = base::FilePath(FILE_PATH_LITERAL("chrome/test/data/nacl")); | 300 *document_root = base::FilePath(FILE_PATH_LITERAL("chrome/test/data/nacl")); |
| 334 return true; | 301 return true; |
| 335 } | 302 } |
| OLD | NEW |