OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/webui/web_ui_browsertest.h" | 4 #include "chrome/browser/ui/webui/web_ui_browsertest.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/printing/print_preview_tab_controller.h" | 15 #include "chrome/browser/printing/print_preview_tab_controller.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
18 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 18 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
19 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | 19 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "chrome/test/base/test_tab_strip_model_observer.h" | 23 #include "chrome/test/base/test_tab_strip_model_observer.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
25 #include "content/browser/tab_contents/tab_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_ui_message_handler.h" | 26 #include "content/public/browser/web_ui_message_handler.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest-spi.h" | 28 #include "testing/gtest/include/gtest/gtest-spi.h" |
29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
30 | 30 |
31 using content::WebContents; | 31 using content::WebContents; |
32 using content::WebUIMessageHandler; | 32 using content::WebUIMessageHandler; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 args.push_back(Value::CreateStringValue(preload_test_fixture)); | 175 args.push_back(Value::CreateStringValue(preload_test_fixture)); |
176 args.push_back(Value::CreateStringValue(preload_test_name)); | 176 args.push_back(Value::CreateStringValue(preload_test_name)); |
177 RunJavascriptUsingHandler( | 177 RunJavascriptUsingHandler( |
178 "preloadJavascriptLibraries", args, false, false, preload_host); | 178 "preloadJavascriptLibraries", args, false, false, preload_host); |
179 libraries_preloaded_ = true; | 179 libraries_preloaded_ = true; |
180 } | 180 } |
181 | 181 |
182 void WebUIBrowserTest::BrowsePreload(const GURL& browse_to) { | 182 void WebUIBrowserTest::BrowsePreload(const GURL& browse_to) { |
183 TestNavigationObserver navigation_observer( | 183 TestNavigationObserver navigation_observer( |
184 content::Source<NavigationController>( | 184 content::Source<NavigationController>( |
185 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 185 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
186 GetController()), | 186 GetController()), |
187 this, 1); | 187 this, 1); |
188 browser::NavigateParams params( | 188 browser::NavigateParams params( |
189 browser(), GURL(browse_to), content::PAGE_TRANSITION_TYPED); | 189 browser(), GURL(browse_to), content::PAGE_TRANSITION_TYPED); |
190 params.disposition = CURRENT_TAB; | 190 params.disposition = CURRENT_TAB; |
191 browser::Navigate(¶ms); | 191 browser::Navigate(¶ms); |
192 navigation_observer.WaitForObservation( | 192 navigation_observer.WaitForObservation( |
193 base::Bind(&ui_test_utils::RunMessageLoop), | 193 base::Bind(&ui_test_utils::RunMessageLoop), |
194 base::Bind(&MessageLoop::Quit, | 194 base::Bind(&MessageLoop::Quit, |
195 base::Unretained(MessageLoopForUI::current()))); | 195 base::Unretained(MessageLoopForUI::current()))); |
(...skipping 10 matching lines...) Expand all Loading... |
206 base::Bind(&ui_test_utils::RunMessageLoop), | 206 base::Bind(&ui_test_utils::RunMessageLoop), |
207 base::Bind(&MessageLoop::Quit, | 207 base::Bind(&MessageLoop::Quit, |
208 base::Unretained(MessageLoopForUI::current()))); | 208 base::Unretained(MessageLoopForUI::current()))); |
209 | 209 |
210 printing::PrintPreviewTabController* tab_controller = | 210 printing::PrintPreviewTabController* tab_controller = |
211 printing::PrintPreviewTabController::GetInstance(); | 211 printing::PrintPreviewTabController::GetInstance(); |
212 ASSERT_TRUE(tab_controller); | 212 ASSERT_TRUE(tab_controller); |
213 TabContentsWrapper* preview_tab = tab_controller->GetPrintPreviewForTab( | 213 TabContentsWrapper* preview_tab = tab_controller->GetPrintPreviewForTab( |
214 browser()->GetSelectedTabContentsWrapper()); | 214 browser()->GetSelectedTabContentsWrapper()); |
215 ASSERT_TRUE(preview_tab); | 215 ASSERT_TRUE(preview_tab); |
216 SetWebUIInstance(preview_tab->tab_contents()->GetWebUI()); | 216 SetWebUIInstance(preview_tab->web_contents()->GetWebUI()); |
217 } | 217 } |
218 | 218 |
219 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; | 219 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; |
220 | 220 |
221 WebUIBrowserTest::WebUIBrowserTest() | 221 WebUIBrowserTest::WebUIBrowserTest() |
222 : test_handler_(new WebUITestHandler()), | 222 : test_handler_(new WebUITestHandler()), |
223 libraries_preloaded_(false), | 223 libraries_preloaded_(false), |
224 override_selected_web_ui_(NULL) {} | 224 override_selected_web_ui_(NULL) {} |
225 | 225 |
226 void WebUIBrowserTest::set_preload_test_fixture( | 226 void WebUIBrowserTest::set_preload_test_fixture( |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 LOG(ERROR) << "Encountered javascript console error(s)"; | 402 LOG(ERROR) << "Encountered javascript console error(s)"; |
403 result = false; | 403 result = false; |
404 error_messages_.Get().clear(); | 404 error_messages_.Get().clear(); |
405 } | 405 } |
406 return result; | 406 return result; |
407 } | 407 } |
408 | 408 |
409 void WebUIBrowserTest::SetupHandlers() { | 409 void WebUIBrowserTest::SetupHandlers() { |
410 WebUI* web_ui_instance = override_selected_web_ui_ ? | 410 WebUI* web_ui_instance = override_selected_web_ui_ ? |
411 override_selected_web_ui_ : | 411 override_selected_web_ui_ : |
412 browser()->GetSelectedTabContents()->GetWebUI(); | 412 browser()->GetSelectedWebContents()->GetWebUI(); |
413 ASSERT_TRUE(web_ui_instance != NULL); | 413 ASSERT_TRUE(web_ui_instance != NULL); |
414 web_ui_instance->set_register_callback_overwrites(true); | 414 web_ui_instance->set_register_callback_overwrites(true); |
415 test_handler_->set_web_ui(web_ui_instance); | 415 test_handler_->set_web_ui(web_ui_instance); |
416 test_handler_->RegisterMessages(); | 416 test_handler_->RegisterMessages(); |
417 | 417 |
418 if (GetMockMessageHandler()) { | 418 if (GetMockMessageHandler()) { |
419 GetMockMessageHandler()->set_web_ui(web_ui_instance); | 419 GetMockMessageHandler()->set_web_ui(web_ui_instance); |
420 GetMockMessageHandler()->RegisterMessages(); | 420 GetMockMessageHandler()->RegisterMessages(); |
421 } | 421 } |
422 } | 422 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 // testDone directly and expect pass result. | 641 // testDone directly and expect pass result. |
642 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 642 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
643 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 643 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
644 } | 644 } |
645 | 645 |
646 // Test that calling testDone during RunJavascriptTest still completes when | 646 // Test that calling testDone during RunJavascriptTest still completes when |
647 // waiting for async result. | 647 // waiting for async result. |
648 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 648 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
649 ASSERT_TRUE(RunJavascriptTest("testDone")); | 649 ASSERT_TRUE(RunJavascriptTest("testDone")); |
650 } | 650 } |
OLD | NEW |