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

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

Issue 1344443002: Implement new password separated sign in flow for chrome desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 2 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" 6 #include "base/prefs/pref_service.h"
7 #include "base/prefs/scoped_user_pref_update.h" 7 #include "base/prefs/scoped_user_pref_update.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/content_settings/cookie_settings_factory.h" 9 #include "chrome/browser/content_settings/cookie_settings_factory.h"
10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
11 #include "chrome/browser/signin/fake_signin_manager_builder.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
10 #include "chrome/browser/signin/signin_manager_factory.h" 13 #include "chrome/browser/signin/signin_manager_factory.h"
11 #include "chrome/browser/signin/signin_promo.h" 14 #include "chrome/browser/signin/signin_promo.h"
12 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" 17 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
15 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 18 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 19 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
18 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" 21 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
19 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/chromium_strings.h" 24 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
23 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/test_browser_window.h" 27 #include "chrome/test/base/test_browser_window.h"
25 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" 28 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
26 #include "chrome/test/base/testing_browser_process.h" 29 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
28 #include "components/content_settings/core/browser/cookie_settings.h" 31 #include "components/content_settings/core/browser/cookie_settings.h"
29 #include "components/guest_view/browser/guest_view_manager.h" 32 #include "components/guest_view/browser/guest_view_manager.h"
33 #include "components/keyed_service/content/browser_context_dependency_manager.h"
34 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
30 #include "components/signin/core/browser/signin_manager.h" 35 #include "components/signin/core/browser/signin_manager.h"
31 #include "components/signin/core/common/profile_management_switches.h" 36 #include "components/signin/core/common/profile_management_switches.h"
32 #include "components/signin/core/common/signin_pref_names.h" 37 #include "components/signin/core/common/signin_pref_names.h"
33 #include "content/public/browser/render_frame_host.h" 38 #include "content/public/browser/render_frame_host.h"
34 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
35 #include "content/public/browser/session_storage_namespace.h" 40 #include "content/public/browser/session_storage_namespace.h"
36 #include "content/public/browser/storage_partition.h" 41 #include "content/public/browser/storage_partition.h"
37 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
38 #include "content/public/browser/web_ui_controller.h" 43 #include "content/public/browser/web_ui_controller.h"
39 #include "content/public/common/url_constants.h" 44 #include "content/public/common/url_constants.h"
40 #include "content/public/test/browser_test_utils.h" 45 #include "content/public/test/browser_test_utils.h"
41 #include "content/public/test/test_navigation_observer.h" 46 #include "content/public/test/test_navigation_observer.h"
42 #include "google_apis/gaia/fake_gaia.h" 47 #include "google_apis/gaia/fake_gaia.h"
43 #include "google_apis/gaia/gaia_switches.h" 48 #include "google_apis/gaia/gaia_switches.h"
49 #include "google_apis/gaia/gaia_urls.h"
44 #include "net/base/url_util.h" 50 #include "net/base/url_util.h"
45 #include "net/test/embedded_test_server/embedded_test_server.h" 51 #include "net/test/embedded_test_server/embedded_test_server.h"
46 #include "net/test/embedded_test_server/http_request.h" 52 #include "net/test/embedded_test_server/http_request.h"
47 #include "net/test/embedded_test_server/http_response.h" 53 #include "net/test/embedded_test_server/http_response.h"
54 #include "net/url_request/test_url_fetcher_factory.h"
55 #include "net/url_request/url_request_status.h"
48 #include "testing/gmock/include/gmock/gmock.h" 56 #include "testing/gmock/include/gmock/gmock.h"
49 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
50 #include "ui/base/l10n/l10n_util.h" 58 #include "ui/base/l10n/l10n_util.h"
51 59
52 using ::testing::_; 60 using ::testing::_;
53 using ::testing::AtLeast; 61 using ::testing::AtLeast;
54 using ::testing::Invoke; 62 using ::testing::Invoke;
55 using ::testing::InvokeWithoutArgs; 63 using ::testing::InvokeWithoutArgs;
56 using ::testing::Return; 64 using ::testing::Return;
57 65
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 }; 117 };
110 118
111 const char kFooWebUIURL[] = "chrome://foo/"; 119 const char kFooWebUIURL[] = "chrome://foo/";
112 120
113 bool AddToSet(std::set<content::WebContents*>* set, 121 bool AddToSet(std::set<content::WebContents*>* set,
114 content::WebContents* web_contents) { 122 content::WebContents* web_contents) {
115 set->insert(web_contents); 123 set->insert(web_contents);
116 return false; 124 return false;
117 } 125 }
118 126
127 // This class is used to mock out virtual methods with side effects so that
128 // tests below can ensure they are called without causing the side effects.
achuithb 2015/10/02 21:51:07 s/the//
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 Done.
129 class MockInlineSigninHelper : public InlineSigninHelper {
130 public:
131 MockInlineSigninHelper(
132 base::WeakPtr<InlineLoginHandlerImpl> handler,
133 net::URLRequestContextGetter* getter,
134 Profile* profile,
135 const GURL& current_url,
136 const std::string& email,
137 const std::string& gaia_id,
138 const std::string& password,
139 const std::string& session_index,
140 const std::string& auth_code,
141 const std::string& signin_scoped_device_id,
142 bool choose_what_to_sync,
143 bool confirm_untrusted_signin);
144
145 MOCK_METHOD1(OnClientOAuthSuccess, void(const ClientOAuthResult& result));
146 MOCK_METHOD1(OnClientOAuthFailure, void(const GoogleServiceAuthError& error));
147 MOCK_METHOD6(CreateSyncStarter,
148 void(Browser*,
149 content::WebContents*,
150 const GURL&,
151 const std::string&,
152 OneClickSigninSyncStarter::StartSyncMode,
153 OneClickSigninSyncStarter::ConfirmationRequired));
154
155 private:
156 DISALLOW_COPY_AND_ASSIGN(MockInlineSigninHelper);
157 };
158
159 MockInlineSigninHelper::MockInlineSigninHelper(
160 base::WeakPtr<InlineLoginHandlerImpl> handler,
161 net::URLRequestContextGetter* getter,
162 Profile* profile,
163 const GURL& current_url,
164 const std::string& email,
165 const std::string& gaia_id,
166 const std::string& password,
167 const std::string& session_index,
168 const std::string& auth_code,
169 const std::string& signin_scoped_device_id,
170 bool choose_what_to_sync,
171 bool confirm_untrusted_signin)
172 : InlineSigninHelper(handler,
173 getter,
174 profile,
175 current_url,
176 email,
177 gaia_id,
178 password,
179 session_index,
180 auth_code,
181 signin_scoped_device_id,
182 choose_what_to_sync,
183 confirm_untrusted_signin) {}
184
185 // This class is used to mock out virtual methods with side effects so that
186 // tests below can ensure they are called without causing the side effects.
achuithb 2015/10/02 21:51:06 s/the//
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 Done.
187 class MockSyncStarterInlineSigninHelper : public InlineSigninHelper {
188 public:
189 MockSyncStarterInlineSigninHelper(
190 base::WeakPtr<InlineLoginHandlerImpl> handler,
191 net::URLRequestContextGetter* getter,
192 Profile* profile,
193 const GURL& current_url,
194 const std::string& email,
195 const std::string& gaia_id,
196 const std::string& password,
197 const std::string& session_index,
198 const std::string& auth_code,
199 const std::string& signin_scoped_device_id,
200 bool choose_what_to_sync,
201 bool confirm_untrusted_signin);
202
203 MOCK_METHOD6(CreateSyncStarter,
204 void(Browser*,
205 content::WebContents*,
206 const GURL&,
207 const std::string&,
208 OneClickSigninSyncStarter::StartSyncMode,
209 OneClickSigninSyncStarter::ConfirmationRequired));
210
211 private:
212 DISALLOW_COPY_AND_ASSIGN(MockSyncStarterInlineSigninHelper);
213 };
214
215 MockSyncStarterInlineSigninHelper::MockSyncStarterInlineSigninHelper(
216 base::WeakPtr<InlineLoginHandlerImpl> handler,
217 net::URLRequestContextGetter* getter,
218 Profile* profile,
219 const GURL& current_url,
220 const std::string& email,
221 const std::string& gaia_id,
222 const std::string& password,
223 const std::string& session_index,
224 const std::string& auth_code,
225 const std::string& signin_scoped_device_id,
226 bool choose_what_to_sync,
227 bool confirm_untrusted_signin)
228 : InlineSigninHelper(handler,
229 getter,
230 profile,
231 current_url,
232 email,
233 gaia_id,
234 password,
235 session_index,
236 auth_code,
237 signin_scoped_device_id,
238 choose_what_to_sync,
239 confirm_untrusted_signin) {}
240
119 } // namespace 241 } // namespace
120 242
121 class InlineLoginUIBrowserTest : public InProcessBrowserTest { 243 class InlineLoginUIBrowserTest : public InProcessBrowserTest {
122 public: 244 public:
123 InlineLoginUIBrowserTest() {} 245 InlineLoginUIBrowserTest() {}
124 246
125 void SetUpSigninManager(const std::string& username); 247 void SetUpSigninManager(const std::string& username);
126 void EnableSigninAllowed(bool enable); 248 void EnableSigninAllowed(bool enable);
127 void EnableOneClick(bool enable); 249 void EnableOneClick(bool enable);
128 void AddEmailToOneClickRejectedList(const std::string& email); 250 void AddEmailToOneClickRejectedList(const std::string& email);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 AllowSigninCookies(false); 445 AllowSigninCookies(false);
324 EnableSigninAllowed(true); 446 EnableSigninAllowed(true);
325 447
326 std::string error_message; 448 std::string error_message;
327 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer( 449 EXPECT_FALSE(InlineLoginHandlerImpl::CanOffer(
328 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL, 450 browser()->profile(), InlineLoginHandlerImpl::CAN_OFFER_FOR_ALL,
329 "12345", "user@gmail.com", &error_message)); 451 "12345", "user@gmail.com", &error_message));
330 EXPECT_EQ("", error_message); 452 EXPECT_EQ("", error_message);
331 } 453 }
332 454
455 class InlineLoginHelperBrowserTest : public InProcessBrowserTest {
456 public:
457 InlineLoginHelperBrowserTest() {}
458
459 void SetUpInProcessBrowserTestFixture() override {
460 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
461
462 will_create_browser_context_services_subscription_ =
463 BrowserContextDependencyManager::GetInstance()
464 ->RegisterWillCreateBrowserContextServicesCallbackForTesting(
465 base::Bind(&InlineLoginHelperBrowserTest::
466 OnWillCreateBrowserContextServices,
467 base::Unretained(this)))
468 .Pass();
469 }
470
471 void OnWillCreateBrowserContextServices(content::BrowserContext* context) {
472 // Replace the signin manager and token service with fakes. Do this ahead of
473 // creating the browser so that a bunch of classes don't register as
474 // observers and end up needing to unregister when the fake is substituted.
475 SigninManagerFactory::GetInstance()->SetTestingFactory(
476 context, &BuildFakeSigninManagerBase);
477 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
478 context, &BuildFakeProfileOAuth2TokenService);
479 }
480
481 void SetUpOnMainThread() override {
482 InProcessBrowserTest::SetUpOnMainThread();
483
484 // Grab references to the fake signin manager and token service.
485 Profile* profile = browser()->profile();
486 signin_manager_ = static_cast<FakeSigninManagerForTesting*>(
487 SigninManagerFactory::GetInstance()->GetForProfile(profile));
488 ASSERT_TRUE(signin_manager_);
489 token_service_ = static_cast<FakeProfileOAuth2TokenService*>(
490 ProfileOAuth2TokenServiceFactory::GetInstance()->GetForProfile(
491 profile));
492 ASSERT_TRUE(token_service_);
493 }
494
495 void SimulateStartCookieForOAuthLoginTokenExchangeSuccess(
496 const std::string& cookie_string) {
497 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
498 ASSERT_TRUE(fetcher);
499 net::ResponseCookies cookies;
500 cookies.push_back(cookie_string);
501 fetcher->set_status(net::URLRequestStatus());
502 fetcher->set_response_code(net::HTTP_OK);
503 fetcher->set_cookies(cookies);
504 fetcher->delegate()->OnURLFetchComplete(fetcher);
505 }
506
507 void SimulateStartAuthCodeForOAuth2TokenExchangeSuccess(
508 const std::string& json_response) {
509 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
510 ASSERT_TRUE(fetcher);
511 fetcher->set_status(net::URLRequestStatus());
512 fetcher->set_response_code(net::HTTP_OK);
513 fetcher->SetResponseString(json_response);
514 fetcher->delegate()->OnURLFetchComplete(fetcher);
515 }
516
517 void SimulateOnClientOAuthSuccess(GaiaAuthConsumer* consumer,
518 const std::string& refresh_token) {
519 GaiaAuthConsumer::ClientOAuthResult result;
520 result.refresh_token = refresh_token;
521 consumer->OnClientOAuthSuccess(result);
522 }
523
524 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
525 FakeProfileOAuth2TokenService* token_service() { return token_service_; }
526
527 private:
528 net::TestURLFetcherFactory url_fetcher_factory_;
529 FakeSigninManagerForTesting* signin_manager_;
530 FakeProfileOAuth2TokenService* token_service_;
531 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription>
532 will_create_browser_context_services_subscription_;
533
534 DISALLOW_COPY_AND_ASSIGN(InlineLoginHelperBrowserTest);
535 };
536
537 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, WithSessionIndex) {
achuithb 2015/10/02 21:51:06 Please add a comment for this and all new tests wh
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 Done.
538 base::WeakPtr<InlineLoginHandlerImpl> handler;
539 MockInlineSigninHelper helper(handler,
540 browser()->profile()->GetRequestContext(),
541 browser()->profile(),
542 GURL(),
543 "foo@gmail.com",
544 "gaiaid-12345",
545 "password",
546 "0", // session index from above
547 std::string(), // auth code
548 std::string(),
549 false, // choose what to sync
550 false); // confirm untrusted signin
551 EXPECT_CALL(helper, OnClientOAuthSuccess(_));
552
553 SimulateStartCookieForOAuthLoginTokenExchangeSuccess(
554 "secure; httponly; oauth_code=code");
555 SimulateStartAuthCodeForOAuth2TokenExchangeSuccess(
556 "{\"access_token\": \"access_token\", \"expires_in\": 1234567890,"
557 " \"refresh_token\": \"refresh_token\"}");
558 }
559
560 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest, WithAuthCode) {
561 base::WeakPtr<InlineLoginHandlerImpl> handler;
562 MockInlineSigninHelper helper(handler,
563 browser()->profile()->GetRequestContext(),
564 browser()->profile(),
565 GURL(),
566 "foo@gmail.com",
567 "gaiaid-12345",
568 "password",
569 "", // session index
570 "auth_code", // auth code
571 std::string(),
572 false, // choose what to sync
573 false); // confirm untrusted signin
574 EXPECT_CALL(helper, OnClientOAuthSuccess(_));
575
576 SimulateStartAuthCodeForOAuth2TokenExchangeSuccess(
577 "{\"access_token\": \"access_token\", \"expires_in\": 1234567890,"
578 " \"refresh_token\": \"refresh_token\"}");
579 }
580
581 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest,
582 SigninCreatesSyncStarter1) {
583 // See Source enum in components/signin/core/browser/signin_metrics.h for
584 // possible values of source=.
achuithb 2015/10/02 21:51:06 Could we also add a comment saying that source 0 i
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 I'd rather not duplicate that info here, which is
585 GURL url("chrome://chrome-signin/?source=0");
586 base::WeakPtr<InlineLoginHandlerImpl> handler;
587 // MockSyncStarterInlineSigninHelper will delete itself when done using
588 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But
589 // do need the RunUntilIdle() at the end.
590 MockSyncStarterInlineSigninHelper* helper =
591 new MockSyncStarterInlineSigninHelper(
592 handler,
593 browser()->profile()->GetRequestContext(),
594 browser()->profile(),
595 url,
596 "foo@gmail.com",
597 "gaiaid-12345",
598 "password",
599 "", // session index
600 "auth_code", // auth code
601 std::string(),
602 false, // choose what to sync
603 false); // confirm untrusted signin
604 EXPECT_CALL(*helper, CreateSyncStarter(
605 _, _, _, "refresh_token",
606 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST,
607 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN));
608
609 SimulateOnClientOAuthSuccess(helper, "refresh_token");
610 base::MessageLoop::current()->RunUntilIdle();
611 }
612
613 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest,
614 SigninCreatesSyncStarter2) {
615 // See Source enum in components/signin/core/browser/signin_metrics.h for
616 // possible values of source=.
617 GURL url("chrome://chrome-signin/?source=0");
achuithb 2015/10/02 21:51:07 const
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 Done.
618 base::WeakPtr<InlineLoginHandlerImpl> handler;
619 // MockSyncStarterInlineSigninHelper will delete itself when done using
620 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But
621 // do need the RunUntilIdle() at the end.
622 MockSyncStarterInlineSigninHelper* helper =
623 new MockSyncStarterInlineSigninHelper(
624 handler,
625 browser()->profile()->GetRequestContext(),
626 browser()->profile(),
627 url,
628 "foo@gmail.com",
629 "gaiaid-12345",
630 "password",
631 "", // session index
632 "auth_code", // auth code
633 std::string(),
634 true, // choose what to sync
635 false); // confirm untrusted signin
636 EXPECT_CALL(*helper, CreateSyncStarter(
637 _, _, _, "refresh_token",
638 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST,
639 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN));
640
641 SimulateOnClientOAuthSuccess(helper, "refresh_token");
642 base::MessageLoop::current()->RunUntilIdle();
643 }
644
645 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest,
646 SigninCreatesSyncStarter3) {
647 // See Source enum in components/signin/core/browser/signin_metrics.h for
648 // possible values of source=.
649 GURL url("chrome://chrome-signin/?source=0");
650 base::WeakPtr<InlineLoginHandlerImpl> handler;
651 // MockSyncStarterInlineSigninHelper will delete itself when done using
652 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But
653 // do need the RunUntilIdle() at the end.
654 MockSyncStarterInlineSigninHelper* helper =
655 new MockSyncStarterInlineSigninHelper(
656 handler,
657 browser()->profile()->GetRequestContext(),
658 browser()->profile(),
659 url,
660 "foo@gmail.com",
661 "gaiaid-12345",
662 "password",
663 "", // session index
664 "auth_code", // auth code
665 std::string(),
666 false, // choose what to sync
667 true); // confirm untrusted signin
668 EXPECT_CALL(*helper, CreateSyncStarter(
669 _, _, _, "refresh_token",
670 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST,
671 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN));
672
673 SimulateOnClientOAuthSuccess(helper, "refresh_token");
674 base::MessageLoop::current()->RunUntilIdle();
675 }
676
677 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest,
678 SigninCreatesSyncStarter4) {
679 // See Source enum in components/signin/core/browser/signin_metrics.h for
680 // possible values of source=.
681 GURL url("chrome://chrome-signin/?source=3");
achuithb 2015/10/02 21:51:06 comment that this is settings
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 Done.
682 base::WeakPtr<InlineLoginHandlerImpl> handler;
683 // MockSyncStarterInlineSigninHelper will delete itself when done using
684 // base::ThreadTaskRunnerHandle::DeleteSoon(), so need to delete here. But
685 // do need the RunUntilIdle() at the end.
686 MockSyncStarterInlineSigninHelper* helper =
687 new MockSyncStarterInlineSigninHelper(
688 handler,
689 browser()->profile()->GetRequestContext(),
690 browser()->profile(),
691 url,
692 "foo@gmail.com",
693 "gaiaid-12345",
694 "password",
695 "", // session index
696 "auth_code", // auth code
697 std::string(),
698 false, // choose what to sync
699 false); // confirm untrusted signin
700
701 // Even though "choose what to sync" is false, the source of the URL is
702 // settings, which means the user wants to CONFIGURE_SYNC_FIRST.
703 EXPECT_CALL(*helper, CreateSyncStarter(
704 _, _, _, "refresh_token",
705 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST,
706 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN));
707
708 SimulateOnClientOAuthSuccess(helper, "refresh_token");
709 base::MessageLoop::current()->RunUntilIdle();
710 }
711
712 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest,
713 ReauthCallsUpdateCredentials) {
714 ASSERT_EQ(0ul, token_service()->GetAccounts().size());
715
716 // See Source enum in components/signin/core/browser/signin_metrics.h for
717 // possible values of source=.
718 GURL url("chrome://chrome-signin/?source=11");
achuithb 2015/10/02 21:51:06 comment that this is Reauth
Roger Tawa OOO till Jul 10th 2015/10/05 12:18:59 Done in function comment.
719 base::WeakPtr<InlineLoginHandlerImpl> handler;
720 InlineSigninHelper helper(handler,
721 browser()->profile()->GetRequestContext(),
722 browser()->profile(),
723 url,
724 "foo@gmail.com",
725 "gaiaid-12345",
726 "password",
727 "", // session index
728 "auth_code", // auth code
729 std::string(),
730 false, // choose what to sync
731 false); // confirm untrusted signin
732 SimulateOnClientOAuthSuccess(&helper, "refresh_token");
733 ASSERT_EQ(1ul, token_service()->GetAccounts().size());
734 base::MessageLoop::current()->RunUntilIdle();
735 }
736
737 IN_PROC_BROWSER_TEST_F(InlineLoginHelperBrowserTest,
738 AddAccountsCallsUpdateCredentials) {
739 ASSERT_EQ(0ul, token_service()->GetAccounts().size());
740
741 // See Source enum in components/signin/core/browser/signin_metrics.h for
742 // possible values of source=.
743 GURL url("chrome://chrome-signin/?source=9");
744 base::WeakPtr<InlineLoginHandlerImpl> handler;
745 InlineSigninHelper helper(handler,
746 browser()->profile()->GetRequestContext(),
747 browser()->profile(),
748 url,
749 "foo@gmail.com",
750 "gaiaid-12345",
751 "password",
752 "", // session index
753 "auth_code", // auth code
754 std::string(),
755 false, // choose what to sync
756 false); // confirm untrusted signin
757 SimulateOnClientOAuthSuccess(&helper, "refresh_token");
758 ASSERT_EQ(1ul, token_service()->GetAccounts().size());
759 base::MessageLoop::current()->RunUntilIdle();
760 }
761
333 #endif // OS_CHROMEOS 762 #endif // OS_CHROMEOS
334 763
335 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { 764 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
336 public: 765 public:
337 FooWebUIProvider& foo_provider() { return foo_provider_; } 766 FooWebUIProvider& foo_provider() { return foo_provider_; }
338 767
339 private: 768 private:
340 void SetUp() override { 769 void SetUp() override {
341 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 770 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
342 771
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 ->AddObserver(&observer); 896 ->AddObserver(&observer);
468 base::RunLoop run_loop; 897 base::RunLoop run_loop;
469 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) 898 EXPECT_CALL(observer, OnUntrustedLoginUIShown())
470 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 899 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
471 900
472 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password"); 901 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password");
473 run_loop.Run(); 902 run_loop.Run();
474 base::MessageLoop::current()->RunUntilIdle(); 903 base::MessageLoop::current()->RunUntilIdle();
475 } 904 }
476 #endif // OS_CHROMEOS 905 #endif // OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698