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