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

Side by Side Diff: chrome/browser/chromeos/login/signin/oauth2_browsertest.cc

Issue 2663063002: Revert of cros: Test for overlapping ContinueSessionRestore calls (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
12 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
13 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" 14 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
16 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" 15 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
17 #include "chrome/browser/chromeos/login/signin_specifics.h" 16 #include "chrome/browser/chromeos/login/signin_specifics.h"
18 #include "chrome/browser/chromeos/login/startup_utils.h" 17 #include "chrome/browser/chromeos/login/startup_utils.h"
19 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" 18 #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
(...skipping 12 matching lines...) Expand all
32 #include "chromeos/login/auth/user_context.h" 31 #include "chromeos/login/auth/user_context.h"
33 #include "components/app_modal/javascript_app_modal_dialog.h" 32 #include "components/app_modal/javascript_app_modal_dialog.h"
34 #include "components/app_modal/native_app_modal_dialog.h" 33 #include "components/app_modal/native_app_modal_dialog.h"
35 #include "components/browser_sync/browser_sync_switches.h" 34 #include "components/browser_sync/browser_sync_switches.h"
36 #include "components/prefs/pref_service.h" 35 #include "components/prefs/pref_service.h"
37 #include "components/signin/core/account_id/account_id.h" 36 #include "components/signin/core/account_id/account_id.h"
38 #include "components/signin/core/browser/account_tracker_service.h" 37 #include "components/signin/core/browser/account_tracker_service.h"
39 #include "components/signin/core/browser/profile_oauth2_token_service.h" 38 #include "components/signin/core/browser/profile_oauth2_token_service.h"
40 #include "components/user_manager/user.h" 39 #include "components/user_manager/user.h"
41 #include "components/user_manager/user_manager.h" 40 #include "components/user_manager/user_manager.h"
42 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
44 #include "content/public/test/browser_test_utils.h" 42 #include "content/public/test/browser_test_utils.h"
45 #include "extensions/browser/process_manager.h" 43 #include "extensions/browser/process_manager.h"
46 #include "extensions/test/extension_test_message_listener.h" 44 #include "extensions/test/extension_test_message_listener.h"
47 #include "extensions/test/result_catcher.h" 45 #include "extensions/test/result_catcher.h"
48 #include "google_apis/gaia/gaia_constants.h" 46 #include "google_apis/gaia/gaia_constants.h"
49 #include "google_apis/gaia/gaia_urls.h" 47 #include "google_apis/gaia/gaia_urls.h"
50 #include "net/cookies/canonical_cookie.h" 48 #include "net/cookies/canonical_cookie.h"
51 #include "net/cookies/cookie_store.h" 49 #include "net/cookies/cookie_store.h"
52 #include "net/test/embedded_test_server/http_request.h" 50 #include "net/test/embedded_test_server/http_request.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 135
138 Profile* profile_; 136 Profile* profile_;
139 std::set<OAuth2LoginManager::SessionRestoreState> states_; 137 std::set<OAuth2LoginManager::SessionRestoreState> states_;
140 bool waiting_for_state_; 138 bool waiting_for_state_;
141 OAuth2LoginManager::SessionRestoreState final_state_; 139 OAuth2LoginManager::SessionRestoreState final_state_;
142 scoped_refptr<content::MessageLoopRunner> runner_; 140 scoped_refptr<content::MessageLoopRunner> runner_;
143 141
144 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter); 142 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManagerStateWaiter);
145 }; 143 };
146 144
147 // Blocks a BrowserThread on construction and unblocks it on destruction.
148 class BrowserThreadBlocker {
149 public:
150 explicit BrowserThreadBlocker(content::BrowserThread::ID identifier)
151 : unblock_event_(new base::WaitableEvent(
152 base::WaitableEvent::ResetPolicy::MANUAL,
153 base::WaitableEvent::InitialState::NOT_SIGNALED)) {
154 content::BrowserThread::PostTask(
155 identifier, FROM_HERE,
156 base::Bind(&BlockThreadOnThread, base::Owned(unblock_event_)));
157 }
158 ~BrowserThreadBlocker() { unblock_event_->Signal(); }
159
160 private:
161 // Blocks the target thread until |event| is signaled.
162 static void BlockThreadOnThread(base::WaitableEvent* event) { event->Wait(); }
163
164 // Owned by the BlockThreadOnThread callback.
165 base::WaitableEvent* const unblock_event_;
166 DISALLOW_COPY_AND_ASSIGN(BrowserThreadBlocker);
167 };
168
169 } // namespace 145 } // namespace
170 146
171 class OAuth2Test : public OobeBaseTest { 147 class OAuth2Test : public OobeBaseTest {
172 protected: 148 protected:
173 OAuth2Test() {} 149 OAuth2Test() {}
174 150
175 void SetUpCommandLine(base::CommandLine* command_line) override { 151 void SetUpCommandLine(base::CommandLine* command_line) override {
176 OobeBaseTest::SetUpCommandLine(command_line); 152 OobeBaseTest::SetUpCommandLine(command_line);
177 153
178 // Disable sync sinc we don't really need this for these tests and it also 154 // Disable sync sinc we don't really need this for these tests and it also
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Use capitalized and dotted user name on purpose to make sure 357 // Use capitalized and dotted user name on purpose to make sure
382 // our email normalization kicks in. 358 // our email normalization kicks in.
383 GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawEmail, 359 GetLoginDisplay()->ShowSigninScreenForCreds(kTestRawEmail,
384 kTestAccountPassword); 360 kTestAccountPassword);
385 session_start_waiter.Wait(); 361 session_start_waiter.Wait();
386 362
387 if (wait_for_merge) { 363 if (wait_for_merge) {
388 // Wait for the session merge to finish. 364 // Wait for the session merge to finish.
389 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); 365 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
390 } 366 }
391 } 367 }
392 368
393 OAuth2LoginManager::SessionRestoreStrategy GetSessionRestoreStrategy() {
394 OAuth2LoginManager* login_manager =
395 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile());
396 return login_manager->restore_strategy_;
397 }
398
399 private:
400 DISALLOW_COPY_AND_ASSIGN(OAuth2Test); 369 DISALLOW_COPY_AND_ASSIGN(OAuth2Test);
401 }; 370 };
402 371
403 class CookieReader : public base::RefCountedThreadSafe<CookieReader> { 372 class CookieReader : public base::RefCountedThreadSafe<CookieReader> {
404 public: 373 public:
405 CookieReader() { 374 CookieReader() {
406 } 375 }
407 376
408 void ReadCookies(Profile* profile) { 377 void ReadCookies(Profile* profile) {
409 context_ = profile->GetRequestContext(); 378 context_ = profile->GetRequestContext();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId), 498 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId),
530 kTestAccountPassword)); 499 kTestAccountPassword));
531 500
532 // Wait for the session merge to finish. 501 // Wait for the session merge to finish.
533 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); 502 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED);
534 503
535 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), 504 EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
536 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); 505 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
537 } 506 }
538 507
539 // Sets up a new user with stored refresh token.
540 IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_OverlappingContinueSessionRestore) {
541 StartNewUserSession(true);
542 }
543
544 // Tests that ContinueSessionRestore could be called multiple times.
545 IN_PROC_BROWSER_TEST_F(OAuth2Test, OverlappingContinueSessionRestore) {
546 SetupGaiaServerForUnexpiredAccount();
547 SimulateNetworkOnline();
548
549 // Waits for login screen to be ready.
550 content::WindowedNotificationObserver(
551 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
552 content::NotificationService::AllSources())
553 .Wait();
554
555 // Blocks DB thread to control TokenService::LoadCredentials timing.
556 std::unique_ptr<BrowserThreadBlocker> db_blocker =
557 base::MakeUnique<BrowserThreadBlocker>(content::BrowserThread::DB);
558
559 // Signs in as the existing user created in pre test.
560 EXPECT_TRUE(
561 TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId),
562 kTestAccountPassword));
563
564 // Session restore should be using the saved tokens.
565 EXPECT_EQ(OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN,
566 GetSessionRestoreStrategy());
567
568 // Checks that refresh token is not yet loaded.
569 ProfileOAuth2TokenService* token_service =
570 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
571 const std::string account_id =
572 PickAccountId(profile(), kTestGaiaId, kTestEmail);
573 EXPECT_FALSE(token_service->RefreshTokenIsAvailable(account_id));
574
575 // Invokes ContinueSessionRestore multiple times and there should be
576 // no DCHECK failures.
577 OAuth2LoginManager* login_manager =
578 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile());
579 login_manager->ContinueSessionRestore();
580 login_manager->ContinueSessionRestore();
581
582 // Let go DB thread to finish TokenService::LoadCredentials.
583 db_blocker.reset();
584
585 // Session restore can finish normally and token is loaded.
586 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
587 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
588 }
589 508
590 const char kGooglePageContent[] = 509 const char kGooglePageContent[] =
591 "<html><title>Hello!</title><script>alert('hello');</script>" 510 "<html><title>Hello!</title><script>alert('hello');</script>"
592 "<body>Hello Google!</body></html>"; 511 "<body>Hello Google!</body></html>";
593 const char kRandomPageContent[] = 512 const char kRandomPageContent[] =
594 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>"; 513 "<html><title>SomthingElse</title><body>I am SomethingElse</body></html>";
595 const char kHelloPagePath[] = "/hello_google"; 514 const char kHelloPagePath[] = "/hello_google";
596 const char kRandomPagePath[] = "/non_google_page"; 515 const char kRandomPagePath[] = "/non_google_page";
597 516
598 517
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 const GURL& server_url = embedded_test_server()->base_url(); 641 const GURL& server_url = embedded_test_server()->base_url();
723 GURL::Replacements replace_google_host; 642 GURL::Replacements replace_google_host;
724 replace_google_host.SetHostStr("www.google.com"); 643 replace_google_host.SetHostStr("www.google.com");
725 GURL google_url = server_url.ReplaceComponents(replace_google_host); 644 GURL google_url = server_url.ReplaceComponents(replace_google_host);
726 fake_google_page_url_ = google_url.Resolve(kHelloPagePath); 645 fake_google_page_url_ = google_url.Resolve(kHelloPagePath);
727 646
728 GURL::Replacements replace_non_google_host; 647 GURL::Replacements replace_non_google_host;
729 replace_non_google_host.SetHostStr("www.somethingelse.org"); 648 replace_non_google_host.SetHostStr("www.somethingelse.org");
730 GURL non_google_url = server_url.ReplaceComponents(replace_non_google_host); 649 GURL non_google_url = server_url.ReplaceComponents(replace_non_google_host);
731 non_google_page_url_ = non_google_url.Resolve(kRandomPagePath); 650 non_google_page_url_ = non_google_url.Resolve(kRandomPagePath);
732 } 651 }
733 652
734 void SetUp() override { 653 void SetUp() override {
735 embedded_test_server()->RegisterRequestHandler(base::Bind( 654 embedded_test_server()->RegisterRequestHandler(
736 &FakeGoogle::HandleRequest, base::Unretained(&fake_google_))); 655 base::Bind(&FakeGoogle::HandleRequest,
656 base::Unretained(&fake_google_)));
737 OAuth2Test::SetUp(); 657 OAuth2Test::SetUp();
738 } 658 }
739 659
740 protected: 660 protected:
741 void UnblockMergeSession() { 661 void UnblockMergeSession() {
742 delayed_fake_gaia_->UnblockMergeSession(); 662 delayed_fake_gaia_->UnblockMergeSession();
743 } 663 }
744 664
745 void WaitForMergeSessionToStart() { 665 void WaitForMergeSessionToStart() {
746 delayed_fake_gaia_->WaitForMergeSessionToStart(); 666 delayed_fake_gaia_->WaitForMergeSessionToStart();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 807
888 if (!catcher.GetNextResult()) { 808 if (!catcher.GetNextResult()) {
889 std::string message = catcher.message(); 809 std::string message = catcher.message();
890 ADD_FAILURE() << "Tests failed: " << message; 810 ADD_FAILURE() << "Tests failed: " << message;
891 } 811 }
892 812
893 EXPECT_TRUE(fake_google_.IsPageRequested()); 813 EXPECT_TRUE(fake_google_.IsPageRequested());
894 } 814 }
895 815
896 } // namespace chromeos 816 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698