| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
| 6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/signin_manager.h" | 9 #include "chrome/browser/signin/signin_manager.h" |
| 10 #include "chrome/browser/signin/signin_manager_fake.h" | 10 #include "chrome/browser/signin/signin_manager_fake.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 EXPECT_CALL(service, IsPassphraseRequired()) | 86 EXPECT_CALL(service, IsPassphraseRequired()) |
| 87 .WillRepeatedly(Return(true)); | 87 .WillRepeatedly(Return(true)); |
| 88 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 88 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 89 .WillRepeatedly(Return(true)); | 89 .WillRepeatedly(Return(true)); |
| 90 VerifySyncGlobalErrorResult( | 90 VerifySyncGlobalErrorResult( |
| 91 &service, signin, GoogleServiceAuthError::NONE, true, true); | 91 &service, signin, GoogleServiceAuthError::NONE, true, true); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 94 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
| 95 // passphrase is required. | 95 // passphrase is required and not for auth errors. |
| 96 TEST(SyncUIUtilTest, AuthAndPassphraseGlobalError) { | 96 TEST(SyncUIUtilTest, AuthAndPassphraseGlobalError) { |
| 97 MessageLoopForUI message_loop; | 97 MessageLoopForUI message_loop; |
| 98 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 98 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 99 scoped_ptr<Profile> profile( | 99 scoped_ptr<Profile> profile( |
| 100 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 100 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 101 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 101 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
| 102 FakeSigninManager signin(profile.get()); | 102 FakeSigninManager signin(profile.get()); |
| 103 browser_sync::SyncBackendHost::Status status; | 103 browser_sync::SyncBackendHost::Status status; |
| 104 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 104 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 105 .WillRepeatedly(Return(false)); | 105 .WillRepeatedly(Return(false)); |
| 106 | 106 |
| 107 EXPECT_CALL(service, IsPassphraseRequired()) | 107 EXPECT_CALL(service, IsPassphraseRequired()) |
| 108 .WillRepeatedly(Return(true)); | 108 .WillRepeatedly(Return(true)); |
| 109 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 109 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 110 .WillRepeatedly(Return(true)); | 110 .WillRepeatedly(Return(true)); |
| 111 EXPECT_CALL(service, HasSyncSetupCompleted()) | 111 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 112 .WillRepeatedly(Return(true)); | 112 .WillRepeatedly(Return(true)); |
| 113 | 113 |
| 114 GoogleServiceAuthError auth_error( | 114 GoogleServiceAuthError auth_error( |
| 115 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 115 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 116 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); | 116 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); |
| 117 string16 menu_label, label2, label3; | 117 string16 menu_label, label2, label3; |
| 118 sync_ui_util::GetStatusLabelsForSyncGlobalError( | 118 sync_ui_util::GetStatusLabelsForSyncGlobalError( |
| 119 &service, signin, &menu_label, &label2, &label3); | 119 &service, signin, &menu_label, &label2, &label3); |
| 120 // Make sure we aren't displaying the passphrase error badge. | 120 // Make sure we are still displaying the passphrase error badge (don't show |
| 121 EXPECT_NE(menu_label, l10n_util::GetStringUTF16( | 121 // auth errors through SyncUIUtil). |
| 122 EXPECT_EQ(menu_label, l10n_util::GetStringUTF16( |
| 122 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM)); | 123 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM)); |
| 123 } | 124 } |
| 124 | 125 |
| 125 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions | 126 // Test that GetStatusLabelsForSyncGlobalError does not indicate errors for |
| 126 // that can be resolved by the user and suppresses errors for conditions that | 127 // auth errors (these are reported through SigninGlobalError). |
| 127 // cannot be resolved by the user. | |
| 128 TEST(SyncUIUtilTest, AuthStateGlobalError) { | 128 TEST(SyncUIUtilTest, AuthStateGlobalError) { |
| 129 MessageLoopForUI message_loop; | 129 MessageLoopForUI message_loop; |
| 130 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 130 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 131 scoped_ptr<Profile> profile( | 131 scoped_ptr<Profile> profile( |
| 132 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 132 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 133 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 133 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
| 134 | 134 |
| 135 browser_sync::SyncBackendHost::Status status; | 135 browser_sync::SyncBackendHost::Status status; |
| 136 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 136 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 137 .WillRepeatedly(Return(false)); | 137 .WillRepeatedly(Return(false)); |
| 138 | 138 |
| 139 struct { | 139 GoogleServiceAuthError::State table[] = { |
| 140 GoogleServiceAuthError::State error_state; | 140 GoogleServiceAuthError::NONE, |
| 141 bool is_error; | 141 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, |
| 142 } table[] = { | 142 GoogleServiceAuthError::USER_NOT_SIGNED_UP, |
| 143 { GoogleServiceAuthError::NONE, false }, | 143 GoogleServiceAuthError::CONNECTION_FAILED, |
| 144 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true }, | 144 GoogleServiceAuthError::CAPTCHA_REQUIRED, |
| 145 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true }, | 145 GoogleServiceAuthError::ACCOUNT_DELETED, |
| 146 { GoogleServiceAuthError::CONNECTION_FAILED, false }, | 146 GoogleServiceAuthError::ACCOUNT_DISABLED, |
| 147 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, | 147 GoogleServiceAuthError::SERVICE_UNAVAILABLE, |
| 148 { GoogleServiceAuthError::ACCOUNT_DELETED, true }, | 148 GoogleServiceAuthError::TWO_FACTOR, |
| 149 { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, | 149 GoogleServiceAuthError::REQUEST_CANCELED, |
| 150 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, | 150 GoogleServiceAuthError::HOSTED_NOT_ALLOWED |
| 151 { GoogleServiceAuthError::TWO_FACTOR, true }, | |
| 152 { GoogleServiceAuthError::REQUEST_CANCELED, true }, | |
| 153 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, | |
| 154 }; | 151 }; |
| 155 | 152 |
| 156 FakeSigninManager signin(profile.get()); | 153 FakeSigninManager signin(profile.get()); |
| 157 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { | 154 for (size_t i = 0; i < arraysize(table); ++i) { |
| 158 VerifySyncGlobalErrorResult( | 155 VerifySyncGlobalErrorResult(&service, signin, table[i], true, false); |
| 159 &service, signin, table[i].error_state, true, table[i].is_error); | 156 VerifySyncGlobalErrorResult(&service, signin, table[i], false, false); |
| 160 VerifySyncGlobalErrorResult( | |
| 161 &service, signin, table[i].error_state, false, false); | |
| 162 } | 157 } |
| 163 } | 158 } |
| 164 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases | 159 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases |
| 165 // in order to perform tests on the generated messages. | 160 // in order to perform tests on the generated messages. |
| 166 void GetDistinctCase(ProfileSyncServiceMock& service, | 161 void GetDistinctCase(ProfileSyncServiceMock& service, |
| 167 SigninManagerMock& signin, | 162 SigninManagerMock& signin, |
| 168 GoogleServiceAuthError** auth_error, | 163 GoogleServiceAuthError** auth_error, |
| 169 int caseNumber) { | 164 int caseNumber) { |
| 170 // Auth Error object is returned by reference in mock and needs to stay in | 165 // Auth Error object is returned by reference in mock and needs to stay in |
| 171 // scope throughout test, so it is owned by calling method. However it is | 166 // scope throughout test, so it is owned by calling method. However it is |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 // Ensures a search for string 'href' (found in links, not a string to be | 336 // Ensures a search for string 'href' (found in links, not a string to be |
| 342 // found in an English language message) fails when links are excluded from | 337 // found in an English language message) fails when links are excluded from |
| 343 // the status label. | 338 // the status label. |
| 344 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 339 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
| 345 string16::npos); | 340 string16::npos); |
| 346 if (auth_error) { | 341 if (auth_error) { |
| 347 delete auth_error; | 342 delete auth_error; |
| 348 } | 343 } |
| 349 } | 344 } |
| 350 } | 345 } |
| OLD | NEW |