| 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 | 4 |
| 5 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 5 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
| 6 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | 6 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
| 7 #include "content/public/browser/web_ui_controller.h" | 7 #include "content/public/browser/web_ui_controller.h" |
| 8 #include "chrome/test/base/in_process_browser_test.h" | 8 #include "chrome/test/base/in_process_browser_test.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using content::WebContents; | 14 using content::WebContents; |
| 15 using content::WebUIController; |
| 15 using ::testing::_; | 16 using ::testing::_; |
| 16 using ::testing::Eq; | 17 using ::testing::Eq; |
| 17 using ::testing::StrictMock; | 18 using ::testing::StrictMock; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Returns a new WebUI object for the TabContents from |arg0|. | 22 // Returns a new WebUI object for the TabContents from |arg0|. |
| 22 ACTION(ReturnNewWebUI) { | 23 ACTION(ReturnNewWebUI) { |
| 23 static content::WebUIController temp_controller; | 24 return new WebUIController(arg0); |
| 24 return new WebUI(arg0, &temp_controller); | |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Mock the TestChromeWebUIFactory::WebUIProvider to prove that we are called as | 27 // Mock the TestChromeWebUIFactory::WebUIProvider to prove that we are called as |
| 28 // expected. | 28 // expected. |
| 29 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { | 29 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { |
| 30 public: | 30 public: |
| 31 MOCK_METHOD2(NewWebUI, WebUI*(WebContents* tab_contents, const GURL& url)); | 31 MOCK_METHOD2(NewWebUI, WebUIController*(WebUI* web_ui, const GURL& url)); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Dummy URL location for us to override. | 34 // Dummy URL location for us to override. |
| 35 const char kChromeTestChromeWebUIFactory[] = | 35 const char kChromeTestChromeWebUIFactory[] = |
| 36 "chrome://ChromeTestChromeWebUIFactory/"; | 36 "chrome://ChromeTestChromeWebUIFactory/"; |
| 37 | 37 |
| 38 // Sets up and tears down the factory override for our url's host. It is | 38 // Sets up and tears down the factory override for our url's host. It is |
| 39 // necessary to do this here, rather than in the test declaration, which is too | 39 // necessary to do this here, rather than in the test declaration, which is too |
| 40 // late to catch the possibility of an initial browse to about:blank mistakenly | 40 // late to catch the possibility of an initial browse to about:blank mistakenly |
| 41 // going to this handler. | 41 // going to this handler. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 // Test that browsing to our test url causes us to be called once. | 61 // Test that browsing to our test url causes us to be called once. |
| 62 IN_PROC_BROWSER_TEST_F(TestChromeWebUIFactoryTest, TestWebUIProvider) { | 62 IN_PROC_BROWSER_TEST_F(TestChromeWebUIFactoryTest, TestWebUIProvider) { |
| 63 const GURL kChromeTestChromeWebUIFactoryURL(kChromeTestChromeWebUIFactory); | 63 const GURL kChromeTestChromeWebUIFactoryURL(kChromeTestChromeWebUIFactory); |
| 64 EXPECT_CALL(mock_provider_, NewWebUI(_, Eq(kChromeTestChromeWebUIFactoryURL))) | 64 EXPECT_CALL(mock_provider_, NewWebUI(_, Eq(kChromeTestChromeWebUIFactoryURL))) |
| 65 .WillOnce(ReturnNewWebUI()); | 65 .WillOnce(ReturnNewWebUI()); |
| 66 ui_test_utils::NavigateToURL(browser(), kChromeTestChromeWebUIFactoryURL); | 66 ui_test_utils::NavigateToURL(browser(), kChromeTestChromeWebUIFactoryURL); |
| 67 } | 67 } |
| OLD | NEW |