Index: components/password_manager/core/browser/password_bubble_experiment_unittest.cc |
diff --git a/components/password_manager/core/browser/password_bubble_experiment_unittest.cc b/components/password_manager/core/browser/password_bubble_experiment_unittest.cc |
index fd13060e111d4ac273ab79f6491a7b8bd2732cf3..e3591d047d40026da2a490f40a29a6fbed970080 100644 |
--- a/components/password_manager/core/browser/password_bubble_experiment_unittest.cc |
+++ b/components/password_manager/core/browser/password_bubble_experiment_unittest.cc |
@@ -7,11 +7,13 @@ |
#include <ostream> |
#include "base/metrics/field_trial.h" |
+#include "base/strings/string_number_conversions.h" |
#include "components/password_manager/core/common/password_manager_pref_names.h" |
#include "components/prefs/pref_registry_simple.h" |
#include "components/prefs/pref_service.h" |
#include "components/prefs/testing_pref_service.h" |
#include "components/sync_driver/fake_sync_service.h" |
+#include "components/variations/variations_associated_data.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -111,6 +113,11 @@ class PasswordManagerPasswordBubbleExperimentTest : public testing::Test { |
void SetUp() override { RegisterPrefs(pref_service_.registry()); } |
+ void TearDown() override { |
+ variations::testing::ClearAllVariationIDs(); |
vabr (Chromium)
2016/06/06 15:23:14
Would this work in a destructor instead?
(See htt
vasilii
2016/06/06 15:45:14
Done.
|
+ variations::testing::ClearAllVariationParams(); |
+ } |
+ |
PrefService* prefs() { return &pref_service_; } |
void EnforceExperimentGroup(const char* group_name) { |
@@ -309,4 +316,38 @@ TEST_F(PasswordManagerPasswordBubbleExperimentTest, |
} |
} |
+TEST_F(PasswordManagerPasswordBubbleExperimentTest, |
+ ShouldShowChromeSignInPasswordPromo) { |
+ // By default the promo is off. |
+ EXPECT_FALSE(ShouldShowChromeSignInPasswordPromo(prefs())); |
+ const struct { |
+ bool was_already_clicked; |
+ int current_shown_count; |
+ int experiment_threshold; |
+ bool result; |
+ } kTestData[] = { |
+ {false, 0, 5, true}, |
+ {false, 5, 5, false}, |
+ {true, 0, 5, false}, |
+ {true, 10, 5, false}, |
+ }; |
+ const char kFakeGroup[] = "FakeGroup"; |
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
+ kChromeSignInPasswordPromoExperimentName, kFakeGroup)); |
+ for (const auto& test_case : kTestData) { |
+ SCOPED_TRACE(testing::Message("#test_case = ") << (&test_case - kTestData)); |
+ prefs()->SetBoolean(password_manager::prefs::kWasSignInPasswordPromoClicked, |
+ test_case.was_already_clicked); |
+ prefs()->SetInteger( |
+ password_manager::prefs::kNumberSignInPasswordPromoShown, |
+ test_case.current_shown_count); |
+ variations::AssociateVariationParams( |
+ kChromeSignInPasswordPromoExperimentName, kFakeGroup, |
+ {{kChromeSignInPasswordPromoThresholdParam, |
+ base::IntToString(test_case.experiment_threshold)}}); |
+ |
+ EXPECT_EQ(test_case.result, ShouldShowChromeSignInPasswordPromo(prefs())); |
+ } |
+} |
+ |
} // namespace password_bubble_experiment |