Chromium Code Reviews| 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 "chrome/browser/signin/signin_promo.h" | 6 #include "chrome/browser/signin/signin_promo.h" |
| 6 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 7 #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" | |
| 10 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | |
| 11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
| 8 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/test_browser_window.h" | |
| 11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 16 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/browser/render_frame_host.h" | |
| 14 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/session_storage_namespace.h" | 21 #include "content/public/browser/session_storage_namespace.h" |
| 16 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
| 17 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_ui_controller.h" | 24 #include "content/public/browser/web_ui_controller.h" |
| 19 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 21 #include "content/public/test/test_navigation_observer.h" | 27 #include "content/public/test/test_navigation_observer.h" |
| 28 #include "google_apis/gaia/fake_gaia.h" | |
| 29 #include "google_apis/gaia/gaia_switches.h" | |
| 22 #include "net/base/url_util.h" | 30 #include "net/base/url_util.h" |
| 23 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #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_response.h" | |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 36 |
| 27 using ::testing::_; | 37 using ::testing::_; |
| 38 using ::testing::Invoke; | |
| 39 using ::testing::InvokeWithoutArgs; | |
| 28 | 40 |
| 29 namespace { | 41 namespace { |
| 30 | 42 |
| 31 struct ContentInfo { | 43 struct ContentInfo { |
| 32 ContentInfo(int pid, content::StoragePartition* storage_partition) { | 44 ContentInfo(int pid, content::StoragePartition* storage_partition) { |
| 33 this->pid = pid; | 45 this->pid = pid; |
| 34 this->storage_partition = storage_partition; | 46 this->storage_partition = storage_partition; |
| 35 } | 47 } |
| 36 | 48 |
| 37 int pid; | 49 int pid; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 58 | 70 |
| 59 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are | 71 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are |
| 60 // not called as expected. | 72 // not called as expected. |
| 61 class FooWebUIProvider | 73 class FooWebUIProvider |
| 62 : public TestChromeWebUIControllerFactory::WebUIProvider { | 74 : public TestChromeWebUIControllerFactory::WebUIProvider { |
| 63 public: | 75 public: |
| 64 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, | 76 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, |
| 65 const GURL& url)); | 77 const GURL& url)); |
| 66 }; | 78 }; |
| 67 | 79 |
| 80 class MockLoginUIObserver : public LoginUIService::Observer { | |
| 81 public: | |
| 82 MOCK_METHOD0(UntrustedSigninUIShown, void()); | |
| 83 }; | |
| 84 | |
| 68 const char kFooWebUIURL[] = "chrome://foo/"; | 85 const char kFooWebUIURL[] = "chrome://foo/"; |
| 69 | 86 |
| 70 } // namespace | 87 } // namespace |
| 71 | 88 |
| 72 class InlineLoginUIBrowserTest : public InProcessBrowserTest { | 89 class InlineLoginUIBrowserTest : public InProcessBrowserTest { |
| 73 public: | 90 public: |
| 74 InlineLoginUIBrowserTest() {} | 91 InlineLoginUIBrowserTest() {} |
| 75 }; | 92 }; |
| 76 | 93 |
| 77 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) { | 94 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 " handler();" | 157 " handler();" |
| 141 "else" | 158 "else" |
| 142 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); | 159 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); |
| 143 | 160 |
| 144 std::string message; | 161 std::string message; |
| 145 do { | 162 do { |
| 146 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 163 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 147 } while (message != "\"ready\""); | 164 } while (message != "\"ready\""); |
| 148 } | 165 } |
| 149 | 166 |
| 167 // Executes JavaScript code in the auth iframe hosted by gaia_auth extension. | |
| 168 void ExecuteJsInSigninFrame(const std::string& js) { | |
| 169 content::WebContents* web_contents = | |
| 170 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 171 ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthIframe( | |
| 172 web_contents, GURL(), "signin-frame"), js)); | |
| 173 } | |
| 174 | |
| 175 protected: | |
| 176 FakeGaia fake_gaia_; | |
| 177 | |
| 150 private: | 178 private: |
| 179 virtual void SetUp() OVERRIDE { | |
| 180 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 181 InProcessBrowserTest::SetUp(); | |
| 182 } | |
| 183 | |
| 151 virtual void SetUpOnMainThread() OVERRIDE { | 184 virtual void SetUpOnMainThread() OVERRIDE { |
| 185 embedded_test_server()->RegisterRequestHandler( | |
| 186 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); | |
| 187 | |
| 152 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 188 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
| 153 ChromeWebUIControllerFactory::GetInstance()); | 189 ChromeWebUIControllerFactory::GetInstance()); |
| 154 test_factory_.reset(new TestChromeWebUIControllerFactory); | 190 test_factory_.reset(new TestChromeWebUIControllerFactory); |
| 155 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); | 191 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); |
| 156 test_factory_->AddFactoryOverride( | 192 test_factory_->AddFactoryOverride( |
| 157 GURL(kFooWebUIURL).host(), &foo_provider_); | 193 GURL(kFooWebUIURL).host(), &foo_provider_); |
| 158 } | 194 } |
| 159 | 195 |
| 160 virtual void CleanUpOnMainThread() OVERRIDE { | 196 virtual void CleanUpOnMainThread() OVERRIDE { |
| 161 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host()); | 197 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host()); |
| 162 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 198 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
| 163 test_factory_.get()); | 199 test_factory_.get()); |
| 164 test_factory_.reset(); | 200 test_factory_.reset(); |
| 165 } | 201 } |
| 166 | 202 |
| 203 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 204 const GURL& base_url = embedded_test_server()->base_url(); | |
| 205 command_line->AppendSwitchASCII(::switches::kGaiaUrl, base_url.spec()); | |
| 206 command_line->AppendSwitchASCII(::switches::kLsoUrl, base_url.spec()); | |
| 207 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, | |
| 208 base_url.spec()); | |
| 209 fake_gaia_.Initialize(); | |
| 210 } | |
| 211 | |
| 167 FooWebUIProvider foo_provider_; | 212 FooWebUIProvider foo_provider_; |
| 213 // MockBrowserWindow mock_browser_window_; | |
|
Charlie Reis
2014/07/24 18:14:38
nit: Remove commented out code.
guohui
2014/07/24 19:37:18
Done.
| |
| 168 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; | 214 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; |
| 169 }; | 215 }; |
| 170 | 216 |
| 171 // Make sure that the foo webui handler is working properly and that it gets | 217 // Make sure that the foo webui handler is working properly and that it gets |
| 172 // created when navigated to normally. | 218 // created when navigated to normally. |
| 173 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { | 219 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { |
| 174 const GURL kUrl(kFooWebUIURL); | 220 const GURL kUrl(kFooWebUIURL); |
| 175 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) | 221 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) |
| 176 .WillOnce(ReturnNewWebUI()); | 222 .WillOnce(ReturnNewWebUI()); |
| 177 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL)); | 223 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 190 #if defined(OS_CHROMEOS) | 236 #if defined(OS_CHROMEOS) |
| 191 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed | 237 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed |
| 192 #else | 238 #else |
| 193 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed | 239 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed |
| 194 #endif | 240 #endif |
| 195 | 241 |
| 196 // Make sure that the gaia iframe cannot trigger top-frame navigation. | 242 // Make sure that the gaia iframe cannot trigger top-frame navigation. |
| 197 // TODO(guohui): flaky on trybot crbug/364759. | 243 // TODO(guohui): flaky on trybot crbug/364759. |
| 198 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 244 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
| 199 MAYBE_TopFrameNavigationDisallowed) { | 245 MAYBE_TopFrameNavigationDisallowed) { |
| 200 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 201 // Loads into gaia iframe a web page that attempts to deframe on load. | 246 // Loads into gaia iframe a web page that attempts to deframe on load. |
| 202 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); | 247 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); |
| 203 GURL url(net::AppendOrReplaceQueryParameter( | 248 GURL url(net::AppendOrReplaceQueryParameter( |
| 204 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), | 249 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), |
| 205 "frameUrl", deframe_url.spec())); | 250 "frameUrl", deframe_url.spec())); |
| 206 ui_test_utils::NavigateToURL(browser(), url); | 251 ui_test_utils::NavigateToURL(browser(), url); |
| 207 WaitUntilUIReady(); | 252 WaitUntilUIReady(); |
| 208 | 253 |
| 209 content::WebContents* contents = | 254 content::WebContents* contents = |
| 210 browser()->tab_strip_model()->GetActiveWebContents(); | 255 browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 232 content::WebContents* contents = | 277 content::WebContents* contents = |
| 233 browser()->tab_strip_model()->GetActiveWebContents(); | 278 browser()->tab_strip_model()->GetActiveWebContents(); |
| 234 ASSERT_TRUE(content::ExecuteScript( | 279 ASSERT_TRUE(content::ExecuteScript( |
| 235 contents, "window.location.href = 'chrome://foo'")); | 280 contents, "window.location.href = 'chrome://foo'")); |
| 236 | 281 |
| 237 content::TestNavigationObserver navigation_observer(contents, 1); | 282 content::TestNavigationObserver navigation_observer(contents, 1); |
| 238 navigation_observer.Wait(); | 283 navigation_observer.Wait(); |
| 239 | 284 |
| 240 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); | 285 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); |
| 241 } | 286 } |
| 287 | |
| 288 #if !defined(OS_CHROMEOS) | |
|
Charlie Reis
2014/07/24 18:14:38
Why doesn't this run on ChromeOS? Do we show the
guohui
2014/07/24 18:31:21
Because the confirmation dialog path in inline_log
xiyuan
2014/07/25 18:07:22
Cros mirror uses inline_login_handler_chromeos.cc.
guohui
2014/08/07 19:53:34
i think for CrOS there is more to clean up, curren
| |
| 289 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | |
| 290 ConfirmationRequiredForNonsecureSignin) { | |
|
Charlie Reis
2014/07/24 18:14:38
Which part of the test goes to an insecure page in
guohui
2014/07/24 18:31:21
Signin page has an embedded gaia iframe, which loa
Charlie Reis
2014/07/24 18:47:11
Ah, ok. Please explain that in a comment here, sin
guohui
2014/07/24 19:37:18
Done.
| |
| 291 fake_gaia_.SetFakeMergeSessionParamsForEmail("email"); | |
| 292 | |
| 293 ui_test_utils::NavigateToURL( | |
| 294 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); | |
| 295 WaitUntilUIReady(); | |
| 296 | |
| 297 MockLoginUIObserver observer; | |
| 298 LoginUIServiceFactory::GetForProfile(browser()->profile()) | |
| 299 ->AddObserver(&observer); | |
| 300 base::RunLoop run_loop; | |
| 301 EXPECT_CALL(observer, UntrustedSigninUIShown()) | |
| 302 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | |
| 303 | |
| 304 content::WebContents* contents = | |
| 305 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 306 std::string js = | |
| 307 "document.getElementById('Email').value = 'email';" | |
| 308 "document.getElementById('Passwd').value = 'password';" | |
| 309 "document.getElementById('signIn').click();"; | |
| 310 ExecuteJsInSigninFrame(js); | |
| 311 | |
| 312 run_loop.Run(); | |
| 313 } | |
| 314 #endif // OS_CHROMEOS | |
| OLD | NEW |