OLD | NEW |
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 "chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.h" | 5 #include "chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.h" |
6 | 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
7 #include "base/command_line.h" | 11 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
9 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "components/os_crypt/os_crypt_mocker.h" |
10 #include "components/prefs/pref_registry_simple.h" | 15 #include "components/prefs/pref_registry_simple.h" |
11 #include "components/prefs/scoped_user_pref_update.h" | 16 #include "components/prefs/scoped_user_pref_update.h" |
12 #include "components/prefs/testing_pref_service.h" | 17 #include "components/prefs/testing_pref_service.h" |
13 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 18 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
14 #include "components/signin/core/browser/signin_error_controller.h" | 19 #include "components/signin/core/browser/signin_error_controller.h" |
15 #include "components/signin/core/browser/test_signin_client.h" | 20 #include "components/signin/core/browser/test_signin_client.h" |
16 #include "components/signin/core/browser/webdata/token_web_data.h" | 21 #include "components/signin/core/browser/webdata/token_web_data.h" |
17 #include "components/signin/core/common/profile_management_switches.h" | 22 #include "components/signin/core/common/profile_management_switches.h" |
18 #include "components/signin/core/common/signin_pref_names.h" | 23 #include "components/signin/core/common/signin_pref_names.h" |
19 #include "google_apis/gaia/gaia_constants.h" | 24 #include "google_apis/gaia/gaia_constants.h" |
20 #include "google_apis/gaia/gaia_urls.h" | 25 #include "google_apis/gaia/gaia_urls.h" |
21 #include "google_apis/gaia/google_service_auth_error.h" | 26 #include "google_apis/gaia/google_service_auth_error.h" |
22 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 27 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
23 #include "google_apis/gaia/oauth2_token_service_test_util.h" | 28 #include "google_apis/gaia/oauth2_token_service_test_util.h" |
24 #include "net/http/http_status_code.h" | 29 #include "net/http/http_status_code.h" |
25 #include "net/url_request/test_url_fetcher_factory.h" | 30 #include "net/url_request/test_url_fetcher_factory.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
27 | 32 |
28 #if defined(OS_MACOSX) | |
29 #include "components/os_crypt/os_crypt.h" | |
30 #endif | |
31 | |
32 // Defining constant here to handle backward compatiblity tests, but this | 33 // Defining constant here to handle backward compatiblity tests, but this |
33 // constant is no longer used in current versions of chrome. | 34 // constant is no longer used in current versions of chrome. |
34 static const char kLSOService[] = "lso"; | 35 static const char kLSOService[] = "lso"; |
35 static const char kEmail[] = "user@gmail.com"; | 36 static const char kEmail[] = "user@gmail.com"; |
36 | 37 |
37 class MutableProfileOAuth2TokenServiceDelegateTest | 38 class MutableProfileOAuth2TokenServiceDelegateTest |
38 : public testing::Test, | 39 : public testing::Test, |
39 public OAuth2AccessTokenConsumer, | 40 public OAuth2AccessTokenConsumer, |
40 public OAuth2TokenService::Observer { | 41 public OAuth2TokenService::Observer { |
41 public: | 42 public: |
42 MutableProfileOAuth2TokenServiceDelegateTest() | 43 MutableProfileOAuth2TokenServiceDelegateTest() |
43 : factory_(NULL), | 44 : factory_(NULL), |
44 access_token_success_count_(0), | 45 access_token_success_count_(0), |
45 access_token_failure_count_(0), | 46 access_token_failure_count_(0), |
46 access_token_failure_(GoogleServiceAuthError::NONE), | 47 access_token_failure_(GoogleServiceAuthError::NONE), |
47 token_available_count_(0), | 48 token_available_count_(0), |
48 token_revoked_count_(0), | 49 token_revoked_count_(0), |
49 tokens_loaded_count_(0), | 50 tokens_loaded_count_(0), |
50 start_batch_changes_(0), | 51 start_batch_changes_(0), |
51 end_batch_changes_(0) {} | 52 end_batch_changes_(0) {} |
52 | 53 |
53 void SetUp() override { | 54 void SetUp() override { |
54 #if defined(OS_MACOSX) | 55 OSCryptMocker::SetUpWithSingleton(); |
55 OSCrypt::UseMockKeychain(true); | |
56 #endif | |
57 | 56 |
58 factory_.SetFakeResponse(GaiaUrls::GetInstance()->oauth2_revoke_url(), "", | 57 factory_.SetFakeResponse(GaiaUrls::GetInstance()->oauth2_revoke_url(), "", |
59 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 58 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
60 | 59 |
61 pref_service_.registry()->RegisterListPref( | 60 pref_service_.registry()->RegisterListPref( |
62 AccountTrackerService::kAccountInfoPref); | 61 AccountTrackerService::kAccountInfoPref); |
63 pref_service_.registry()->RegisterIntegerPref( | 62 pref_service_.registry()->RegisterIntegerPref( |
64 prefs::kAccountIdMigrationState, | 63 prefs::kAccountIdMigrationState, |
65 AccountTrackerService::MIGRATION_NOT_STARTED); | 64 AccountTrackerService::MIGRATION_NOT_STARTED); |
66 client_.reset(new TestSigninClient(&pref_service_)); | 65 client_.reset(new TestSigninClient(&pref_service_)); |
67 client_->SetURLRequestContext(new net::TestURLRequestContextGetter( | 66 client_->SetURLRequestContext(new net::TestURLRequestContextGetter( |
68 base::ThreadTaskRunnerHandle::Get())); | 67 base::ThreadTaskRunnerHandle::Get())); |
69 client_->LoadTokenDatabase(); | 68 client_->LoadTokenDatabase(); |
70 account_tracker_service_.Initialize(client_.get()); | 69 account_tracker_service_.Initialize(client_.get()); |
71 oauth2_service_delegate_.reset(new MutableProfileOAuth2TokenServiceDelegate( | 70 oauth2_service_delegate_.reset(new MutableProfileOAuth2TokenServiceDelegate( |
72 client_.get(), &signin_error_controller_, &account_tracker_service_)); | 71 client_.get(), &signin_error_controller_, &account_tracker_service_)); |
73 // Make sure PO2TS has a chance to load itself before continuing. | 72 // Make sure PO2TS has a chance to load itself before continuing. |
74 base::RunLoop().RunUntilIdle(); | 73 base::RunLoop().RunUntilIdle(); |
75 oauth2_service_delegate_->AddObserver(this); | 74 oauth2_service_delegate_->AddObserver(this); |
76 } | 75 } |
77 | 76 |
78 void TearDown() override { | 77 void TearDown() override { |
79 oauth2_service_delegate_->RemoveObserver(this); | 78 oauth2_service_delegate_->RemoveObserver(this); |
80 oauth2_service_delegate_->Shutdown(); | 79 oauth2_service_delegate_->Shutdown(); |
| 80 OSCryptMocker::TearDown(); |
81 } | 81 } |
82 | 82 |
83 void AddAuthTokenManually(const std::string& service, | 83 void AddAuthTokenManually(const std::string& service, |
84 const std::string& value) { | 84 const std::string& value) { |
85 scoped_refptr<TokenWebData> token_web_data = client_->GetDatabase(); | 85 scoped_refptr<TokenWebData> token_web_data = client_->GetDatabase(); |
86 if (token_web_data.get()) | 86 if (token_web_data.get()) |
87 token_web_data->SetTokenForService(service, value); | 87 token_web_data->SetTokenForService(service, value); |
88 } | 88 } |
89 | 89 |
90 // OAuth2AccessTokenConusmer implementation | 90 // OAuth2AccessTokenConusmer implementation |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 EXPECT_EQ(1, tokens_loaded_count_); | 686 EXPECT_EQ(1, tokens_loaded_count_); |
687 EXPECT_EQ(2, token_available_count_); | 687 EXPECT_EQ(2, token_available_count_); |
688 EXPECT_EQ(0, token_revoked_count_); | 688 EXPECT_EQ(0, token_revoked_count_); |
689 EXPECT_EQ(1, start_batch_changes_); | 689 EXPECT_EQ(1, start_batch_changes_); |
690 EXPECT_EQ(1, end_batch_changes_); | 690 EXPECT_EQ(1, end_batch_changes_); |
691 EXPECT_TRUE( | 691 EXPECT_TRUE( |
692 oauth2_service_delegate_->RefreshTokenIsAvailable(primary_account)); | 692 oauth2_service_delegate_->RefreshTokenIsAvailable(primary_account)); |
693 EXPECT_TRUE( | 693 EXPECT_TRUE( |
694 oauth2_service_delegate_->RefreshTokenIsAvailable(secondary_account)); | 694 oauth2_service_delegate_->RefreshTokenIsAvailable(secondary_account)); |
695 } | 695 } |
OLD | NEW |