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 #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/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/printing/print_preview_tab_controller.h" | 16 #include "chrome/browser/printing/print_preview_tab_controller.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
20 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 20 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
21 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 21 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
22 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | 22 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "chrome/test/base/test_tab_strip_model_observer.h" | 26 #include "chrome/test/base/test_tab_strip_model_observer.h" |
27 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
28 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_ui_controller.h" | 30 #include "content/public/browser/web_ui_controller.h" |
31 #include "content/public/browser/web_ui_message_handler.h" | 31 #include "content/public/browser/web_ui_message_handler.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 263 |
264 std::string GetMimeType(const std::string& path) const OVERRIDE { | 264 std::string GetMimeType(const std::string& path) const OVERRIDE { |
265 return "text/html"; | 265 return "text/html"; |
266 } | 266 } |
267 | 267 |
268 DISALLOW_COPY_AND_ASSIGN(MockWebUIDataSource); | 268 DISALLOW_COPY_AND_ASSIGN(MockWebUIDataSource); |
269 }; | 269 }; |
270 | 270 |
271 // WebUIProvider to allow attaching the DataSource for the dummy URL when | 271 // WebUIProvider to allow attaching the DataSource for the dummy URL when |
272 // testing. | 272 // testing. |
273 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { | 273 class MockWebUIProvider |
| 274 : public TestChromeWebUIControllerFactory::WebUIProvider { |
274 public: | 275 public: |
275 MockWebUIProvider() {} | 276 MockWebUIProvider() {} |
276 | 277 |
277 // Returns a new WebUI | 278 // Returns a new WebUI |
278 WebUIController* NewWebUI(content::WebUI* web_ui, const GURL& url) OVERRIDE { | 279 WebUIController* NewWebUI(content::WebUI* web_ui, const GURL& url) OVERRIDE { |
279 WebUIController* controller = new content::WebUIController(web_ui); | 280 WebUIController* controller = new content::WebUIController(web_ui); |
280 Profile* profile = Profile::FromWebUI(web_ui); | 281 Profile* profile = Profile::FromWebUI(web_ui); |
281 profile->GetChromeURLDataManager()->AddDataSource( | 282 profile->GetChromeURLDataManager()->AddDataSource( |
282 new MockWebUIDataSource()); | 283 new MockWebUIDataSource()); |
283 return controller; | 284 return controller; |
(...skipping 15 matching lines...) Expand all Loading... |
299 } | 300 } |
300 | 301 |
301 void WebUIBrowserTest::CleanUpOnMainThread() { | 302 void WebUIBrowserTest::CleanUpOnMainThread() { |
302 InProcessBrowserTest::CleanUpOnMainThread(); | 303 InProcessBrowserTest::CleanUpOnMainThread(); |
303 | 304 |
304 logging::SetLogMessageHandler(NULL); | 305 logging::SetLogMessageHandler(NULL); |
305 } | 306 } |
306 | 307 |
307 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { | 308 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { |
308 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 309 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
309 TestChromeWebUIFactory::AddFactoryOverride(GURL(kDummyURL).host(), | 310 TestChromeWebUIControllerFactory::AddFactoryOverride( |
310 mock_provider_.Pointer()); | 311 GURL(kDummyURL).host(), mock_provider_.Pointer()); |
311 | 312 |
312 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); | 313 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); |
313 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); | 314 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); |
314 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, | 315 ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, |
315 &gen_test_data_directory_)); | 316 &gen_test_data_directory_)); |
316 | 317 |
317 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. | 318 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. |
318 FilePath resources_pack_path; | 319 FilePath resources_pack_path; |
319 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 320 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
320 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); | 321 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
321 | 322 |
322 FilePath mockPath; | 323 FilePath mockPath; |
323 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &mockPath)); | 324 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &mockPath)); |
324 mockPath = mockPath.AppendASCII("chrome"); | 325 mockPath = mockPath.AppendASCII("chrome"); |
325 mockPath = mockPath.AppendASCII("third_party"); | 326 mockPath = mockPath.AppendASCII("third_party"); |
326 mockPath = mockPath.AppendASCII("mock4js"); | 327 mockPath = mockPath.AppendASCII("mock4js"); |
327 mockPath = mockPath.Append(kMockJS); | 328 mockPath = mockPath.Append(kMockJS); |
328 AddLibrary(mockPath); | 329 AddLibrary(mockPath); |
329 AddLibrary(FilePath(kWebUILibraryJS)); | 330 AddLibrary(FilePath(kWebUILibraryJS)); |
330 } | 331 } |
331 | 332 |
332 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { | 333 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { |
333 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 334 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
334 TestChromeWebUIFactory::RemoveFactoryOverride(GURL(kDummyURL).host()); | 335 TestChromeWebUIControllerFactory::RemoveFactoryOverride( |
| 336 GURL(kDummyURL).host()); |
335 } | 337 } |
336 | 338 |
337 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { | 339 void WebUIBrowserTest::SetWebUIInstance(content::WebUI* web_ui) { |
338 override_selected_web_ui_ = web_ui; | 340 override_selected_web_ui_ = web_ui; |
339 } | 341 } |
340 | 342 |
341 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { | 343 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { |
342 return NULL; | 344 return NULL; |
343 } | 345 } |
344 | 346 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 // testDone directly and expect pass result. | 685 // testDone directly and expect pass result. |
684 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 686 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
685 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 687 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
686 } | 688 } |
687 | 689 |
688 // Test that calling testDone during RunJavascriptTest still completes when | 690 // Test that calling testDone during RunJavascriptTest still completes when |
689 // waiting for async result. | 691 // waiting for async result. |
690 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 692 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
691 ASSERT_TRUE(RunJavascriptTest("testDone")); | 693 ASSERT_TRUE(RunJavascriptTest("testDone")); |
692 } | 694 } |
OLD | NEW |