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

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: add desktop_ios_promotion_util unittest 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 {
sky 2017/02/17 19:06:30 This is a good start on test coverage, but you nee
mrefaat 2017/02/17 21:53:15 If possible, i prefer to do this on a separate CL
sky 2017/02/17 22:49:32 In the future, please have test coverage ready at
mrefaat 2017/02/18 00:03:25 Acknowledged.
mrefaat 2017/02/18 00:03:25 Acknowledged.
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 };
sky 2017/02/17 19:06:29 DISALLOW...
mrefaat 2017/02/17 21:53:15 Done.
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 };
sky 2017/02/17 19:06:29 private: DISALLOW...
mrefaat 2017/02/17 21:53:15 Done.
70
71 TEST_F(DesktopIOSPromotionUtilTest, IsEligibleForIOSPromotionForSavePassword) {
72 desktop_ios_promotion::PromotionEntryPoint entry_point =
73 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE;
74 // By default the promo is off.
75 EXPECT_FALSE(desktop_ios_promotion::IsEligibleForIOSPromotion(
76 prefs(), nullptr, entry_point));
77 base::test::ScopedFeatureList scoped_feature_list;
78 scoped_feature_list.InitAndEnableFeature(features::kDesktopIOSPromotion);
79 std::string locales[] = {"en-US", "en-CA", "en-AU", "es-US"};
80 constexpr struct {
81 bool is_sync_allowed;
82 int locale_index;
83 bool is_dismissed;
84 int show_count;
85 int last_impression_days;
86 int sms_entrypoint;
87 bool is_user_eligible;
88 bool promo_done;
89 bool result;
90 } kTestData[] = {
91 {false, 0, false, 0, 1, 0, false, false, false},
sky 2017/02/17 19:06:29 Use the enum values in here as otherwise it isn't
mrefaat 2017/02/17 21:53:15 Non of them has enum values on desktop_ios_promot
sky 2017/02/17 22:49:32 Aren't the bitmask values created from an enum? I'
mrefaat 2017/02/18 00:03:25 Done.
92 {false, 1, false, 0, 3, 0, true, false, false},
93 {true, 3, false, 0, 4, 0, true, false, false},
94 {true, 2, false, 0, 10, 0, true, false, false},
95 {true, 0, true, 1, 3, 0, true, false, false},
96 {true, 0, false, 3, 1, 0, true, false, false},
97 {true, 0, false, 1, 3, 2, true, false, false},
98 {true, 0, false, 0, 4, 4, true, false, false},
99 {true, 0, false, 1, 10, 0, false, false, false},
100 {true, 0, false, 0, 1, 0, true, true, false},
101 {true, 1, false, 1, 1, 0, true, false, true},
102 {true, 1, false, 0, 2, 0, true, false, true},
103 {true, 0, false, 0, 8, 2, true, false, true},
104 };
105 std::string locale = base::i18n::GetConfiguredLocale();
106 for (const auto& test_case : kTestData) {
107 SCOPED_TRACE(testing::Message("#test_case = ") << (&test_case - kTestData));
108 sync_service()->set_sync_allowed(test_case.is_sync_allowed);
109 local_state()->SetBoolean(prefs::kSavePasswordsBubbleIOSPromoDismissed,
110 test_case.is_dismissed);
111 local_state()->SetInteger(prefs::kNumberSavePasswordsBubbleIOSPromoShown,
112 test_case.show_count);
113 base::i18n::SetICUDefaultLocale(locales[test_case.locale_index]);
114 prefs()->SetDouble(prefs::kIOSPromotionLastImpression,
115 GetDoubleNDayOldDate(test_case.last_impression_days));
116 prefs()->SetInteger(prefs::kIOSPromotionSMSEntryPoint,
117 test_case.sms_entrypoint);
118 prefs()->SetBoolean(prefs::kIOSPromotionEligible,
119 test_case.is_user_eligible);
120 prefs()->SetBoolean(prefs::kIOSPromotionDone, test_case.promo_done);
121 EXPECT_EQ(test_case.result,
122 IsEligibleForIOSPromotion(prefs(), sync_service(), entry_point));
123 }
124 base::i18n::SetICUDefaultLocale(locale);
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698