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

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

Issue 8308005: Suppress bubble view for CONNECTION_FAILED error (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed failure in debug build Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/sync_ui_util.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/sync/sync_ui_util.h" 7 #include "chrome/browser/sync/sync_ui_util.h"
8 #include "chrome/browser/sync/profile_sync_service_mock.h" 8 #include "chrome/browser/sync/profile_sync_service_mock.h"
9 #include "content/browser/browser_thread.h" 9 #include "content/browser/browser_thread.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gmock/include/gmock/gmock-actions.h" 11 #include "testing/gmock/include/gmock/gmock-actions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using ::testing::Return; 14 using ::testing::Return;
15 using ::testing::NiceMock; 15 using ::testing::NiceMock;
16
17 namespace {
18
19 // Utility function to test that GetStatusLabelsForSyncGlobalError returns
20 // the correct results for the given states.
21 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
22 GoogleServiceAuthError::State error_state,
23 bool is_signed_in,
24 bool is_error) {
25 GoogleServiceAuthError auth_error(error_state);
26 service->UpdateAuthErrorState(auth_error);
27
28 EXPECT_CALL(*service, HasSyncSetupCompleted())
29 .WillRepeatedly(Return(is_signed_in));
30 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
31 EXPECT_CALL(*service, GetAuthenticatedUsername())
32 .WillRepeatedly(Return(UTF8ToUTF16("")));
33 } else {
34 EXPECT_CALL(*service, GetAuthenticatedUsername())
35 .WillRepeatedly(Return(UTF8ToUTF16("foo")));
36 }
37
38 string16 label1, label2, label3;
39 sync_ui_util::GetStatusLabelsForSyncGlobalError(
40 service, &label1, &label2, &label3);
41 EXPECT_EQ(label1.empty(), !is_error);
42 EXPECT_EQ(label2.empty(), !is_error);
43 EXPECT_EQ(label3.empty(), !is_error);
44 }
45
46 } // namespace
47
16 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { 48 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) {
17 MessageLoopForUI message_loop; 49 MessageLoopForUI message_loop;
18 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 50 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
19 NiceMock<ProfileSyncServiceMock> service; 51 NiceMock<ProfileSyncServiceMock> service;
20 DictionaryValue strings; 52 DictionaryValue strings;
21 53
22 // Will be released when the dictionary is destroyed 54 // Will be released when the dictionary is destroyed
23 string16 str(ASCIIToUTF16("none")); 55 string16 str(ASCIIToUTF16("none"));
24 56
25 browser_sync::SyncBackendHost::Status status; 57 browser_sync::SyncBackendHost::Status status;
(...skipping 15 matching lines...) Expand all
41 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); 73 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected"));
42 } 74 }
43 75
44 // Test that GetStatusLabelsForSyncGlobalError returns an error if a 76 // Test that GetStatusLabelsForSyncGlobalError returns an error if a
45 // passphrase is required. 77 // passphrase is required.
46 TEST(SyncUIUtilTest, PassphraseGlobalError) { 78 TEST(SyncUIUtilTest, PassphraseGlobalError) {
47 MessageLoopForUI message_loop; 79 MessageLoopForUI message_loop;
48 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 80 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
49 NiceMock<ProfileSyncServiceMock> service; 81 NiceMock<ProfileSyncServiceMock> service;
50 82
51 EXPECT_CALL(service, HasSyncSetupCompleted())
52 .WillOnce(Return(true));
53 EXPECT_CALL(service, IsPassphraseRequired()) 83 EXPECT_CALL(service, IsPassphraseRequired())
54 .WillOnce(Return(true)); 84 .WillOnce(Return(true));
55 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 85 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
56 .WillOnce(Return(true)); 86 .WillOnce(Return(true));
87 VerifySyncGlobalErrorResult(
88 &service, GoogleServiceAuthError::NONE, true, true);
89 }
57 90
58 sync_ui_util::MessageType type = 91 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions
59 sync_ui_util::GetStatusLabelsForSyncGlobalError( 92 // that can be resolved by the user and suppresses errors for conditions that
60 &service, NULL, NULL, NULL); 93 // cannot be resolved by the user.
61 EXPECT_EQ(type, sync_ui_util::SYNC_ERROR); 94 TEST(SyncUIUtilTest, AuthStateGlobalError) {
95 MessageLoopForUI message_loop;
96 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
97 NiceMock<ProfileSyncServiceMock> service;
98
99 browser_sync::SyncBackendHost::Status status;
100 EXPECT_CALL(service, QueryDetailedSyncStatus())
101 .WillRepeatedly(Return(status));
102
103 struct {
104 GoogleServiceAuthError::State error_state;
105 bool is_error;
106 } table[] = {
107 { GoogleServiceAuthError::NONE, false },
108 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true },
109 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true },
110 { GoogleServiceAuthError::CONNECTION_FAILED, false },
111 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true },
112 { GoogleServiceAuthError::ACCOUNT_DELETED, true },
113 { GoogleServiceAuthError::ACCOUNT_DISABLED, true },
114 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true },
115 { GoogleServiceAuthError::TWO_FACTOR, true },
116 { GoogleServiceAuthError::REQUEST_CANCELED, true },
117 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
118 };
119
120 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
121 VerifySyncGlobalErrorResult(
122 &service, table[i].error_state, true, table[i].is_error);
123 VerifySyncGlobalErrorResult(
124 &service, table[i].error_state, false, false);
125 }
62 } 126 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_ui_util.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698