Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chrome/test/base/test_chrome_web_ui_controller_factory_browsertest.cc

Issue 12084029: Simplify how TestChromeWebUIControllerFactory is registered now that multiple WebUIControllerFactor… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 4
5 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" 5 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
6 #include "content/public/browser/web_ui_controller.h" 6 #include "content/public/browser/web_ui_controller.h"
7 #include "chrome/test/base/in_process_browser_test.h" 7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 using content::WebContents; 13 using content::WebContents;
14 using content::WebUI; 14 using content::WebUI;
15 using content::WebUIController; 15 using content::WebUIController;
(...skipping 20 matching lines...) Expand all
36 // Dummy URL location for us to override. 36 // Dummy URL location for us to override.
37 const char kChromeTestChromeWebUIControllerFactory[] = 37 const char kChromeTestChromeWebUIControllerFactory[] =
38 "chrome://ChromeTestChromeWebUIControllerFactory/"; 38 "chrome://ChromeTestChromeWebUIControllerFactory/";
39 39
40 // Sets up and tears down the factory override for our url's host. It is 40 // Sets up and tears down the factory override for our url's host. It is
41 // necessary to do this here, rather than in the test declaration, which is too 41 // necessary to do this here, rather than in the test declaration, which is too
42 // late to catch the possibility of an initial browse to about:blank mistakenly 42 // late to catch the possibility of an initial browse to about:blank mistakenly
43 // going to this handler. 43 // going to this handler.
44 class TestChromeWebUIControllerFactoryTest : public InProcessBrowserTest { 44 class TestChromeWebUIControllerFactoryTest : public InProcessBrowserTest {
45 public: 45 public:
46 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 46 virtual void SetUpOnMainThread() OVERRIDE {
47 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); 47 content::WebUIControllerFactory::UnregisterFactoryForTesting(
48 TestChromeWebUIControllerFactory::AddFactoryOverride( 48 ChromeWebUIControllerFactory::GetInstance());
49 test_factory_.reset(new TestChromeWebUIControllerFactory);
50 content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
51 test_factory_->AddFactoryOverride(
49 GURL(kChromeTestChromeWebUIControllerFactory).host(), &mock_provider_); 52 GURL(kChromeTestChromeWebUIControllerFactory).host(), &mock_provider_);
50 } 53 }
51 54
52 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 55 virtual void CleanUpOnMainThread() OVERRIDE {
53 TestChromeWebUIControllerFactory::RemoveFactoryOverride( 56 test_factory_->RemoveFactoryOverride(
54 GURL(kChromeTestChromeWebUIControllerFactory).host()); 57 GURL(kChromeTestChromeWebUIControllerFactory).host());
58 content::WebUIControllerFactory::UnregisterFactoryForTesting(
59 test_factory_.get());
60
61 test_factory_.reset();
55 } 62 }
56 63
57 protected: 64 protected:
58 StrictMock<MockWebUIProvider> mock_provider_; 65 StrictMock<MockWebUIProvider> mock_provider_;
66 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_;
59 }; 67 };
60 68
61 } // namespace 69 } // namespace
62 70
63 // Test that browsing to our test url causes us to be called once. 71 // Test that browsing to our test url causes us to be called once.
64 IN_PROC_BROWSER_TEST_F(TestChromeWebUIControllerFactoryTest, 72 IN_PROC_BROWSER_TEST_F(TestChromeWebUIControllerFactoryTest,
65 TestWebUIProvider) { 73 TestWebUIProvider) {
66 const GURL kChromeTestChromeWebUIControllerFactoryURL( 74 const GURL kChromeTestChromeWebUIControllerFactoryURL(
67 kChromeTestChromeWebUIControllerFactory); 75 kChromeTestChromeWebUIControllerFactory);
68 EXPECT_CALL(mock_provider_, 76 EXPECT_CALL(mock_provider_,
69 NewWebUI(_, Eq(kChromeTestChromeWebUIControllerFactoryURL))) 77 NewWebUI(_, Eq(kChromeTestChromeWebUIControllerFactoryURL)))
70 .WillOnce(ReturnNewWebUI()); 78 .WillOnce(ReturnNewWebUI());
71 ui_test_utils::NavigateToURL(browser(), 79 ui_test_utils::NavigateToURL(browser(),
72 kChromeTestChromeWebUIControllerFactoryURL); 80 kChromeTestChromeWebUIControllerFactoryURL);
73 } 81 }
OLDNEW
« no previous file with comments | « chrome/test/base/test_chrome_web_ui_controller_factory.cc ('k') | chrome/test/base/web_ui_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698