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 "base/command_line.h" |
| 6 #include "base/prefs/pref_service.h" | |
| 7 #include "base/prefs/scoped_user_pref_update.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/content_settings/cookie_settings.h" | |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 6 #include "chrome/browser/signin/signin_promo.h" | 11 #include "chrome/browser/signin/signin_promo.h" |
| 7 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" | |
| 9 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 15 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
| 10 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" | 18 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
| 13 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/grit/chromium_strings.h" | |
| 22 #include "chrome/grit/generated_resources.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/test_browser_window.h" | 24 #include "chrome/test/base/test_browser_window.h" |
| 17 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 25 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "components/signin/core/browser/signin_manager.h" | |
| 20 #include "components/signin/core/common/profile_management_switches.h" | 29 #include "components/signin/core/common/profile_management_switches.h" |
| 30 #include "components/signin/core/common/signin_pref_names.h" | |
| 21 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/session_storage_namespace.h" | 33 #include "content/public/browser/session_storage_namespace.h" |
| 24 #include "content/public/browser/storage_partition.h" | 34 #include "content/public/browser/storage_partition.h" |
| 25 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_ui_controller.h" | 36 #include "content/public/browser/web_ui_controller.h" |
| 27 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/public/test/test_navigation_observer.h" | 39 #include "content/public/test/test_navigation_observer.h" |
| 30 #include "extensions/browser/guest_view/guest_view_manager.h" | 40 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 31 #include "google_apis/gaia/fake_gaia.h" | 41 #include "google_apis/gaia/fake_gaia.h" |
| 32 #include "google_apis/gaia/gaia_switches.h" | 42 #include "google_apis/gaia/gaia_switches.h" |
| 33 #include "net/base/url_util.h" | 43 #include "net/base/url_util.h" |
| 34 #include "net/test/embedded_test_server/embedded_test_server.h" | 44 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 35 #include "net/test/embedded_test_server/http_request.h" | 45 #include "net/test/embedded_test_server/http_request.h" |
| 36 #include "net/test/embedded_test_server/http_response.h" | 46 #include "net/test/embedded_test_server/http_response.h" |
| 37 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
| 49 #include "ui/base/l10n/l10n_util.h" | |
| 39 | 50 |
| 40 using ::testing::_; | 51 using ::testing::_; |
| 52 using ::testing::AtLeast; | |
| 41 using ::testing::Invoke; | 53 using ::testing::Invoke; |
| 42 using ::testing::InvokeWithoutArgs; | 54 using ::testing::InvokeWithoutArgs; |
| 55 using ::testing::Return; | |
| 43 | 56 |
| 44 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame; | 57 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame; |
| 45 using login_ui_test_utils::WaitUntilUIReady; | 58 using login_ui_test_utils::WaitUntilUIReady; |
| 46 | 59 |
| 47 namespace { | 60 namespace { |
| 48 | 61 |
| 49 struct ContentInfo { | 62 struct ContentInfo { |
| 50 ContentInfo(content::WebContents* contents, | 63 ContentInfo(content::WebContents* contents, |
| 51 int pid, | 64 int pid, |
| 52 content::StoragePartition* storage_partition) { | 65 content::StoragePartition* storage_partition) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 content::WebContents* web_contents) { | 112 content::WebContents* web_contents) { |
| 100 set->insert(web_contents); | 113 set->insert(web_contents); |
| 101 return false; | 114 return false; |
| 102 } | 115 } |
| 103 | 116 |
| 104 } // namespace | 117 } // namespace |
| 105 | 118 |
| 106 class InlineLoginUIBrowserTest : public InProcessBrowserTest { | 119 class InlineLoginUIBrowserTest : public InProcessBrowserTest { |
| 107 public: | 120 public: |
| 108 InlineLoginUIBrowserTest() {} | 121 InlineLoginUIBrowserTest() {} |
| 122 | |
| 123 void SetUpSigninManager(const std::string& username); | |
| 124 void EnableSigninAllowed(bool enable); | |
| 125 void EnableOneClick(bool enable); | |
| 126 void AddEmailToOneClickRejectedList(const std::string& email); | |
| 127 void AllowSigninCookies(bool enable); | |
| 128 void SetAllowedUsernamePattern(const std::string& pattern); | |
| 129 | |
| 130 protected: | |
| 131 content::WebContents* web_contents() { return nullptr; } | |
| 109 }; | 132 }; |
| 110 | 133 |
| 134 void InlineLoginUIBrowserTest::SetUpSigninManager(const std::string& username) { | |
| 135 if (username.empty()) | |
| 136 return; | |
| 137 | |
| 138 SigninManagerBase* signin_manager = | |
| 139 SigninManagerFactory::GetForProfile(browser()->profile()); | |
| 140 signin_manager->SetAuthenticatedUsername(username); | |
| 141 } | |
| 142 | |
| 143 void InlineLoginUIBrowserTest::EnableSigninAllowed(bool enable) { | |
| 144 PrefService* pref_service = browser()->profile()->GetPrefs(); | |
| 145 pref_service->SetBoolean(prefs::kSigninAllowed, enable); | |
| 146 } | |
| 147 | |
| 148 void InlineLoginUIBrowserTest::EnableOneClick(bool enable) { | |
| 149 PrefService* pref_service = browser()->profile()->GetPrefs(); | |
| 150 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, enable); | |
| 151 } | |
| 152 | |
| 153 void InlineLoginUIBrowserTest::AddEmailToOneClickRejectedList( | |
| 154 const std::string& email) { | |
| 155 PrefService* pref_service = browser()->profile()->GetPrefs(); | |
| 156 ListPrefUpdate updater(pref_service, | |
| 157 prefs::kReverseAutologinRejectedEmailList); | |
| 158 updater->AppendIfNotPresent(new base::StringValue(email)); | |
| 159 } | |
| 160 | |
| 161 void InlineLoginUIBrowserTest::AllowSigninCookies(bool enable) { | |
| 162 CookieSettings* cookie_settings = | |
| 163 CookieSettings::Factory::GetForProfile(browser()->profile()).get(); | |
| 164 cookie_settings->SetDefaultCookieSetting(enable ? CONTENT_SETTING_ALLOW | |
| 165 : CONTENT_SETTING_BLOCK); | |
| 166 } | |
| 167 | |
| 168 void InlineLoginUIBrowserTest::SetAllowedUsernamePattern( | |
| 169 const std::string& pattern) { | |
| 170 PrefService* local_state = g_browser_process->local_state(); | |
| 171 local_state->SetString(prefs::kGoogleServicesUsernamePattern, pattern); | |
| 172 } | |
| 173 | |
| 111 #if defined(OS_LINUX) || defined(OS_WIN) | 174 #if defined(OS_LINUX) || defined(OS_WIN) |
| 112 // crbug.com/422868 | 175 // crbug.com/422868 |
| 113 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId | 176 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId |
| 114 #else | 177 #else |
| 115 #define MAYBE_DifferentStorageId DifferentStorageId | 178 #define MAYBE_DifferentStorageId DifferentStorageId |
| 116 #endif | 179 #endif |
| 117 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) { | 180 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) { |
| 118 if (switches::IsEnableWebviewBasedSignin()) { | 181 if (switches::IsEnableWebviewBasedSignin()) { |
| 119 ContentInfo info = NavigateAndGetInfo( | 182 ContentInfo info = NavigateAndGetInfo( |
| 120 browser(), | 183 browser(), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB); | 240 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB); |
| 178 ContentInfo info3 = NavigateAndGetInfo( | 241 ContentInfo info3 = NavigateAndGetInfo( |
| 179 browser(), | 242 browser(), |
| 180 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), | 243 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), |
| 181 CURRENT_TAB); | 244 CURRENT_TAB); |
| 182 | 245 |
| 183 ASSERT_EQ(info1.pid, info2.pid); | 246 ASSERT_EQ(info1.pid, info2.pid); |
| 184 ASSERT_NE(info1.pid, info3.pid); | 247 ASSERT_NE(info1.pid, info3.pid); |
| 185 } | 248 } |
| 186 | 249 |
| 250 #if !defined(OS_CHROMEOS) | |
| 251 | |
| 252 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferNoProfile) { | |
| 253 std::string error_message; | |
| 254 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( | |
| 255 NULL, InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 256 "user@gmail.com", &error_message)); | |
|
noms (inactive)
2015/02/25 15:44:02
super optional nit: make this, and foo@gmail.com c
Roger Tawa OOO till Jul 10th
2015/02/25 19:05:07
I think I'll leave it like this, I think the tests
| |
| 257 EXPECT_EQ("", error_message); | |
| 258 } | |
| 259 | |
| 260 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOffer) { | |
| 261 EnableOneClick(true); | |
| 262 EXPECT_TRUE(InlineLoginHandlerImpl::CanOffer( | |
| 263 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 264 "user@gmail.com", NULL)); | |
| 265 | |
| 266 EnableOneClick(false); | |
| 267 | |
| 268 std::string error_message; | |
| 269 | |
| 270 EXPECT_TRUE(InlineLoginHandlerImpl::CanOffer( | |
| 271 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 272 "user@gmail.com", &error_message)); | |
| 273 } | |
| 274 | |
| 275 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferProfileConnected) { | |
| 276 SetUpSigninManager("foo@gmail.com"); | |
| 277 EnableSigninAllowed(true); | |
| 278 | |
| 279 std::string error_message; | |
| 280 | |
| 281 EXPECT_TRUE(InlineLoginHandlerImpl::CanOffer( | |
| 282 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 283 "foo@gmail.com", &error_message)); | |
| 284 EXPECT_TRUE(InlineLoginHandlerImpl::CanOffer( | |
| 285 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 286 "foo", &error_message)); | |
| 287 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( | |
| 288 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 289 "user@gmail.com", &error_message)); | |
| 290 EXPECT_EQ(l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL, | |
| 291 base::UTF8ToUTF16("foo@gmail.com")), | |
| 292 error_message); | |
| 293 } | |
| 294 | |
| 295 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferUsernameNotAllowed) { | |
| 296 SetAllowedUsernamePattern("*.google.com"); | |
| 297 | |
| 298 std::string error_message; | |
| 299 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( | |
| 300 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 301 "foo@gmail.com", &error_message)); | |
| 302 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SYNC_LOGIN_NAME_PROHIBITED), | |
| 303 error_message); | |
| 304 } | |
| 305 | |
| 306 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferWithRejectedEmail) { | |
| 307 EnableSigninAllowed(true); | |
| 308 | |
| 309 AddEmailToOneClickRejectedList("foo@gmail.com"); | |
| 310 AddEmailToOneClickRejectedList("user@gmail.com"); | |
| 311 | |
| 312 std::string error_message; | |
| 313 EXPECT_TRUE(InlineLoginHandlerImpl::CanOffer( | |
| 314 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 315 "foo@gmail.com", &error_message)); | |
| 316 EXPECT_TRUE(InlineLoginHandlerImpl::CanOffer( | |
| 317 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 318 "user@gmail.com", &error_message)); | |
| 319 } | |
| 320 | |
| 321 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, CanOfferNoSigninCookies) { | |
| 322 AllowSigninCookies(false); | |
| 323 EnableSigninAllowed(true); | |
| 324 | |
| 325 std::string error_message; | |
| 326 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( | |
| 327 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, | |
| 328 "user@gmail.com", &error_message)); | |
| 329 EXPECT_EQ("", error_message); | |
| 330 } | |
| 331 | |
| 332 #endif // OS_CHROMEOS | |
| 333 | |
| 187 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { | 334 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { |
| 188 public: | 335 public: |
| 189 FooWebUIProvider& foo_provider() { return foo_provider_; } | 336 FooWebUIProvider& foo_provider() { return foo_provider_; } |
| 190 | 337 |
| 191 private: | 338 private: |
| 192 void SetUp() override { | 339 void SetUp() override { |
| 193 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 340 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 194 | 341 |
| 195 // EmbeddedTestServer spawns a thread to initialize socket. | 342 // EmbeddedTestServer spawns a thread to initialize socket. |
| 196 // Stop IO thread in preparation for fork and exec. | 343 // Stop IO thread in preparation for fork and exec. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 ->AddObserver(&observer); | 466 ->AddObserver(&observer); |
| 320 base::RunLoop run_loop; | 467 base::RunLoop run_loop; |
| 321 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) | 468 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) |
| 322 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 469 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 323 | 470 |
| 324 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); | 471 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); |
| 325 run_loop.Run(); | 472 run_loop.Run(); |
| 326 base::MessageLoop::current()->RunUntilIdle(); | 473 base::MessageLoop::current()->RunUntilIdle(); |
| 327 } | 474 } |
| 328 #endif // OS_CHROMEOS | 475 #endif // OS_CHROMEOS |
| OLD | NEW |