OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signin/signin_promo.h" | 5 #include "chrome/browser/signin/signin_promo.h" |
6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/session_storage_namespace.h" | 15 #include "content/public/browser/session_storage_namespace.h" |
16 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui_controller.h" | 18 #include "content/public/browser/web_ui_controller.h" |
19 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 21 #include "content/public/test/test_navigation_observer.h" |
21 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
22 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using ::testing::_; | 27 using ::testing::_; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 struct ContentInfo { | 31 struct ContentInfo { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 120 |
120 ASSERT_EQ(info1.pid, info2.pid); | 121 ASSERT_EQ(info1.pid, info2.pid); |
121 ASSERT_NE(info1.pid, info3.pid); | 122 ASSERT_NE(info1.pid, info3.pid); |
122 } | 123 } |
123 | 124 |
124 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { | 125 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { |
125 public: | 126 public: |
126 FooWebUIProvider& foo_provider() { return foo_provider_; } | 127 FooWebUIProvider& foo_provider() { return foo_provider_; } |
127 | 128 |
128 void WaitUntilUIReady() { | 129 void WaitUntilUIReady() { |
| 130 content::DOMMessageQueue message_queue; |
129 ASSERT_TRUE(content::ExecuteScript( | 131 ASSERT_TRUE(content::ExecuteScript( |
130 browser()->tab_strip_model()->GetActiveWebContents(), | 132 browser()->tab_strip_model()->GetActiveWebContents(), |
131 "if (!inline.login.getAuthExtHost())" | 133 "if (!inline.login.getAuthExtHost())" |
132 " inline.login.initialize();" | 134 " inline.login.initialize();" |
133 "var handler = function() {" | 135 "var handler = function() {" |
134 " window.domAutomationController.setAutomationId(0);" | 136 " window.domAutomationController.setAutomationId(0);" |
135 " window.domAutomationController.send('ready');" | 137 " window.domAutomationController.send('ready');" |
136 "};" | 138 "};" |
137 "if (inline.login.isAuthReady())" | 139 "if (inline.login.isAuthReady())" |
138 " handler();" | 140 " handler();" |
139 "else" | 141 "else" |
140 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); | 142 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); |
141 | 143 |
142 content::DOMMessageQueue message_queue; | |
143 std::string message; | 144 std::string message; |
144 // TODO(guohui): this timeouts on trybot sometimes. | 145 do { |
145 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 146 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
146 EXPECT_EQ("\"ready\"", message); | 147 } while (message != "\"ready\""); |
147 } | 148 } |
148 | 149 |
149 private: | 150 private: |
150 virtual void SetUpOnMainThread() OVERRIDE { | 151 virtual void SetUpOnMainThread() OVERRIDE { |
151 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 152 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
152 ChromeWebUIControllerFactory::GetInstance()); | 153 ChromeWebUIControllerFactory::GetInstance()); |
153 test_factory_.reset(new TestChromeWebUIControllerFactory); | 154 test_factory_.reset(new TestChromeWebUIControllerFactory); |
154 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); | 155 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); |
155 test_factory_->AddFactoryOverride( | 156 test_factory_->AddFactoryOverride( |
156 GURL(kFooWebUIURL).host(), &foo_provider_); | 157 GURL(kFooWebUIURL).host(), &foo_provider_); |
(...skipping 21 matching lines...) Expand all Loading... |
178 | 179 |
179 // Make sure that the foo webui handler does not get created when we try to | 180 // Make sure that the foo webui handler does not get created when we try to |
180 // load it inside the iframe of the login ui. | 181 // load it inside the iframe of the login ui. |
181 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) { | 182 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) { |
182 GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false). | 183 GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false). |
183 Resolve("?source=0&frameUrl=chrome://foo"); | 184 Resolve("?source=0&frameUrl=chrome://foo"); |
184 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0); | 185 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0); |
185 ui_test_utils::NavigateToURL(browser(), url); | 186 ui_test_utils::NavigateToURL(browser(), url); |
186 } | 187 } |
187 | 188 |
| 189 // Flaky on CrOS, http://crbug.com/364759. |
| 190 #if defined(OS_CHROMEOS) |
| 191 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed |
| 192 #else |
| 193 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed |
| 194 #endif |
| 195 |
188 // Make sure that the gaia iframe cannot trigger top-frame navigation. | 196 // Make sure that the gaia iframe cannot trigger top-frame navigation. |
189 // TODO(guohui): flaky on trybot crbug/364759. | 197 // TODO(guohui): flaky on trybot crbug/364759. |
190 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 198 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
191 DISABLED_TopFrameNavigationDisallowed) { | 199 MAYBE_TopFrameNavigationDisallowed) { |
192 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 200 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
193 // Loads into gaia iframe a web page that attempts to deframe on load. | 201 // Loads into gaia iframe a web page that attempts to deframe on load. |
194 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); | 202 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); |
195 GURL url(net::AppendOrReplaceQueryParameter( | 203 GURL url(net::AppendOrReplaceQueryParameter( |
196 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), | 204 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), |
197 "frameUrl", deframe_url.spec())); | 205 "frameUrl", deframe_url.spec())); |
198 ui_test_utils::NavigateToURL(browser(), url); | 206 ui_test_utils::NavigateToURL(browser(), url); |
199 WaitUntilUIReady(); | 207 WaitUntilUIReady(); |
200 | 208 |
201 content::WebContents* contents = | 209 content::WebContents* contents = |
202 browser()->tab_strip_model()->GetActiveWebContents(); | 210 browser()->tab_strip_model()->GetActiveWebContents(); |
203 EXPECT_EQ(url, contents->GetVisibleURL()); | 211 EXPECT_EQ(url, contents->GetVisibleURL()); |
204 | 212 |
205 content::NavigationController& controller = contents->GetController(); | 213 content::NavigationController& controller = contents->GetController(); |
206 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 214 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
207 } | 215 } |
| 216 |
| 217 // Flaky on CrOS, http://crbug.com/364759. |
| 218 #if defined(OS_CHROMEOS) |
| 219 #define MAYBE_NavigationToOtherChromeURLDisallowed \ |
| 220 DISABLED_NavigationToOtherChromeURLDisallowed |
| 221 #else |
| 222 #define MAYBE_NavigationToOtherChromeURLDisallowed \ |
| 223 NavigationToOtherChromeURLDisallowed |
| 224 #endif |
| 225 |
| 226 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 227 MAYBE_NavigationToOtherChromeURLDisallowed) { |
| 228 ui_test_utils::NavigateToURL( |
| 229 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); |
| 230 WaitUntilUIReady(); |
| 231 |
| 232 content::WebContents* contents = |
| 233 browser()->tab_strip_model()->GetActiveWebContents(); |
| 234 ASSERT_TRUE(content::ExecuteScript( |
| 235 contents, "window.location.href = 'chrome://foo'")); |
| 236 |
| 237 content::TestNavigationObserver navigation_observer(contents, 1); |
| 238 navigation_observer.Wait(); |
| 239 |
| 240 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); |
| 241 } |
OLD | NEW |