| 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" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 SendResponse(request_id, response); | 261 SendResponse(request_id, response); |
| 262 } | 262 } |
| 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 // WebUI to attach the DataSource for the dummy URL. | 271 // WebUIProvider to allow attaching the DataSource for the dummy URL when |
| 272 class MockWebUI : public WebUI { | |
| 273 public: | |
| 274 explicit MockWebUI(WebContents* contents, WebUIController* controller) | |
| 275 : WebUI(contents, controller) { | |
| 276 Profile* profile = | |
| 277 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
| 278 profile->GetChromeURLDataManager()->AddDataSource( | |
| 279 new MockWebUIDataSource()); | |
| 280 } | |
| 281 | |
| 282 private: | |
| 283 DISALLOW_COPY_AND_ASSIGN(MockWebUI); | |
| 284 }; | |
| 285 | |
| 286 // WebUIProvider to allow injection of our WebUI classes for the dummy URL when | |
| 287 // testing. | 272 // testing. |
| 288 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { | 273 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { |
| 289 public: | 274 public: |
| 290 MockWebUIProvider() {} | 275 MockWebUIProvider() {} |
| 291 | 276 |
| 292 // Returns a new WebUI | 277 // Returns a new WebUI |
| 293 WebUI* NewWebUI(WebContents* web_contents, const GURL& url) OVERRIDE { | 278 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) OVERRIDE { |
| 294 static content::WebUIController temp_controller; | 279 WebUIController* controller = new content::WebUIController(web_ui); |
| 295 return new MockWebUI(web_contents, &temp_controller); | 280 Profile* profile = Profile::FromBrowserContext( |
| 281 web_ui->web_contents()->GetBrowserContext()); |
| 282 profile->GetChromeURLDataManager()->AddDataSource( |
| 283 new MockWebUIDataSource()); |
| 284 return controller; |
| 296 } | 285 } |
| 297 | 286 |
| 298 private: | 287 private: |
| 299 DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider); | 288 DISALLOW_COPY_AND_ASSIGN(MockWebUIProvider); |
| 300 }; | 289 }; |
| 301 | 290 |
| 302 base::LazyInstance<MockWebUIProvider> mock_provider_ = | 291 base::LazyInstance<MockWebUIProvider> mock_provider_ = |
| 303 LAZY_INSTANCE_INITIALIZER; | 292 LAZY_INSTANCE_INITIALIZER; |
| 304 | 293 |
| 305 } // namespace | 294 } // namespace |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 // testDone directly and expect pass result. | 684 // testDone directly and expect pass result. |
| 696 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { | 685 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPassesAsync) { |
| 697 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); | 686 ASSERT_TRUE(RunJavascriptAsyncTest("testDone")); |
| 698 } | 687 } |
| 699 | 688 |
| 700 // Test that calling testDone during RunJavascriptTest still completes when | 689 // Test that calling testDone during RunJavascriptTest still completes when |
| 701 // waiting for async result. | 690 // waiting for async result. |
| 702 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { | 691 IN_PROC_BROWSER_TEST_F(WebUIBrowserAsyncTest, TestTestDoneEarlyPasses) { |
| 703 ASSERT_TRUE(RunJavascriptTest("testDone")); | 692 ASSERT_TRUE(RunJavascriptTest("testDone")); |
| 704 } | 693 } |
| OLD | NEW |