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

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: 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
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
31 string16 label1, label2, label3;
32 sync_ui_util::GetStatusLabelsForSyncGlobalError(
33 service, &label1, &label2, &label3);
34 EXPECT_EQ(label1.empty(), !is_error);
35 EXPECT_EQ(label2.empty(), !is_error);
36 EXPECT_EQ(label3.empty(), !is_error);
37 }
38
39 } // namespace
40
16 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { 41 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) {
17 MessageLoopForUI message_loop; 42 MessageLoopForUI message_loop;
18 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 43 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
19 NiceMock<ProfileSyncServiceMock> service; 44 NiceMock<ProfileSyncServiceMock> service;
20 DictionaryValue strings; 45 DictionaryValue strings;
21 46
22 // Will be released when the dictionary is destroyed 47 // Will be released when the dictionary is destroyed
23 string16 str(ASCIIToUTF16("none")); 48 string16 str(ASCIIToUTF16("none"));
24 49
25 browser_sync::SyncBackendHost::Status status; 50 browser_sync::SyncBackendHost::Status status;
(...skipping 15 matching lines...) Expand all
41 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); 66 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected"));
42 } 67 }
43 68
44 // Test that GetStatusLabelsForSyncGlobalError returns an error if a 69 // Test that GetStatusLabelsForSyncGlobalError returns an error if a
45 // passphrase is required. 70 // passphrase is required.
46 TEST(SyncUIUtilTest, PassphraseGlobalError) { 71 TEST(SyncUIUtilTest, PassphraseGlobalError) {
47 MessageLoopForUI message_loop; 72 MessageLoopForUI message_loop;
48 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 73 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
49 NiceMock<ProfileSyncServiceMock> service; 74 NiceMock<ProfileSyncServiceMock> service;
50 75
51 EXPECT_CALL(service, HasSyncSetupCompleted())
52 .WillOnce(Return(true));
53 EXPECT_CALL(service, IsPassphraseRequired()) 76 EXPECT_CALL(service, IsPassphraseRequired())
54 .WillOnce(Return(true)); 77 .WillOnce(Return(true));
55 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) 78 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
56 .WillOnce(Return(true)); 79 .WillOnce(Return(true));
80 VerifySyncGlobalErrorResult(
81 &service, GoogleServiceAuthError::NONE, true, true);
82 }
57 83
58 sync_ui_util::MessageType type = 84 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions
59 sync_ui_util::GetStatusLabelsForSyncGlobalError( 85 // that can be resolved by the user and suppresses errors for conditions that
60 &service, NULL, NULL, NULL); 86 // cannot be resolved by the user.
61 EXPECT_EQ(type, sync_ui_util::SYNC_ERROR); 87 TEST(SyncUIUtilTest, AuthStateGlobalError) {
88 MessageLoopForUI message_loop;
89 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
90 NiceMock<ProfileSyncServiceMock> service;
91
92 EXPECT_CALL(service, GetAuthenticatedUsername())
93 .WillRepeatedly(Return(UTF8ToUTF16("foo")));
94 browser_sync::SyncBackendHost::Status status;
95 EXPECT_CALL(service, QueryDetailedSyncStatus())
96 .WillRepeatedly(Return(status));
97
98 struct {
99 GoogleServiceAuthError::State error_state;
100 bool is_error;
101 } table[] = {
102 { GoogleServiceAuthError::NONE, false },
103 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true },
104 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true },
105 { GoogleServiceAuthError::CONNECTION_FAILED, false },
106 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true },
107 { GoogleServiceAuthError::ACCOUNT_DELETED, true },
108 { GoogleServiceAuthError::ACCOUNT_DISABLED, true },
109 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true },
110 { GoogleServiceAuthError::TWO_FACTOR, true },
111 { GoogleServiceAuthError::REQUEST_CANCELED, true },
112 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
113 };
114
115 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
116 VerifySyncGlobalErrorResult(
117 &service, table[i].error_state, true, table[i].is_error);
118 VerifySyncGlobalErrorResult(
119 &service, table[i].error_state, false, false);
120 }
62 } 121 }
OLDNEW
« chrome/browser/sync/sync_ui_util.cc ('K') | « chrome/browser/sync/sync_ui_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698