Skip to content

Commit

Permalink
Added the Reset Profile Settings banner to the top of the Settings page.
Browse files Browse the repository at this point in the history
BUG=298036

Review URL: https://codereview.chromium.org/108053003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240179 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
engedy@chromium.org committed Dec 11, 2013
1 parent 96517ef commit 87e146c
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 2 deletions.
3 changes: 3 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -15089,6 +15089,9 @@ Do you accept?
</message>

<!-- Reset Profile Settings strings -->
<message name="IDS_RESET_PROFILE_SETTINGS_BANNER_TEXT" desc="The text to show in a banner at the top of the chrome://settings page. The banner is displayed when Chrome detects that the settings might have been changed without the user's knowledge.">
Some of your settings may have been changed without your knowledge.
</message>
<message name="IDS_RESET_PROFILE_SETTINGS_SECTION_TITLE" desc="The title of the section in chrome://settings that allows resetting some settings in a profile">
Reset browser settings
</message>
Expand Down
17 changes: 17 additions & 0 deletions chrome/browser/profile_resetter/automatic_profile_resetter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile)
enumeration_of_loaded_modules_ready_(false),
template_url_service_ready_(false),
has_already_dismissed_prompt_(false),
should_show_reset_banner_(false),
weak_ptr_factory_(this) {
DCHECK(profile_);
}
Expand Down Expand Up @@ -438,6 +439,7 @@ void AutomaticProfileResetter::TriggerProfileReset(bool send_feedback) {
DCHECK_EQ(state_, STATE_HAS_SHOWN_BUBBLE);

state_ = STATE_PERFORMING_RESET;
should_show_reset_banner_ = false;

ReportPromptResult(PROMPT_ACTION_RESET);
delegate_->TriggerProfileSettingsReset(
Expand All @@ -450,6 +452,8 @@ void AutomaticProfileResetter::SkipProfileReset() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK_EQ(state_, STATE_HAS_SHOWN_BUBBLE);

should_show_reset_banner_ = false;

ReportPromptResult(PROMPT_ACTION_NO_RESET);
delegate_->DismissPrompt();
FinishResetPromptFlow();
Expand All @@ -460,6 +464,11 @@ bool AutomaticProfileResetter::IsResetPromptFlowActive() const {
state_ == STATE_HAS_SHOWN_BUBBLE;
}

bool AutomaticProfileResetter::ShouldShowResetBanner() const {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
return should_show_reset_banner_ && ShouldPerformLiveRun();
}

void AutomaticProfileResetter::NotifyDidShowResetBubble() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK_EQ(state_, STATE_HAS_TRIGGERED_PROMPT);
Expand Down Expand Up @@ -506,6 +515,11 @@ void AutomaticProfileResetter::NotifyDidCloseWebUIResetDialog(
}
}

void AutomaticProfileResetter::NotifyDidCloseWebUIResetBanner() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
should_show_reset_banner_ = false;
}

void AutomaticProfileResetter::SetProgramForTesting(
const std::string& program) {
program_ = program;
Expand Down Expand Up @@ -676,6 +690,9 @@ void AutomaticProfileResetter::FinishEvaluationFlow(
ReportStatistics(results->satisfied_criteria_mask,
results->combined_status_mask);

if (results->should_prompt)
should_show_reset_banner_ = true;

if (results->should_prompt && !results->had_prompted_already) {
evaluation_results_ = results.Pass();
BeginResetPromptFlow();
Expand Down
10 changes: 10 additions & 0 deletions chrome/browser/profile_resetter/automatic_profile_resetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class AutomaticProfileResetter : public BrowserContextKeyedService {
// definitive action (and we are not yet performing a reset).
bool IsResetPromptFlowActive() const;

// Returns whether or not the profile reset banner should be shown on the
// WebUI-based settings page.
bool ShouldShowResetBanner() const;

// Called to give notice that the reset bubble has actually been shown.
void NotifyDidShowResetBubble();

Expand All @@ -111,6 +115,10 @@ class AutomaticProfileResetter : public BrowserContextKeyedService {
// without setting off any resets in the future.
void NotifyDidCloseWebUIResetDialog(bool performed_reset);

// Called to give notice that reset banner has been dismissed as a result of
// user action on the WebUI-based settings page itself.
void NotifyDidCloseWebUIResetBanner();

base::WeakPtr<AutomaticProfileResetter> AsWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
Expand Down Expand Up @@ -247,6 +255,8 @@ class AutomaticProfileResetter : public BrowserContextKeyedService {

scoped_ptr<EvaluationResults> evaluation_results_;

bool should_show_reset_banner_;

scoped_ptr<AutomaticProfileResetterDelegate> delegate_;
scoped_refptr<base::TaskRunner> task_runner_for_waiting_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ class AutomaticProfileResetterTestBase : public testing::Test {

UnleashResetterAndWait();

EXPECT_TRUE(resetter().ShouldShowResetBanner());
testing::Mock::VerifyAndClearExpectations(&resetter());
testing::Mock::VerifyAndClearExpectations(&mock_delegate());
}
Expand Down Expand Up @@ -674,6 +675,8 @@ TEST_F(AutomaticProfileResetterTestDisabled, NothingIsDoneWhenDisabled) {
// No calls are expected to the delegate.

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

ExpectAllMementoValuesEqualTo(std::string());
Expand All @@ -688,6 +691,8 @@ TEST_F(AutomaticProfileResetterTestDryRun, CriteriaNotSatisfied) {
EXPECT_CALL(resetter(), ReportStatistics(0x1fu, 0x00u));

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

ExpectAllMementoValuesEqualTo(std::string());
Expand All @@ -706,6 +711,7 @@ TEST_F(AutomaticProfileResetterTestDryRun, OddCriteriaSatisfied) {
UnleashResetterAndWait();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -722,6 +728,7 @@ TEST_F(AutomaticProfileResetterTestDryRun, EvenCriteriaSatisfied) {
UnleashResetterAndWait();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -740,6 +747,7 @@ TEST_F(AutomaticProfileResetterTestDryRun, ProgramSetThroughVariationParams) {
UnleashResetterAndWait();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}
#endif
Expand All @@ -762,6 +770,7 @@ TEST_F(AutomaticProfileResetterTestDryRun,
UnleashResetterAndWait();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -776,6 +785,8 @@ TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) {
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u));

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue());
Expand All @@ -794,6 +805,8 @@ TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) {
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u));

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
Expand All @@ -812,6 +825,8 @@ TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) {
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u));

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
Expand All @@ -826,6 +841,8 @@ TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) {
// No calls are expected to the delegate.

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

ExpectAllMementoValuesEqualTo(std::string());
Expand All @@ -840,6 +857,8 @@ TEST_F(AutomaticProfileResetterTest, CriteriaNotSatisfied) {
EXPECT_CALL(resetter(), ReportStatistics(0x1fu, 0x00u));

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

ExpectAllMementoValuesEqualTo(std::string());
Expand All @@ -856,6 +875,7 @@ TEST_F(AutomaticProfileResetterTest, OddCriteriaSatisfied) {

UnleashResetterAndWait();

EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -870,6 +890,7 @@ TEST_F(AutomaticProfileResetterTest, EvenCriteriaSatisfied) {

UnleashResetterAndWait();

EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -890,6 +911,7 @@ TEST_F(AutomaticProfileResetterTest, ProgramSetThroughVariationParams) {
resetter().NotifyDidShowResetBubble();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}
#endif
Expand All @@ -913,6 +935,7 @@ TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) {
resetter().NotifyDidShowResetBubble();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -927,6 +950,8 @@ TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) {
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u));

UnleashResetterAndWait();

EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue());
Expand All @@ -945,6 +970,8 @@ TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) {
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u));

UnleashResetterAndWait();

EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
Expand All @@ -963,6 +990,8 @@ TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) {
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u));

UnleashResetterAndWait();

EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
Expand All @@ -977,6 +1006,8 @@ TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) {
// No calls are expected to the delegate.

UnleashResetterAndWait();

EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

ExpectAllMementoValuesEqualTo(std::string());
Expand Down Expand Up @@ -1005,6 +1036,7 @@ TEST_F(AutomaticProfileResetterTest, PromptNotSupported) {
UnleashResetterAndWait();

ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand Down Expand Up @@ -1036,6 +1068,7 @@ TEST_F(AutomaticProfileResetterTest, PromptActionReset) {

EXPECT_CALL(mock_delegate(), DismissPrompt());
mock_delegate().EmulateProfileResetCompleted();
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1057,6 +1090,7 @@ TEST_F(AutomaticProfileResetterTest, PromptActionResetWithFeedback) {

EXPECT_CALL(mock_delegate(), DismissPrompt());
mock_delegate().EmulateProfileResetCompleted();
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1073,6 +1107,7 @@ TEST_F(AutomaticProfileResetterTest, PromptActionNoReset) {
EXPECT_CALL(resetter(), ReportPromptResult(
AutomaticProfileResetter::PROMPT_ACTION_NO_RESET));
resetter().SkipProfileReset();
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1092,6 +1127,7 @@ TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUIReset) {
EXPECT_CALL(resetter(), ReportPromptResult(
AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET));
resetter().NotifyDidCloseWebUIResetDialog(true);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1111,6 +1147,7 @@ TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUINoReset) {
EXPECT_CALL(resetter(), ReportPromptResult(
AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_NO_RESET));
resetter().NotifyDidCloseWebUIResetDialog(false);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1132,6 +1169,7 @@ TEST_F(AutomaticProfileResetterTest, PromptFollowedByIncidentalWebUIReset) {
EXPECT_CALL(resetter(), ReportPromptResult(
AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET));
resetter().NotifyDidCloseWebUIResetDialog(true);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1146,6 +1184,7 @@ TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUIReset) {
AutomaticProfileResetter::PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_RESET));
resetter().NotifyDidCloseWebUIResetDialog(true);
ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

Expand All @@ -1160,9 +1199,40 @@ TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUINoReset) {
PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_NO_RESET));
resetter().NotifyDidCloseWebUIResetDialog(false);
ExpectAllMementoValuesEqualTo(kTestMementoValue);
EXPECT_TRUE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();
}

TEST_F(AutomaticProfileResetterTest, BannerDismissed) {
OrchestrateThroughEvaluationFlow();

EXPECT_CALL(resetter(), ReportPromptResult(
AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
resetter().NotifyDidShowResetBubble();
ExpectAllMementoValuesEqualTo(kTestMementoValue);
testing::Mock::VerifyAndClearExpectations(&resetter());

resetter().NotifyDidCloseWebUIResetBanner();

EXPECT_TRUE(resetter().IsResetPromptFlowActive());
EXPECT_FALSE(resetter().ShouldShowResetBanner());

// Note: we use strict mocks, so this also checks the bubble is not closed.
VerifyExpectationsThenShutdownResetter();
}

TEST_F(AutomaticProfileResetterTest, BannerDismissedWhilePromptSuppressed) {
OrchestrateThroughEvaluationFlow();

resetter().NotifyDidCloseWebUIResetBanner();

EXPECT_TRUE(resetter().IsResetPromptFlowActive());
EXPECT_FALSE(resetter().ShouldShowResetBanner());
VerifyExpectationsThenShutdownResetter();

ExpectAllMementoValuesEqualTo(std::string());
}

// Please see comments above ConstructProgramToCheckPreferences() to understand
// how the following tests work.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions chrome/browser/resources/options/browser_options.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<header>
<h1 i18n-content="settingsTitle"></h1>
</header>
<include src="reset_profile_settings_banner.html">
<if expr="not pp_ifdef('chromeos')">
<include src="sync_section.html">
</if>
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/resources/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<link rel="stylesheet" href="managed_user_learn_more.css">
<link rel="stylesheet" href="password_manager.css">
<link rel="stylesheet" href="password_manager_list.css">
<link rel="stylesheet" href="reset_profile_settings_banner.css">
<link rel="stylesheet" href="reset_profile_settings_overlay.css">
<link rel="stylesheet" href="search_engine_manager.css">
<link rel="stylesheet" href="search_page.css">
Expand Down
Loading

0 comments on commit 87e146c

Please sign in to comment.