Chromium Code Reviews| 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. | |
| 36 class TestChromeWebUIFactoryTest : public InProcessBrowserTest { | |
| 37 public: | |
| 38 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
| 39 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 40 TestChromeWebUIFactory::AddFactoryOverride( | |
| 41 GURL(kChromeTestChromeWebUIFactory).host(), &mock_provider_); | |
| 42 } | |
| 43 | |
| 44 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
| 45 TestChromeWebUIFactory::RemoveFactoryOverride( | |
| 46 GURL(kChromeTestChromeWebUIFactory).host()); | |
|
Evan Stade
2011/05/24 17:25:59
is there a reason to do this setup and teardown he
Sheridan Rawlins
2011/05/24 20:17:22
In fact, putting this here uncovered a bug. I wan
Evan Stade
2011/05/25 18:49:04
no, I meant why is everything within SetUp and Tea
Sheridan Rawlins
2011/05/25 21:02:55
If I move the add/remove to the method, then I'm n
| |
| 47 } | |
| 48 | |
| 49 protected: | |
| 50 StrictMock<MockWebUIProvider> mock_provider_; | |
| 51 }; | |
| 52 | |
| 53 // Test that browsing to our test url causes us to be called once. | |
| 54 IN_PROC_BROWSER_TEST_F(TestChromeWebUIFactoryTest, TestWebUIProvider) { | |
| 55 const GURL kChromeTestChromeWebUIFactoryURL(kChromeTestChromeWebUIFactory); | |
| 56 EXPECT_CALL(mock_provider_, NewWebUI(_, Eq(kChromeTestChromeWebUIFactoryURL))) | |
| 57 .WillOnce(ReturnNewWebUI()); | |
|
Evan Stade
2011/05/24 17:25:59
. goes on EOL
Sheridan Rawlins
2011/05/24 20:17:22
I'd prefer to keep in the style of gmock examples,
| |
| 58 ui_test_utils::NavigateToURL(browser(), kChromeTestChromeWebUIFactoryURL); | |
| 59 } | |
| 60 | |
| 61 } //namespace | |
|
Evan Stade
2011/05/24 17:25:59
space after //
Lei Zhang (Do not use)
2011/05/24 18:00:06
No need to put the actual tests inside an anonymou
Sheridan Rawlins
2011/05/24 20:17:22
Done.
Sheridan Rawlins
2011/05/24 20:17:22
Done.
| |
| OLD | NEW |