OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | |
14 #include "chrome/browser/prefs/browser_prefs.h" | 13 #include "chrome/browser/prefs/browser_prefs.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/web_resource/notification_promo.h" | 15 #include "chrome/browser/web_resource/notification_promo.h" |
17 #include "chrome/browser/web_resource/promo_resource_service.h" | 16 #include "chrome/browser/web_resource/promo_resource_service.h" |
18 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/url_constants.h" | |
20 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
21 #include "chrome/test/base/testing_pref_service.h" | 21 #include "chrome/test/base/testing_pref_service.h" |
22 #include "chrome/test/base/testing_profile.h" | |
23 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
25 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 | 26 |
28 class PromoResourceServiceTest : public testing::Test { | 27 class PromoResourceServiceTest : public testing::Test { |
29 public: | 28 public: |
30 PromoResourceServiceTest() | 29 PromoResourceServiceTest() |
31 : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)), | 30 : local_state_(TestingBrowserProcess::GetGlobal()) { |
32 web_resource_service_(new PromoResourceService(&profile_)) { | 31 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.Get()); |
Robert Sesek
2013/01/04 01:16:13
Same
| |
32 // |promo_resource_service_| must be created after local state is set. | |
33 promo_resource_service_ = new PromoResourceService; | |
33 } | 34 } |
34 | 35 |
35 protected: | 36 protected: |
36 TestingProfile profile_; | |
37 ScopedTestingLocalState local_state_; | 37 ScopedTestingLocalState local_state_; |
38 scoped_refptr<PromoResourceService> web_resource_service_; | 38 scoped_refptr<PromoResourceService> promo_resource_service_; |
39 MessageLoop loop_; | 39 MessageLoop loop_; |
40 }; | 40 }; |
41 | 41 |
42 class NotificationPromoTest { | 42 class NotificationPromoTest { |
43 public: | 43 public: |
44 explicit NotificationPromoTest(Profile* profile) | 44 NotificationPromoTest() |
45 : profile_(profile), | 45 : received_notification_(false), |
46 prefs_(profile->GetPrefs()), | |
47 notification_promo_(profile), | |
48 received_notification_(false), | |
49 start_(0.0), | 46 start_(0.0), |
50 end_(0.0), | 47 end_(0.0), |
51 num_groups_(0), | 48 num_groups_(0), |
52 initial_segment_(0), | 49 initial_segment_(0), |
53 increment_(1), | 50 increment_(1), |
54 time_slice_(0), | 51 time_slice_(0), |
55 max_group_(0), | 52 max_group_(0), |
56 max_views_(0), | 53 max_views_(0), |
57 closed_(false), | 54 closed_(false) { |
58 gplus_required_(false) { | |
59 } | 55 } |
60 | 56 |
61 void Init(const std::string& json, | 57 void Init(const std::string& json, |
62 const std::string& promo_text, | 58 const std::string& promo_text, |
63 double start, double end, | 59 double start, double end, |
64 int num_groups, int initial_segment, int increment, | 60 int num_groups, int initial_segment, int increment, |
65 int time_slice, int max_group, int max_views, | 61 int time_slice, int max_group, int max_views) { |
66 bool gplus_required) { | |
67 Value* value(base::JSONReader::Read(json)); | 62 Value* value(base::JSONReader::Read(json)); |
68 ASSERT_TRUE(value); | 63 ASSERT_TRUE(value); |
69 DictionaryValue* dict = NULL; | 64 DictionaryValue* dict = NULL; |
70 value->GetAsDictionary(&dict); | 65 value->GetAsDictionary(&dict); |
71 ASSERT_TRUE(dict); | 66 ASSERT_TRUE(dict); |
72 test_json_.reset(dict); | 67 test_json_.reset(dict); |
73 | 68 |
74 promo_type_ = NotificationPromo::NTP_NOTIFICATION_PROMO; | 69 promo_type_ = NotificationPromo::NTP_NOTIFICATION_PROMO; |
75 promo_text_ = promo_text; | 70 promo_text_ = promo_text; |
76 | 71 |
77 start_ = start; | 72 start_ = start; |
78 end_ = end; | 73 end_ = end; |
79 | 74 |
80 num_groups_ = num_groups; | 75 num_groups_ = num_groups; |
81 initial_segment_ = initial_segment; | 76 initial_segment_ = initial_segment; |
82 increment_ = increment; | 77 increment_ = increment; |
83 time_slice_ = time_slice; | 78 time_slice_ = time_slice; |
84 max_group_ = max_group; | 79 max_group_ = max_group; |
85 | 80 |
86 max_views_ = max_views; | 81 max_views_ = max_views; |
87 | 82 |
88 gplus_required_ = gplus_required; | |
89 | |
90 closed_ = false; | 83 closed_ = false; |
91 received_notification_ = false; | 84 received_notification_ = false; |
92 } | 85 } |
93 | 86 |
94 void InitPromoFromJson(bool should_receive_notification) { | 87 void InitPromoFromJson(bool should_receive_notification) { |
95 notification_promo_.InitFromJson(*test_json_, promo_type_); | 88 notification_promo_.InitFromJson(*test_json_, promo_type_); |
96 EXPECT_EQ(should_receive_notification, | 89 EXPECT_EQ(should_receive_notification, |
97 notification_promo_.new_notification()); | 90 notification_promo_.new_notification()); |
98 | 91 |
99 // Test the fields. | 92 // Test the fields. |
(...skipping 15 matching lines...) Expand all Loading... | |
115 | 108 |
116 EXPECT_EQ(notification_promo_.max_views_, max_views_); | 109 EXPECT_EQ(notification_promo_.max_views_, max_views_); |
117 EXPECT_EQ(notification_promo_.closed_, closed_); | 110 EXPECT_EQ(notification_promo_.closed_, closed_); |
118 | 111 |
119 // Check group within bounds. | 112 // Check group within bounds. |
120 EXPECT_GE(notification_promo_.group_, 0); | 113 EXPECT_GE(notification_promo_.group_, 0); |
121 EXPECT_LT(notification_promo_.group_, num_groups_); | 114 EXPECT_LT(notification_promo_.group_, num_groups_); |
122 | 115 |
123 // Views should be 0 for now. | 116 // Views should be 0 for now. |
124 EXPECT_EQ(notification_promo_.views_, 0); | 117 EXPECT_EQ(notification_promo_.views_, 0); |
125 | |
126 EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_); | |
127 } | 118 } |
128 | 119 |
129 // Create a new NotificationPromo from prefs and compare to current | 120 // Create a new NotificationPromo from prefs and compare to current |
130 // notification. | 121 // notification. |
131 void TestInitFromPrefs() { | 122 void TestInitFromPrefs() { |
132 NotificationPromo prefs_notification_promo(profile_); | 123 NotificationPromo prefs_notification_promo; |
133 prefs_notification_promo.InitFromPrefs(promo_type_); | 124 prefs_notification_promo.InitFromPrefs(promo_type_); |
134 | 125 |
135 EXPECT_EQ(notification_promo_.prefs_, | 126 EXPECT_EQ(notification_promo_.prefs_, |
136 prefs_notification_promo.prefs_); | 127 prefs_notification_promo.prefs_); |
137 EXPECT_EQ(notification_promo_.promo_text_, | 128 EXPECT_EQ(notification_promo_.promo_text_, |
138 prefs_notification_promo.promo_text_); | 129 prefs_notification_promo.promo_text_); |
139 EXPECT_EQ(notification_promo_.start_, | 130 EXPECT_EQ(notification_promo_.start_, |
140 prefs_notification_promo.start_); | 131 prefs_notification_promo.start_); |
141 EXPECT_EQ(notification_promo_.end_, | 132 EXPECT_EQ(notification_promo_.end_, |
142 prefs_notification_promo.end_); | 133 prefs_notification_promo.end_); |
143 EXPECT_EQ(notification_promo_.num_groups_, | 134 EXPECT_EQ(notification_promo_.num_groups_, |
144 prefs_notification_promo.num_groups_); | 135 prefs_notification_promo.num_groups_); |
145 EXPECT_EQ(notification_promo_.initial_segment_, | 136 EXPECT_EQ(notification_promo_.initial_segment_, |
146 prefs_notification_promo.initial_segment_); | 137 prefs_notification_promo.initial_segment_); |
147 EXPECT_EQ(notification_promo_.increment_, | 138 EXPECT_EQ(notification_promo_.increment_, |
148 prefs_notification_promo.increment_); | 139 prefs_notification_promo.increment_); |
149 EXPECT_EQ(notification_promo_.time_slice_, | 140 EXPECT_EQ(notification_promo_.time_slice_, |
150 prefs_notification_promo.time_slice_); | 141 prefs_notification_promo.time_slice_); |
151 EXPECT_EQ(notification_promo_.max_group_, | 142 EXPECT_EQ(notification_promo_.max_group_, |
152 prefs_notification_promo.max_group_); | 143 prefs_notification_promo.max_group_); |
153 EXPECT_EQ(notification_promo_.max_views_, | 144 EXPECT_EQ(notification_promo_.max_views_, |
154 prefs_notification_promo.max_views_); | 145 prefs_notification_promo.max_views_); |
155 EXPECT_EQ(notification_promo_.group_, | 146 EXPECT_EQ(notification_promo_.group_, |
156 prefs_notification_promo.group_); | 147 prefs_notification_promo.group_); |
157 EXPECT_EQ(notification_promo_.views_, | 148 EXPECT_EQ(notification_promo_.views_, |
158 prefs_notification_promo.views_); | 149 prefs_notification_promo.views_); |
159 EXPECT_EQ(notification_promo_.closed_, | 150 EXPECT_EQ(notification_promo_.closed_, |
160 prefs_notification_promo.closed_); | 151 prefs_notification_promo.closed_); |
161 EXPECT_EQ(notification_promo_.gplus_required_, | |
162 prefs_notification_promo.gplus_required_); | |
163 } | 152 } |
164 | 153 |
165 void TestGroup() { | 154 void TestGroup() { |
166 // Test out of range groups. | 155 // Test out of range groups. |
167 const int incr = num_groups_ / 20; | 156 const int incr = num_groups_ / 20; |
168 for (int i = max_group_; i < num_groups_; i += incr) { | 157 for (int i = max_group_; i < num_groups_; i += incr) { |
169 notification_promo_.group_ = i; | 158 notification_promo_.group_ = i; |
170 EXPECT_FALSE(notification_promo_.CanShow()); | 159 EXPECT_FALSE(notification_promo_.CanShow()); |
171 } | 160 } |
172 | 161 |
173 // Test in-range groups. | 162 // Test in-range groups. |
174 for (int i = 0; i < max_group_; i += incr) { | 163 for (int i = 0; i < max_group_; i += incr) { |
175 notification_promo_.group_ = i; | 164 notification_promo_.group_ = i; |
176 EXPECT_TRUE(notification_promo_.CanShow()); | 165 EXPECT_TRUE(notification_promo_.CanShow()); |
177 } | 166 } |
178 | 167 |
179 // When max_group_ is 0, all groups pass. | 168 // When max_group_ is 0, all groups pass. |
180 notification_promo_.max_group_ = 0; | 169 notification_promo_.max_group_ = 0; |
181 for (int i = 0; i < num_groups_; i += incr) { | 170 for (int i = 0; i < num_groups_; i += incr) { |
182 notification_promo_.group_ = i; | 171 notification_promo_.group_ = i; |
183 EXPECT_TRUE(notification_promo_.CanShow()); | 172 EXPECT_TRUE(notification_promo_.CanShow()); |
184 } | 173 } |
185 notification_promo_.WritePrefs(); | 174 notification_promo_.WritePrefs(); |
186 } | 175 } |
187 | 176 |
188 void TestViews() { | 177 void TestViews() { |
189 notification_promo_.views_ = notification_promo_.max_views_ - 2; | 178 notification_promo_.views_ = notification_promo_.max_views_ - 2; |
190 notification_promo_.WritePrefs(); | 179 notification_promo_.WritePrefs(); |
191 | 180 |
192 NotificationPromo::HandleViewed(profile_, promo_type_); | 181 NotificationPromo::HandleViewed(promo_type_); |
193 NotificationPromo new_promo(profile_); | 182 NotificationPromo new_promo; |
194 new_promo.InitFromPrefs(promo_type_); | 183 new_promo.InitFromPrefs(promo_type_); |
195 EXPECT_EQ(new_promo.max_views_ - 1, new_promo.views_); | 184 EXPECT_EQ(new_promo.max_views_ - 1, new_promo.views_); |
196 EXPECT_TRUE(new_promo.CanShow()); | 185 EXPECT_TRUE(new_promo.CanShow()); |
197 NotificationPromo::HandleViewed(profile_, promo_type_); | 186 NotificationPromo::HandleViewed(promo_type_); |
198 new_promo.InitFromPrefs(promo_type_); | 187 new_promo.InitFromPrefs(promo_type_); |
199 EXPECT_EQ(new_promo.max_views_, new_promo.views_); | 188 EXPECT_EQ(new_promo.max_views_, new_promo.views_); |
200 EXPECT_FALSE(new_promo.CanShow()); | 189 EXPECT_FALSE(new_promo.CanShow()); |
201 | 190 |
202 // Test out of range views. | 191 // Test out of range views. |
203 for (int i = max_views_; i < max_views_ * 2; ++i) { | 192 for (int i = max_views_; i < max_views_ * 2; ++i) { |
204 new_promo.views_ = i; | 193 new_promo.views_ = i; |
205 EXPECT_FALSE(new_promo.CanShow()); | 194 EXPECT_FALSE(new_promo.CanShow()); |
206 } | 195 } |
207 | 196 |
208 // Test in range views. | 197 // Test in range views. |
209 for (int i = 0; i < max_views_; ++i) { | 198 for (int i = 0; i < max_views_; ++i) { |
210 new_promo.views_ = i; | 199 new_promo.views_ = i; |
211 EXPECT_TRUE(new_promo.CanShow()); | 200 EXPECT_TRUE(new_promo.CanShow()); |
212 } | 201 } |
213 new_promo.WritePrefs(); | 202 new_promo.WritePrefs(); |
214 } | 203 } |
215 | 204 |
216 void TestClosed() { | 205 void TestClosed() { |
217 NotificationPromo new_promo(profile_); | 206 NotificationPromo new_promo; |
218 new_promo.InitFromPrefs(promo_type_); | 207 new_promo.InitFromPrefs(promo_type_); |
219 EXPECT_FALSE(new_promo.closed_); | 208 EXPECT_FALSE(new_promo.closed_); |
220 EXPECT_TRUE(new_promo.CanShow()); | 209 EXPECT_TRUE(new_promo.CanShow()); |
221 | 210 |
222 NotificationPromo::HandleClosed(profile_, promo_type_); | 211 NotificationPromo::HandleClosed(promo_type_); |
223 new_promo.InitFromPrefs(promo_type_); | 212 new_promo.InitFromPrefs(promo_type_); |
224 EXPECT_TRUE(new_promo.closed_); | 213 EXPECT_TRUE(new_promo.closed_); |
225 EXPECT_FALSE(new_promo.CanShow()); | 214 EXPECT_FALSE(new_promo.CanShow()); |
226 | 215 |
227 new_promo.closed_ = false; | 216 new_promo.closed_ = false; |
228 EXPECT_TRUE(new_promo.CanShow()); | 217 EXPECT_TRUE(new_promo.CanShow()); |
229 new_promo.WritePrefs(); | 218 new_promo.WritePrefs(); |
230 } | 219 } |
231 | 220 |
232 void TestPromoText() { | 221 void TestPromoText() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 notification_promo_.group_ = 16; | 288 notification_promo_.group_ = 16; |
300 EXPECT_TRUE(notification_promo_.CanShow()); | 289 EXPECT_TRUE(notification_promo_.CanShow()); |
301 notification_promo_.group_ = 17; | 290 notification_promo_.group_ = 17; |
302 EXPECT_FALSE(notification_promo_.CanShow()); | 291 EXPECT_FALSE(notification_promo_.CanShow()); |
303 | 292 |
304 // Test last increment. | 293 // Test last increment. |
305 notification_promo_.start_ -= slice; | 294 notification_promo_.start_ -= slice; |
306 EXPECT_TRUE(notification_promo_.CanShow()); | 295 EXPECT_TRUE(notification_promo_.CanShow()); |
307 } | 296 } |
308 | 297 |
309 void TestGplus() { | |
310 notification_promo_.gplus_required_ = true; | |
311 | |
312 // Test G+ required. | |
313 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, true); | |
314 EXPECT_TRUE(notification_promo_.CanShow()); | |
315 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, false); | |
316 EXPECT_FALSE(notification_promo_.CanShow()); | |
317 | |
318 notification_promo_.gplus_required_ = false; | |
319 | |
320 // Test G+ not required. | |
321 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, true); | |
322 EXPECT_TRUE(notification_promo_.CanShow()); | |
323 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, false); | |
324 EXPECT_TRUE(notification_promo_.CanShow()); | |
325 } | |
326 | |
327 private: | 298 private: |
328 Profile* profile_; | |
329 PrefService* prefs_; | |
330 NotificationPromo notification_promo_; | 299 NotificationPromo notification_promo_; |
331 bool received_notification_; | 300 bool received_notification_; |
332 scoped_ptr<DictionaryValue> test_json_; | 301 scoped_ptr<DictionaryValue> test_json_; |
333 | 302 |
334 NotificationPromo::PromoType promo_type_; | 303 NotificationPromo::PromoType promo_type_; |
335 std::string promo_text_; | 304 std::string promo_text_; |
336 | 305 |
337 double start_; | 306 double start_; |
338 double end_; | 307 double end_; |
339 | 308 |
340 int num_groups_; | 309 int num_groups_; |
341 int initial_segment_; | 310 int initial_segment_; |
342 int increment_; | 311 int increment_; |
343 int time_slice_; | 312 int time_slice_; |
344 int max_group_; | 313 int max_group_; |
345 | 314 |
346 int max_views_; | 315 int max_views_; |
347 | 316 |
348 bool closed_; | 317 bool closed_; |
349 | |
350 bool gplus_required_; | |
351 }; | 318 }; |
352 | 319 |
353 // Test that everything gets parsed correctly, notifications are sent, | 320 // Test that everything gets parsed correctly, notifications are sent, |
354 // and CanShow() is handled correctly under variety of conditions. | 321 // and CanShow() is handled correctly under variety of conditions. |
355 // Additionally, test that the first string in |strings| is used if | 322 // Additionally, test that the first string in |strings| is used if |
356 // no payload.promo_short_message is specified in the JSON response. | 323 // no payload.promo_short_message is specified in the JSON response. |
357 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { | 324 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { |
358 // Check that prefs are set correctly. | 325 // Check that prefs are set correctly. |
359 PrefService* prefs = profile_.GetPrefs(); | 326 NotificationPromoTest promo_test; |
360 ASSERT_TRUE(prefs != NULL); | |
361 | |
362 NotificationPromoTest promo_test(&profile_); | |
363 | 327 |
364 // Set up start and end dates and promo line in a Dictionary as if parsed | 328 // Set up start and end dates and promo line in a Dictionary as if parsed |
365 // from the service. | 329 // from the service. |
366 promo_test.Init("{" | 330 promo_test.Init("{" |
367 " \"ntp_notification_promo\": [" | 331 " \"ntp_notification_promo\": [" |
368 " {" | 332 " {" |
369 " \"date\":" | 333 " \"date\":" |
370 " [" | 334 " [" |
371 " {" | 335 " {" |
372 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | 336 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
373 " \"end\":\"7 Jan 2013 5:40:75 PST\"" | 337 " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
374 " }" | 338 " }" |
375 " ]," | 339 " ]," |
376 " \"strings\":" | 340 " \"strings\":" |
377 " {" | 341 " {" |
378 " \"NTP4_HOW_DO_YOU_FEEL_ABOUT_CHROME\":" | 342 " \"NTP4_HOW_DO_YOU_FEEL_ABOUT_CHROME\":" |
379 " \"What do you think of Chrome?\"" | 343 " \"What do you think of Chrome?\"" |
380 " }," | 344 " }," |
381 " \"grouping\":" | 345 " \"grouping\":" |
382 " {" | 346 " {" |
383 " \"buckets\":1000," | 347 " \"buckets\":1000," |
384 " \"segment\":200," | 348 " \"segment\":200," |
385 " \"increment\":100," | 349 " \"increment\":100," |
386 " \"increment_frequency\":3600," | 350 " \"increment_frequency\":3600," |
387 " \"increment_max\":400" | 351 " \"increment_max\":400" |
388 " }," | 352 " }," |
389 " \"payload\":" | 353 " \"payload\":" |
390 " {" | 354 " {" |
391 " \"days_active\":7," | 355 " \"days_active\":7," |
392 " \"install_age_days\":21," | 356 " \"install_age_days\":21" |
393 " \"gplus_required\":false" | |
394 " }," | 357 " }," |
395 " \"max_views\":30" | 358 " \"max_views\":30" |
396 " }" | 359 " }" |
397 " ]" | 360 " ]" |
398 "}", | 361 "}", |
399 "What do you think of Chrome?", | 362 "What do you think of Chrome?", |
400 // The starting date is in 1999 to make tests pass | 363 // The starting date is in 1999 to make tests pass |
401 // on Android devices with incorrect or unset date/time. | 364 // on Android devices with incorrect or unset date/time. |
402 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 365 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
403 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. | 366 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
404 1000, 200, 100, 3600, 400, 30, false); | 367 1000, 200, 100, 3600, 400, 30); |
405 | 368 |
406 promo_test.InitPromoFromJson(true); | 369 promo_test.InitPromoFromJson(true); |
407 | 370 |
408 // Second time should not trigger a notification. | 371 // Second time should not trigger a notification. |
409 promo_test.InitPromoFromJson(false); | 372 promo_test.InitPromoFromJson(false); |
410 | 373 |
411 promo_test.TestInitFromPrefs(); | 374 promo_test.TestInitFromPrefs(); |
412 | 375 |
413 // Test various conditions of CanShow. | 376 // Test various conditions of CanShow. |
414 // TestGroup Has the side effect of setting us to a passing group. | 377 // TestGroup Has the side effect of setting us to a passing group. |
415 promo_test.TestGroup(); | 378 promo_test.TestGroup(); |
416 promo_test.TestViews(); | 379 promo_test.TestViews(); |
417 promo_test.TestClosed(); | 380 promo_test.TestClosed(); |
418 promo_test.TestPromoText(); | 381 promo_test.TestPromoText(); |
419 promo_test.TestTime(); | 382 promo_test.TestTime(); |
420 promo_test.TestIncrement(); | 383 promo_test.TestIncrement(); |
421 promo_test.TestGplus(); | |
422 } | 384 } |
423 | 385 |
424 // Test that payload.promo_message_short is used if present. | 386 // Test that payload.promo_message_short is used if present. |
425 TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { | 387 TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { |
426 // Check that prefs are set correctly. | 388 // Check that prefs are set correctly. |
427 PrefService* prefs = profile_.GetPrefs(); | 389 NotificationPromoTest promo_test; |
428 ASSERT_TRUE(prefs != NULL); | |
429 | |
430 NotificationPromoTest promo_test(&profile_); | |
431 | 390 |
432 // Set up start and end dates and promo line in a Dictionary as if parsed | 391 // Set up start and end dates and promo line in a Dictionary as if parsed |
433 // from the service. | 392 // from the service. |
434 promo_test.Init("{" | 393 promo_test.Init("{" |
435 " \"ntp_notification_promo\": [" | 394 " \"ntp_notification_promo\": [" |
436 " {" | 395 " {" |
437 " \"date\":" | 396 " \"date\":" |
438 " [" | 397 " [" |
439 " {" | 398 " {" |
440 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | 399 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
441 " \"end\":\"7 Jan 2013 5:40:75 PST\"" | 400 " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
442 " }" | 401 " }" |
443 " ]," | 402 " ]," |
444 " \"grouping\":" | 403 " \"grouping\":" |
445 " {" | 404 " {" |
446 " \"buckets\":1000," | 405 " \"buckets\":1000," |
447 " \"segment\":200," | 406 " \"segment\":200," |
448 " \"increment\":100," | 407 " \"increment\":100," |
449 " \"increment_frequency\":3600," | 408 " \"increment_frequency\":3600," |
450 " \"increment_max\":400" | 409 " \"increment_max\":400" |
451 " }," | 410 " }," |
452 " \"payload\":" | 411 " \"payload\":" |
453 " {" | 412 " {" |
454 " \"promo_message_short\":" | 413 " \"promo_message_short\":" |
455 " \"What do you think of Chrome?\"," | 414 " \"What do you think of Chrome?\"," |
456 " \"days_active\":7," | 415 " \"days_active\":7," |
457 " \"install_age_days\":21," | 416 " \"install_age_days\":21" |
458 " \"gplus_required\":false" | |
459 " }," | 417 " }," |
460 " \"max_views\":30" | 418 " \"max_views\":30" |
461 " }" | 419 " }" |
462 " ]" | 420 " ]" |
463 "}", | 421 "}", |
464 "What do you think of Chrome?", | 422 "What do you think of Chrome?", |
465 // The starting date is in 1999 to make tests pass | 423 // The starting date is in 1999 to make tests pass |
466 // on Android devices with incorrect or unset date/time. | 424 // on Android devices with incorrect or unset date/time. |
467 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 425 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
468 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. | 426 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
469 1000, 200, 100, 3600, 400, 30, false); | 427 1000, 200, 100, 3600, 400, 30); |
470 | 428 |
471 promo_test.InitPromoFromJson(true); | 429 promo_test.InitPromoFromJson(true); |
472 // Second time should not trigger a notification. | 430 // Second time should not trigger a notification. |
473 promo_test.InitPromoFromJson(false); | 431 promo_test.InitPromoFromJson(false); |
474 promo_test.TestInitFromPrefs(); | 432 promo_test.TestInitFromPrefs(); |
475 } | 433 } |
476 | 434 |
477 // Test that strings.|payload.promo_message_short| is used if present. | 435 // Test that strings.|payload.promo_message_short| is used if present. |
478 TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { | 436 TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { |
479 // Check that prefs are set correctly. | 437 // Check that prefs are set correctly. |
480 PrefService* prefs = profile_.GetPrefs(); | 438 NotificationPromoTest promo_test; |
481 ASSERT_TRUE(prefs != NULL); | |
482 | |
483 NotificationPromoTest promo_test(&profile_); | |
484 | 439 |
485 // Set up start and end dates and promo line in a Dictionary as if parsed | 440 // Set up start and end dates and promo line in a Dictionary as if parsed |
486 // from the service. | 441 // from the service. |
487 promo_test.Init("{" | 442 promo_test.Init("{" |
488 " \"ntp_notification_promo\": [" | 443 " \"ntp_notification_promo\": [" |
489 " {" | 444 " {" |
490 " \"date\":" | 445 " \"date\":" |
491 " [" | 446 " [" |
492 " {" | 447 " {" |
493 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | 448 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
(...skipping 12 matching lines...) Expand all Loading... | |
506 " {" | 461 " {" |
507 " \"bogus\":\"string\"," | 462 " \"bogus\":\"string\"," |
508 " \"GOOD_STRING\":" | 463 " \"GOOD_STRING\":" |
509 " \"What do you think of Chrome?\"" | 464 " \"What do you think of Chrome?\"" |
510 " }," | 465 " }," |
511 " \"payload\":" | 466 " \"payload\":" |
512 " {" | 467 " {" |
513 " \"promo_message_short\":" | 468 " \"promo_message_short\":" |
514 " \"GOOD_STRING\"," | 469 " \"GOOD_STRING\"," |
515 " \"days_active\":7," | 470 " \"days_active\":7," |
516 " \"install_age_days\":21," | 471 " \"install_age_days\":21" |
517 " \"gplus_required\":false" | |
518 " }," | 472 " }," |
519 " \"max_views\":30" | 473 " \"max_views\":30" |
520 " }" | 474 " }" |
521 " ]" | 475 " ]" |
522 "}", | 476 "}", |
523 "What do you think of Chrome?", | 477 "What do you think of Chrome?", |
524 // The starting date is in 1999 to make tests pass | 478 // The starting date is in 1999 to make tests pass |
525 // on Android devices with incorrect or unset date/time. | 479 // on Android devices with incorrect or unset date/time. |
526 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 480 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
527 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. | 481 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
528 1000, 200, 100, 3600, 400, 30, false); | 482 1000, 200, 100, 3600, 400, 30); |
529 | 483 |
530 promo_test.InitPromoFromJson(true); | 484 promo_test.InitPromoFromJson(true); |
531 // Second time should not trigger a notification. | 485 // Second time should not trigger a notification. |
532 promo_test.InitPromoFromJson(false); | 486 promo_test.InitPromoFromJson(false); |
533 promo_test.TestInitFromPrefs(); | 487 promo_test.TestInitFromPrefs(); |
534 } | 488 } |
535 | 489 |
536 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { | 490 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { |
537 GURL promo_server_url = NotificationPromo::PromoServerURL(); | 491 GURL promo_server_url = NotificationPromo::PromoServerURL(); |
538 EXPECT_FALSE(promo_server_url.is_empty()); | 492 EXPECT_FALSE(promo_server_url.is_empty()); |
539 EXPECT_TRUE(promo_server_url.SchemeIs("https")); | 493 EXPECT_TRUE(promo_server_url.is_valid()); |
494 EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme)); | |
540 // TODO(achuith): Test this better. | 495 // TODO(achuith): Test this better. |
541 } | 496 } |
OLD | NEW |