| 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/browser/ui/webui/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_tab_controller.h" | 17 #include "chrome/browser/printing/print_preview_tab_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_navigator.h" | 20 #include "chrome/browser/ui/browser_navigator.h" |
| 21 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 21 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 22 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" | 22 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" |
| 23 #include "chrome/browser/ui/webui/web_ui_test_handler.h" | 23 #include "chrome/browser/ui/webui/web_ui_test_handler.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.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/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_ui_controller.h" | 31 #include "content/public/browser/web_ui_controller.h" |
| 32 #include "content/public/browser/web_ui_message_handler.h" | 32 #include "content/public/browser/web_ui_message_handler.h" |
| 33 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 args.push_back(Value::CreateStringValue(preload_test_fixture)); | 189 args.push_back(Value::CreateStringValue(preload_test_fixture)); |
| 190 args.push_back(Value::CreateStringValue(preload_test_name)); | 190 args.push_back(Value::CreateStringValue(preload_test_name)); |
| 191 RunJavascriptUsingHandler( | 191 RunJavascriptUsingHandler( |
| 192 "preloadJavascriptLibraries", args, false, false, preload_host); | 192 "preloadJavascriptLibraries", args, false, false, preload_host); |
| 193 libraries_preloaded_ = true; | 193 libraries_preloaded_ = true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void WebUIBrowserTest::BrowsePreload(const GURL& browse_to) { | 196 void WebUIBrowserTest::BrowsePreload(const GURL& browse_to) { |
| 197 content::TestNavigationObserver navigation_observer( | 197 content::TestNavigationObserver navigation_observer( |
| 198 content::Source<NavigationController>( | 198 content::Source<NavigationController>( |
| 199 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 199 &browser()->GetActiveWebContents()->GetController()), |
| 200 GetController()), | |
| 201 this, 1); | 200 this, 1); |
| 202 browser::NavigateParams params( | 201 browser::NavigateParams params( |
| 203 browser(), GURL(browse_to), content::PAGE_TRANSITION_TYPED); | 202 browser(), GURL(browse_to), content::PAGE_TRANSITION_TYPED); |
| 204 params.disposition = CURRENT_TAB; | 203 params.disposition = CURRENT_TAB; |
| 205 browser::Navigate(¶ms); | 204 browser::Navigate(¶ms); |
| 206 navigation_observer.WaitForObservation( | 205 navigation_observer.WaitForObservation( |
| 207 base::Bind(&ui_test_utils::RunMessageLoop), | 206 base::Bind(&ui_test_utils::RunMessageLoop), |
| 208 base::Bind(&MessageLoop::Quit, | 207 base::Bind(&MessageLoop::Quit, |
| 209 base::Unretained(MessageLoopForUI::current()))); | 208 base::Unretained(MessageLoopForUI::current()))); |
| 210 } | 209 } |
| 211 | 210 |
| 212 void WebUIBrowserTest::BrowsePrintPreload(const GURL& browse_to) { | 211 void WebUIBrowserTest::BrowsePrintPreload(const GURL& browse_to) { |
| 213 ui_test_utils::NavigateToURL(browser(), browse_to); | 212 ui_test_utils::NavigateToURL(browser(), browse_to); |
| 214 | 213 |
| 215 TestTabStripModelObserver tabstrip_observer( | 214 TestTabStripModelObserver tabstrip_observer( |
| 216 browser()->tab_strip_model(), this); | 215 browser()->tab_strip_model(), this); |
| 217 browser()->Print(); | 216 browser()->Print(); |
| 218 tabstrip_observer.WaitForObservation( | 217 tabstrip_observer.WaitForObservation( |
| 219 base::Bind(&ui_test_utils::RunMessageLoop), | 218 base::Bind(&ui_test_utils::RunMessageLoop), |
| 220 base::Bind(&MessageLoop::Quit, | 219 base::Bind(&MessageLoop::Quit, |
| 221 base::Unretained(MessageLoopForUI::current()))); | 220 base::Unretained(MessageLoopForUI::current()))); |
| 222 | 221 |
| 223 printing::PrintPreviewTabController* tab_controller = | 222 printing::PrintPreviewTabController* tab_controller = |
| 224 printing::PrintPreviewTabController::GetInstance(); | 223 printing::PrintPreviewTabController::GetInstance(); |
| 225 ASSERT_TRUE(tab_controller); | 224 ASSERT_TRUE(tab_controller); |
| 226 TabContentsWrapper* preview_tab = tab_controller->GetPrintPreviewForTab( | 225 TabContents* preview_tab = tab_controller->GetPrintPreviewForTab( |
| 227 browser()->GetSelectedTabContentsWrapper()); | 226 browser()->GetActiveTabContents()); |
| 228 ASSERT_TRUE(preview_tab); | 227 ASSERT_TRUE(preview_tab); |
| 229 SetWebUIInstance(preview_tab->web_contents()->GetWebUI()); | 228 SetWebUIInstance(preview_tab->web_contents()->GetWebUI()); |
| 230 } | 229 } |
| 231 | 230 |
| 232 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; | 231 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; |
| 233 | 232 |
| 234 WebUIBrowserTest::WebUIBrowserTest() | 233 WebUIBrowserTest::WebUIBrowserTest() |
| 235 : test_handler_(new WebUITestHandler()), | 234 : test_handler_(new WebUITestHandler()), |
| 236 libraries_preloaded_(false), | 235 libraries_preloaded_(false), |
| 237 override_selected_web_ui_(NULL) {} | 236 override_selected_web_ui_(NULL) {} |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 LOG(ERROR) << "Encountered javascript console error(s)"; | 457 LOG(ERROR) << "Encountered javascript console error(s)"; |
| 459 result = false; | 458 result = false; |
| 460 error_messages_.Get().clear(); | 459 error_messages_.Get().clear(); |
| 461 } | 460 } |
| 462 return result; | 461 return result; |
| 463 } | 462 } |
| 464 | 463 |
| 465 void WebUIBrowserTest::SetupHandlers() { | 464 void WebUIBrowserTest::SetupHandlers() { |
| 466 content::WebUI* web_ui_instance = override_selected_web_ui_ ? | 465 content::WebUI* web_ui_instance = override_selected_web_ui_ ? |
| 467 override_selected_web_ui_ : | 466 override_selected_web_ui_ : |
| 468 browser()->GetSelectedWebContents()->GetWebUI(); | 467 browser()->GetActiveWebContents()->GetWebUI(); |
| 469 ASSERT_TRUE(web_ui_instance != NULL); | 468 ASSERT_TRUE(web_ui_instance != NULL); |
| 470 | 469 |
| 471 test_handler_->set_web_ui(web_ui_instance); | 470 test_handler_->set_web_ui(web_ui_instance); |
| 472 test_handler_->RegisterMessages(); | 471 test_handler_->RegisterMessages(); |
| 473 | 472 |
| 474 if (GetMockMessageHandler()) { | 473 if (GetMockMessageHandler()) { |
| 475 GetMockMessageHandler()->set_web_ui(web_ui_instance); | 474 GetMockMessageHandler()->set_web_ui(web_ui_instance); |
| 476 GetMockMessageHandler()->RegisterMessages(); | 475 GetMockMessageHandler()->RegisterMessages(); |
| 477 } | 476 } |
| 478 } | 477 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 // testDone directly and expect pass result. | 696 // testDone directly and expect pass result. |
| 698 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 697 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 699 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 698 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 700 } | 699 } |
| 701 | 700 |
| 702 // Test that calling testDone during RunJavascriptTest still completes when | 701 // Test that calling testDone during RunJavascriptTest still completes when |
| 703 // waiting for async result. | 702 // waiting for async result. |
| 704 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 703 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 705 ASSERT_TRUE(RunJavascriptTest("testDone")); | 704 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 706 } | 705 } |
| OLD | NEW |