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

Side by Side Diff: chrome/browser/sync/sync_ui_util_unittest.cc

Issue 8665011: sync: remove GetAuthenticatedUsername from ProfileSyncService/SyncBackendHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/stringprintf.h"
6 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/prefs/pref_service_mock_builder.h"
9 #include "chrome/browser/prefs/testing_pref_store.h"
7 #include "chrome/browser/sync/profile_sync_service_mock.h" 10 #include "chrome/browser/sync/profile_sync_service_mock.h"
11 #include "chrome/browser/sync/signin_manager.h"
8 #include "chrome/browser/sync/sync_ui_util.h" 12 #include "chrome/browser/sync/sync_ui_util.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_profile.h"
9 #include "content/test/test_browser_thread.h" 15 #include "content/test/test_browser_thread.h"
10 #include "testing/gmock/include/gmock/gmock-actions.h" 16 #include "testing/gmock/include/gmock/gmock-actions.h"
11 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
13 19
14 using ::testing::Return; 20 using ::testing::Return;
15 using ::testing::NiceMock; 21 using ::testing::NiceMock;
16 using content::BrowserThread; 22 using content::BrowserThread;
17 23
18 namespace { 24 namespace {
19 25
20 // Utility function to test that GetStatusLabelsForSyncGlobalError returns 26 // Utility function to test that GetStatusLabelsForSyncGlobalError returns
21 // the correct results for the given states. 27 // the correct results for the given states.
22 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, 28 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
23 GoogleServiceAuthError::State error_state, 29 GoogleServiceAuthError::State error_state,
24 bool is_signed_in, 30 bool is_signed_in,
25 bool is_error) { 31 bool is_error) {
26 GoogleServiceAuthError auth_error(error_state); 32 GoogleServiceAuthError auth_error(error_state);
27 service->UpdateAuthErrorState(auth_error); 33 service->UpdateAuthErrorState(auth_error);
28 34
29 EXPECT_CALL(*service, HasSyncSetupCompleted()) 35 EXPECT_CALL(*service, HasSyncSetupCompleted())
30 .WillRepeatedly(Return(is_signed_in)); 36 .WillRepeatedly(Return(is_signed_in));
31 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
32 EXPECT_CALL(*service, GetAuthenticatedUsername())
33 .WillRepeatedly(Return(UTF8ToUTF16("")));
34 } else {
35 EXPECT_CALL(*service, GetAuthenticatedUsername())
36 .WillRepeatedly(Return(UTF8ToUTF16("foo")));
37 }
38 37
39 string16 label1, label2, label3; 38 string16 label1, label2, label3;
40 sync_ui_util::GetStatusLabelsForSyncGlobalError( 39 sync_ui_util::GetStatusLabelsForSyncGlobalError(
41 service, &label1, &label2, &label3); 40 service, &label1, &label2, &label3);
42 EXPECT_EQ(label1.empty(), !is_error); 41 EXPECT_EQ(label1.empty(), !is_error);
43 EXPECT_EQ(label2.empty(), !is_error); 42 EXPECT_EQ(label2.empty(), !is_error);
44 EXPECT_EQ(label3.empty(), !is_error); 43 EXPECT_EQ(label3.empty(), !is_error);
45 } 44 }
46 45
46 Profile* MakeProfile() {
47 TestingProfile* profile = new TestingProfile();
48 TestingPrefStore* user_prefs = new TestingPrefStore();
49 PrefService* prefs = PrefServiceMockBuilder()
50 .WithUserPrefs(user_prefs)
51 .Create();
52 profile->SetPrefService(prefs);
53 SigninManager::RegisterUserPrefs(prefs);
54 user_prefs->SetString(prefs::kGoogleServicesUsername, "foo");
55 return profile;
Andrew T Wilson (Slow) 2011/11/24 01:48:16 I wonder if this could be refactored into ProfileS
tim (not reviewing) 2011/11/24 03:59:42 Yeahh, in fact that method above is duplicated as
56 }
57
47 } // namespace 58 } // namespace
48 59
49 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { 60 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) {
50 MessageLoopForUI message_loop; 61 MessageLoopForUI message_loop;
51 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 62 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
52 NiceMock<ProfileSyncServiceMock> service; 63 scoped_ptr<Profile> profile(MakeProfile());
64 NiceMock<ProfileSyncServiceMock> service(profile.get());
53 DictionaryValue strings; 65 DictionaryValue strings;
54 66
55 // Will be released when the dictionary is destroyed 67 // Will be released when the dictionary is destroyed
56 string16 str(ASCIIToUTF16("none")); 68 string16 str(ASCIIToUTF16("none"));
57 69
58 browser_sync::SyncBackendHost::Status status; 70 browser_sync::SyncBackendHost::Status status;
59 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; 71 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE;
60 72
61 EXPECT_CALL(service, HasSyncSetupCompleted()) 73 EXPECT_CALL(service, HasSyncSetupCompleted())
62 .WillOnce(Return(true)); 74 .WillOnce(Return(true));
63 EXPECT_CALL(service, QueryDetailedSyncStatus()) 75 EXPECT_CALL(service, QueryDetailedSyncStatus())
64 .WillOnce(Return(status)); 76 .WillOnce(Return(status));
65 77
66 EXPECT_CALL(service, unrecoverable_error_detected()) 78 EXPECT_CALL(service, unrecoverable_error_detected())
67 .WillOnce(Return(true)); 79 .WillOnce(Return(true));
68 80
69 EXPECT_CALL(service, GetLastSyncedTimeString()) 81 EXPECT_CALL(service, GetLastSyncedTimeString())
70 .WillOnce(Return(str)); 82 .WillOnce(Return(str));
71 83
72 sync_ui_util::ConstructAboutInformation(&service, &strings); 84 sync_ui_util::ConstructAboutInformation(&service, &strings);
73 85
74 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); 86 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected"));
75 } 87 }
76 88
77 // Test that GetStatusLabelsForSyncGlobalError returns an error if a 89 // Test that GetStatusLabelsForSyncGlobalError returns an error if a
78 // passphrase is required. 90 // passphrase is required.
79 TEST(SyncUIUtilTest, PassphraseGlobalError) { 91 TEST(SyncUIUtilTest, PassphraseGlobalError) {
80 MessageLoopForUI message_loop; 92 MessageLoopForUI message_loop;
81 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 93 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
82 NiceMock<ProfileSyncServiceMock> service; 94 scoped_ptr<Profile> profile(MakeProfile());
95 NiceMock<ProfileSyncServiceMock> service(profile.get());
83 96
84 EXPECT_CALL(service, IsPassphraseRequired()) 97 EXPECT_CALL(service, IsPassphraseRequired())
85 .WillOnce(Return(true)); 98 .WillOnce(Return(true));
86 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 99 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
87 .WillOnce(Return(true)); 100 .WillOnce(Return(true));
88 VerifySyncGlobalErrorResult( 101 VerifySyncGlobalErrorResult(
89 &service, GoogleServiceAuthError::NONE, true, true); 102 &service, GoogleServiceAuthError::NONE, true, true);
90 } 103 }
91 104
92 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions 105 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions
93 // that can be resolved by the user and suppresses errors for conditions that 106 // that can be resolved by the user and suppresses errors for conditions that
94 // cannot be resolved by the user. 107 // cannot be resolved by the user.
95 TEST(SyncUIUtilTest, AuthStateGlobalError) { 108 TEST(SyncUIUtilTest, AuthStateGlobalError) {
96 MessageLoopForUI message_loop; 109 MessageLoopForUI message_loop;
97 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 110 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
98 NiceMock<ProfileSyncServiceMock> service; 111 scoped_ptr<Profile> profile(MakeProfile());
112 NiceMock<ProfileSyncServiceMock> service(profile.get());
99 113
100 browser_sync::SyncBackendHost::Status status; 114 browser_sync::SyncBackendHost::Status status;
101 EXPECT_CALL(service, QueryDetailedSyncStatus()) 115 EXPECT_CALL(service, QueryDetailedSyncStatus())
102 .WillRepeatedly(Return(status)); 116 .WillRepeatedly(Return(status));
103 117
104 struct { 118 struct {
105 GoogleServiceAuthError::State error_state; 119 GoogleServiceAuthError::State error_state;
106 bool is_error; 120 bool is_error;
107 } table[] = { 121 } table[] = {
108 { GoogleServiceAuthError::NONE, false }, 122 { GoogleServiceAuthError::NONE, false },
109 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true }, 123 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true },
110 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true }, 124 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true },
111 { GoogleServiceAuthError::CONNECTION_FAILED, false }, 125 { GoogleServiceAuthError::CONNECTION_FAILED, false },
112 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, 126 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true },
113 { GoogleServiceAuthError::ACCOUNT_DELETED, true }, 127 { GoogleServiceAuthError::ACCOUNT_DELETED, true },
114 { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, 128 { GoogleServiceAuthError::ACCOUNT_DISABLED, true },
115 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, 129 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true },
116 { GoogleServiceAuthError::TWO_FACTOR, true }, 130 { GoogleServiceAuthError::TWO_FACTOR, true },
117 { GoogleServiceAuthError::REQUEST_CANCELED, true }, 131 { GoogleServiceAuthError::REQUEST_CANCELED, true },
118 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, 132 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
119 }; 133 };
120 134
121 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { 135 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
136 SCOPED_TRACE(base::StringPrintf("iteration: %d", (int)i));
Andrew T Wilson (Slow) 2011/11/24 01:48:16 Did you mean to leave this in?
122 VerifySyncGlobalErrorResult( 137 VerifySyncGlobalErrorResult(
123 &service, table[i].error_state, true, table[i].is_error); 138 &service, table[i].error_state, true, table[i].is_error);
124 VerifySyncGlobalErrorResult( 139 VerifySyncGlobalErrorResult(
125 &service, table[i].error_state, false, false); 140 &service, table[i].error_state, false, false);
126 } 141 }
127 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698