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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 using content::WebUIController; | 48 using content::WebUIController; |
49 using content::WebUIMessageHandler; | 49 using content::WebUIMessageHandler; |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 base::LazyInstance<std::vector<std::string> > error_messages_ = | 53 base::LazyInstance<std::vector<std::string> > error_messages_ = |
54 LAZY_INSTANCE_INITIALIZER; | 54 LAZY_INSTANCE_INITIALIZER; |
55 | 55 |
56 // Intercepts all log messages. | 56 // Intercepts all log messages. |
57 bool LogHandler(int severity, | 57 bool LogHandler(int severity, |
58 const char* file, | 58 const std::string& file, |
59 int line, | 59 int line, |
60 size_t message_start, | |
61 const std::string& str) { | 60 const std::string& str) { |
62 if (severity == logging::LOG_ERROR && file && | 61 if (severity == logging::LOG_ERROR && std::string("CONSOLE") == file) { |
63 std::string("CONSOLE") == file) { | |
64 error_messages_.Get().push_back(str); | 62 error_messages_.Get().push_back(str); |
65 } | 63 } |
66 | 64 |
67 return false; | 65 return false; |
68 } | 66 } |
69 | 67 |
70 class WebUIJsInjectionReadyObserver : public content::WebContentsObserver { | 68 class WebUIJsInjectionReadyObserver : public content::WebContentsObserver { |
71 public: | 69 public: |
72 WebUIJsInjectionReadyObserver(content::WebContents* web_contents, | 70 WebUIJsInjectionReadyObserver(content::WebContents* web_contents, |
73 WebUIBrowserTest* browser_test, | 71 WebUIBrowserTest* browser_test, |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 }; | 374 }; |
377 | 375 |
378 base::LazyInstance<MockWebUIProvider> mock_provider_ = | 376 base::LazyInstance<MockWebUIProvider> mock_provider_ = |
379 LAZY_INSTANCE_INITIALIZER; | 377 LAZY_INSTANCE_INITIALIZER; |
380 | 378 |
381 } // namespace | 379 } // namespace |
382 | 380 |
383 void WebUIBrowserTest::SetUpOnMainThread() { | 381 void WebUIBrowserTest::SetUpOnMainThread() { |
384 JavaScriptBrowserTest::SetUpOnMainThread(); | 382 JavaScriptBrowserTest::SetUpOnMainThread(); |
385 | 383 |
386 logging::SetLogMessageHandler(&LogHandler); | 384 logging::AddLogMessageHandler(&LogHandler); |
387 | 385 |
388 AddLibrary(base::FilePath(kA11yAuditLibraryJSPath)); | 386 AddLibrary(base::FilePath(kA11yAuditLibraryJSPath)); |
389 | 387 |
390 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 388 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
391 ChromeWebUIControllerFactory::GetInstance()); | 389 ChromeWebUIControllerFactory::GetInstance()); |
392 | 390 |
393 test_factory_.reset(new TestChromeWebUIControllerFactory); | 391 test_factory_.reset(new TestChromeWebUIControllerFactory); |
394 | 392 |
395 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); | 393 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); |
396 | 394 |
397 test_factory_->AddFactoryOverride(GURL(kDummyURL).host(), | 395 test_factory_->AddFactoryOverride(GURL(kDummyURL).host(), |
398 mock_provider_.Pointer()); | 396 mock_provider_.Pointer()); |
399 test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost, | 397 test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost, |
400 mock_provider_.Pointer()); | 398 mock_provider_.Pointer()); |
401 } | 399 } |
402 | 400 |
403 void WebUIBrowserTest::TearDownOnMainThread() { | 401 void WebUIBrowserTest::TearDownOnMainThread() { |
404 logging::SetLogMessageHandler(NULL); | 402 logging::RemoveLogMessageHandler(&LogHandler); |
405 | 403 |
406 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); | 404 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); |
407 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 405 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
408 test_factory_.get()); | 406 test_factory_.get()); |
409 | 407 |
410 // This is needed to avoid a debug assert after the test completes, see stack | 408 // This is needed to avoid a debug assert after the test completes, see stack |
411 // trace in http://crrev.com/179347 | 409 // trace in http://crrev.com/179347 |
412 content::WebUIControllerFactory::RegisterFactory( | 410 content::WebUIControllerFactory::RegisterFactory( |
413 ChromeWebUIControllerFactory::GetInstance()); | 411 ChromeWebUIControllerFactory::GetInstance()); |
414 | 412 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 } | 497 } |
500 | 498 |
501 GURL WebUIBrowserTest::WebUITestDataPathToURL( | 499 GURL WebUIBrowserTest::WebUITestDataPathToURL( |
502 const base::FilePath::StringType& path) { | 500 const base::FilePath::StringType& path) { |
503 base::FilePath dir_test_data; | 501 base::FilePath dir_test_data; |
504 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); | 502 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); |
505 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); | 503 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); |
506 EXPECT_TRUE(base::PathExists(test_path)); | 504 EXPECT_TRUE(base::PathExists(test_path)); |
507 return net::FilePathToFileURL(test_path); | 505 return net::FilePathToFileURL(test_path); |
508 } | 506 } |
OLD | NEW |