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

Side by Side Diff: chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util_unittest.cc

Issue 2694893002: Integrate SMS service with Desktop iOS promotion (Closed)
Patch Set: unique_ptr Created 3 years, 10 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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/desktop_ios_promotion/desktop_ios_promotion_util.h"
6
7 #include "base/i18n/rtl.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/test/scoped_feature_list.h"
10 #include "chrome/browser/sync/profile_sync_test_util.h"
11 #include "chrome/common/chrome_features.h"
12 #include "chrome/test/base/testing_browser_process.h"
13 #include "components/browser_sync/profile_sync_service.h"
14 #include "components/prefs/pref_service.h"
15 #include "components/sync/driver/fake_sync_service.h"
16 #include "components/sync_preferences/testing_pref_service_syncable.h"
17
18 namespace {
19
20 class TestSyncService : public syncer::FakeSyncService {
21 public:
22 // FakeSyncService overrides.
23 bool IsSyncAllowed() const override { return is_sync_allowed_; }
24
25 void set_sync_allowed(bool sync_allowed) { is_sync_allowed_ = sync_allowed; }
26
27 private:
28 bool is_sync_allowed_ = true;
29 };
30
31 } // namespace
32
33 class DesktopIOSPromotionUtilTest : public testing::Test {
34 public:
35 DesktopIOSPromotionUtilTest() {}
36 ~DesktopIOSPromotionUtilTest() override {}
37
38 void SetUp() override {
39 local_state_.reset(new TestingPrefServiceSimple);
40 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get());
41 desktop_ios_promotion::RegisterLocalPrefs(local_state_->registry());
42 pref_service_ = new sync_preferences::TestingPrefServiceSyncable();
43 desktop_ios_promotion::RegisterProfilePrefs(pref_service_->registry());
44 }
45
46 void TearDown() override {
47 // Ensure that g_accept_requests gets set back to true after test execution.
48 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
49 local_state_.reset();
50 }
51
52 PrefService* local_state() { return local_state_.get(); }
53
54 TestSyncService* sync_service() { return &fake_sync_service_; }
55 sync_preferences::TestingPrefServiceSyncable* prefs() {
56 return pref_service_;
57 }
58
59 double GetDoubleNDayOldDate(int days) {
60 base::Time time_result =
61 base::Time::NowFromSystemTime() - base::TimeDelta::FromDays(days);
62 return time_result.ToDoubleT();
63 }
64
65 protected:
66 std::unique_ptr<TestingPrefServiceSimple> local_state_;
67 sync_preferences::TestingPrefServiceSyncable* pref_service_;
68 TestSyncService fake_sync_service_;
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(DesktopIOSPromotionUtilTest);
72 };
73
74 TEST_F(DesktopIOSPromotionUtilTest, IsEligibleForIOSPromotionForSavePassword) {
75 desktop_ios_promotion::PromotionEntryPoint entry_point =
76 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE;
77 // By default the promo is off.
78 EXPECT_FALSE(desktop_ios_promotion::IsEligibleForIOSPromotion(
79 prefs(), nullptr, entry_point));
80 base::test::ScopedFeatureList scoped_feature_list;
81 scoped_feature_list.InitAndEnableFeature(features::kDesktopIOSPromotion);
82 std::string locales[] = {"en-US", "en-CA", "en-AU", "es-US"};
83 constexpr struct {
84 bool is_sync_allowed;
85 int locale_index;
86 bool is_dismissed;
87 int show_count;
88 int last_impression_days;
89 int sms_entrypoint;
90 bool is_user_eligible;
91 bool promo_done;
92 bool result;
93 } kTestData[] = {
94 // {sync allowed, locale, dismissed before, impression count, seen days
95 // ago, bitmask with entry points seen, is user eligible, flow was
96 // completed before, expected result }
97 {false, 0, false, 0, 1, 0, false, false, false},
98 {false, 1, false, 0, 3, 0, true, false, false},
99 {true, 3, false, 0, 4, 0, true, false, false},
100 {true, 2, false, 0, 10, 0, true, false, false},
101 {true, 0, true, 1, 3, 0, true, false, false},
102 {true, 0, false, 3, 1, 0, true, false, false},
103 {true, 0, false, 1, 3,
104 1 << static_cast<int>(
105 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE),
106 true, false, false},
107 {true, 0, false, 0, 4,
108 1 << static_cast<int>(
109 desktop_ios_promotion::PromotionEntryPoint::BOOKMARKS_BUBBLE),
110 true, false, false},
111 {true, 0, false, 1, 10, 0, false, false, false},
112 {true, 0, false, 0, 1, 0, true, true, false},
113 {true, 1, false, 1, 1, 0, true, false, true},
114 {true, 1, false, 0, 2, 0, true, false, true},
115 {true, 0, false, 0, 8,
116 1 << static_cast<int>(
117 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE),
118 true, false, true},
119 };
120 std::string locale = base::i18n::GetConfiguredLocale();
121 for (const auto& test_case : kTestData) {
122 SCOPED_TRACE(testing::Message("#test_case = ") << (&test_case - kTestData));
123 sync_service()->set_sync_allowed(test_case.is_sync_allowed);
124 local_state()->SetBoolean(prefs::kSavePasswordsBubbleIOSPromoDismissed,
125 test_case.is_dismissed);
126 local_state()->SetInteger(prefs::kNumberSavePasswordsBubbleIOSPromoShown,
127 test_case.show_count);
128 base::i18n::SetICUDefaultLocale(locales[test_case.locale_index]);
129 prefs()->SetDouble(prefs::kIOSPromotionLastImpression,
130 GetDoubleNDayOldDate(test_case.last_impression_days));
131 prefs()->SetInteger(prefs::kIOSPromotionSMSEntryPoint,
132 test_case.sms_entrypoint);
133 prefs()->SetBoolean(prefs::kIOSPromotionEligible,
134 test_case.is_user_eligible);
135 prefs()->SetBoolean(prefs::kIOSPromotionDone, test_case.promo_done);
136 EXPECT_EQ(test_case.result,
137 IsEligibleForIOSPromotion(prefs(), sync_service(), entry_point));
138 }
139 base::i18n::SetICUDefaultLocale(locale);
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698