| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/signin/signin_promo.h" | 6 #include "chrome/browser/signin/signin_promo.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 9 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
| 10 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 10 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/test_browser_window.h" | 16 #include "chrome/test/base/test_browser_window.h" |
| 16 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 17 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 17 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/session_storage_namespace.h" | 22 #include "content/public/browser/session_storage_namespace.h" |
| 22 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_ui_controller.h" | 25 #include "content/public/browser/web_ui_controller.h" |
| 25 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 27 #include "content/public/test/test_navigation_observer.h" | 28 #include "content/public/test/test_navigation_observer.h" |
| 28 #include "google_apis/gaia/fake_gaia.h" | 29 #include "google_apis/gaia/fake_gaia.h" |
| 29 #include "google_apis/gaia/gaia_switches.h" | 30 #include "google_apis/gaia/gaia_switches.h" |
| 30 #include "net/base/url_util.h" | 31 #include "net/base/url_util.h" |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 32 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 #include "net/test/embedded_test_server/http_request.h" | 33 #include "net/test/embedded_test_server/http_request.h" |
| 33 #include "net/test/embedded_test_server/http_response.h" | 34 #include "net/test/embedded_test_server/http_response.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 37 |
| 37 using ::testing::_; | 38 using ::testing::_; |
| 38 using ::testing::Invoke; | 39 using ::testing::Invoke; |
| 39 using ::testing::InvokeWithoutArgs; | 40 using ::testing::InvokeWithoutArgs; |
| 40 | 41 |
| 42 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame; |
| 43 using login_ui_test_utils::WaitUntilUIReady; |
| 44 |
| 41 namespace { | 45 namespace { |
| 42 | 46 |
| 43 struct ContentInfo { | 47 struct ContentInfo { |
| 44 ContentInfo(int pid, content::StoragePartition* storage_partition) { | 48 ContentInfo(int pid, content::StoragePartition* storage_partition) { |
| 45 this->pid = pid; | 49 this->pid = pid; |
| 46 this->storage_partition = storage_partition; | 50 this->storage_partition = storage_partition; |
| 47 } | 51 } |
| 48 | 52 |
| 49 int pid; | 53 int pid; |
| 50 content::StoragePartition* storage_partition; | 54 content::StoragePartition* storage_partition; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 CURRENT_TAB); | 146 CURRENT_TAB); |
| 143 | 147 |
| 144 ASSERT_EQ(info1.pid, info2.pid); | 148 ASSERT_EQ(info1.pid, info2.pid); |
| 145 ASSERT_NE(info1.pid, info3.pid); | 149 ASSERT_NE(info1.pid, info3.pid); |
| 146 } | 150 } |
| 147 | 151 |
| 148 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { | 152 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { |
| 149 public: | 153 public: |
| 150 FooWebUIProvider& foo_provider() { return foo_provider_; } | 154 FooWebUIProvider& foo_provider() { return foo_provider_; } |
| 151 | 155 |
| 152 void WaitUntilUIReady() { | |
| 153 content::DOMMessageQueue message_queue; | |
| 154 ASSERT_TRUE(content::ExecuteScript( | |
| 155 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 156 "if (!inline.login.getAuthExtHost())" | |
| 157 " inline.login.initialize();" | |
| 158 "var handler = function() {" | |
| 159 " window.domAutomationController.setAutomationId(0);" | |
| 160 " window.domAutomationController.send('ready');" | |
| 161 "};" | |
| 162 "if (inline.login.isAuthReady())" | |
| 163 " handler();" | |
| 164 "else" | |
| 165 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); | |
| 166 | |
| 167 std::string message; | |
| 168 do { | |
| 169 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 170 } while (message != "\"ready\""); | |
| 171 } | |
| 172 | |
| 173 // Executes JavaScript code in the auth iframe hosted by gaia_auth extension. | |
| 174 void ExecuteJsInSigninFrame(const std::string& js) { | |
| 175 content::WebContents* web_contents = | |
| 176 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 177 ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthIframe( | |
| 178 web_contents, GURL(), "signin-frame"), js)); | |
| 179 } | |
| 180 | |
| 181 private: | 156 private: |
| 182 void SetUp() override { | 157 void SetUp() override { |
| 183 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 158 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 184 | 159 |
| 185 // EmbeddedTestServer spawns a thread to initialize socket. | 160 // EmbeddedTestServer spawns a thread to initialize socket. |
| 186 // Stop IO thread in preparation for fork and exec. | 161 // Stop IO thread in preparation for fork and exec. |
| 187 embedded_test_server()->StopThread(); | 162 embedded_test_server()->StopThread(); |
| 188 | 163 |
| 189 InProcessBrowserTest::SetUp(); | 164 InProcessBrowserTest::SetUp(); |
| 190 } | 165 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // Make sure that the gaia iframe cannot trigger top-frame navigation. | 223 // Make sure that the gaia iframe cannot trigger top-frame navigation. |
| 249 // TODO(guohui): flaky on trybot crbug/364759. | 224 // TODO(guohui): flaky on trybot crbug/364759. |
| 250 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 225 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 251 MAYBE_TopFrameNavigationDisallowed) { | 226 MAYBE_TopFrameNavigationDisallowed) { |
| 252 // Loads into gaia iframe a web page that attempts to deframe on load. | 227 // Loads into gaia iframe a web page that attempts to deframe on load. |
| 253 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); | 228 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); |
| 254 GURL url(net::AppendOrReplaceQueryParameter( | 229 GURL url(net::AppendOrReplaceQueryParameter( |
| 255 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), | 230 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), |
| 256 "frameUrl", deframe_url.spec())); | 231 "frameUrl", deframe_url.spec())); |
| 257 ui_test_utils::NavigateToURL(browser(), url); | 232 ui_test_utils::NavigateToURL(browser(), url); |
| 258 WaitUntilUIReady(); | 233 WaitUntilUIReady(browser()); |
| 259 | 234 |
| 260 content::WebContents* contents = | 235 content::WebContents* contents = |
| 261 browser()->tab_strip_model()->GetActiveWebContents(); | 236 browser()->tab_strip_model()->GetActiveWebContents(); |
| 262 EXPECT_EQ(url, contents->GetVisibleURL()); | 237 EXPECT_EQ(url, contents->GetVisibleURL()); |
| 263 | 238 |
| 264 content::NavigationController& controller = contents->GetController(); | 239 content::NavigationController& controller = contents->GetController(); |
| 265 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 240 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
| 266 } | 241 } |
| 267 | 242 |
| 268 // Flaky on CrOS, http://crbug.com/364759. | 243 // Flaky on CrOS, http://crbug.com/364759. |
| 269 #if defined(OS_CHROMEOS) | 244 #if defined(OS_CHROMEOS) |
| 270 #define MAYBE_NavigationToOtherChromeURLDisallowed \ | 245 #define MAYBE_NavigationToOtherChromeURLDisallowed \ |
| 271 DISABLED_NavigationToOtherChromeURLDisallowed | 246 DISABLED_NavigationToOtherChromeURLDisallowed |
| 272 #else | 247 #else |
| 273 #define MAYBE_NavigationToOtherChromeURLDisallowed \ | 248 #define MAYBE_NavigationToOtherChromeURLDisallowed \ |
| 274 NavigationToOtherChromeURLDisallowed | 249 NavigationToOtherChromeURLDisallowed |
| 275 #endif | 250 #endif |
| 276 | 251 |
| 277 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 252 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 278 MAYBE_NavigationToOtherChromeURLDisallowed) { | 253 MAYBE_NavigationToOtherChromeURLDisallowed) { |
| 279 ui_test_utils::NavigateToURL( | 254 ui_test_utils::NavigateToURL( |
| 280 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); | 255 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); |
| 281 WaitUntilUIReady(); | 256 WaitUntilUIReady(browser()); |
| 282 | 257 |
| 283 content::WebContents* contents = | 258 content::WebContents* contents = |
| 284 browser()->tab_strip_model()->GetActiveWebContents(); | 259 browser()->tab_strip_model()->GetActiveWebContents(); |
| 285 ASSERT_TRUE(content::ExecuteScript( | 260 ASSERT_TRUE(content::ExecuteScript( |
| 286 contents, "window.location.href = 'chrome://foo'")); | 261 contents, "window.location.href = 'chrome://foo'")); |
| 287 | 262 |
| 288 content::TestNavigationObserver navigation_observer(contents, 1); | 263 content::TestNavigationObserver navigation_observer(contents, 1); |
| 289 navigation_observer.Wait(); | 264 navigation_observer.Wait(); |
| 290 | 265 |
| 291 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); | 266 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); |
| 292 } | 267 } |
| 293 | 268 |
| 294 #if !defined(OS_CHROMEOS) | 269 #if !defined(OS_CHROMEOS) |
| 295 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 270 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 296 ConfirmationRequiredForNonsecureSignin) { | 271 ConfirmationRequiredForNonsecureSignin) { |
| 297 FakeGaia fake_gaia; | 272 FakeGaia fake_gaia; |
| 298 fake_gaia.Initialize(); | 273 fake_gaia.Initialize(); |
| 299 | 274 |
| 300 embedded_test_server()->RegisterRequestHandler( | 275 embedded_test_server()->RegisterRequestHandler( |
| 301 base::Bind(&FakeGaia::HandleRequest, | 276 base::Bind(&FakeGaia::HandleRequest, |
| 302 base::Unretained(&fake_gaia))); | 277 base::Unretained(&fake_gaia))); |
| 303 fake_gaia.SetFakeMergeSessionParams( | 278 fake_gaia.SetFakeMergeSessionParams( |
| 304 "email", "fake-sid-cookie", "fake-lsid-cookie"); | 279 "email", "fake-sid-cookie", "fake-lsid-cookie"); |
| 305 | 280 |
| 306 // Navigates to the Chrome signin page which loads the fake gaia auth page. | 281 // Navigates to the Chrome signin page which loads the fake gaia auth page. |
| 307 // Since the fake gaia auth page is served over HTTP, thus expects to see an | 282 // Since the fake gaia auth page is served over HTTP, thus expects to see an |
| 308 // untrusted signin confirmation dialog upon submitting credentials below. | 283 // untrusted signin confirmation dialog upon submitting credentials below. |
| 309 ui_test_utils::NavigateToURL( | 284 ui_test_utils::NavigateToURL( |
| 310 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); | 285 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); |
| 311 WaitUntilUIReady(); | 286 WaitUntilUIReady(browser()); |
| 312 | 287 |
| 313 MockLoginUIObserver observer; | 288 MockLoginUIObserver observer; |
| 314 LoginUIServiceFactory::GetForProfile(browser()->profile()) | 289 LoginUIServiceFactory::GetForProfile(browser()->profile()) |
| 315 ->AddObserver(&observer); | 290 ->AddObserver(&observer); |
| 316 base::RunLoop run_loop; | 291 base::RunLoop run_loop; |
| 317 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) | 292 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) |
| 318 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 293 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 319 | 294 |
| 320 std::string js = | 295 ExecuteJsToSigninInSigninFrame(browser(), "email", "password"); |
| 321 "document.getElementById('Email').value = 'email';" | |
| 322 "document.getElementById('Passwd').value = 'password';" | |
| 323 "document.getElementById('signIn').click();"; | |
| 324 ExecuteJsInSigninFrame(js); | |
| 325 | |
| 326 run_loop.Run(); | 296 run_loop.Run(); |
| 327 base::MessageLoop::current()->RunUntilIdle(); | 297 base::MessageLoop::current()->RunUntilIdle(); |
| 328 } | 298 } |
| 329 #endif // OS_CHROMEOS | 299 #endif // OS_CHROMEOS |
| OLD | NEW |