Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc

Issue 998513002: Revert of Remove OneClickSigninHelper since it is no longer used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ocl
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/signin/signin_promo.h" 6 #include "chrome/browser/signin/signin_promo.h"
12 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
15 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 9 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 10 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
18 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" 12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
19 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h"
23 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/test_browser_window.h" 16 #include "chrome/test/base/test_browser_window.h"
25 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" 17 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
26 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
28 #include "components/signin/core/browser/signin_manager.h"
29 #include "components/signin/core/common/profile_management_switches.h" 20 #include "components/signin/core/common/profile_management_switches.h"
30 #include "components/signin/core/common/signin_pref_names.h"
31 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
32 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/session_storage_namespace.h" 23 #include "content/public/browser/session_storage_namespace.h"
34 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
35 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/web_ui_controller.h" 26 #include "content/public/browser/web_ui_controller.h"
37 #include "content/public/common/url_constants.h" 27 #include "content/public/common/url_constants.h"
38 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
39 #include "content/public/test/test_navigation_observer.h" 29 #include "content/public/test/test_navigation_observer.h"
40 #include "extensions/browser/guest_view/guest_view_manager.h" 30 #include "extensions/browser/guest_view/guest_view_manager.h"
41 #include "google_apis/gaia/fake_gaia.h" 31 #include "google_apis/gaia/fake_gaia.h"
42 #include "google_apis/gaia/gaia_switches.h" 32 #include "google_apis/gaia/gaia_switches.h"
43 #include "net/base/url_util.h" 33 #include "net/base/url_util.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h" 34 #include "net/test/embedded_test_server/embedded_test_server.h"
45 #include "net/test/embedded_test_server/http_request.h" 35 #include "net/test/embedded_test_server/http_request.h"
46 #include "net/test/embedded_test_server/http_response.h" 36 #include "net/test/embedded_test_server/http_response.h"
47 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
48 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
49 #include "ui/base/l10n/l10n_util.h"
50 39
51 using ::testing::_; 40 using ::testing::_;
52 using ::testing::AtLeast;
53 using ::testing::Invoke; 41 using ::testing::Invoke;
54 using ::testing::InvokeWithoutArgs; 42 using ::testing::InvokeWithoutArgs;
55 using ::testing::Return;
56 43
57 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame; 44 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame;
58 using login_ui_test_utils::WaitUntilUIReady; 45 using login_ui_test_utils::WaitUntilUIReady;
59 46
60 namespace { 47 namespace {
61 48
62 struct ContentInfo { 49 struct ContentInfo {
63 ContentInfo(content::WebContents* contents, 50 ContentInfo(content::WebContents* contents,
64 int pid, 51 int pid,
65 content::StoragePartition* storage_partition) { 52 content::StoragePartition* storage_partition) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 content::WebContents* web_contents) { 99 content::WebContents* web_contents) {
113 set->insert(web_contents); 100 set->insert(web_contents);
114 return false; 101 return false;
115 } 102 }
116 103
117 } // namespace 104 } // namespace
118 105
119 class InlineLoginUIBrowserTest : public InProcessBrowserTest { 106 class InlineLoginUIBrowserTest : public InProcessBrowserTest {
120 public: 107 public:
121 InlineLoginUIBrowserTest() {} 108 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; }
132 }; 109 };
133 110
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
174 #if defined(OS_LINUX) || defined(OS_WIN) 111 #if defined(OS_LINUX) || defined(OS_WIN)
175 // crbug.com/422868 112 // crbug.com/422868
176 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId 113 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId
177 #else 114 #else
178 #define MAYBE_DifferentStorageId DifferentStorageId 115 #define MAYBE_DifferentStorageId DifferentStorageId
179 #endif 116 #endif
180 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) { 117 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) {
181 if (switches::IsEnableWebviewBasedSignin()) { 118 if (switches::IsEnableWebviewBasedSignin()) {
182 ContentInfo info = NavigateAndGetInfo( 119 ContentInfo info = NavigateAndGetInfo(
183 browser(), 120 browser(),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB); 177 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB);
241 ContentInfo info3 = NavigateAndGetInfo( 178 ContentInfo info3 = NavigateAndGetInfo(
242 browser(), 179 browser(),
243 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), 180 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false),
244 CURRENT_TAB); 181 CURRENT_TAB);
245 182
246 ASSERT_EQ(info1.pid, info2.pid); 183 ASSERT_EQ(info1.pid, info2.pid);
247 ASSERT_NE(info1.pid, info3.pid); 184 ASSERT_NE(info1.pid, info3.pid);
248 } 185 }
249 186
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));
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
334 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { 187 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
335 public: 188 public:
336 FooWebUIProvider& foo_provider() { return foo_provider_; } 189 FooWebUIProvider& foo_provider() { return foo_provider_; }
337 190
338 private: 191 private:
339 void SetUp() override { 192 void SetUp() override {
340 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 193 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
341 194
342 // EmbeddedTestServer spawns a thread to initialize socket. 195 // EmbeddedTestServer spawns a thread to initialize socket.
343 // Stop IO thread in preparation for fork and exec. 196 // Stop IO thread in preparation for fork and exec.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 ->AddObserver(&observer); 319 ->AddObserver(&observer);
467 base::RunLoop run_loop; 320 base::RunLoop run_loop;
468 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) 321 EXPECT_CALL(observer, OnUntrustedLoginUIShown())
469 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 322 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
470 323
471 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); 324 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password");
472 run_loop.Run(); 325 run_loop.Run();
473 base::MessageLoop::current()->RunUntilIdle(); 326 base::MessageLoop::current()->RunUntilIdle();
474 } 327 }
475 #endif // OS_CHROMEOS 328 #endif // OS_CHROMEOS
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_handler_impl.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698