OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
| 6 #include "chrome/test/in_process_browser_test.h" |
| 7 #include "chrome/test/ui_test_utils.h" |
| 8 #include "googleurl/src/gurl.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 using ::testing::_; |
| 13 using ::testing::Eq; |
| 14 using ::testing::StrictMock; |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Returns a new WebUI object for the TabContents from |arg0|. |
| 19 ACTION(ReturnNewWebUI) { |
| 20 return new WebUI(arg0); |
| 21 } |
| 22 |
| 23 // Mock the TestChromeWebUIFactory::WebUIProvider to prove that we are called as |
| 24 // expected. |
| 25 class MockWebUIProvider : public TestChromeWebUIFactory::WebUIProvider { |
| 26 public: |
| 27 MOCK_METHOD2(NewWebUI, WebUI*(TabContents* tab_contents, const GURL& url)); |
| 28 }; |
| 29 |
| 30 // Dummy URL location for us to override. |
| 31 const char kChromeTestChromeWebUIFactory[] = |
| 32 "chrome://ChromeTestChromeWebUIFactory/"; |
| 33 |
| 34 // Sets up and tears down the factory override for our url's host. It is |
| 35 // necessary to do this here, rather than in the test declaration, which is too |
| 36 // late to catch the possibility of an initial browse to about:blank mistakenly |
| 37 // going to this handler. |
| 38 class TestChromeWebUIFactoryTest : public InProcessBrowserTest { |
| 39 public: |
| 40 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 41 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 42 TestChromeWebUIFactory::AddFactoryOverride( |
| 43 GURL(kChromeTestChromeWebUIFactory).host(), &mock_provider_); |
| 44 } |
| 45 |
| 46 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 47 TestChromeWebUIFactory::RemoveFactoryOverride( |
| 48 GURL(kChromeTestChromeWebUIFactory).host()); |
| 49 } |
| 50 |
| 51 protected: |
| 52 StrictMock<MockWebUIProvider> mock_provider_; |
| 53 }; |
| 54 |
| 55 } // namespace |
| 56 |
| 57 // Test that browsing to our test url causes us to be called once. |
| 58 IN_PROC_BROWSER_TEST_F(TestChromeWebUIFactoryTest, TestWebUIProvider) { |
| 59 const GURL kChromeTestChromeWebUIFactoryURL(kChromeTestChromeWebUIFactory); |
| 60 EXPECT_CALL(mock_provider_, NewWebUI(_, Eq(kChromeTestChromeWebUIFactoryURL))) |
| 61 .WillOnce(ReturnNewWebUI()); |
| 62 ui_test_utils::NavigateToURL(browser(), kChromeTestChromeWebUIFactoryURL); |
| 63 } |
OLD | NEW |