OLD | NEW |
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 <set> | 5 #include <set> |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
| 7 #include "base/stringprintf.h" |
7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/sync/profile_sync_service_mock.h" | 10 #include "chrome/browser/sync/profile_sync_service_mock.h" |
9 #include "chrome/browser/sync/sync_ui_util.h" | 11 #include "chrome/browser/sync/sync_ui_util.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::AtMost; | 17 using ::testing::AtMost; |
16 using ::testing::Return; | 18 using ::testing::Return; |
17 using ::testing::ReturnRef; | 19 using ::testing::ReturnRef; |
(...skipping 17 matching lines...) Expand all Loading... |
35 | 37 |
36 // Utility function to test that GetStatusLabelsForSyncGlobalError returns | 38 // Utility function to test that GetStatusLabelsForSyncGlobalError returns |
37 // the correct results for the given states. | 39 // the correct results for the given states. |
38 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 40 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
39 GoogleServiceAuthError::State error_state, | 41 GoogleServiceAuthError::State error_state, |
40 bool is_signed_in, | 42 bool is_signed_in, |
41 bool is_error) { | 43 bool is_error) { |
42 EXPECT_CALL(*service, HasSyncSetupCompleted()) | 44 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
43 .WillRepeatedly(Return(is_signed_in)); | 45 .WillRepeatedly(Return(is_signed_in)); |
44 | 46 |
45 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | |
46 EXPECT_CALL(*service, GetAuthenticatedUsername()) | |
47 .WillRepeatedly(Return(UTF8ToUTF16(""))); | |
48 } else { | |
49 EXPECT_CALL(*service, GetAuthenticatedUsername()) | |
50 .WillRepeatedly(Return(UTF8ToUTF16("foo"))); | |
51 } | |
52 | |
53 GoogleServiceAuthError auth_error(error_state); | 47 GoogleServiceAuthError auth_error(error_state); |
54 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); | 48 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); |
55 | 49 |
56 string16 label1, label2, label3; | 50 string16 label1, label2, label3; |
57 sync_ui_util::GetStatusLabelsForSyncGlobalError( | 51 sync_ui_util::GetStatusLabelsForSyncGlobalError( |
58 service, &label1, &label2, &label3); | 52 service, &label1, &label2, &label3); |
59 EXPECT_EQ(label1.empty(), !is_error); | 53 EXPECT_EQ(label1.empty(), !is_error); |
60 EXPECT_EQ(label2.empty(), !is_error); | 54 EXPECT_EQ(label2.empty(), !is_error); |
61 EXPECT_EQ(label3.empty(), !is_error); | 55 EXPECT_EQ(label3.empty(), !is_error); |
62 } | 56 } |
63 | 57 |
64 } // namespace | 58 } // namespace |
65 | 59 |
66 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { | 60 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { |
67 MessageLoopForUI message_loop; | 61 MessageLoopForUI message_loop; |
68 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 62 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
69 NiceMock<ProfileSyncServiceMock> service; | 63 scoped_ptr<Profile> profile( |
| 64 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 65 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
70 DictionaryValue strings; | 66 DictionaryValue strings; |
71 | 67 |
72 // Will be released when the dictionary is destroyed | 68 // Will be released when the dictionary is destroyed |
73 string16 str(ASCIIToUTF16("none")); | 69 string16 str(ASCIIToUTF16("none")); |
74 | 70 |
75 browser_sync::SyncBackendHost::Status status; | 71 browser_sync::SyncBackendHost::Status status; |
76 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; | 72 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; |
77 | 73 |
78 EXPECT_CALL(service, HasSyncSetupCompleted()) | 74 EXPECT_CALL(service, HasSyncSetupCompleted()) |
79 .WillOnce(Return(true)); | 75 .WillOnce(Return(true)); |
(...skipping 12 matching lines...) Expand all Loading... |
92 sync_ui_util::ConstructAboutInformation(&service, &strings); | 88 sync_ui_util::ConstructAboutInformation(&service, &strings); |
93 | 89 |
94 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); | 90 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); |
95 } | 91 } |
96 | 92 |
97 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 93 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
98 // passphrase is required. | 94 // passphrase is required. |
99 TEST(SyncUIUtilTest, PassphraseGlobalError) { | 95 TEST(SyncUIUtilTest, PassphraseGlobalError) { |
100 MessageLoopForUI message_loop; | 96 MessageLoopForUI message_loop; |
101 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 97 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
102 NiceMock<ProfileSyncServiceMock> service; | 98 scoped_ptr<Profile> profile( |
| 99 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 100 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
103 | 101 |
104 EXPECT_CALL(service, IsPassphraseRequired()) | 102 EXPECT_CALL(service, IsPassphraseRequired()) |
105 .WillOnce(Return(true)); | 103 .WillOnce(Return(true)); |
106 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 104 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
107 .WillOnce(Return(true)); | 105 .WillOnce(Return(true)); |
108 VerifySyncGlobalErrorResult( | 106 VerifySyncGlobalErrorResult( |
109 &service, GoogleServiceAuthError::NONE, true, true); | 107 &service, GoogleServiceAuthError::NONE, true, true); |
110 } | 108 } |
111 | 109 |
112 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions | 110 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions |
113 // that can be resolved by the user and suppresses errors for conditions that | 111 // that can be resolved by the user and suppresses errors for conditions that |
114 // cannot be resolved by the user. | 112 // cannot be resolved by the user. |
115 TEST(SyncUIUtilTest, AuthStateGlobalError) { | 113 TEST(SyncUIUtilTest, AuthStateGlobalError) { |
116 MessageLoopForUI message_loop; | 114 MessageLoopForUI message_loop; |
117 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 115 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
118 NiceMock<ProfileSyncServiceMock> service; | 116 scoped_ptr<Profile> profile( |
| 117 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 118 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
119 | 119 |
120 browser_sync::SyncBackendHost::Status status; | 120 browser_sync::SyncBackendHost::Status status; |
121 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 121 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
122 .WillRepeatedly(Return(status)); | 122 .WillRepeatedly(Return(status)); |
123 | 123 |
124 struct { | 124 struct { |
125 GoogleServiceAuthError::State error_state; | 125 GoogleServiceAuthError::State error_state; |
126 bool is_error; | 126 bool is_error; |
127 } table[] = { | 127 } table[] = { |
128 { GoogleServiceAuthError::NONE, false }, | 128 { GoogleServiceAuthError::NONE, false }, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // Ensures a search for string 'href' (found in links, not a string to be | 330 // Ensures a search for string 'href' (found in links, not a string to be |
331 // found in an English language message) fails when links are excluded from | 331 // found in an English language message) fails when links are excluded from |
332 // the status label. | 332 // the status label. |
333 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 333 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
334 string16::npos); | 334 string16::npos); |
335 if (auth_error) { | 335 if (auth_error) { |
336 delete auth_error; | 336 delete auth_error; |
337 } | 337 } |
338 } | 338 } |
339 } | 339 } |
OLD | NEW |