| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/web_ui_browser_test.h" | 5 #include "chrome/test/base/web_ui_browser_test.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 using content::WebContents; | 46 using content::WebContents; |
| 47 using content::WebUIController; | 47 using content::WebUIController; |
| 48 using content::WebUIMessageHandler; | 48 using content::WebUIMessageHandler; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 base::LazyInstance<std::vector<std::string> > error_messages_ = | 52 base::LazyInstance<std::vector<std::string> > error_messages_ = |
| 53 LAZY_INSTANCE_INITIALIZER; | 53 LAZY_INSTANCE_INITIALIZER; |
| 54 | 54 |
| 55 // Intercepts all log messages. | 55 // Intercepts all log messages. |
| 56 bool LogHandler(int severity, | 56 void LogListener(int severity, |
| 57 const char* file, | 57 const char* file, |
| 58 int line, | 58 int line, |
| 59 size_t message_start, | 59 size_t message_start, |
| 60 const std::string& str) { | 60 const std::string& str) { |
| 61 if (severity == logging::LOG_ERROR && file && | 61 if (severity == logging::LOG_ERROR && file && |
| 62 std::string("CONSOLE") == file) { | 62 std::string("CONSOLE") == file) { |
| 63 error_messages_.Get().push_back(str); | 63 error_messages_.Get().push_back(str); |
| 64 } | 64 } |
| 65 | |
| 66 return false; | |
| 67 } | 65 } |
| 68 | 66 |
| 69 class WebUIJsInjectionReadyObserver : public content::WebContentsObserver { | 67 class WebUIJsInjectionReadyObserver : public content::WebContentsObserver { |
| 70 public: | 68 public: |
| 71 WebUIJsInjectionReadyObserver(content::WebContents* web_contents, | 69 WebUIJsInjectionReadyObserver(content::WebContents* web_contents, |
| 72 WebUIBrowserTest* browser_test, | 70 WebUIBrowserTest* browser_test, |
| 73 const std::string& preload_test_fixture, | 71 const std::string& preload_test_fixture, |
| 74 const std::string& preload_test_name) | 72 const std::string& preload_test_name) |
| 75 : content::WebContentsObserver(web_contents), | 73 : content::WebContentsObserver(web_contents), |
| 76 browser_test_(browser_test), | 74 browser_test_(browser_test), |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 #else | 290 #else |
| 293 NOTREACHED(); | 291 NOTREACHED(); |
| 294 #endif | 292 #endif |
| 295 } | 293 } |
| 296 | 294 |
| 297 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; | 295 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; |
| 298 | 296 |
| 299 WebUIBrowserTest::WebUIBrowserTest() | 297 WebUIBrowserTest::WebUIBrowserTest() |
| 300 : test_handler_(new WebUITestHandler()), | 298 : test_handler_(new WebUITestHandler()), |
| 301 libraries_preloaded_(false), | 299 libraries_preloaded_(false), |
| 302 override_selected_web_ui_(NULL) { | 300 override_selected_web_ui_(NULL), |
| 301 log_listener_(LogListener) { |
| 303 } | 302 } |
| 304 | 303 |
| 305 void WebUIBrowserTest::set_preload_test_fixture( | 304 void WebUIBrowserTest::set_preload_test_fixture( |
| 306 const std::string& preload_test_fixture) { | 305 const std::string& preload_test_fixture) { |
| 307 preload_test_fixture_ = preload_test_fixture; | 306 preload_test_fixture_ = preload_test_fixture; |
| 308 } | 307 } |
| 309 | 308 |
| 310 void WebUIBrowserTest::set_preload_test_name( | 309 void WebUIBrowserTest::set_preload_test_name( |
| 311 const std::string& preload_test_name) { | 310 const std::string& preload_test_name) { |
| 312 preload_test_name_ = preload_test_name; | 311 preload_test_name_ = preload_test_name; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 }; | 364 }; |
| 366 | 365 |
| 367 base::LazyInstance<MockWebUIProvider> mock_provider_ = | 366 base::LazyInstance<MockWebUIProvider> mock_provider_ = |
| 368 LAZY_INSTANCE_INITIALIZER; | 367 LAZY_INSTANCE_INITIALIZER; |
| 369 | 368 |
| 370 } // namespace | 369 } // namespace |
| 371 | 370 |
| 372 void WebUIBrowserTest::SetUpOnMainThread() { | 371 void WebUIBrowserTest::SetUpOnMainThread() { |
| 373 JavaScriptBrowserTest::SetUpOnMainThread(); | 372 JavaScriptBrowserTest::SetUpOnMainThread(); |
| 374 | 373 |
| 375 logging::SetLogMessageHandler(&LogHandler); | |
| 376 | |
| 377 AddLibrary(base::FilePath(kA11yAuditLibraryJSPath)); | 374 AddLibrary(base::FilePath(kA11yAuditLibraryJSPath)); |
| 378 | 375 |
| 379 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 376 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
| 380 ChromeWebUIControllerFactory::GetInstance()); | 377 ChromeWebUIControllerFactory::GetInstance()); |
| 381 | 378 |
| 382 test_factory_.reset(new TestChromeWebUIControllerFactory); | 379 test_factory_.reset(new TestChromeWebUIControllerFactory); |
| 383 | 380 |
| 384 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); | 381 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); |
| 385 | 382 |
| 386 test_factory_->AddFactoryOverride(GURL(kDummyURL).host(), | 383 test_factory_->AddFactoryOverride(GURL(kDummyURL).host(), |
| 387 mock_provider_.Pointer()); | 384 mock_provider_.Pointer()); |
| 388 test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost, | 385 test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost, |
| 389 mock_provider_.Pointer()); | 386 mock_provider_.Pointer()); |
| 390 } | 387 } |
| 391 | 388 |
| 392 void WebUIBrowserTest::TearDownOnMainThread() { | 389 void WebUIBrowserTest::TearDownOnMainThread() { |
| 393 logging::SetLogMessageHandler(NULL); | |
| 394 | |
| 395 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); | 390 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); |
| 396 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 391 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
| 397 test_factory_.get()); | 392 test_factory_.get()); |
| 398 | 393 |
| 399 // This is needed to avoid a debug assert after the test completes, see stack | 394 // This is needed to avoid a debug assert after the test completes, see stack |
| 400 // trace in http://crrev.com/179347 | 395 // trace in http://crrev.com/179347 |
| 401 content::WebUIControllerFactory::RegisterFactory( | 396 content::WebUIControllerFactory::RegisterFactory( |
| 402 ChromeWebUIControllerFactory::GetInstance()); | 397 ChromeWebUIControllerFactory::GetInstance()); |
| 403 | 398 |
| 404 test_factory_.reset(); | 399 test_factory_.reset(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 478 } |
| 484 | 479 |
| 485 GURL WebUIBrowserTest::WebUITestDataPathToURL( | 480 GURL WebUIBrowserTest::WebUITestDataPathToURL( |
| 486 const base::FilePath::StringType& path) { | 481 const base::FilePath::StringType& path) { |
| 487 base::FilePath dir_test_data; | 482 base::FilePath dir_test_data; |
| 488 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); | 483 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); |
| 489 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); | 484 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); |
| 490 EXPECT_TRUE(base::PathExists(test_path)); | 485 EXPECT_TRUE(base::PathExists(test_path)); |
| 491 return net::FilePathToFileURL(test_path); | 486 return net::FilePathToFileURL(test_path); |
| 492 } | 487 } |
| OLD | NEW |