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