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

Unified Diff: chrome/browser/sync/sync_ui_util_unittest.cc

Issue 12077030: Allow signin to continue even if sync is disabled by policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows sync integration test failure Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/sync_ui_util.cc ('k') | chrome/browser/sync/test/integration/migration_errors_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/sync_ui_util_unittest.cc
diff --git a/chrome/browser/sync/sync_ui_util_unittest.cc b/chrome/browser/sync/sync_ui_util_unittest.cc
index 839792f723503f43247f5adc45c1ca2aeb830b3c..09367d1d3c07c8462443f76d050941cdd0f4a5d4 100644
--- a/chrome/browser/sync/sync_ui_util_unittest.cc
+++ b/chrome/browser/sync/sync_ui_util_unittest.cc
@@ -6,6 +6,7 @@
#include "base/basictypes.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/fake_auth_status_provider.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_fake.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
@@ -35,17 +36,12 @@ enum DistinctState {
STATUS_CASE_PROTOCOL_ERROR,
STATUS_CASE_PASSPHRASE_ERROR,
STATUS_CASE_SYNCED,
+ STATUS_CASE_SYNC_DISABLED_BY_POLICY,
NUMBER_OF_STATUS_CASES
};
namespace {
-// Mock that allows us to mock a SigninManager that is authenticating.
-class SigninManagerMock : public SigninManager {
- public:
- MOCK_CONST_METHOD0(AuthInProgress, bool());
-};
-
// Utility function to test that GetStatusLabelsForSyncGlobalError returns
// the correct results for the given states.
void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
@@ -82,7 +78,6 @@ TEST(SyncUIUtilTest, PassphraseGlobalError) {
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
.WillRepeatedly(Return(false));
-
EXPECT_CALL(service, IsPassphraseRequired())
.WillRepeatedly(Return(true));
EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
@@ -159,8 +154,8 @@ TEST(SyncUIUtilTest, AuthStateGlobalError) {
// Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases
// in order to perform tests on the generated messages.
void GetDistinctCase(ProfileSyncServiceMock& service,
- SigninManagerMock& signin,
- GoogleServiceAuthError** auth_error,
+ FakeSigninManager* signin,
+ FakeAuthStatusProvider* provider,
int caseNumber) {
// Auth Error object is returned by reference in mock and needs to stay in
// scope throughout test, so it is owned by calling method. However it is
@@ -168,116 +163,121 @@ void GetDistinctCase(ProfileSyncServiceMock& service,
switch (caseNumber) {
case STATUS_CASE_SETUP_IN_PROGRESS: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(false));
+ .WillRepeatedly(Return(false));
EXPECT_CALL(service, FirstSetupInProgress())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
- *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
- EXPECT_CALL(service, GetAuthError())
- .WillOnce(ReturnRef(**auth_error));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false));
return;
}
case STATUS_CASE_SETUP_ERROR: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(false));
+ .WillRepeatedly(Return(false));
EXPECT_CALL(service, FirstSetupInProgress())
- .WillOnce(Return(false));
+ .WillRepeatedly(Return(false));
EXPECT_CALL(service, HasUnrecoverableError())
- .WillOnce(Return(true));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false));
+ .WillRepeatedly(Return(true));
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
return;
}
case STATUS_CASE_AUTHENTICATING: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true));
+ EXPECT_CALL(service, IsPassphraseRequired())
+ .WillRepeatedly(Return(false));
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
EXPECT_CALL(service, HasUnrecoverableError())
- .WillOnce(Return(false));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(true));
- *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
- EXPECT_CALL(service, GetAuthError())
- .WillOnce(ReturnRef(**auth_error));
+ .WillRepeatedly(Return(false));
+ signin->set_auth_in_progress(true);
return;
}
case STATUS_CASE_AUTH_ERROR: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true));
+ EXPECT_CALL(service, IsPassphraseRequired())
+ .WillRepeatedly(Return(false));
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
- *auth_error = new GoogleServiceAuthError(
- GoogleServiceAuthError::SERVICE_UNAVAILABLE);
+ provider->SetAuthError(GoogleServiceAuthError(
+ GoogleServiceAuthError::SERVICE_UNAVAILABLE));
EXPECT_CALL(service, HasUnrecoverableError())
- .WillOnce(Return(false));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false));
- EXPECT_CALL(service, GetAuthError())
- .WillOnce(ReturnRef(**auth_error));
+ .WillRepeatedly(Return(false));
return;
}
case STATUS_CASE_PROTOCOL_ERROR: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true));
+ EXPECT_CALL(service, IsPassphraseRequired())
+ .WillRepeatedly(Return(false));
syncer::SyncProtocolError protocolError;
protocolError.action = syncer::STOP_AND_RESTART_SYNC;
browser_sync::SyncBackendHost::Status status;
status.sync_protocol_error = protocolError;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
- *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
- EXPECT_CALL(service, GetAuthError())
- .WillOnce(ReturnRef(**auth_error));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false));
EXPECT_CALL(service, HasUnrecoverableError())
- .WillOnce(Return(false));
+ .WillRepeatedly(Return(false));
return;
}
case STATUS_CASE_PASSPHRASE_ERROR: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true));
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
- *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
- EXPECT_CALL(service, GetAuthError())
- .WillOnce(ReturnRef(**auth_error));
EXPECT_CALL(service, HasUnrecoverableError())
- .WillOnce(Return(false));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false));
+ .WillRepeatedly(Return(false));
EXPECT_CALL(service, IsPassphraseRequired())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
return;
}
case STATUS_CASE_SYNCED: {
EXPECT_CALL(service, HasSyncSetupCompleted())
- .WillOnce(Return(true));
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true));
+ EXPECT_CALL(service, IsPassphraseRequired())
+ .WillRepeatedly(Return(false));
browser_sync::SyncBackendHost::Status status;
EXPECT_CALL(service, QueryDetailedSyncStatus(_))
- .WillOnce(DoAll(SetArgPointee<0>(status),
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
Return(false)));
- *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
- EXPECT_CALL(service, GetAuthError())
- .WillOnce(ReturnRef(**auth_error));
- EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false));
EXPECT_CALL(service, HasUnrecoverableError())
- .WillOnce(Return(false));
+ .WillRepeatedly(Return(false));
+ EXPECT_CALL(service, IsPassphraseRequired())
+ .WillRepeatedly(Return(false));
+ return;
+ }
+ case STATUS_CASE_SYNC_DISABLED_BY_POLICY: {
+ EXPECT_CALL(service, IsManaged()).WillRepeatedly(Return(true));
+ EXPECT_CALL(service, HasSyncSetupCompleted())
+ .WillRepeatedly(Return(false));
+ EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(false));
EXPECT_CALL(service, IsPassphraseRequired())
- .WillOnce(Return(false));
+ .WillRepeatedly(Return(false));
+ browser_sync::SyncBackendHost::Status status;
+ EXPECT_CALL(service, QueryDetailedSyncStatus(_))
+ .WillRepeatedly(DoAll(SetArgPointee<0>(status),
+ Return(false)));
+ EXPECT_CALL(service, HasUnrecoverableError())
+ .WillRepeatedly(Return(false));
return;
}
default:
@@ -294,9 +294,10 @@ TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
scoped_ptr<Profile> profile(
ProfileSyncServiceMock::MakeSignedInTestingProfile());
ProfileSyncServiceMock service(profile.get());
- NiceMock<SigninManagerMock> signin;
- GoogleServiceAuthError* auth_error = NULL;
- GetDistinctCase(service, signin, &auth_error, idx);
+ FakeSigninManager signin(profile.get());
+ signin.SetAuthenticatedUsername("test_user@test.com");
+ FakeAuthStatusProvider provider(signin.signin_global_error());
+ GetDistinctCase(service, &signin, &provider, idx);
string16 status_label;
string16 link_label;
sync_ui_util::GetStatusLabels(&service,
@@ -307,12 +308,15 @@ TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
// If the status and link message combination is already present in the set
// of messages already seen, this is a duplicate rather than a unique
// message, and the test has failed.
+ EXPECT_FALSE(status_label.empty()) <<
+ "Empty status label returned for case #" << idx;
string16 combined_label =
status_label + string16(ASCIIToUTF16("#")) + link_label;
- EXPECT_TRUE(messages.find(combined_label) == messages.end());
+ EXPECT_TRUE(messages.find(combined_label) == messages.end()) <<
+ "Duplicate message for case #" << idx << ": " << combined_label;
messages.insert(combined_label);
- if (auth_error)
- delete auth_error;
+ testing::Mock::VerifyAndClearExpectations(&service);
+ testing::Mock::VerifyAndClearExpectations(&signin);
}
}
@@ -323,9 +327,10 @@ TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
scoped_ptr<Profile> profile(
ProfileSyncServiceMock::MakeSignedInTestingProfile());
ProfileSyncServiceMock service(profile.get());
- NiceMock<SigninManagerMock> signin;
- GoogleServiceAuthError* auth_error = NULL;
- GetDistinctCase(service, signin, &auth_error, idx);
+ FakeSigninManager signin(profile.get());
+ signin.SetAuthenticatedUsername("test_user@test.com");
+ FakeAuthStatusProvider provider(signin.signin_global_error());
+ GetDistinctCase(service, &signin, &provider, idx);
string16 status_label;
string16 link_label;
sync_ui_util::GetStatusLabels(&service,
@@ -333,13 +338,14 @@ TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
sync_ui_util::PLAIN_TEXT,
&status_label,
&link_label);
+
// Ensures a search for string 'href' (found in links, not a string to be
// found in an English language message) fails when links are excluded from
// the status label.
+ EXPECT_FALSE(status_label.empty());
EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))),
string16::npos);
- if (auth_error) {
- delete auth_error;
- }
+ testing::Mock::VerifyAndClearExpectations(&service);
+ testing::Mock::VerifyAndClearExpectations(&signin);
}
}
« no previous file with comments | « chrome/browser/sync/sync_ui_util.cc ('k') | chrome/browser/sync/test/integration/migration_errors_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698