Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: components/password_manager/core/browser/password_manager_url_collection_experiment_unittest.cc

Issue 789613004: Decision whenever "Allow to collect URL?" bubble should be shown or not (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes which belong to this CL. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/password_manager_url_collection_experiment_unittest.cc
diff --git a/components/password_manager/core/browser/password_manager_url_collection_experiment_unittest.cc b/components/password_manager/core/browser/password_manager_url_collection_experiment_unittest.cc
index 12a4c04f811969e16fc26977fccbe616ea3d133d..c1d8c0af23c97a202256848bffd83c125247d3fd 100644
--- a/components/password_manager/core/browser/password_manager_url_collection_experiment_unittest.cc
+++ b/components/password_manager/core/browser/password_manager_url_collection_experiment_unittest.cc
@@ -5,23 +5,115 @@
#include "components/password_manager/core/browser/password_manager_url_collection_experiment.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/metrics/field_trial.h"
+#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/testing_pref_service.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/test/simple_test_clock.h"
+#include "components/password_manager/core/common/password_manager_pref_names.h"
+#include "components/variations/entropy_provider.h"
+#include "components/variations/variations_associated_data.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
+const char kProfileUuid[] = "42";
+int kParamTimePeriodInDaysValue = 7;
+int kParamLengthInDaysValue = 365;
+
+void SetupShowBubbleExperimentGroup() {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ password_manager::urls_collection_experiment::kExperimentName,
+ password_manager::urls_collection_experiment::kGroupShowBubble));
+ std::map<std::string, std::string> params;
+ params[password_manager::urls_collection_experiment::kParamTimePeriodInDays] =
+ base::IntToString(kParamTimePeriodInDaysValue);
+ params[password_manager::urls_collection_experiment::kParamLengthInDays] =
+ base::IntToString(kParamLengthInDaysValue);
+ ASSERT_TRUE(variations::AssociateVariationParams(
+ password_manager::urls_collection_experiment::kExperimentName,
+ password_manager::urls_collection_experiment::kGroupShowBubble, params));
+}
+
+void SetupNeverShowBubbleExperimentGroup() {
+ ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
+ password_manager::urls_collection_experiment::kExperimentName,
melandory 2014/12/11 08:37:38 asvitkine@: "Nit: It's best practice to put the te
+ password_manager::urls_collection_experiment::kGroupNeverShowBubble));
+}
+
+} // namespace
+
class PasswordManagerUrlsCollectionExperimentTest : public testing::Test {
public:
+ PasswordManagerUrlsCollectionExperimentTest()
+ : field_trial_list_(new metrics::SHA1EntropyProvider("foo")) {}
+
+ void SetUp() override {
+ pref_service_.registry()->RegisterBooleanPref(
+ password_manager::prefs::kWasAllowToCollectURLBubbleShown, false);
+ variations::testing::ClearAllVariationParams();
+ }
+
+ void PretendThatThisIsTimeSpanWhenBubbleAppears(
+ const std::string& profile_uuid,
+ int experiment_length_in_days) {
+ base::Time starting_time = password_manager::urls_collection_experiment::
+ DetermineStartOfActivityPeriod(profile_uuid, experiment_length_in_days);
+ test_clock()->SetNow(starting_time);
+ }
+
+ void PretendThatThisIsTimeSpanWhenBubbleDoesNotAppear(
+ const std::string& profile_uuid,
+ int experiment_length_in_days) {
+ base::Time starting_time = password_manager::urls_collection_experiment::
+ DetermineStartOfActivityPeriod(profile_uuid, experiment_length_in_days);
+ test_clock()->SetNow(
+ starting_time + base::TimeDelta::FromDays(kParamTimePeriodInDaysValue));
+ }
+
+ void PretendThatBubbleWasAlreadyShown() {
+ prefs()->SetBoolean(
+ password_manager::prefs::kWasAllowToCollectURLBubbleShown, true);
+ }
+
PrefService* prefs() { return &pref_service_; }
+ base::SimpleTestClock* test_clock() { return &test_clock_; }
+
private:
TestingPrefServiceSimple pref_service_;
+ base::FieldTrialList field_trial_list_;
+ base::SimpleTestClock test_clock_;
};
-TEST_F(PasswordManagerUrlsCollectionExperimentTest, TestDefault) {
- EXPECT_FALSE(
- password_manager::urls_collection_experiment::ShouldShowBubble(prefs()));
+TEST_F(PasswordManagerUrlsCollectionExperimentTest,
+ TestShowBubbleGroupTimeSpanWhenBubbleShouldAppear) {
+ SetupShowBubbleExperimentGroup();
+ PretendThatThisIsTimeSpanWhenBubbleAppears(kProfileUuid,
+ kParamLengthInDaysValue);
+ EXPECT_TRUE(password_manager::urls_collection_experiment::ShouldShowBubble(
+ prefs(), kProfileUuid, test_clock()));
}
-} // namespace
+TEST_F(PasswordManagerUrlsCollectionExperimentTest,
+ TestShowBubbleGroupTimeSpanWhenBubbleShouldNotAppear) {
+ SetupShowBubbleExperimentGroup();
+ PretendThatThisIsTimeSpanWhenBubbleDoesNotAppear(kProfileUuid,
+ kParamLengthInDaysValue);
+ EXPECT_FALSE(password_manager::urls_collection_experiment::ShouldShowBubble(
+ prefs(), kProfileUuid, test_clock()));
+}
+
+TEST_F(PasswordManagerUrlsCollectionExperimentTest, TestNeverShowBubbleGroup) {
+ SetupNeverShowBubbleExperimentGroup();
vabr (Chromium) 2014/12/10 18:19:55 Should we also call PretendThatThisIsTimeSpanWhenB
vabr (Chromium) 2014/12/11 09:37:55 I'd like to ping this comment. :)
melandory 2014/12/11 13:16:10 We should call only SetupNeverShowBubbleExperiment
vabr (Chromium) 2014/12/11 14:05:13 Well that's how it works now. But the purpose of t
+ EXPECT_FALSE(password_manager::urls_collection_experiment::ShouldShowBubble(
+ prefs(), kProfileUuid, test_clock()));
+}
+
+TEST_F(PasswordManagerUrlsCollectionExperimentTest, TestBubbleWasAlreadyShown) {
+ SetupShowBubbleExperimentGroup();
+ PretendThatBubbleWasAlreadyShown();
+ EXPECT_FALSE(password_manager::urls_collection_experiment::ShouldShowBubble(
+ prefs(), kProfileUuid, test_clock()));
+}

Powered by Google App Engine
This is Rietveld 408576698