Adding parameter to GetStatusLabels to indicate if links are acceptable, as...

Adding parameter to GetStatusLabels to indicate if links are acceptable, as some platforms cannot handle links in all the places these messages are shown.

Also adding unit tests for other functionality of GetStatusLabels.

BUG=none, discussed beforehand with akalin
TEST=HtmlNotIncludedInStatusIfNotRequested


Review URL: http://codereview.chromium.org/8383036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110905 0039d316-1c4b-4281-b951-d872f2087c98
parent b5bbc7fc
...@@ -10199,6 +10199,9 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -10199,6 +10199,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
Synced as <ph name="USER_EMAIL_ADDRESS">$1<ex>foo@gmail.com</ex></ph>. Last synced: <ph name="LAST_SYNC_TIME">$2<ex>12 seconds ago</ex></ph> Synced as <ph name="USER_EMAIL_ADDRESS">$1<ex>foo@gmail.com</ex></ph>. Last synced: <ph name="LAST_SYNC_TIME">$2<ex>12 seconds ago</ex></ph>
</message> </message>
<message name="IDS_SYNC_ACCOUNT_SYNCING_TO_USER" desc="The message that appears in the options dialog indicating that account is syncing to a user with the given email address."> <message name="IDS_SYNC_ACCOUNT_SYNCING_TO_USER" desc="The message that appears in the options dialog indicating that account is syncing to a user with the given email address.">
Signed in as <ph name="USER_EMAIL_ADDRESS">$1<ex>foo@gmail.com</ex></ph>.
</message>
<message name="IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK" desc="The message that appears in the options dialog indicating that account is syncing to a user with the given email address, together with a link to manage their data (where supported, or not possible through the application)">
Signed in as <ph name="USER_EMAIL_ADDRESS">$1<ex>foo@gmail.com</ex></ph>. Manage your synced data on <ph name="BEGIN_LINK">&lt;a href="$2"&gt;</ph>Google Dashboard<ph name="END_LINK">&lt;/a&gt;.</ph> Signed in as <ph name="USER_EMAIL_ADDRESS">$1<ex>foo@gmail.com</ex></ph>. Manage your synced data on <ph name="BEGIN_LINK">&lt;a href="$2"&gt;</ph>Google Dashboard<ph name="END_LINK">&lt;/a&gt;.</ph>
</message> </message>
<message name="IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED" desc="The sync setup is underway and the user has not yet entered credentials."> <message name="IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED" desc="The sync setup is underway and the user has not yet entered credentials.">
......
...@@ -996,6 +996,10 @@ SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { ...@@ -996,6 +996,10 @@ SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() {
} }
} }
const GoogleServiceAuthError& ProfileSyncService::GetAuthError() const {
return last_auth_error_;
}
bool ProfileSyncService::SetupInProgress() const { bool ProfileSyncService::SetupInProgress() const {
return !HasSyncSetupCompleted() && WizardIsVisible(); return !HasSyncSetupCompleted() && WizardIsVisible();
} }
...@@ -1023,6 +1027,10 @@ bool ProfileSyncService::unrecoverable_error_detected() const { ...@@ -1023,6 +1027,10 @@ bool ProfileSyncService::unrecoverable_error_detected() const {
return unrecoverable_error_detected_; return unrecoverable_error_detected_;
} }
bool ProfileSyncService::UIShouldDepictAuthInProgress() const {
return is_auth_in_progress_;
}
bool ProfileSyncService::IsPassphraseRequired() const { bool ProfileSyncService::IsPassphraseRequired() const {
return passphrase_required_reason_ != return passphrase_required_reason_ !=
sync_api::REASON_PASSPHRASE_NOT_REQUIRED; sync_api::REASON_PASSPHRASE_NOT_REQUIRED;
......
...@@ -247,9 +247,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, ...@@ -247,9 +247,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary(); browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary();
virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus(); virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus();
const GoogleServiceAuthError& GetAuthError() const { virtual const GoogleServiceAuthError& GetAuthError() const;
return last_auth_error_;
}
// Displays a dialog for the user to enter GAIA credentials and attempt // Displays a dialog for the user to enter GAIA credentials and attempt
// re-authentication, and returns true if it actually opened the dialog. // re-authentication, and returns true if it actually opened the dialog.
...@@ -301,9 +299,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, ...@@ -301,9 +299,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
return unrecoverable_error_location_; return unrecoverable_error_location_;
} }
bool UIShouldDepictAuthInProgress() const { virtual bool UIShouldDepictAuthInProgress() const;
return is_auth_in_progress_;
}
// Returns true if OnPassphraseRequired has been called for any reason. // Returns true if OnPassphraseRequired has been called for any reason.
virtual bool IsPassphraseRequired() const; virtual bool IsPassphraseRequired() const;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/sync_protocol_error.h" #include "chrome/browser/sync/protocol/sync_protocol_error.h"
#include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
class ProfileSyncServiceMock : public ProfileSyncService { class ProfileSyncServiceMock : public ProfileSyncService {
...@@ -59,8 +60,11 @@ class ProfileSyncServiceMock : public ProfileSyncService { ...@@ -59,8 +60,11 @@ class ProfileSyncServiceMock : public ProfileSyncService {
MOCK_CONST_METHOD0(GetLastSessionSnapshot, MOCK_CONST_METHOD0(GetLastSessionSnapshot,
const browser_sync::sessions::SyncSessionSnapshot*()); const browser_sync::sessions::SyncSessionSnapshot*());
MOCK_CONST_METHOD0(UIShouldDepictAuthInProgress, bool());
MOCK_METHOD0(QueryDetailedSyncStatus, MOCK_METHOD0(QueryDetailedSyncStatus,
browser_sync::SyncBackendHost::Status()); browser_sync::SyncBackendHost::Status());
MOCK_CONST_METHOD0(GetAuthError, const GoogleServiceAuthError&());
MOCK_CONST_METHOD0(SetupInProgress, bool());
MOCK_CONST_METHOD0(GetLastSyncedTimeString, string16()); MOCK_CONST_METHOD0(GetLastSyncedTimeString, string16());
MOCK_CONST_METHOD0(unrecoverable_error_detected, bool()); MOCK_CONST_METHOD0(unrecoverable_error_detected, bool());
MOCK_METHOD1(OnActionableError, void( MOCK_METHOD1(OnActionableError, void(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ::testing::Return; using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::NiceMock; using ::testing::NiceMock;
using content::BrowserThread; using content::BrowserThread;
...@@ -25,9 +26,6 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, ...@@ -25,9 +26,6 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
GoogleServiceAuthError::State error_state, GoogleServiceAuthError::State error_state,
bool is_signed_in, bool is_signed_in,
bool is_error) { bool is_error) {
GoogleServiceAuthError auth_error(error_state);
service->UpdateAuthErrorState(auth_error);
EXPECT_CALL(*service, HasSyncSetupCompleted()) EXPECT_CALL(*service, HasSyncSetupCompleted())
.WillRepeatedly(Return(is_signed_in)); .WillRepeatedly(Return(is_signed_in));
if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
...@@ -38,6 +36,9 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, ...@@ -38,6 +36,9 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
.WillRepeatedly(Return(UTF8ToUTF16("foo"))); .WillRepeatedly(Return(UTF8ToUTF16("foo")));
} }
GoogleServiceAuthError auth_error(error_state);
EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error));
error->OnStateChanged(); error->OnStateChanged();
// If there is an error then a wrench button badge, menu item, and bubble view // If there is an error then a wrench button badge, menu item, and bubble view
......
...@@ -132,16 +132,28 @@ void GetStatusLabelsForAuthError(const AuthError& auth_error, ...@@ -132,16 +132,28 @@ void GetStatusLabelsForAuthError(const AuthError& auth_error,
// Returns the message that should be displayed when the user is authenticated // Returns the message that should be displayed when the user is authenticated
// and can connect to the sync server. If the user hasn't yet authenticated, an // and can connect to the sync server. If the user hasn't yet authenticated, an
// empty string is returned. // empty string is returned.
string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { string16 GetSyncedStateStatusLabel(ProfileSyncService* service,
StatusLabelStyle style) {
string16 label; string16 label;
string16 user_name(service->GetAuthenticatedUsername()); string16 user_name(service->GetAuthenticatedUsername());
if (user_name.empty()) if (user_name.empty())
return label; return label;
return l10n_util::GetStringFUTF16( // Message may also carry additional advice with an HTML link, if acceptable.
IDS_SYNC_ACCOUNT_SYNCING_TO_USER, switch (style) {
user_name, case PLAIN_TEXT:
ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); return l10n_util::GetStringFUTF16(
IDS_SYNC_ACCOUNT_SYNCING_TO_USER,
user_name);
case WITH_HTML:
return l10n_util::GetStringFUTF16(
IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK,
user_name,
ASCIIToUTF16(chrome::kSyncGoogleDashboardURL));
default:
NOTREACHED();
return NULL;
}
} }
void GetStatusForActionableError( void GetStatusForActionableError(
...@@ -175,6 +187,7 @@ void GetStatusForActionableError( ...@@ -175,6 +187,7 @@ void GetStatusForActionableError(
// status_label and link_label must either be both NULL or both non-NULL. // status_label and link_label must either be both NULL or both non-NULL.
MessageType GetStatusInfo(ProfileSyncService* service, MessageType GetStatusInfo(ProfileSyncService* service,
StatusLabelStyle style,
string16* status_label, string16* status_label,
string16* link_label) { string16* link_label) {
DCHECK_EQ(status_label == NULL, link_label == NULL); DCHECK_EQ(status_label == NULL, link_label == NULL);
...@@ -237,7 +250,7 @@ MessageType GetStatusInfo(ProfileSyncService* service, ...@@ -237,7 +250,7 @@ MessageType GetStatusInfo(ProfileSyncService* service,
// current synced status. Return SYNC_PROMO so that // current synced status. Return SYNC_PROMO so that
// the configure link will still be shown. // the configure link will still be shown.
if (status_label && link_label) { if (status_label && link_label) {
status_label->assign(GetSyncedStateStatusLabel(service)); status_label->assign(GetSyncedStateStatusLabel(service, style));
link_label->assign( link_label->assign(
l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION));
} }
...@@ -247,7 +260,7 @@ MessageType GetStatusInfo(ProfileSyncService* service, ...@@ -247,7 +260,7 @@ MessageType GetStatusInfo(ProfileSyncService* service,
// There is no error. Display "Last synced..." message. // There is no error. Display "Last synced..." message.
if (status_label) if (status_label)
status_label->assign(GetSyncedStateStatusLabel(service)); status_label->assign(GetSyncedStateStatusLabel(service, style));
return SYNCED; return SYNCED;
} else { } else {
// Either show auth error information with a link to re-login, auth in prog, // Either show auth error information with a link to re-login, auth in prog,
...@@ -329,17 +342,18 @@ MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service, ...@@ -329,17 +342,18 @@ MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service,
} }
// Fallback to default. // Fallback to default.
return GetStatusInfo(service, status_label, link_label); return GetStatusInfo(service, WITH_HTML, status_label, link_label);
} }
} // namespace } // namespace
MessageType GetStatusLabels(ProfileSyncService* service, MessageType GetStatusLabels(ProfileSyncService* service,
StatusLabelStyle style,
string16* status_label, string16* status_label,
string16* link_label) { string16* link_label) {
DCHECK(status_label); DCHECK(status_label);
DCHECK(link_label); DCHECK(link_label);
return sync_ui_util::GetStatusInfo(service, status_label, link_label); return sync_ui_util::GetStatusInfo(service, style, status_label, link_label);
} }
MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service,
...@@ -390,7 +404,7 @@ void GetStatusLabelsForSyncGlobalError(ProfileSyncService* service, ...@@ -390,7 +404,7 @@ void GetStatusLabelsForSyncGlobalError(ProfileSyncService* service,
} }
MessageType GetStatus(ProfileSyncService* service) { MessageType GetStatus(ProfileSyncService* service) {
return sync_ui_util::GetStatusInfo(service, NULL, NULL); return sync_ui_util::GetStatusInfo(service, WITH_HTML, NULL, NULL);
} }
string16 GetSyncMenuLabel(ProfileSyncService* service) { string16 GetSyncMenuLabel(ProfileSyncService* service) {
......
...@@ -32,13 +32,19 @@ enum MessageType { ...@@ -32,13 +32,19 @@ enum MessageType {
// attention, but not as an error. // attention, but not as an error.
}; };
enum StatusLabelStyle {
PLAIN_TEXT, // Label will be plain-text only.
WITH_HTML // Label may contain an HTML-formatted link.
};
// TODO(akalin): audit the use of ProfileSyncService* service below, // TODO(akalin): audit the use of ProfileSyncService* service below,
// and use const ProfileSyncService& service where possible. // and use const ProfileSyncService& service where possible.
// Create status and link labels for the current status labels and link text // Create status and link labels for the current status labels and link text
// by querying |service|. // by querying |service|.
// |status_label| may contain an HTML-formatted link. // |style| sets the link properties, see |StatusLabelStyle|.
MessageType GetStatusLabels(ProfileSyncService* service, MessageType GetStatusLabels(ProfileSyncService* service,
StatusLabelStyle style,
string16* status_label, string16* status_label,
string16* link_label); string16* link_label);
......
...@@ -252,7 +252,8 @@ void PersonalOptionsHandler::OnStateChanged() { ...@@ -252,7 +252,8 @@ void PersonalOptionsHandler::OnStateChanged() {
bool managed = service->IsManaged(); bool managed = service->IsManaged();
bool sync_setup_completed = service->HasSyncSetupCompleted(); bool sync_setup_completed = service->HasSyncSetupCompleted();
bool status_has_error = sync_ui_util::GetStatusLabels( bool status_has_error = sync_ui_util::GetStatusLabels(
service, &status_label, &link_label) == sync_ui_util::SYNC_ERROR; service, sync_ui_util::WITH_HTML, &status_label, &link_label) ==
sync_ui_util::SYNC_ERROR;
string16 start_stop_button_label; string16 start_stop_button_label;
bool is_start_stop_button_visible = false; bool is_start_stop_button_visible = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment