Index: chrome/browser/sync/sync_ui_util_unittest.cc |
diff --git a/chrome/browser/sync/sync_ui_util_unittest.cc b/chrome/browser/sync/sync_ui_util_unittest.cc |
index d527f0f464d99a16527f5ba7f957a09935992ee1..336aa20b3b1226114fd7f60a66269bad3a8da3d0 100644 |
--- a/chrome/browser/sync/sync_ui_util_unittest.cc |
+++ b/chrome/browser/sync/sync_ui_util_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <set> |
#include "base/basictypes.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/sync/profile_sync_service_mock.h" |
@@ -12,8 +13,22 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
using ::testing::Return; |
+using ::testing::ReturnRef; |
using ::testing::NiceMock; |
+// A number of distinct states of the ProfileSyncService can be generated for |
+// tests. |
+enum DistinctState { |
+ STATUS_CASE_SETUP_IN_PROGRESS, |
+ STATUS_CASE_SETUP_ERROR, |
+ STATUS_CASE_AUTHENTICATING, |
+ STATUS_CASE_AUTH_ERROR, |
+ STATUS_CASE_PROTOCOL_ERROR, |
+ STATUS_CASE_PASSPHRASE_ERROR, |
+ STATUS_CASE_SYNCED, |
+ NUMBER_OF_STATUS_CASES |
+}; |
+ |
namespace { |
// Utility function to test that GetStatusLabelsForSyncGlobalError returns |
@@ -124,3 +139,185 @@ TEST(SyncUIUtilTest, AuthStateGlobalError) { |
&service, table[i].error_state, false, false); |
} |
} |
+// Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases |
+// in order to perform tests on the generated messages. |
+void GetDistinctCase(ProfileSyncServiceMock& service, |
+ GoogleServiceAuthError** auth_error, |
+ int caseNumber) { |
+ // Auth Error object is returned by reference in mock and needs to stay in |
+ // scope throughout test, so it is owned by calling method. However it is |
+ // immutable so can only be allocated in this method. |
+ switch (caseNumber) { |
+ case STATUS_CASE_SETUP_IN_PROGRESS: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(false)); |
+ EXPECT_CALL(service, SetupInProgress()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
+ EXPECT_CALL(service, GetAuthError()) |
+ .WillOnce(ReturnRef(**auth_error)); |
+ EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
+ .WillOnce(Return(false)); |
+ return; |
+ } |
+ case STATUS_CASE_SETUP_ERROR: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(false)); |
+ EXPECT_CALL(service, SetupInProgress()) |
+ .WillOnce(Return(false)); |
+ EXPECT_CALL(service, unrecoverable_error_detected()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ return; |
+ } |
+ case STATUS_CASE_AUTHENTICATING: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
+ .WillOnce(Return(true)); |
+ *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
+ EXPECT_CALL(service, GetAuthError()) |
+ .WillOnce(ReturnRef(**auth_error)); |
+ return; |
+ } |
+ case STATUS_CASE_AUTH_ERROR: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ *auth_error = new GoogleServiceAuthError( |
+ GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
+ EXPECT_CALL(service, GetAuthenticatedUsername()) |
+ .WillOnce(Return(ASCIIToUTF16(""))); |
+ EXPECT_CALL(service, GetAuthError()) |
+ .WillOnce(ReturnRef(**auth_error)); |
+ EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
+ .WillOnce(Return(false)); |
+ return; |
+ } |
+ case STATUS_CASE_PROTOCOL_ERROR: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncProtocolError protocolError; |
+ protocolError.action = browser_sync::STOP_AND_RESTART_SYNC; |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ status.sync_protocol_error = protocolError; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
+ EXPECT_CALL(service, GetAuthError()) |
+ .WillOnce(ReturnRef(**auth_error)); |
+ EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
+ .WillOnce(Return(false)); |
+ return; |
+ } |
+ case STATUS_CASE_PASSPHRASE_ERROR: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
+ EXPECT_CALL(service, GetAuthError()) |
+ .WillOnce(ReturnRef(**auth_error)); |
+ EXPECT_CALL(service, GetAuthenticatedUsername()) |
+ .WillOnce(Return(ASCIIToUTF16("example@example.com"))); |
+ EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
+ .WillOnce(Return(false)); |
+ EXPECT_CALL(service, IsPassphraseRequired()) |
+ .WillOnce(Return(true)); |
+ EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
+ .WillOnce(Return(true)); |
+ return; |
+ } |
+ case STATUS_CASE_SYNCED: { |
+ EXPECT_CALL(service, HasSyncSetupCompleted()) |
+ .WillOnce(Return(true)); |
+ browser_sync::SyncBackendHost::Status status; |
+ status.summary = browser_sync::SyncBackendHost::Status::READY; |
+ EXPECT_CALL(service, QueryDetailedSyncStatus()) |
+ .WillOnce(Return(status)); |
+ *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
+ EXPECT_CALL(service, GetAuthError()) |
+ .WillOnce(ReturnRef(**auth_error)); |
+ EXPECT_CALL(service, GetAuthenticatedUsername()) |
+ .WillOnce(Return(ASCIIToUTF16("example@example.com"))); |
+ EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
+ .WillOnce(Return(false)); |
+ EXPECT_CALL(service, IsPassphraseRequired()) |
+ .WillOnce(Return(false)); |
+ return; |
+ } |
+ default: |
+ NOTREACHED(); |
+ } |
+} |
+ |
+// This test ensures that a each distinctive ProfileSyncService statuses |
+// will return a unique combination of status and link messages from |
+// GetStatusLabels(). |
+TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
+ ProfileSyncServiceMock service; |
+ |
+ std::set<string16> messages; |
+ for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
+ ProfileSyncServiceMock service; |
+ GoogleServiceAuthError* auth_error = NULL; |
+ GetDistinctCase(service, &auth_error, idx); |
+ string16 status_label; |
+ string16 link_label; |
+ sync_ui_util::GetStatusLabels(&service, |
+ &status_label, |
+ &link_label, |
+ true); |
+ // If the status and link message combination is already present in the set |
+ // of messages already seen, this is a duplicate rather than a unique |
+ // message, and the test has failed. |
+ string16 combined_label = |
+ status_label + string16(ASCIIToUTF16("#")) + link_label; |
+ EXPECT_EQ(messages.find(combined_label), messages.end()); |
+ messages.insert(combined_label); |
+ if (auth_error) |
+ delete auth_error; |
+ } |
+} |
+ |
+// This test ensures that the html_links parameter on GetStatusLabels() is |
+// honored. |
+TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
+ ProfileSyncServiceMock service; |
+ for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
+ ProfileSyncServiceMock service; |
+ GoogleServiceAuthError* auth_error = NULL; |
+ GetDistinctCase(service, &auth_error, idx); |
+ string16 status_label; |
+ string16 link_label; |
+ sync_ui_util::GetStatusLabels(&service, |
+ &status_label, |
+ &link_label, |
+ false); |
+ // Ensures a search for string 'href' (found in links, not a string to be |
+ // found in an English language message) fails when links are excluded from |
+ // the status label. |
+ EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
+ string16::npos); |
+ if (auth_error) { |
+ delete auth_error; |
+ } |
+ } |
+} |