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

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: init Created 9 years 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;
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 NiceMock<ProfileSyncServiceMock> service(MakeProfile());
53 DictionaryValue strings; 64 DictionaryValue strings;
54 65
55 // Will be released when the dictionary is destroyed 66 // Will be released when the dictionary is destroyed
56 string16 str(ASCIIToUTF16("none")); 67 string16 str(ASCIIToUTF16("none"));
57 68
58 browser_sync::SyncBackendHost::Status status; 69 browser_sync::SyncBackendHost::Status status;
59 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; 70 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE;
60 71
61 EXPECT_CALL(service, HasSyncSetupCompleted()) 72 EXPECT_CALL(service, HasSyncSetupCompleted())
62 .WillOnce(Return(true)); 73 .WillOnce(Return(true));
63 EXPECT_CALL(service, QueryDetailedSyncStatus()) 74 EXPECT_CALL(service, QueryDetailedSyncStatus())
64 .WillOnce(Return(status)); 75 .WillOnce(Return(status));
65 76
66 EXPECT_CALL(service, unrecoverable_error_detected()) 77 EXPECT_CALL(service, unrecoverable_error_detected())
67 .WillOnce(Return(true)); 78 .WillOnce(Return(true));
68 79
69 EXPECT_CALL(service, GetLastSyncedTimeString()) 80 EXPECT_CALL(service, GetLastSyncedTimeString())
70 .WillOnce(Return(str)); 81 .WillOnce(Return(str));
71 82
72 sync_ui_util::ConstructAboutInformation(&service, &strings); 83 sync_ui_util::ConstructAboutInformation(&service, &strings);
73 84
74 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); 85 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected"));
75 } 86 }
76 87
77 // Test that GetStatusLabelsForSyncGlobalError returns an error if a 88 // Test that GetStatusLabelsForSyncGlobalError returns an error if a
78 // passphrase is required. 89 // passphrase is required.
79 TEST(SyncUIUtilTest, PassphraseGlobalError) { 90 TEST(SyncUIUtilTest, PassphraseGlobalError) {
80 MessageLoopForUI message_loop; 91 MessageLoopForUI message_loop;
81 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 92 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
82 NiceMock<ProfileSyncServiceMock> service; 93 NiceMock<ProfileSyncServiceMock> service(MakeProfile());
83 94
84 EXPECT_CALL(service, IsPassphraseRequired()) 95 EXPECT_CALL(service, IsPassphraseRequired())
85 .WillOnce(Return(true)); 96 .WillOnce(Return(true));
86 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 97 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
87 .WillOnce(Return(true)); 98 .WillOnce(Return(true));
88 VerifySyncGlobalErrorResult( 99 VerifySyncGlobalErrorResult(
89 &service, GoogleServiceAuthError::NONE, true, true); 100 &service, GoogleServiceAuthError::NONE, true, true);
90 } 101 }
91 102
92 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions 103 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions
93 // that can be resolved by the user and suppresses errors for conditions that 104 // that can be resolved by the user and suppresses errors for conditions that
94 // cannot be resolved by the user. 105 // cannot be resolved by the user.
95 TEST(SyncUIUtilTest, AuthStateGlobalError) { 106 TEST(SyncUIUtilTest, AuthStateGlobalError) {
96 MessageLoopForUI message_loop; 107 MessageLoopForUI message_loop;
97 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 108 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
98 NiceMock<ProfileSyncServiceMock> service; 109 NiceMock<ProfileSyncServiceMock> service(MakeProfile());
99 110
100 browser_sync::SyncBackendHost::Status status; 111 browser_sync::SyncBackendHost::Status status;
101 EXPECT_CALL(service, QueryDetailedSyncStatus()) 112 EXPECT_CALL(service, QueryDetailedSyncStatus())
102 .WillRepeatedly(Return(status)); 113 .WillRepeatedly(Return(status));
103 114
104 struct { 115 struct {
105 GoogleServiceAuthError::State error_state; 116 GoogleServiceAuthError::State error_state;
106 bool is_error; 117 bool is_error;
107 } table[] = { 118 } table[] = {
108 { GoogleServiceAuthError::NONE, false }, 119 { GoogleServiceAuthError::NONE, false },
109 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true }, 120 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true },
110 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true }, 121 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true },
111 { GoogleServiceAuthError::CONNECTION_FAILED, false }, 122 { GoogleServiceAuthError::CONNECTION_FAILED, false },
112 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, 123 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true },
113 { GoogleServiceAuthError::ACCOUNT_DELETED, true }, 124 { GoogleServiceAuthError::ACCOUNT_DELETED, true },
114 { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, 125 { GoogleServiceAuthError::ACCOUNT_DISABLED, true },
115 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, 126 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true },
116 { GoogleServiceAuthError::TWO_FACTOR, true }, 127 { GoogleServiceAuthError::TWO_FACTOR, true },
117 { GoogleServiceAuthError::REQUEST_CANCELED, true }, 128 { GoogleServiceAuthError::REQUEST_CANCELED, true },
118 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, 129 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
119 }; 130 };
120 131
121 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { 132 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
133 SCOPED_TRACE(base::StringPrintf("iteration: %d", (int)i));
122 VerifySyncGlobalErrorResult( 134 VerifySyncGlobalErrorResult(
123 &service, table[i].error_state, true, table[i].is_error); 135 &service, table[i].error_state, true, table[i].is_error);
124 VerifySyncGlobalErrorResult( 136 VerifySyncGlobalErrorResult(
125 &service, table[i].error_state, false, false); 137 &service, table[i].error_state, false, false);
126 } 138 }
127 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698