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

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

Issue 8665011: sync: remove GetAuthenticatedUsername from ProfileSyncService/SyncBackendHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review2 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 "chrome/browser/sync/sync_global_error.h" 5 #include "chrome/browser/sync/sync_global_error.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/sync/profile_sync_service_mock.h" 9 #include "chrome/browser/sync/profile_sync_service_mock.h"
10 #include "chrome/browser/sync/signin_manager.h"
11 #include "chrome/test/base/testing_profile.h"
10 #include "content/test/test_browser_thread.h" 12 #include "content/test/test_browser_thread.h"
11 #include "testing/gmock/include/gmock/gmock-actions.h" 13 #include "testing/gmock/include/gmock/gmock-actions.h"
12 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 using ::testing::Return; 17 using ::testing::Return;
16 using ::testing::ReturnRef; 18 using ::testing::ReturnRef;
17 using ::testing::NiceMock; 19 using ::testing::NiceMock;
18 using content::BrowserThread; 20 using content::BrowserThread;
19 21
20 namespace { 22 namespace {
21 23
22 // Utility function to test that SyncGlobalError behaves correct for the given 24 // Utility function to test that SyncGlobalError behaves correct for the given
23 // error condition. 25 // error condition.
24 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, 26 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
25 SyncGlobalError* error, 27 SyncGlobalError* error,
26 GoogleServiceAuthError::State error_state, 28 GoogleServiceAuthError::State error_state,
27 bool is_signed_in, 29 bool is_signed_in,
28 bool is_error) { 30 bool is_error) {
29 EXPECT_CALL(*service, HasSyncSetupCompleted()) 31 EXPECT_CALL(*service, HasSyncSetupCompleted())
30 .WillRepeatedly(Return(is_signed_in)); 32 .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 33
39 GoogleServiceAuthError auth_error(error_state); 34 GoogleServiceAuthError auth_error(error_state);
40 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); 35 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error));
41 36
42 error->OnStateChanged(); 37 error->OnStateChanged();
43 38
44 // If there is an error then a wrench button badge, menu item, and bubble view 39 // If there is an error then a wrench button badge, menu item, and bubble view
45 // should be shown. 40 // should be shown.
46 EXPECT_EQ(error->HasBadge(), is_error); 41 EXPECT_EQ(error->HasBadge(), is_error);
47 EXPECT_EQ(error->HasMenuItem() || error->HasCustomizedSyncMenuItem(), 42 EXPECT_EQ(error->HasMenuItem() || error->HasCustomizedSyncMenuItem(),
(...skipping 19 matching lines...) Expand all
67 error->BubbleViewDidClose(); 62 error->BubbleViewDidClose();
68 } 63 }
69 } 64 }
70 65
71 } // namespace 66 } // namespace
72 67
73 // Test that SyncGlobalError shows an error if a passphrase is required. 68 // Test that SyncGlobalError shows an error if a passphrase is required.
74 TEST(SyncGlobalErrorTest, PassphraseGlobalError) { 69 TEST(SyncGlobalErrorTest, PassphraseGlobalError) {
75 MessageLoopForUI message_loop; 70 MessageLoopForUI message_loop;
76 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 71 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
77 NiceMock<ProfileSyncServiceMock> service; 72 scoped_ptr<Profile> profile(
73 ProfileSyncServiceMock::MakeSignedInTestingProfile());
74 NiceMock<ProfileSyncServiceMock> service(profile.get());
78 SyncGlobalError error(&service); 75 SyncGlobalError error(&service);
79 76
80 EXPECT_CALL(service, IsPassphraseRequired()) 77 EXPECT_CALL(service, IsPassphraseRequired())
81 .WillRepeatedly(Return(true)); 78 .WillRepeatedly(Return(true));
82 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 79 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
83 .WillRepeatedly(Return(true)); 80 .WillRepeatedly(Return(true));
84 VerifySyncGlobalErrorResult( 81 VerifySyncGlobalErrorResult(
85 &service, &error, GoogleServiceAuthError::NONE, true, true); 82 &service, &error, GoogleServiceAuthError::NONE, true, true);
86 } 83 }
87 84
88 // Test that SyncGlobalError shows an error for conditions that can be resolved 85 // Test that SyncGlobalError shows an error for conditions that can be resolved
89 // by the user and suppresses errors for conditions that cannot be resolved by 86 // by the user and suppresses errors for conditions that cannot be resolved by
90 // the user. 87 // the user.
91 TEST(SyncGlobalErrorTest, AuthStateGlobalError) { 88 TEST(SyncGlobalErrorTest, AuthStateGlobalError) {
92 MessageLoopForUI message_loop; 89 MessageLoopForUI message_loop;
93 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 90 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
94 NiceMock<ProfileSyncServiceMock> service; 91 scoped_ptr<Profile> profile(
92 ProfileSyncServiceMock::MakeSignedInTestingProfile());
93 NiceMock<ProfileSyncServiceMock> service(profile.get());
95 SyncGlobalError error(&service); 94 SyncGlobalError error(&service);
96 95
97 browser_sync::SyncBackendHost::Status status; 96 browser_sync::SyncBackendHost::Status status;
98 EXPECT_CALL(service, QueryDetailedSyncStatus()) 97 EXPECT_CALL(service, QueryDetailedSyncStatus())
99 .WillRepeatedly(Return(status)); 98 .WillRepeatedly(Return(status));
100 99
101 struct { 100 struct {
102 GoogleServiceAuthError::State error_state; 101 GoogleServiceAuthError::State error_state;
103 bool is_error; 102 bool is_error;
104 } table[] = { 103 } table[] = {
(...skipping 10 matching lines...) Expand all
115 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, 114 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
116 }; 115 };
117 116
118 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { 117 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
119 VerifySyncGlobalErrorResult( 118 VerifySyncGlobalErrorResult(
120 &service, &error, table[i].error_state, true, table[i].is_error); 119 &service, &error, table[i].error_state, true, table[i].is_error);
121 VerifySyncGlobalErrorResult( 120 VerifySyncGlobalErrorResult(
122 &service, &error, table[i].error_state, false, false); 121 &service, &error, table[i].error_state, false, false);
123 } 122 }
124 } 123 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.cc ('k') | chrome/browser/sync/sync_setup_flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698