OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | |
6 | |
7 #include "base/files/scoped_temp_dir.h" | |
8 #include "base/metrics/field_trial.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "base/strings/string_number_conversions.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "chrome/test/base/testing_profile.h" | |
13 #include "components/variations/entropy_provider.h" | |
14 #include "components/variations/variations_associated_data.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 namespace { | |
18 | |
19 const int kTimeSpanDays = 2; | |
20 const int kTimeSpanThreshold = 3; | |
21 const int kProbabilityFakeSaves = 0; | |
22 const int kProbabilityHistory = 10; | |
23 | |
24 void SetupTimeSpanExperiment() { | |
25 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
26 password_bubble_experiment::kExperimentName, | |
27 password_bubble_experiment::kGroupTimeSpanBased)); | |
28 std::map<std::string, std::string> params; | |
29 params[password_bubble_experiment::kParamTimeSpan] = | |
30 base::IntToString(kTimeSpanDays); | |
31 params[password_bubble_experiment::kParamTimeSpanNopeThreshold] = | |
32 base::IntToString(kTimeSpanThreshold); | |
33 ASSERT_TRUE(variations::AssociateVariationParams( | |
34 password_bubble_experiment::kExperimentName, | |
35 password_bubble_experiment::kGroupTimeSpanBased, | |
36 params)); | |
37 } | |
38 | |
39 void SetupProbabilityExperiment() { | |
40 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
41 password_bubble_experiment::kExperimentName, | |
42 password_bubble_experiment::kGroupProbabilityBased)); | |
43 std::map<std::string, std::string> params; | |
44 params[password_bubble_experiment::kParamProbabilityFakeSaves] = | |
45 base::IntToString(kProbabilityFakeSaves); | |
46 params[password_bubble_experiment::kParamProbabilityInteractionsCount] = | |
47 base::IntToString(kProbabilityHistory); | |
48 ASSERT_TRUE(variations::AssociateVariationParams( | |
49 password_bubble_experiment::kExperimentName, | |
50 password_bubble_experiment::kGroupProbabilityBased, | |
51 params)); | |
52 } | |
53 | |
54 } // namespace | |
55 | |
56 class PasswordBubbleExperimentTest : public testing::Test { | |
57 public: | |
58 void SetUp() override { | |
59 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
60 profile_.reset(new TestingProfile(temp_dir_.path())); | |
61 | |
62 field_trial_list_.reset(new base::FieldTrialList( | |
63 new metrics::SHA1EntropyProvider("foo"))); | |
64 variations::testing::ClearAllVariationParams(); | |
65 } | |
66 | |
67 PrefService* prefs() { return profile_->GetPrefs(); } | |
68 | |
69 private: | |
70 base::ScopedTempDir temp_dir_; | |
71 scoped_ptr<TestingProfile> profile_; | |
72 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
73 }; | |
74 | |
75 TEST_F(PasswordBubbleExperimentTest, TimeSpan) { | |
76 SetupTimeSpanExperiment(); | |
77 | |
78 EXPECT_TRUE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
79 // Don't save password enough times. | |
80 for (int i = 0; i < kTimeSpanThreshold; ++i) { | |
81 password_manager::metrics_util::UIDismissalReason reason = i % 2 ? | |
82 password_manager::metrics_util::NO_DIRECT_INTERACTION : | |
83 password_manager::metrics_util::CLICKED_NOPE; | |
84 password_bubble_experiment::RecordBubbleClosed(prefs(), reason); | |
85 } | |
86 EXPECT_FALSE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
87 | |
88 // Save password many times. It doesn't bring the bubble back while the time | |
89 // apn isn't over. | |
vabr (Chromium)
2014/11/11 10:10:58
typo? apn->span
vasilii
2014/11/11 10:39:40
Done.
| |
90 for (int i = 0; i < 2*kTimeSpanThreshold; ++i) { | |
91 password_bubble_experiment::RecordBubbleClosed( | |
92 prefs(), | |
93 password_manager::metrics_util::CLICKED_SAVE); | |
94 } | |
95 EXPECT_FALSE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
96 } | |
97 | |
98 TEST_F(PasswordBubbleExperimentTest, TimeSpanOver) { | |
99 SetupTimeSpanExperiment(); | |
100 | |
101 base::Time past_interval = | |
102 base::Time::Now() - base::TimeDelta::FromDays(kTimeSpanDays + 1); | |
103 prefs()->SetInt64(prefs::kPasswordBubbleTimeStamp, | |
104 past_interval.ToInternalValue()); | |
105 prefs()->SetInteger(prefs::kPasswordBubbleNopesCount, kTimeSpanThreshold); | |
106 // The time span is over. The bubble should be shown. | |
107 EXPECT_TRUE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
108 EXPECT_EQ(0, prefs()->GetInteger(prefs::kPasswordBubbleNopesCount)); | |
109 | |
110 // Set the old time span again and record "Nope". The counter restart from 0. | |
vabr (Chromium)
2014/11/11 10:10:58
grammar nit: "counter restarts"
vasilii
2014/11/11 10:39:40
Done.
| |
111 prefs()->SetInt64(prefs::kPasswordBubbleTimeStamp, | |
112 past_interval.ToInternalValue()); | |
113 password_bubble_experiment::RecordBubbleClosed( | |
114 prefs(), password_manager::metrics_util::CLICKED_NOPE); | |
115 EXPECT_TRUE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
116 EXPECT_EQ(1, prefs()->GetInteger(prefs::kPasswordBubbleNopesCount)); | |
117 } | |
118 | |
119 TEST_F(PasswordBubbleExperimentTest, Probability) { | |
120 SetupProbabilityExperiment(); | |
121 | |
122 EXPECT_TRUE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
123 // Don't save password enough times. | |
124 for (int i = 0; i < kProbabilityHistory; ++i) { | |
125 password_manager::metrics_util::UIDismissalReason reason = i % 2 ? | |
126 password_manager::metrics_util::NO_DIRECT_INTERACTION : | |
127 password_manager::metrics_util::CLICKED_NOPE; | |
128 password_bubble_experiment::RecordBubbleClosed(prefs(), reason); | |
129 } | |
130 EXPECT_FALSE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
131 | |
132 // Save password enough times. | |
133 for (int i = 0; i < kProbabilityHistory; ++i) { | |
134 password_bubble_experiment::RecordBubbleClosed( | |
135 prefs(), | |
136 password_manager::metrics_util::CLICKED_SAVE); | |
137 } | |
138 EXPECT_TRUE(password_bubble_experiment::ShouldShowBubble(prefs())); | |
139 } | |
OLD | NEW |