Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / passwords / password_bubble_experiment_unittest.cc
blobe6084b950e060fa9134a3c02038c674eb533b151
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.
5 #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
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"
17 namespace {
19 const char kGroupName[] = "SomeGroupName";
20 const int kNopeThreshold = 10;
22 void SetupExperiment() {
23 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
24 password_bubble_experiment::kExperimentName,
25 kGroupName));
26 std::map<std::string, std::string> params;
27 params[password_bubble_experiment::kParamNopeThreshold] =
28 base::IntToString(kNopeThreshold);
29 ASSERT_TRUE(variations::AssociateVariationParams(
30 password_bubble_experiment::kExperimentName,
31 kGroupName,
32 params));
35 } // namespace
37 class PasswordBubbleExperimentTest : public testing::Test {
38 public:
39 void SetUp() override {
40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
41 profile_.reset(new TestingProfile(temp_dir_.path()));
43 field_trial_list_.reset(new base::FieldTrialList(
44 new metrics::SHA1EntropyProvider("foo")));
47 void TearDown() override {
48 variations::testing::ClearAllVariationParams();
51 PrefService* prefs() { return profile_->GetPrefs(); }
53 private:
54 base::ScopedTempDir temp_dir_;
55 scoped_ptr<TestingProfile> profile_;
56 scoped_ptr<base::FieldTrialList> field_trial_list_;
59 TEST_F(PasswordBubbleExperimentTest, NoExperiment) {
60 EXPECT_FALSE(
61 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
62 for (int i = 0; i <= kNopeThreshold; ++i) {
63 password_bubble_experiment::RecordBubbleClosed(
64 prefs(), password_manager::metrics_util::CLICKED_NOPE);
65 EXPECT_FALSE(
66 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
70 TEST_F(PasswordBubbleExperimentTest, WithExperiment) {
71 SetupExperiment();
73 // Repeatedly click "Never". It shouldn't affect the state.
74 for (int i = 0; i < kNopeThreshold; ++i) {
75 password_manager::metrics_util::UIDismissalReason reason =
76 password_manager::metrics_util::CLICKED_NEVER;
77 password_bubble_experiment::RecordBubbleClosed(prefs(), reason);
79 EXPECT_FALSE(
80 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
81 // Repeatedly refuse to save password, for |kNopeThreshold|-1 times.
82 for (int i = 0; i < kNopeThreshold - 1; ++i) {
83 password_manager::metrics_util::UIDismissalReason reason =
84 password_manager::metrics_util::CLICKED_NOPE;
85 password_bubble_experiment::RecordBubbleClosed(prefs(), reason);
87 EXPECT_FALSE(
88 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
90 // Refuse to save once more to make Never the default button.
91 password_bubble_experiment::RecordBubbleClosed(
92 prefs(), password_manager::metrics_util::CLICKED_NOPE);
93 EXPECT_TRUE(
94 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
95 password_bubble_experiment::RecordBubbleClosed(
96 prefs(), password_manager::metrics_util::CLICKED_SAVE);
97 EXPECT_FALSE(
98 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
100 // Repeatedly refuse to save password, for |kNopeThreshold| times.
101 for (int i = 0; i < kNopeThreshold; ++i) {
102 password_manager::metrics_util::UIDismissalReason reason =
103 password_manager::metrics_util::CLICKED_NOPE;
104 password_bubble_experiment::RecordBubbleClosed(prefs(), reason);
106 EXPECT_TRUE(
107 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));
108 // Repeatedly click "Never". It shouldn't affect the state.
109 for (int i = 0; i < kNopeThreshold; ++i) {
110 password_manager::metrics_util::UIDismissalReason reason =
111 password_manager::metrics_util::CLICKED_NEVER;
112 password_bubble_experiment::RecordBubbleClosed(prefs(), reason);
114 EXPECT_TRUE(
115 password_bubble_experiment::ShouldShowNeverForThisSiteDefault(prefs()));