Chromium Code Reviews| 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/browser/ui/webui/web_ui_browsertest.h" | 5 #include "chrome/test/base/web_ui_browsertest.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 17 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_navigator.h" | 21 #include "chrome/browser/ui/browser_navigator.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" | |
| 24 #include "chrome/browser/ui/webui/web_ui_test_handler.h" | 23 #include "chrome/browser/ui/webui/web_ui_test_handler.h" |
| 25 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | |
| 27 #include "chrome/test/base/test_tab_strip_model_observer.h" | 27 #include "chrome/test/base/test_tab_strip_model_observer.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/url_data_source.h" | 30 #include "content/public/browser/url_data_source.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/browser/web_ui_controller.h" | 32 #include "content/public/browser/web_ui_controller.h" |
| 33 #include "content/public/browser/web_ui_message_handler.h" | 33 #include "content/public/browser/web_ui_message_handler.h" |
| 34 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest-spi.h" | 36 #include "testing/gtest/include/gtest/gtest-spi.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 private: | 313 private: |
| 314 DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider); | 314 DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider); |
| 315 }; | 315 }; |
| 316 | 316 |
| 317 base::LazyInstance<MockWebUIProvider> mock_provider_ = | 317 base::LazyInstance<MockWebUIProvider> mock_provider_ = |
| 318 LAZY_INSTANCE_INITIALIZER; | 318 LAZY_INSTANCE_INITIALIZER; |
| 319 | 319 |
| 320 } // namespace | 320 } // namespace |
| 321 | 321 |
| 322 void WebUIBrowserTest::SetUpOnMainThread() { | 322 void WebUIBrowserTest::SetUpOnMainThread() { |
| 323 InProcessBrowserTest::SetUpOnMainThread(); | 323 logging::SetLogMessageHandler(&LogHandler); |
| 324 | 324 |
| 325 logging::SetLogMessageHandler(&LogHandler); | 325 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
| 326 } | 326 ChromeWebUIControllerFactory::GetInstance()); |
|
scr
2013/01/29 01:01:54
See comment below - would it be easier to use if t
scr
2013/01/29 01:30:10
Per IM, the goal is to get to multiple non-overlap
| |
| 327 | 327 |
| 328 void WebUIBrowserTest::CleanUpOnMainThread() { | 328 test_factory_.reset(new TestChromeWebUIControllerFactory); |
| 329 InProcessBrowserTest::CleanUpOnMainThread(); | |
| 330 | 329 |
| 331 logging::SetLogMessageHandler(NULL); | 330 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); |
| 332 } | |
| 333 | 331 |
| 334 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { | 332 test_factory_->AddFactoryOverride( |
| 335 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 336 TestChromeWebUIControllerFactory::AddFactoryOverride( | |
| 337 GURL(kDummyURL).host(), mock_provider_.Pointer()); | 333 GURL(kDummyURL).host(), mock_provider_.Pointer()); |
| 338 | 334 |
| 339 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); | 335 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); |
| 340 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); | 336 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); |
| 341 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, | 337 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, |
| 342 &gen_test_data_directory_)); | 338 &gen_test_data_directory_)); |
| 343 | 339 |
| 344 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. | 340 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. |
| 345 FilePath resources_pack_path; | 341 FilePath resources_pack_path; |
| 346 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 342 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 347 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 343 ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| 348 resources_pack_path, ui::SCALE_FACTOR_NONE); | 344 resources_pack_path, ui::SCALE_FACTOR_NONE); |
| 349 | 345 |
| 350 AddLibraryFromSourceRoot(this, FilePath(kA11yAuditLibraryJSPath)); | 346 AddLibraryFromSourceRoot(this, FilePath(kA11yAuditLibraryJSPath)); |
| 351 AddLibraryFromSourceRoot(this, FilePath(kMockJSPath)); | 347 AddLibraryFromSourceRoot(this, FilePath(kMockJSPath)); |
| 352 AddLibrary(FilePath(kWebUILibraryJS)); | 348 AddLibrary(FilePath(kWebUILibraryJS)); |
| 353 } | 349 } |
| 354 | 350 |
| 355 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { | 351 void WebUIBrowserTest::CleanUpOnMainThread() { |
| 356 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 352 logging::SetLogMessageHandler(NULL); |
| 357 TestChromeWebUIControllerFactory::RemoveFactoryOverride( | 353 |
| 358 GURL(kDummyURL).host()); | 354 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); |
| 355 content::WebUIControllerFactory::UnregisterFactoryForTesting( | |
| 356 test_factory_.get()); | |
|
scr
2013/01/29 01:01:54
Should the old one be put back? If so, would some
scr
2013/01/29 01:30:10
Neg - read above.
| |
| 357 | |
| 358 test_factory_.reset(); | |
| 359 } | 359 } |
| 360 | 360 |
| 361 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { | 361 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { |
| 362 override_selected_web_ui_ = web_ui; | 362 override_selected_web_ui_ = web_ui; |
| 363 } | 363 } |
| 364 | 364 |
| 365 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { | 365 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { |
| 366 return NULL; | 366 return NULL; |
| 367 } | 367 } |
| 368 | 368 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 // testDone directly and expect pass result. | 711 // testDone directly and expect pass result. |
| 712 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 712 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 713 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 713 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 714 } | 714 } |
| 715 | 715 |
| 716 // Test that calling testDone during RunJavascriptTest still completes when | 716 // Test that calling testDone during RunJavascriptTest still completes when |
| 717 // waiting for async result. | 717 // waiting for async result. |
| 718 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 718 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 719 ASSERT_TRUE(RunJavascriptTest("testDone")); | 719 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 720 } | 720 } |
| OLD | NEW |