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 "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 "content/test/test_browser_thread.h" | 10 #include "content/test/test_browser_thread.h" |
11 #include "testing/gmock/include/gmock/gmock-actions.h" | 11 #include "testing/gmock/include/gmock/gmock-actions.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using ::testing::Return; | 15 using ::testing::Return; |
16 using ::testing::ReturnRef; | |
17 using ::testing::NiceMock; | 16 using ::testing::NiceMock; |
18 using content::BrowserThread; | 17 using content::BrowserThread; |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // Utility function to test that SyncGlobalError behaves correct for the given | 21 // Utility function to test that SyncGlobalError behaves correct for the given |
23 // error condition. | 22 // error condition. |
24 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 23 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
25 SyncGlobalError* error, | 24 SyncGlobalError* error, |
26 GoogleServiceAuthError::State error_state, | 25 GoogleServiceAuthError::State error_state, |
27 bool is_signed_in, | 26 bool is_signed_in, |
28 bool is_error) { | 27 bool is_error) { |
| 28 GoogleServiceAuthError auth_error(error_state); |
| 29 service->UpdateAuthErrorState(auth_error); |
| 30 |
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) { | 33 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { |
32 EXPECT_CALL(*service, GetAuthenticatedUsername()) | 34 EXPECT_CALL(*service, GetAuthenticatedUsername()) |
33 .WillRepeatedly(Return(UTF8ToUTF16(""))); | 35 .WillRepeatedly(Return(UTF8ToUTF16(""))); |
34 } else { | 36 } else { |
35 EXPECT_CALL(*service, GetAuthenticatedUsername()) | 37 EXPECT_CALL(*service, GetAuthenticatedUsername()) |
36 .WillRepeatedly(Return(UTF8ToUTF16("foo"))); | 38 .WillRepeatedly(Return(UTF8ToUTF16("foo"))); |
37 } | 39 } |
38 | 40 |
39 GoogleServiceAuthError auth_error(error_state); | |
40 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); | |
41 | |
42 error->OnStateChanged(); | 41 error->OnStateChanged(); |
43 | 42 |
44 // If there is an error then a wrench button badge, menu item, and bubble view | 43 // If there is an error then a wrench button badge, menu item, and bubble view |
45 // should be shown. | 44 // should be shown. |
46 EXPECT_EQ(error->HasBadge(), is_error); | 45 EXPECT_EQ(error->HasBadge(), is_error); |
47 EXPECT_EQ(error->HasMenuItem() || error->HasCustomizedSyncMenuItem(), | 46 EXPECT_EQ(error->HasMenuItem() || error->HasCustomizedSyncMenuItem(), |
48 is_error); | 47 is_error); |
49 EXPECT_EQ(error->HasBubbleView(), is_error); | 48 EXPECT_EQ(error->HasBubbleView(), is_error); |
50 | 49 |
51 // If there is an error then labels should not be empty. | 50 // If there is an error then labels should not be empty. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |