Index: chrome/browser/profile_resetter/automatic_profile_resetter_unittest.cc |
diff --git a/chrome/browser/profile_resetter/automatic_profile_resetter_unittest.cc b/chrome/browser/profile_resetter/automatic_profile_resetter_unittest.cc |
index ed7b67ab398c1c5f04b611c1a130a01934c1b533..14524716f5665bac634182204145f5fbff1c44c4 100644 |
--- a/chrome/browser/profile_resetter/automatic_profile_resetter_unittest.cc |
+++ b/chrome/browser/profile_resetter/automatic_profile_resetter_unittest.cc |
@@ -32,7 +32,6 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
using testing::_; |
-using testing::Invoke; |
namespace { |
@@ -66,6 +65,8 @@ class AutomaticProfileResetterUnderTest : public AutomaticProfileResetter { |
virtual ~AutomaticProfileResetterUnderTest() {} |
MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); |
+ MOCK_METHOD1(ReportPromptResult, |
+ void(AutomaticProfileResetter::PromptResult)); |
private: |
DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterUnderTest); |
@@ -85,12 +86,18 @@ class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { |
MOCK_CONST_METHOD1(RequestCallbackWhenTemplateURLServiceIsLoaded, |
void(const base::Closure&)); |
+ MOCK_METHOD0(FetchBrandcodedDefaultSettingsIfNeeded, void()); |
+ MOCK_CONST_METHOD1(RequestCallbackWhenBrandcodedDefaultsAreFetched, |
+ void(const base::Closure&)); |
+ |
MOCK_CONST_METHOD0(OnGetLoadedModuleNameDigestsCalled, void()); |
MOCK_CONST_METHOD0(OnGetDefaultSearchProviderDetailsCalled, void()); |
MOCK_CONST_METHOD0(OnIsDefaultSearchProviderManagedCalled, void()); |
MOCK_CONST_METHOD0(OnGetPrepopulatedSearchProvidersDetailsCalled, void()); |
- MOCK_METHOD0(ShowPrompt, void()); |
+ MOCK_METHOD0(ShowPrompt, bool()); |
+ MOCK_METHOD2(TriggerProfileSettingsReset, void(bool, const base::Closure&)); |
+ MOCK_METHOD0(DismissPrompt, void()); |
virtual scoped_ptr<base::ListValue> |
GetLoadedModuleNameDigests() const OVERRIDE { |
@@ -124,9 +131,9 @@ class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { |
EXPECT_CALL(*this, EnumerateLoadedModulesIfNeeded()); |
EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded()); |
EXPECT_CALL(*this, RequestCallbackWhenLoadedModulesAreEnumerated(_)) |
- .WillOnce(Invoke(ClosureInvoker)); |
+ .WillOnce(testing::Invoke(ClosureInvoker)); |
EXPECT_CALL(*this, RequestCallbackWhenTemplateURLServiceIsLoaded(_)) |
- .WillOnce(Invoke(ClosureInvoker)); |
+ .WillOnce(testing::Invoke(ClosureInvoker)); |
} |
void ExpectCallsToGetterMethods() { |
@@ -136,6 +143,16 @@ class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { |
EXPECT_CALL(*this, OnGetPrepopulatedSearchProvidersDetailsCalled()); |
} |
+ void ExpectCallToShowPrompt() { |
+ EXPECT_CALL(*this, ShowPrompt()).WillRepeatedly(testing::Return(true)); |
+ EXPECT_CALL(*this, FetchBrandcodedDefaultSettingsIfNeeded()); |
+ } |
+ |
+ void ExpectCallToTriggerReset(bool send_feedback) { |
+ EXPECT_CALL(*this, TriggerProfileSettingsReset(send_feedback, _)) |
+ .WillOnce(testing::WithArgs<1>(testing::Invoke(ClosureInvoker))); |
+ } |
+ |
base::DictionaryValue& emulated_default_search_provider_details() { |
return emulated_default_search_provider_details_; |
} |
@@ -407,6 +424,10 @@ class AutomaticProfileResetterTestBase : public testing::Test { |
: waiting_task_runner_(new base::TestSimpleTaskRunner), |
local_state_(TestingBrowserProcess::GetGlobal()), |
profile_(new TestingProfile()), |
+ field_trials_(new base::FieldTrialList(NULL)), |
+ memento_in_prefs_(new PreferenceHostedPromptMemento(profile())), |
+ memento_in_local_state_(new LocalStateHostedPromptMemento(profile())), |
+ memento_in_file_(new FileHostedPromptMementoSynchronous(profile())), |
experiment_group_name_(experiment_group_name), |
inject_data_through_variation_params_(false), |
mock_delegate_(NULL) { |
@@ -424,13 +445,11 @@ class AutomaticProfileResetterTestBase : public testing::Test { |
profile_->GetTestingPrefService()->registry(); |
DCHECK(user_prefs_registry); |
user_prefs_registry->RegisterStringPref( |
- kTestPreferencePath, |
- "", |
+ kTestPreferencePath, std::string(), |
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
} |
virtual void SetUp() OVERRIDE { |
- field_trials_.reset(new base::FieldTrialList(NULL)); |
chrome_variations::testing::ClearAllVariationParams(); |
base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, |
experiment_group_name_); |
@@ -439,6 +458,8 @@ class AutomaticProfileResetterTestBase : public testing::Test { |
mock_delegate_owned_.reset( |
new testing::StrictMock<MockProfileResetterDelegate>()); |
mock_delegate_ = mock_delegate_owned_.get(); |
+ |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
void SetTestingHashSeed(const std::string& hash_seed) { |
@@ -453,6 +474,30 @@ class AutomaticProfileResetterTestBase : public testing::Test { |
inject_data_through_variation_params_ = value; |
} |
+ // Goes through an evaluation flow such that the reset criteria are satisfied. |
+ // Used to reduce boilerplate for tests that need to verify behavior during |
+ // the reset prompt flow. |
+ void OrchestrateThroughEvaluationFlow() { |
+ SetTestingProgram(ConstructProgram(true, true)); |
+ SetTestingHashSeed(kTestHashSeed); |
+ |
+ mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
+ mock_delegate().ExpectCallsToGetterMethods(); |
+ mock_delegate().ExpectCallToShowPrompt(); |
+ EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
+ |
+ UnleashResetterAndWait(); |
+ |
+ testing::Mock::VerifyAndClearExpectations(&resetter()); |
+ testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
+ } |
+ |
+ void ExpectAllMementoValuesEqualTo(const std::string& value) { |
+ EXPECT_EQ(value, memento_in_prefs_->ReadValue()); |
+ EXPECT_EQ(value, memento_in_local_state_->ReadValue()); |
+ EXPECT_EQ(value, memento_in_file_->ReadValue()); |
+ } |
+ |
void UnleashResetterAndWait() { |
if (inject_data_through_variation_params_) { |
std::map<std::string, std::string> variation_params; |
@@ -483,9 +528,26 @@ class AutomaticProfileResetterTestBase : public testing::Test { |
base::RunLoop().RunUntilIdle(); |
} |
+ void ShutdownResetter() { |
+ resetter_->Shutdown(); |
+ resetter_.reset(); |
+ } |
+ |
TestingProfile* profile() { return profile_.get(); } |
TestingPrefServiceSimple* local_state() { return local_state_.Get(); } |
+ PreferenceHostedPromptMemento& memento_in_prefs() { |
+ return *memento_in_prefs_; |
+ } |
+ |
+ LocalStateHostedPromptMemento& memento_in_local_state() { |
+ return *memento_in_local_state_; |
+ } |
+ |
+ FileHostedPromptMementoSynchronous& memento_in_file() { |
+ return *memento_in_file_; |
+ } |
+ |
MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } |
AutomaticProfileResetterUnderTest& resetter() { return *resetter_; } |
@@ -495,6 +557,10 @@ class AutomaticProfileResetterTestBase : public testing::Test { |
ScopedTestingLocalState local_state_; |
scoped_ptr<TestingProfile> profile_; |
scoped_ptr<base::FieldTrialList> field_trials_; |
+ scoped_ptr<PreferenceHostedPromptMemento> memento_in_prefs_; |
+ scoped_ptr<LocalStateHostedPromptMemento> memento_in_local_state_; |
+ scoped_ptr<FileHostedPromptMementoSynchronous> memento_in_file_; |
+ |
std::string experiment_group_name_; |
std::string testing_program_; |
std::string testing_hash_seed_; |
@@ -530,35 +596,18 @@ class AutomaticProfileResetterTestDisabled |
// Tests --------------------------------------------------------------------- |
TEST_F(AutomaticProfileResetterTestDisabled, NothingIsDoneWhenDisabled) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
// No calls are expected to the delegate. |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, ConditionsNotSatisfied) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(false, false)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -567,68 +616,47 @@ TEST_F(AutomaticProfileResetterTestDryRun, ConditionsNotSatisfied) { |
EXPECT_CALL(resetter(), ReportStatistics(0x00u, 0x00u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(true, false)); |
SetTestingHashSeed(kTestHashSeed); |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
EXPECT_CALL(resetter(), ReportStatistics(0x01u, 0x01u)); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_NOT_SHOWN)); |
UnleashResetterAndWait(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(false, true)); |
SetTestingHashSeed(kTestHashSeed); |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
EXPECT_CALL(resetter(), ReportStatistics(0x02u, 0x01u)); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_NOT_SHOWN)); |
UnleashResetterAndWait(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
} |
#if defined(GOOGLE_CHROME_BUILD) |
TEST_F(AutomaticProfileResetterTestDryRun, ProgramSetThroughVariationParams) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
AllowInjectingTestDataThroughVariationParams(true); |
@@ -636,24 +664,22 @@ TEST_F(AutomaticProfileResetterTestDryRun, ProgramSetThroughVariationParams) { |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_NOT_SHOWN)); |
UnleashResetterAndWait(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
} |
#endif |
TEST_F(AutomaticProfileResetterTestDryRun, |
ConditionsSatisfiedAndInvalidMementos) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_prefs.StoreValue(kTestInvalidMementoValue); |
- memento_in_local_state.StoreValue(kTestInvalidMementoValue); |
- memento_in_file.StoreValue(kTestInvalidMementoValue); |
+ memento_in_prefs().StoreValue(kTestInvalidMementoValue); |
+ memento_in_local_state().StoreValue(kTestInvalidMementoValue); |
+ memento_in_file().StoreValue(kTestInvalidMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -661,20 +687,18 @@ TEST_F(AutomaticProfileResetterTestDryRun, |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_NOT_SHOWN)); |
UnleashResetterAndWait(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_prefs.StoreValue(kTestMementoValue); |
+ memento_in_prefs().StoreValue(kTestMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -684,18 +708,15 @@ TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_local_state.StoreValue(kTestMementoValue); |
+ memento_in_local_state().StoreValue(kTestMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -705,18 +726,15 @@ TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
+ EXPECT_EQ(kTestMementoValue, memento_in_local_state().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_file.StoreValue(kTestMementoValue); |
+ memento_in_file().StoreValue(kTestMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -726,38 +744,26 @@ TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
+ EXPECT_EQ(kTestMementoValue, memento_in_file().ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- SetTestingProgram(""); |
- SetTestingHashSeed(""); |
+ SetTestingProgram(std::string()); |
+ SetTestingHashSeed(std::string()); |
// No calls are expected to the delegate. |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
TEST_F(AutomaticProfileResetterTest, ConditionsNotSatisfied) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(false, false)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -766,117 +772,202 @@ TEST_F(AutomaticProfileResetterTest, ConditionsNotSatisfied) { |
EXPECT_CALL(resetter(), ReportStatistics(0x00u, 0x00u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(true, false)); |
SetTestingHashSeed(kTestHashSeed); |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
- EXPECT_CALL(mock_delegate(), ShowPrompt()); |
+ mock_delegate().ExpectCallToShowPrompt(); |
EXPECT_CALL(resetter(), ReportStatistics(0x01u, 0x01u)); |
UnleashResetterAndWait(); |
- |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
- |
SetTestingProgram(ConstructProgram(false, true)); |
SetTestingHashSeed(kTestHashSeed); |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
- EXPECT_CALL(mock_delegate(), ShowPrompt()); |
+ mock_delegate().ExpectCallToShowPrompt(); |
EXPECT_CALL(resetter(), ReportStatistics(0x02u, 0x01u)); |
UnleashResetterAndWait(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptSuppressed) { |
+ OrchestrateThroughEvaluationFlow(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ShutdownResetter(); |
+ |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
-#if defined(GOOGLE_CHROME_BUILD) |
-TEST_F(AutomaticProfileResetterTest, ProgramSetThroughVariationParams) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
+TEST_F(AutomaticProfileResetterTest, PromptIgnored) { |
+ OrchestrateThroughEvaluationFlow(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ resetter().NotifyDidShowResetBubble(); |
+ ShutdownResetter(); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptActionReset) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ mock_delegate().ExpectCallToTriggerReset(false); |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_ACTION_RESET)); |
+ |
+ resetter().NotifyDidShowResetBubble(); |
+ resetter().TriggerProfileReset(false /*send_feedback*/); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptActionResetWithFeedback) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ mock_delegate().ExpectCallToTriggerReset(true); |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_ACTION_RESET)); |
+ |
+ resetter().NotifyDidShowResetBubble(); |
+ resetter().TriggerProfileReset(true /*send_feedback*/); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptActionNoReset) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_ACTION_NO_RESET)); |
+ |
+ resetter().NotifyDidShowResetBubble(); |
+ resetter().SkipProfileReset(); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUIReset) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET)); |
+ |
+ resetter().NotifyDidShowResetBubble(); |
+ resetter().NotifyDidOpenWebUIResetDialog(); |
+ resetter().NotifyDidCloseWebUIResetDialog(true); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUINoReset) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_NO_RESET)); |
+ |
+ resetter().NotifyDidShowResetBubble(); |
+ resetter().NotifyDidOpenWebUIResetDialog(); |
+ resetter().NotifyDidCloseWebUIResetDialog(false); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUIReset) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_SUPPRESSED_BUT_HAD_WEBUI_RESET)); |
+ |
+ resetter().NotifyDidOpenWebUIResetDialog(); |
+ resetter().NotifyDidCloseWebUIResetDialog(true); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUINoReset) { |
+ OrchestrateThroughEvaluationFlow(); |
+ |
+ EXPECT_CALL(mock_delegate(), DismissPrompt()); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_SUPPRESSED_BUT_HAD_WEBUI_NO_RESET)); |
+ |
+ resetter().NotifyDidOpenWebUIResetDialog(); |
+ resetter().NotifyDidCloseWebUIResetDialog(false); |
+ |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
+ |
+ ShutdownResetter(); |
+} |
+ |
+#if defined(GOOGLE_CHROME_BUILD) |
+TEST_F(AutomaticProfileResetterTest, ProgramSetThroughVariationParams) { |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
AllowInjectingTestDataThroughVariationParams(true); |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
- EXPECT_CALL(mock_delegate(), ShowPrompt()); |
+ mock_delegate().ExpectCallToShowPrompt(); |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_IGNORED)); |
UnleashResetterAndWait(); |
+ resetter().NotifyDidShowResetBubble(); |
+ ShutdownResetter(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
} |
#endif |
TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_prefs.StoreValue(kTestInvalidMementoValue); |
- memento_in_local_state.StoreValue(kTestInvalidMementoValue); |
- memento_in_file.StoreValue(kTestInvalidMementoValue); |
- |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
- EXPECT_CALL(mock_delegate(), ShowPrompt()); |
+ mock_delegate().ExpectCallToShowPrompt(); |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
+ EXPECT_CALL(resetter(), ReportPromptResult( |
+ AutomaticProfileResetter::PROMPT_IGNORED)); |
UnleashResetterAndWait(); |
+ resetter().NotifyDidShowResetBubble(); |
+ ShutdownResetter(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(kTestMementoValue); |
} |
TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_prefs.StoreValue(kTestMementoValue); |
+ memento_in_prefs().StoreValue(kTestMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -886,18 +977,15 @@ TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_local_state.StoreValue(kTestMementoValue); |
+ memento_in_local_state().StoreValue(kTestMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -907,18 +995,15 @@ TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
+ EXPECT_EQ(kTestMementoValue, memento_in_local_state().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- memento_in_file.StoreValue(kTestMementoValue); |
+ memento_in_file().StoreValue(kTestMementoValue); |
SetTestingProgram(ConstructProgram(true, true)); |
SetTestingHashSeed(kTestHashSeed); |
@@ -928,27 +1013,23 @@ TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { |
EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u)); |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
+ EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
+ EXPECT_EQ(kTestMementoValue, memento_in_file().ReadValue()); |
} |
TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { |
- PreferenceHostedPromptMemento memento_in_prefs(profile()); |
- LocalStateHostedPromptMemento memento_in_local_state(profile()); |
- FileHostedPromptMementoSynchronous memento_in_file(profile()); |
- |
- SetTestingProgram(""); |
- SetTestingHashSeed(""); |
+ SetTestingProgram(std::string()); |
+ SetTestingHashSeed(std::string()); |
// No calls are expected to the delegate. |
UnleashResetterAndWait(); |
+ ShutdownResetter(); |
- EXPECT_EQ("", memento_in_prefs.ReadValue()); |
- EXPECT_EQ("", memento_in_local_state.ReadValue()); |
- EXPECT_EQ("", memento_in_file.ReadValue()); |
+ ExpectAllMementoValuesEqualTo(std::string()); |
} |
// Please see comments above ConstructProgramToCheckPreferences() to understand |
@@ -963,8 +1044,8 @@ TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) { |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
- uint32 expected_mask = |
- HAS_EXPECTED_USER_PREFERENCE | USER_PREFERENCE_IS_USER_CONTROLLED; |
+ uint32 expected_mask = HAS_EXPECTED_USER_PREFERENCE | |
+ USER_PREFERENCE_IS_USER_CONTROLLED; |
EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); |
UnleashResetterAndWait(); |
@@ -979,8 +1060,8 @@ TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) { |
mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
mock_delegate().ExpectCallsToGetterMethods(); |
- uint32 expected_mask = |
- HAS_EXPECTED_LOCAL_STATE_PREFERENCE | LOCAL_STATE_IS_USER_CONTROLLED; |
+ uint32 expected_mask = HAS_EXPECTED_LOCAL_STATE_PREFERENCE | |
+ LOCAL_STATE_IS_USER_CONTROLLED; |
EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); |
UnleashResetterAndWait(); |