| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/signin/signin_promo.h" | |
| 6 #include "chrome/browser/ui/browser.h" | |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 8 #include "chrome/common/chrome_switches.h" | |
| 9 #include "chrome/common/url_constants.h" | |
| 10 #include "chrome/test/base/in_process_browser_test.h" | |
| 11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | |
| 12 #include "chrome/test/base/testing_browser_process.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "content/public/browser/render_process_host.h" | |
| 15 #include "content/public/browser/session_storage_namespace.h" | |
| 16 #include "content/public/browser/storage_partition.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "content/public/browser/web_ui_controller.h" | |
| 19 #include "content/public/common/url_constants.h" | |
| 20 #include "content/public/test/browser_test_utils.h" | |
| 21 #include "testing/gmock/include/gmock/gmock.h" | |
| 22 #include "testing/gtest/include/gtest/gtest.h" | |
| 23 | |
| 24 using ::testing::_; | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 struct ContentInfo { | |
| 29 ContentInfo(int pid, content::StoragePartition* storage_partition) { | |
| 30 this->pid = pid; | |
| 31 this->storage_partition = storage_partition; | |
| 32 } | |
| 33 | |
| 34 int pid; | |
| 35 content::StoragePartition* storage_partition; | |
| 36 }; | |
| 37 | |
| 38 ContentInfo NavigateAndGetInfo( | |
| 39 Browser* browser, | |
| 40 const GURL& url, | |
| 41 WindowOpenDisposition disposition) { | |
| 42 ui_test_utils::NavigateToURLWithDisposition( | |
| 43 browser, url, disposition, | |
| 44 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 45 content::WebContents* contents = | |
| 46 browser->tab_strip_model()->GetActiveWebContents(); | |
| 47 content::RenderProcessHost* process = contents->GetRenderProcessHost(); | |
| 48 return ContentInfo(process->GetID(), process->GetStoragePartition()); | |
| 49 } | |
| 50 | |
| 51 // Returns a new WebUI object for the WebContents from |arg0|. | |
| 52 ACTION(ReturnNewWebUI) { | |
| 53 return new content::WebUIController(arg0); | |
| 54 } | |
| 55 | |
| 56 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are | |
| 57 // not called as expected. | |
| 58 class FooWebUIProvider | |
| 59 : public TestChromeWebUIControllerFactory::WebUIProvider { | |
| 60 public: | |
| 61 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, | |
| 62 const GURL& url)); | |
| 63 }; | |
| 64 | |
| 65 const char kFooWebUIURL[] = "chrome://foo/"; | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 class InlineLoginUIBrowserTest : public InProcessBrowserTest { | |
| 70 public: | |
| 71 InlineLoginUIBrowserTest() {} | |
| 72 }; | |
| 73 | |
| 74 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) { | |
| 75 GURL test_url = ui_test_utils::GetTestUrl( | |
| 76 base::FilePath(base::FilePath::kCurrentDirectory), | |
| 77 base::FilePath(FILE_PATH_LITERAL("title1.html"))); | |
| 78 | |
| 79 ContentInfo info1 = | |
| 80 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); | |
| 81 ContentInfo info2 = | |
| 82 NavigateAndGetInfo(browser(), | |
| 83 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), | |
| 84 CURRENT_TAB); | |
| 85 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); | |
| 86 ContentInfo info3 = | |
| 87 NavigateAndGetInfo(browser(), | |
| 88 signin::GetPromoURL( signin::SOURCE_START_PAGE, false), | |
| 89 NEW_FOREGROUND_TAB); | |
| 90 | |
| 91 // The info for signin should be the same. | |
| 92 ASSERT_EQ(info2.storage_partition, info3.storage_partition); | |
| 93 // The info for test_url and signin should be different. | |
| 94 ASSERT_NE(info1.storage_partition, info2.storage_partition); | |
| 95 } | |
| 96 | |
| 97 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) { | |
| 98 GURL test_url_1 = ui_test_utils::GetTestUrl( | |
| 99 base::FilePath(base::FilePath::kCurrentDirectory), | |
| 100 base::FilePath(FILE_PATH_LITERAL("title1.html"))); | |
| 101 GURL test_url_2 = ui_test_utils::GetTestUrl( | |
| 102 base::FilePath(base::FilePath::kCurrentDirectory), | |
| 103 base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!"))); | |
| 104 | |
| 105 // Even when the process limit is set to one, the signin process should | |
| 106 // still be given its own process and storage partition. | |
| 107 content::RenderProcessHost::SetMaxRendererProcessCount(1); | |
| 108 | |
| 109 ContentInfo info1 = | |
| 110 NavigateAndGetInfo(browser(), test_url_1, CURRENT_TAB); | |
| 111 ContentInfo info2 = | |
| 112 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB); | |
| 113 ContentInfo info3 = | |
| 114 NavigateAndGetInfo(browser(), | |
| 115 signin::GetPromoURL( signin::SOURCE_START_PAGE, false), | |
| 116 CURRENT_TAB); | |
| 117 | |
| 118 ASSERT_EQ(info1.pid, info2.pid); | |
| 119 ASSERT_NE(info1.pid, info3.pid); | |
| 120 } | |
| 121 | |
| 122 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { | |
| 123 public: | |
| 124 FooWebUIProvider& foo_provider() { return foo_provider_; } | |
| 125 | |
| 126 private: | |
| 127 virtual void SetUpOnMainThread() OVERRIDE { | |
| 128 content::WebUIControllerFactory::UnregisterFactoryForTesting( | |
| 129 ChromeWebUIControllerFactory::GetInstance()); | |
| 130 test_factory_.reset(new TestChromeWebUIControllerFactory); | |
| 131 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); | |
| 132 test_factory_->AddFactoryOverride( | |
| 133 GURL(kFooWebUIURL).host(), &foo_provider_); | |
| 134 } | |
| 135 | |
| 136 virtual void CleanUpOnMainThread() OVERRIDE { | |
| 137 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host()); | |
| 138 content::WebUIControllerFactory::UnregisterFactoryForTesting( | |
| 139 test_factory_.get()); | |
| 140 test_factory_.reset(); | |
| 141 } | |
| 142 | |
| 143 FooWebUIProvider foo_provider_; | |
| 144 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; | |
| 145 }; | |
| 146 | |
| 147 // Make sure that the foo webui handler is working properly and that it gets | |
| 148 // created when navigated to normally. | |
| 149 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { | |
| 150 const GURL kUrl(kFooWebUIURL); | |
| 151 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) | |
| 152 .WillOnce(ReturnNewWebUI()); | |
| 153 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL)); | |
| 154 } | |
| 155 | |
| 156 // Make sure that the foo webui handler does not get created when we try to | |
| 157 // load it inside the iframe of the login ui. | |
| 158 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) { | |
| 159 GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false). | |
| 160 Resolve("?source=0&frameUrl=chrome://foo"); | |
| 161 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0); | |
| 162 ui_test_utils::NavigateToURL(browser(), url); | |
| 163 } | |
| OLD | NEW |