Commit fc4869db authored by Andrey Zaytsev's avatar Andrey Zaytsev Committed by Commit Bot

Safety check: renamed displayedString to displayString for consistency with...

Safety check: renamed displayedString to displayString for consistency with the rest of the codebase

Bug: 1015841
Change-Id: I65edf49f7224ab118ba164f9039fa1c717e578b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096696Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Andrey Zaytsev <andzaytsev@google.com>
Cr-Commit-Position: refs/heads/master@{#748713}
parent e97ce6f4
...@@ -32,7 +32,7 @@ constexpr char kSafeBrowsingEvent[] = ...@@ -32,7 +32,7 @@ constexpr char kSafeBrowsingEvent[] =
"safety-check-safe-browsing-status-changed"; "safety-check-safe-browsing-status-changed";
constexpr char kPerformSafetyCheck[] = "performSafetyCheck"; constexpr char kPerformSafetyCheck[] = "performSafetyCheck";
constexpr char kNewState[] = "newState"; constexpr char kNewState[] = "newState";
constexpr char kDisplayedString[] = "displayedString"; constexpr char kDisplayString[] = "displayString";
constexpr char kPasswordsCompromised[] = "passwordsCompromised"; constexpr char kPasswordsCompromised[] = "passwordsCompromised";
// Converts the VersionUpdater::Status to the UpdateStatus enum to be passed // Converts the VersionUpdater::Status to the UpdateStatus enum to be passed
...@@ -140,7 +140,7 @@ void SafetyCheckHandler::OnUpdateCheckResult(VersionUpdater::Status status, ...@@ -140,7 +140,7 @@ void SafetyCheckHandler::OnUpdateCheckResult(VersionUpdater::Status status,
UpdateStatus update_status = ConvertToUpdateStatus(status); UpdateStatus update_status = ConvertToUpdateStatus(status);
base::DictionaryValue event; base::DictionaryValue event;
event.SetIntKey(kNewState, static_cast<int>(update_status)); event.SetIntKey(kNewState, static_cast<int>(update_status));
event.SetStringKey(kDisplayedString, GetStringForUpdates(update_status)); event.SetStringKey(kDisplayString, GetStringForUpdates(update_status));
FireWebUIListener(kUpdatesEvent, event); FireWebUIListener(kUpdatesEvent, event);
} }
...@@ -148,7 +148,7 @@ void SafetyCheckHandler::OnSafeBrowsingCheckResult( ...@@ -148,7 +148,7 @@ void SafetyCheckHandler::OnSafeBrowsingCheckResult(
SafetyCheckHandler::SafeBrowsingStatus status) { SafetyCheckHandler::SafeBrowsingStatus status) {
base::DictionaryValue event; base::DictionaryValue event;
event.SetIntKey(kNewState, static_cast<int>(status)); event.SetIntKey(kNewState, static_cast<int>(status));
event.SetStringKey(kDisplayedString, GetStringForSafeBrowsing(status)); event.SetStringKey(kDisplayString, GetStringForSafeBrowsing(status));
FireWebUIListener(kSafeBrowsingEvent, event); FireWebUIListener(kSafeBrowsingEvent, event);
} }
...@@ -159,7 +159,7 @@ void SafetyCheckHandler::OnPasswordsCheckResult(PasswordsStatus status, ...@@ -159,7 +159,7 @@ void SafetyCheckHandler::OnPasswordsCheckResult(PasswordsStatus status,
if (status == PasswordsStatus::kCompromisedExist) { if (status == PasswordsStatus::kCompromisedExist) {
event.SetIntKey(kPasswordsCompromised, num_compromised); event.SetIntKey(kPasswordsCompromised, num_compromised);
} }
event.SetStringKey(kDisplayedString, event.SetStringKey(kDisplayString,
GetStringForPasswords(status, num_compromised)); GetStringForPasswords(status, num_compromised));
FireWebUIListener(kPasswordsEvent, event); FireWebUIListener(kPasswordsEvent, event);
} }
......
...@@ -54,10 +54,10 @@ class SafetyCheckHandlerTest : public ChromeRenderViewHostTestHarness { ...@@ -54,10 +54,10 @@ class SafetyCheckHandlerTest : public ChromeRenderViewHostTestHarness {
const std::string& component, const std::string& component,
int new_state); int new_state);
void VerifyDisplayedString(const base::DictionaryValue* event, void VerifyDisplayString(const base::DictionaryValue* event,
const base::string16& expected); const base::string16& expected);
void VerifyDisplayedString(const base::DictionaryValue* event, void VerifyDisplayString(const base::DictionaryValue* event,
const std::string& expected); const std::string& expected);
protected: protected:
TestVersionUpdater* version_updater_ = nullptr; TestVersionUpdater* version_updater_ = nullptr;
...@@ -116,24 +116,24 @@ SafetyCheckHandlerTest::GetSafetyCheckStatusChangedWithDataIfExists( ...@@ -116,24 +116,24 @@ SafetyCheckHandlerTest::GetSafetyCheckStatusChangedWithDataIfExists(
return nullptr; return nullptr;
} }
void SafetyCheckHandlerTest::VerifyDisplayedString( void SafetyCheckHandlerTest::VerifyDisplayString(
const base::DictionaryValue* event, const base::DictionaryValue* event,
const base::string16& expected) { const base::string16& expected) {
base::string16 displayed; base::string16 display;
ASSERT_TRUE(event->GetString("displayedString", &displayed)); ASSERT_TRUE(event->GetString("displayString", &display));
ReplaceBrowserName(&displayed); ReplaceBrowserName(&display);
// Need to also replace any instances of Chrome and Chromium in the expected // Need to also replace any instances of Chrome and Chromium in the expected
// string due to an edge case on ChromeOS, where a device name is "Chrome", // string due to an edge case on ChromeOS, where a device name is "Chrome",
// which gets replaced in the displayed string. // which gets replaced in the display string.
base::string16 expected_replaced = expected; base::string16 expected_replaced = expected;
ReplaceBrowserName(&expected_replaced); ReplaceBrowserName(&expected_replaced);
EXPECT_EQ(expected_replaced, displayed); EXPECT_EQ(expected_replaced, display);
} }
void SafetyCheckHandlerTest::VerifyDisplayedString( void SafetyCheckHandlerTest::VerifyDisplayString(
const base::DictionaryValue* event, const base::DictionaryValue* event,
const std::string& expected) { const std::string& expected) {
VerifyDisplayedString(event, base::ASCIIToUTF16(expected)); VerifyDisplayString(event, base::ASCIIToUTF16(expected));
} }
void SafetyCheckHandlerTest::ReplaceBrowserName(base::string16* s) { void SafetyCheckHandlerTest::ReplaceBrowserName(base::string16* s) {
...@@ -159,7 +159,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Checking) { ...@@ -159,7 +159,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Checking) {
kUpdates, kUpdates,
static_cast<int>(SafetyCheckHandler::UpdateStatus::kChecking)); static_cast<int>(SafetyCheckHandler::UpdateStatus::kChecking));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString(event, base::UTF8ToUTF16("Running…")); VerifyDisplayString(event, base::UTF8ToUTF16("Running…"));
} }
TEST_F(SafetyCheckHandlerTest, CheckUpdates_Updated) { TEST_F(SafetyCheckHandlerTest, CheckUpdates_Updated) {
...@@ -174,9 +174,9 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Updated) { ...@@ -174,9 +174,9 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Updated) {
base::string16 expected = base::ASCIIToUTF16("Your ") + base::string16 expected = base::ASCIIToUTF16("Your ") +
ui::GetChromeOSDeviceName() + ui::GetChromeOSDeviceName() +
base::ASCIIToUTF16(" is up to date"); base::ASCIIToUTF16(" is up to date");
VerifyDisplayedString(event, expected); VerifyDisplayString(event, expected);
#else #else
VerifyDisplayedString(event, "Browser is up to date"); VerifyDisplayString(event, "Browser is up to date");
#endif #endif
} }
...@@ -189,9 +189,9 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Updating) { ...@@ -189,9 +189,9 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Updating) {
static_cast<int>(SafetyCheckHandler::UpdateStatus::kUpdating)); static_cast<int>(SafetyCheckHandler::UpdateStatus::kUpdating));
ASSERT_TRUE(event); ASSERT_TRUE(event);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
VerifyDisplayedString(event, "Updating your device"); VerifyDisplayString(event, "Updating your device");
#else #else
VerifyDisplayedString(event, "Updating Browser"); VerifyDisplayString(event, "Updating Browser");
#endif #endif
} }
...@@ -204,12 +204,12 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Relaunch) { ...@@ -204,12 +204,12 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Relaunch) {
static_cast<int>(SafetyCheckHandler::UpdateStatus::kRelaunch)); static_cast<int>(SafetyCheckHandler::UpdateStatus::kRelaunch));
ASSERT_TRUE(event); ASSERT_TRUE(event);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
VerifyDisplayedString( VerifyDisplayString(
event, "Nearly up to date! Restart your device to finish updating."); event, "Nearly up to date! Restart your device to finish updating.");
#else #else
VerifyDisplayedString(event, VerifyDisplayString(event,
"Nearly up to date! Relaunch Browser to finish " "Nearly up to date! Relaunch Browser to finish "
"updating. Incognito windows won't reopen."); "updating. Incognito windows won't reopen.");
#endif #endif
} }
...@@ -222,7 +222,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_DisabledByAdmin) { ...@@ -222,7 +222,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_DisabledByAdmin) {
kUpdates, kUpdates,
static_cast<int>(SafetyCheckHandler::UpdateStatus::kDisabledByAdmin)); static_cast<int>(SafetyCheckHandler::UpdateStatus::kDisabledByAdmin));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString( VerifyDisplayString(
event, event,
"Updates are managed by <a target=\"_blank\" " "Updates are managed by <a target=\"_blank\" "
"href=\"https://support.google.com/accounts/answer/6208960\">your " "href=\"https://support.google.com/accounts/answer/6208960\">your "
...@@ -237,9 +237,9 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_FailedOffline) { ...@@ -237,9 +237,9 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_FailedOffline) {
kUpdates, kUpdates,
static_cast<int>(SafetyCheckHandler::UpdateStatus::kFailedOffline)); static_cast<int>(SafetyCheckHandler::UpdateStatus::kFailedOffline));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString(event, VerifyDisplayString(event,
"Browser can't check for updates. Try checking your " "Browser can't check for updates. Try checking your "
"internet connection."); "internet connection.");
} }
TEST_F(SafetyCheckHandlerTest, CheckUpdates_Failed) { TEST_F(SafetyCheckHandlerTest, CheckUpdates_Failed) {
...@@ -250,7 +250,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Failed) { ...@@ -250,7 +250,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Failed) {
kUpdates, kUpdates,
static_cast<int>(SafetyCheckHandler::UpdateStatus::kFailed)); static_cast<int>(SafetyCheckHandler::UpdateStatus::kFailed));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString( VerifyDisplayString(
event, event,
"Browser didn't update, something went wrong. <a target=\"_blank\" " "Browser didn't update, something went wrong. <a target=\"_blank\" "
"href=\"https://support.google.com/chrome/answer/111996\">Fix Browser " "href=\"https://support.google.com/chrome/answer/111996\">Fix Browser "
...@@ -267,9 +267,9 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_Enabled) { ...@@ -267,9 +267,9 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_Enabled) {
kSafeBrowsing, kSafeBrowsing,
static_cast<int>(SafetyCheckHandler::SafeBrowsingStatus::kEnabled)); static_cast<int>(SafetyCheckHandler::SafeBrowsingStatus::kEnabled));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString(event, VerifyDisplayString(event,
"Safe Browsing is up to date and protecting you from " "Safe Browsing is up to date and protecting you from "
"harmful sites and downloads"); "harmful sites and downloads");
} }
TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_Disabled) { TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_Disabled) {
...@@ -282,7 +282,7 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_Disabled) { ...@@ -282,7 +282,7 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_Disabled) {
kSafeBrowsing, kSafeBrowsing,
static_cast<int>(SafetyCheckHandler::SafeBrowsingStatus::kDisabled)); static_cast<int>(SafetyCheckHandler::SafeBrowsingStatus::kDisabled));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString( VerifyDisplayString(
event, "Safe Browsing is off. To stay safe on the web, turn it on."); event, "Safe Browsing is off. To stay safe on the web, turn it on.");
} }
...@@ -299,7 +299,7 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_DisabledByAdmin) { ...@@ -299,7 +299,7 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_DisabledByAdmin) {
static_cast<int>( static_cast<int>(
SafetyCheckHandler::SafeBrowsingStatus::kDisabledByAdmin)); SafetyCheckHandler::SafeBrowsingStatus::kDisabledByAdmin));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString( VerifyDisplayString(
event, event,
"<a target=\"_blank\" " "<a target=\"_blank\" "
"href=\"https://support.google.com/accounts/answer/6208960\">Your " "href=\"https://support.google.com/accounts/answer/6208960\">Your "
...@@ -319,7 +319,7 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_DisabledByExtension) { ...@@ -319,7 +319,7 @@ TEST_F(SafetyCheckHandlerTest, CheckSafeBrowsing_DisabledByExtension) {
static_cast<int>( static_cast<int>(
SafetyCheckHandler::SafeBrowsingStatus::kDisabledByExtension)); SafetyCheckHandler::SafeBrowsingStatus::kDisabledByExtension));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString(event, "An extension has turned off Safe Browsing"); VerifyDisplayString(event, "An extension has turned off Safe Browsing");
} }
TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverRemovedAfterError) { TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverRemovedAfterError) {
...@@ -332,7 +332,7 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverRemovedAfterError) { ...@@ -332,7 +332,7 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverRemovedAfterError) {
kPasswords, kPasswords,
static_cast<int>(SafetyCheckHandler::PasswordsStatus::kChecking)); static_cast<int>(SafetyCheckHandler::PasswordsStatus::kChecking));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString(event, base::UTF8ToUTF16("Running…")); VerifyDisplayString(event, base::UTF8ToUTF16("Running…"));
// Second, an "offline" state. // Second, an "offline" state.
test_leak_service_->set_state_and_notify( test_leak_service_->set_state_and_notify(
password_manager::BulkLeakCheckService::State::kNetworkError); password_manager::BulkLeakCheckService::State::kNetworkError);
...@@ -341,9 +341,9 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverRemovedAfterError) { ...@@ -341,9 +341,9 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverRemovedAfterError) {
kPasswords, kPasswords,
static_cast<int>(SafetyCheckHandler::PasswordsStatus::kOffline)); static_cast<int>(SafetyCheckHandler::PasswordsStatus::kOffline));
ASSERT_TRUE(event2); ASSERT_TRUE(event2);
VerifyDisplayedString(event2, VerifyDisplayString(event2,
"Browser can't check your passwords. Try checking your " "Browser can't check your passwords. Try checking your "
"internet connection."); "internet connection.");
// Another error, but since the previous state is terminal, the handler should // Another error, but since the previous state is terminal, the handler should
// no longer be observing the BulkLeakCheckService state. // no longer be observing the BulkLeakCheckService state.
test_leak_service_->set_state_and_notify( test_leak_service_->set_state_and_notify(
...@@ -365,7 +365,7 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_InterruptedAndRefreshed) { ...@@ -365,7 +365,7 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_InterruptedAndRefreshed) {
kPasswords, kPasswords,
static_cast<int>(SafetyCheckHandler::PasswordsStatus::kChecking)); static_cast<int>(SafetyCheckHandler::PasswordsStatus::kChecking));
ASSERT_TRUE(event); ASSERT_TRUE(event);
VerifyDisplayedString(event, base::UTF8ToUTF16("Running…")); VerifyDisplayString(event, base::UTF8ToUTF16("Running…"));
// The check gets interrupted and the page is refreshed. // The check gets interrupted and the page is refreshed.
safety_check_->DisallowJavascript(); safety_check_->DisallowJavascript();
safety_check_->AllowJavascript(); safety_check_->AllowJavascript();
...@@ -385,7 +385,7 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_InterruptedAndRefreshed) { ...@@ -385,7 +385,7 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_InterruptedAndRefreshed) {
kPasswords, kPasswords,
static_cast<int>(SafetyCheckHandler::PasswordsStatus::kSignedOut)); static_cast<int>(SafetyCheckHandler::PasswordsStatus::kSignedOut));
ASSERT_TRUE(event3); ASSERT_TRUE(event3);
VerifyDisplayedString( VerifyDisplayString(
event3, event3,
"Browser can't check your passwords because you're not signed in"); "Browser can't check your passwords because you're not signed in");
} }
...@@ -409,6 +409,6 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_StartedTwice) { ...@@ -409,6 +409,6 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_StartedTwice) {
kPasswords, kPasswords,
static_cast<int>(SafetyCheckHandler::PasswordsStatus::kError)); static_cast<int>(SafetyCheckHandler::PasswordsStatus::kError));
ASSERT_TRUE(event2); ASSERT_TRUE(event2);
VerifyDisplayedString(event2, VerifyDisplayString(event2,
"Browser can't check your passwords. Try again later."); "Browser can't check your passwords. Try again later.");
} }
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