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
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 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>
</message>
<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() {
}
}
const GoogleServiceAuthError& ProfileSyncService::GetAuthError() const {
return last_auth_error_;
}
bool ProfileSyncService::SetupInProgress() const {
return !HasSyncSetupCompleted() && WizardIsVisible();
}
......@@ -1023,6 +1027,10 @@ bool ProfileSyncService::unrecoverable_error_detected() const {
return unrecoverable_error_detected_;
}
bool ProfileSyncService::UIShouldDepictAuthInProgress() const {
return is_auth_in_progress_;
}
bool ProfileSyncService::IsPassphraseRequired() const {
return passphrase_required_reason_ !=
sync_api::REASON_PASSPHRASE_NOT_REQUIRED;
......
......@@ -247,9 +247,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary();
virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus();
const GoogleServiceAuthError& GetAuthError() const {
return last_auth_error_;
}
virtual const GoogleServiceAuthError& GetAuthError() const;
// Displays a dialog for the user to enter GAIA credentials and attempt
// re-authentication, and returns true if it actually opened the dialog.
......@@ -301,9 +299,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
return unrecoverable_error_location_;
}
bool UIShouldDepictAuthInProgress() const {
return is_auth_in_progress_;
}
virtual bool UIShouldDepictAuthInProgress() const;
// Returns true if OnPassphraseRequired has been called for any reason.
virtual bool IsPassphraseRequired() const;
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/sync_protocol_error.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"
class ProfileSyncServiceMock : public ProfileSyncService {
......@@ -59,8 +60,11 @@ class ProfileSyncServiceMock : public ProfileSyncService {
MOCK_CONST_METHOD0(GetLastSessionSnapshot,
const browser_sync::sessions::SyncSessionSnapshot*());
MOCK_CONST_METHOD0(UIShouldDepictAuthInProgress, bool());
MOCK_METHOD0(QueryDetailedSyncStatus,
browser_sync::SyncBackendHost::Status());
MOCK_CONST_METHOD0(GetAuthError, const GoogleServiceAuthError&());
MOCK_CONST_METHOD0(SetupInProgress, bool());
MOCK_CONST_METHOD0(GetLastSyncedTimeString, string16());
MOCK_CONST_METHOD0(unrecoverable_error_detected, bool());
MOCK_METHOD1(OnActionableError, void(
......
......@@ -13,6 +13,7 @@
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::NiceMock;
using content::BrowserThread;
......@@ -25,9 +26,6 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
GoogleServiceAuthError::State error_state,
bool is_signed_in,
bool is_error) {
GoogleServiceAuthError auth_error(error_state);
service->UpdateAuthErrorState(auth_error);
EXPECT_CALL(*service, HasSyncSetupCompleted())
.WillRepeatedly(Return(is_signed_in));
if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
......@@ -38,6 +36,9 @@ void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
.WillRepeatedly(Return(UTF8ToUTF16("foo")));
}
GoogleServiceAuthError auth_error(error_state);
EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error));
error->OnStateChanged();
// 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,
// 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
// empty string is returned.
string16 GetSyncedStateStatusLabel(ProfileSyncService* service) {
string16 GetSyncedStateStatusLabel(ProfileSyncService* service,
StatusLabelStyle style) {
string16 label;
string16 user_name(service->GetAuthenticatedUsername());
if (user_name.empty())
return label;
// Message may also carry additional advice with an HTML link, if acceptable.
switch (style) {
case PLAIN_TEXT:
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(
......@@ -175,6 +187,7 @@ void GetStatusForActionableError(
// status_label and link_label must either be both NULL or both non-NULL.
MessageType GetStatusInfo(ProfileSyncService* service,
StatusLabelStyle style,
string16* status_label,
string16* link_label) {
DCHECK_EQ(status_label == NULL, link_label == NULL);
......@@ -237,7 +250,7 @@ MessageType GetStatusInfo(ProfileSyncService* service,
// current synced status. Return SYNC_PROMO so that
// the configure link will still be shown.
if (status_label && link_label) {
status_label->assign(GetSyncedStateStatusLabel(service));
status_label->assign(GetSyncedStateStatusLabel(service, style));
link_label->assign(
l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION));
}
......@@ -247,7 +260,7 @@ MessageType GetStatusInfo(ProfileSyncService* service,
// There is no error. Display "Last synced..." message.
if (status_label)
status_label->assign(GetSyncedStateStatusLabel(service));
status_label->assign(GetSyncedStateStatusLabel(service, style));
return SYNCED;
} else {
// Either show auth error information with a link to re-login, auth in prog,
......@@ -329,17 +342,18 @@ MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service,
}
// Fallback to default.
return GetStatusInfo(service, status_label, link_label);
return GetStatusInfo(service, WITH_HTML, status_label, link_label);
}
} // namespace
MessageType GetStatusLabels(ProfileSyncService* service,
StatusLabelStyle style,
string16* status_label,
string16* link_label) {
DCHECK(status_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,
......@@ -390,7 +404,7 @@ void GetStatusLabelsForSyncGlobalError(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) {
......
......@@ -32,13 +32,19 @@ enum MessageType {
// 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,
// and use const ProfileSyncService& service where possible.
// Create status and link labels for the current status labels and link text
// by querying |service|.
// |status_label| may contain an HTML-formatted link.
// |style| sets the link properties, see |StatusLabelStyle|.
MessageType GetStatusLabels(ProfileSyncService* service,
StatusLabelStyle style,
string16* status_label,
string16* link_label);
......
......@@ -252,7 +252,8 @@ void PersonalOptionsHandler::OnStateChanged() {
bool managed = service->IsManaged();
bool sync_setup_completed = service->HasSyncSetupCompleted();
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;
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