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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 TestTabStripModelObserver tabstrip_observer( | 200 TestTabStripModelObserver tabstrip_observer( |
201 browser()->tabstrip_model(), this); | 201 browser()->tabstrip_model(), this); |
202 browser()->Print(); | 202 browser()->Print(); |
203 tabstrip_observer.WaitForObservation(); | 203 tabstrip_observer.WaitForObservation(); |
204 } | 204 } |
205 | 205 |
206 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; | 206 const char WebUIBrowserTest::kDummyURL[] = "chrome://DummyURL"; |
207 | 207 |
208 WebUIBrowserTest::WebUIBrowserTest() | 208 WebUIBrowserTest::WebUIBrowserTest() |
209 : test_handler_(new WebUITestHandler()), | 209 : test_handler_(new WebUITestHandler()), |
210 libraries_preloaded_(false) {} | 210 libraries_preloaded_(false), |
| 211 web_ui_instance_(NULL) {} |
211 | 212 |
212 namespace { | 213 namespace { |
213 | 214 |
214 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { | 215 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { |
215 public: | 216 public: |
216 MockWebUIProvider() {} | 217 MockWebUIProvider() {} |
217 | 218 |
218 // Returns a new ChromeWebUI | 219 // Returns a new ChromeWebUI |
219 WebUI* NewWebUI(TabContents* tab_contents, const GURL& url) OVERRIDE { | 220 WebUI* NewWebUI(TabContents* tab_contents, const GURL& url) OVERRIDE { |
220 return new ChromeWebUI(tab_contents); | 221 return new ChromeWebUI(tab_contents); |
(...skipping 26 matching lines...) Expand all Loading... |
247 mockPath = mockPath.Append(kMockJS); | 248 mockPath = mockPath.Append(kMockJS); |
248 AddLibrary(mockPath); | 249 AddLibrary(mockPath); |
249 AddLibrary(FilePath(kWebUILibraryJS)); | 250 AddLibrary(FilePath(kWebUILibraryJS)); |
250 } | 251 } |
251 | 252 |
252 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { | 253 void WebUIBrowserTest::TearDownInProcessBrowserTestFixture() { |
253 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 254 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
254 TestChromeWebUIFactory::RemoveFactoryOverride(GURL(kDummyURL).host()); | 255 TestChromeWebUIFactory::RemoveFactoryOverride(GURL(kDummyURL).host()); |
255 } | 256 } |
256 | 257 |
| 258 void WebUIBrowserTest::SetWebUIInstance(WebUI* web_ui) { |
| 259 web_ui_instance_ = web_ui; |
| 260 } |
| 261 |
257 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { | 262 WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { |
258 return NULL; | 263 return NULL; |
259 } | 264 } |
260 | 265 |
261 GURL WebUIBrowserTest::WebUITestDataPathToURL( | 266 GURL WebUIBrowserTest::WebUITestDataPathToURL( |
262 const FilePath::StringType& path) { | 267 const FilePath::StringType& path) { |
263 FilePath dir_test_data; | 268 FilePath dir_test_data; |
264 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); | 269 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); |
265 FilePath test_path(dir_test_data.AppendASCII("webui")); | 270 FilePath test_path(dir_test_data.AppendASCII("webui")); |
266 test_path = test_path.Append(path); | 271 test_path = test_path.Append(path); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 361 |
357 if (error_messages_.Get().size() > 0) { | 362 if (error_messages_.Get().size() > 0) { |
358 LOG(ERROR) << "Encountered javascript console error(s)"; | 363 LOG(ERROR) << "Encountered javascript console error(s)"; |
359 result = false; | 364 result = false; |
360 error_messages_.Get().clear(); | 365 error_messages_.Get().clear(); |
361 } | 366 } |
362 return result; | 367 return result; |
363 } | 368 } |
364 | 369 |
365 void WebUIBrowserTest::SetupHandlers() { | 370 void WebUIBrowserTest::SetupHandlers() { |
366 WebUI* web_ui_instance = | 371 WebUI* web_ui_instance = web_ui_instance_ ? web_ui_instance_ : |
367 browser()->GetSelectedTabContents()->web_ui(); | 372 browser()->GetSelectedTabContents()->web_ui(); |
368 ASSERT_TRUE(web_ui_instance != NULL); | 373 ASSERT_TRUE(web_ui_instance != NULL); |
369 web_ui_instance->set_register_callback_overwrites(true); | 374 web_ui_instance->set_register_callback_overwrites(true); |
370 test_handler_->Attach(web_ui_instance); | 375 test_handler_->Attach(web_ui_instance); |
371 | 376 |
372 if (GetMockMessageHandler()) | 377 if (GetMockMessageHandler()) |
373 GetMockMessageHandler()->Attach(web_ui_instance); | 378 GetMockMessageHandler()->Attach(web_ui_instance); |
374 } | 379 } |
375 | 380 |
376 // According to the interface for EXPECT_FATAL_FAILURE | 381 // According to the interface for EXPECT_FATAL_FAILURE |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // testDone directly and expect pass result. | 586 // testDone directly and expect pass result. |
582 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 587 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
583 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 588 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
584 } | 589 } |
585 | 590 |
586 // Test that calling testDone during RunJavascriptTest still completes when | 591 // Test that calling testDone during RunJavascriptTest still completes when |
587 // waiting for async result. | 592 // waiting for async result. |
588 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 593 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
589 ASSERT_TRUE(RunJavascriptTest("testDone")); | 594 ASSERT_TRUE(RunJavascriptTest("testDone")); |
590 } | 595 } |
OLD | NEW |