OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 " {" | 96 " {" |
97 " \"name\": \"sign_in_promo\"," | 97 " \"name\": \"sign_in_promo\"," |
98 " \"question\": \""; | 98 " \"question\": \""; |
99 | 99 |
100 std::string json_footer = "\"" | 100 std::string json_footer = "\"" |
101 " }" | 101 " }" |
102 " ]" | 102 " ]" |
103 " }" | 103 " }" |
104 "}"; | 104 "}"; |
105 | 105 |
106 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 106 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
107 base::JSONReader::Read(json_header + question + json_footer, false))); | 107 base::JSONReader::Read(json_header + question + json_footer, false))); |
108 web_resource_service_->UnpackNTPSignInPromoSignal(*(test_json.get())); | 108 web_resource_service_->UnpackNTPSignInPromoSignal(*(test_json.get())); |
109 } | 109 } |
110 | 110 |
111 private: | 111 private: |
112 int notifications_received_; | 112 int notifications_received_; |
113 content::NotificationRegistrar registrar_; | 113 content::NotificationRegistrar registrar_; |
114 }; | 114 }; |
115 | 115 |
116 // Verifies that custom dates read from a web resource server are written to | 116 // Verifies that custom dates read from a web resource server are written to |
117 // the preferences file. | 117 // the preferences file. |
118 TEST_F(PromoResourceServiceTest, UnpackLogoSignal) { | 118 TEST_F(PromoResourceServiceTest, UnpackLogoSignal) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 // Check that prefs are set correctly. | 187 // Check that prefs are set correctly. |
188 web_resource_service_->UnpackLogoSignal(*(test_json.get())); | 188 web_resource_service_->UnpackLogoSignal(*(test_json.get())); |
189 logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); | 189 logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); |
190 EXPECT_EQ(logo_start, 0); // date value reset to 0; | 190 EXPECT_EQ(logo_start, 0); // date value reset to 0; |
191 logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); | 191 logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); |
192 EXPECT_EQ(logo_end, 0); // date value reset to 0; | 192 EXPECT_EQ(logo_end, 0); // date value reset to 0; |
193 } | 193 } |
194 | 194 |
195 class NotificationPromoTestDelegate : public NotificationPromo::Delegate { | 195 class NotificationPromoTestDelegate : public NotificationPromo::Delegate { |
196 public: | 196 public: |
197 explicit NotificationPromoTestDelegate(PrefService* prefs) | 197 explicit NotificationPromoTestDelegate(Profile* profile) |
198 : prefs_(prefs), | 198 : profile_(profile), |
199 prefs_(profile->GetPrefs()), | |
199 notification_promo_(NULL), | 200 notification_promo_(NULL), |
201 should_receive_notification_(false), | |
200 received_notification_(false), | 202 received_notification_(false), |
201 build_targeted_(true), | 203 build_targeted_(true), |
202 start_(0.0), | 204 start_(0.0), |
203 end_(0.0), | 205 end_(0.0), |
204 build_(PromoResourceService::NO_BUILD), | 206 build_(PromoResourceService::NO_BUILD), |
205 time_slice_(0), | 207 time_slice_(0), |
206 max_group_(0), | 208 max_group_(0), |
207 max_views_(0), | 209 max_views_(0), |
208 platform_(NotificationPromo::PLATFORM_NONE), | 210 platform_(NotificationPromo::PLATFORM_NONE), |
209 text_(), | 211 text_(), |
210 closed_(false), | 212 closed_(false), |
211 current_platform_(NotificationPromo::CurrentPlatform()) { | 213 current_platform_(NotificationPromo::CurrentPlatform()), |
214 gplus_(false), | |
215 feature_mask_(0) { | |
212 } | 216 } |
213 | 217 |
214 void Init(NotificationPromo* notification_promo, | 218 void Init(NotificationPromo* notification_promo, |
215 const std::string& json, | 219 const std::string& json, |
216 double start, double end, | 220 double start, double end, |
217 int build, int time_slice, | 221 int build, int time_slice, |
218 int max_group, int max_views, int platform, | 222 int max_group, int max_views, int platform, |
219 const std::string& text, bool closed) { | 223 int feature_mask, const std::string& text, bool closed, |
224 bool gplus) { | |
220 notification_promo_ = notification_promo; | 225 notification_promo_ = notification_promo; |
221 | 226 |
222 test_json_.reset(static_cast<DictionaryValue*>( | 227 test_json_.reset(static_cast<DictionaryValue*>( |
223 base::JSONReader::Read(json, false))); | 228 base::JSONReader::Read(json, false))); |
224 | 229 |
225 start_ = start; | 230 start_ = start; |
226 end_ = end; | 231 end_ = end; |
227 | 232 |
228 build_ = build; | 233 build_ = build; |
229 time_slice_ = time_slice; | 234 time_slice_ = time_slice; |
230 max_group_ = max_group; | 235 max_group_ = max_group; |
231 max_views_ = max_views; | 236 max_views_ = max_views; |
232 platform_ = platform; | 237 platform_ = platform; |
233 | 238 |
234 text_ = text; | 239 text_ = text; |
235 closed_ = closed; | 240 closed_ = closed; |
241 gplus_ = gplus; | |
242 feature_mask_ = feature_mask; | |
236 | 243 |
237 received_notification_ = false; | 244 received_notification_ = false; |
238 } | 245 } |
239 | 246 |
240 // NotificationPromo::Delegate implementation. | 247 // NotificationPromo::Delegate implementation. |
241 virtual void OnNewNotification(double start, double end) { | 248 virtual void OnNotificationParsed(double start, double end, |
242 EXPECT_EQ(CalcStart(), start); | 249 bool new_notification) { |
243 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), start); | 250 if (should_receive_notification_) { |
244 EXPECT_EQ(notification_promo_->end_, end); | 251 EXPECT_EQ(CalcStart(), start); |
245 received_notification_ = true; | 252 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), start); |
253 EXPECT_EQ(notification_promo_->end_, end); | |
254 } | |
255 | |
256 received_notification_ = new_notification; | |
257 | |
achuithb
2011/11/29 03:18:05
nit: don't think this newline is necessary.
| |
258 EXPECT_TRUE(received_notification_ == should_receive_notification_); | |
246 } | 259 } |
247 | 260 |
248 virtual bool IsBuildAllowed(int builds_targeted) const { | 261 virtual bool IsBuildAllowed(int builds_targeted) const { |
249 EXPECT_EQ(builds_targeted, build_); | 262 EXPECT_EQ(builds_targeted, build_); |
250 return build_targeted_; | 263 return build_targeted_; |
251 } | 264 } |
252 | 265 |
253 virtual int CurrentPlatform() const { | 266 virtual int CurrentPlatform() const { |
254 return current_platform_; | 267 return current_platform_; |
255 } | 268 } |
256 | 269 |
257 const base::DictionaryValue& TestJson() const { | 270 const base::DictionaryValue& TestJson() const { |
258 return *test_json_; | 271 return *test_json_; |
259 } | 272 } |
260 | 273 |
261 double CalcStart() const { | 274 double CalcStart() const { |
262 return start_ + notification_promo_->group_ * time_slice_ * 60.0 * 60.0; | 275 return start_ + notification_promo_->group_ * time_slice_ * 60.0 * 60.0; |
263 } | 276 } |
264 | 277 |
265 void InitPromoFromJson(bool should_receive_notification) { | 278 void InitPromoFromJson(bool should_receive_notification) { |
279 should_receive_notification_ = should_receive_notification; | |
266 received_notification_ = false; | 280 received_notification_ = false; |
267 notification_promo_->InitFromJson(TestJson()); | 281 notification_promo_->InitFromJson(TestJson(), false); |
268 EXPECT_TRUE(received_notification_ == should_receive_notification); | 282 EXPECT_TRUE(received_notification_ == should_receive_notification); |
269 | 283 |
270 // Test the fields. | 284 // Test the fields. |
271 TestNotification(); | 285 TestNotification(); |
272 TestPrefs(); | 286 TestPrefs(); |
273 } | 287 } |
274 | 288 |
289 void TestCookie(const std::string& cookies, | |
290 bool should_receive_notification, bool should_find_cookie) { | |
291 gplus_ = should_find_cookie; | |
292 should_receive_notification_ = should_receive_notification; | |
293 received_notification_ = false; | |
294 | |
295 bool found_cookie = NotificationPromo::CheckForGPlusCookie(cookies); | |
296 EXPECT_TRUE(found_cookie == should_find_cookie); | |
297 | |
298 notification_promo_->CheckForNewNotification(found_cookie); | |
299 EXPECT_TRUE(received_notification_ == should_receive_notification); | |
300 | |
301 // Test the fields. | |
302 EXPECT_EQ(notification_promo_->gplus_, gplus_); | |
303 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_); | |
304 // Test the prefs. | |
305 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_); | |
306 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_); | |
307 | |
308 // Set group_ manually to a passing group. | |
309 notification_promo_->group_ = max_group_ - 1; | |
310 // Assumes feature_mask = GPLUS_FEATURE, so whether or not the promo is | |
311 // is shown depends only on the value of gplus_. | |
312 EXPECT_TRUE(notification_promo_->CanShow() == gplus_); | |
313 } | |
314 | |
315 void TestGPlus() { | |
316 feature_mask_ = NotificationPromo::FEATURE_GPLUS; | |
317 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS; | |
318 // Force a notification when gplus_ is found to be false. | |
319 notification_promo_->prefs_-> | |
320 SetBoolean(prefs::kNTPPromoIsLoggedInToPlus, true); | |
321 | |
322 TestCookie("WRONG=123456;", true, false); | |
323 // Should not trigger notification on second call. | |
324 TestCookie("WRONG=123456;", false, false); | |
325 | |
326 TestCookie("SID=123456;", true, true); | |
327 // Should not trigger notification on second call. | |
328 TestCookie("SID=123456;", false, true); | |
329 | |
330 // Reset the notification_promo to its original state. | |
331 feature_mask_ = NotificationPromo::NO_FEATURE; | |
332 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE; | |
333 gplus_ = false; | |
334 notification_promo_->prefs_-> | |
335 SetBoolean(prefs::kNTPPromoIsLoggedInToPlus, false); | |
336 notification_promo_->gplus_ = false; | |
337 } | |
338 | |
275 void TestNotification() { | 339 void TestNotification() { |
276 // Check values. | 340 // Check values. |
277 EXPECT_EQ(notification_promo_->start_, start_); | 341 EXPECT_EQ(notification_promo_->start_, start_); |
278 EXPECT_EQ(notification_promo_->end_, end_); | 342 EXPECT_EQ(notification_promo_->end_, end_); |
279 EXPECT_EQ(notification_promo_->build_, build_); | 343 EXPECT_EQ(notification_promo_->build_, build_); |
280 EXPECT_EQ(notification_promo_->time_slice_, time_slice_); | 344 EXPECT_EQ(notification_promo_->time_slice_, time_slice_); |
281 EXPECT_EQ(notification_promo_->max_group_, max_group_); | 345 EXPECT_EQ(notification_promo_->max_group_, max_group_); |
282 EXPECT_EQ(notification_promo_->max_views_, max_views_); | 346 EXPECT_EQ(notification_promo_->max_views_, max_views_); |
283 EXPECT_EQ(notification_promo_->platform_, platform_); | 347 EXPECT_EQ(notification_promo_->platform_, platform_); |
284 EXPECT_EQ(notification_promo_->text_, text_); | 348 EXPECT_EQ(notification_promo_->text_, text_); |
285 EXPECT_EQ(notification_promo_->closed_, closed_); | 349 EXPECT_EQ(notification_promo_->closed_, closed_); |
350 EXPECT_EQ(notification_promo_->gplus_, gplus_); | |
351 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_); | |
286 | 352 |
287 // Check group within bounds. | 353 // Check group within bounds. |
288 EXPECT_GE(notification_promo_->group_, 0); | 354 EXPECT_GE(notification_promo_->group_, 0); |
289 EXPECT_LT(notification_promo_->group_, 100); | 355 EXPECT_LT(notification_promo_->group_, 100); |
290 | 356 |
291 // Views should be 0 for now. | 357 // Views should be 0 for now. |
292 EXPECT_EQ(notification_promo_->views_, 0); | 358 EXPECT_EQ(notification_promo_->views_, 0); |
293 | 359 |
294 // Check calculated time. | 360 // Check calculated time. |
295 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart()); | 361 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart()); |
296 } | 362 } |
297 | 363 |
298 void TestPrefs() { | 364 void TestPrefs() { |
299 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_); | 365 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_); |
300 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_); | 366 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_); |
301 | 367 |
302 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_); | 368 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_); |
303 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_); | 369 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_); |
304 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_); | 370 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_); |
305 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_); | 371 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_); |
306 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_); | 372 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_); |
307 | 373 |
308 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup), | 374 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup), |
309 notification_promo_ ? notification_promo_->group_: 0); | 375 notification_promo_ ? notification_promo_->group_: 0); |
310 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0); | 376 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0); |
311 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_); | 377 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_); |
312 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_); | 378 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_); |
379 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_); | |
380 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_); | |
313 } | 381 } |
314 | 382 |
315 // Create a new NotificationPromo from prefs and compare to current | 383 // Create a new NotificationPromo from prefs and compare to current |
316 // notification. | 384 // notification. |
317 void TestInitFromPrefs() { | 385 void TestInitFromPrefs() { |
318 NotificationPromo prefs_notification_promo(prefs_, this); | 386 scoped_refptr<NotificationPromo> prefs_notification_promo = |
319 prefs_notification_promo.InitFromPrefs(); | 387 NotificationPromo::Create(profile_, this); |
320 const bool is_equal = *notification_promo_ == prefs_notification_promo; | 388 prefs_notification_promo->InitFromPrefs(); |
389 const bool is_equal = *notification_promo_ == *prefs_notification_promo; | |
321 EXPECT_TRUE(is_equal); | 390 EXPECT_TRUE(is_equal); |
322 } | 391 } |
323 | 392 |
324 void TestGroup() { | 393 void TestGroup() { |
325 // Test out of range groups. | 394 // Test out of range groups. |
326 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) { | 395 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) { |
327 notification_promo_->group_ = i; | 396 notification_promo_->group_ = i; |
328 EXPECT_FALSE(notification_promo_->CanShow()); | 397 EXPECT_FALSE(notification_promo_->CanShow()); |
329 } | 398 } |
330 | 399 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 // End time has past. | 577 // End time has past. |
509 notification_promo_->start_ = now - qhour; | 578 notification_promo_->start_ = now - qhour; |
510 notification_promo_->end_ = now - qhour; | 579 notification_promo_->end_ = now - qhour; |
511 EXPECT_FALSE(notification_promo_->CanShow()); | 580 EXPECT_FALSE(notification_promo_->CanShow()); |
512 | 581 |
513 notification_promo_->start_ = start_; | 582 notification_promo_->start_ = start_; |
514 notification_promo_->end_ = end_; | 583 notification_promo_->end_ = end_; |
515 EXPECT_TRUE(notification_promo_->CanShow()); | 584 EXPECT_TRUE(notification_promo_->CanShow()); |
516 } | 585 } |
517 | 586 |
587 void TestFeatureMask() { | |
588 // No gplus cookie, feature mask in use. | |
589 notification_promo_->gplus_ = false; | |
590 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS; | |
591 EXPECT_FALSE(notification_promo_->CanShow()); | |
592 | |
593 // Gplus cookie, feature mask in use. | |
594 notification_promo_->gplus_ = true; | |
595 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS; | |
596 EXPECT_TRUE(notification_promo_->CanShow()); | |
597 | |
598 // If no feature mask, gplus_ value is ignored. | |
599 notification_promo_->gplus_ = true; | |
600 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE; | |
601 EXPECT_TRUE(notification_promo_->CanShow()); | |
602 | |
603 notification_promo_->gplus_ = false; | |
604 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE; | |
605 EXPECT_TRUE(notification_promo_->CanShow()); | |
606 } | |
607 | |
518 private: | 608 private: |
609 Profile* profile_; | |
519 PrefService* prefs_; | 610 PrefService* prefs_; |
520 NotificationPromo* notification_promo_; | 611 NotificationPromo* notification_promo_; |
521 bool received_notification_; | 612 bool received_notification_; |
613 bool should_receive_notification_; | |
522 bool build_targeted_; | 614 bool build_targeted_; |
523 scoped_ptr<DictionaryValue> test_json_; | 615 scoped_ptr<DictionaryValue> test_json_; |
524 | 616 |
525 double start_; | 617 double start_; |
526 double end_; | 618 double end_; |
527 | 619 |
528 int build_; | 620 int build_; |
529 int time_slice_; | 621 int time_slice_; |
530 int max_group_; | 622 int max_group_; |
531 int max_views_; | 623 int max_views_; |
532 int platform_; | 624 int platform_; |
625 int feature_mask_; | |
533 | 626 |
534 std::string text_; | 627 std::string text_; |
535 bool closed_; | 628 bool closed_; |
536 | 629 |
630 bool gplus_; | |
537 int current_platform_; | 631 int current_platform_; |
538 }; | 632 }; |
539 | 633 |
540 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { | 634 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { |
541 // Check that prefs are set correctly. | 635 // Check that prefs are set correctly. |
542 PrefService* prefs = profile_.GetPrefs(); | 636 PrefService* prefs = profile_.GetPrefs(); |
543 ASSERT_TRUE(prefs != NULL); | 637 ASSERT_TRUE(prefs != NULL); |
544 | 638 |
545 NotificationPromoTestDelegate delegate(prefs); | 639 NotificationPromoTestDelegate delegate(&profile_); |
546 NotificationPromo notification_promo(prefs, &delegate); | 640 scoped_refptr<NotificationPromo> notification_promo = |
641 NotificationPromo::Create(&profile_, &delegate); | |
547 | 642 |
548 // Make sure prefs are unset. | 643 // Make sure prefs are unset. |
549 delegate.TestPrefs(); | 644 delegate.TestPrefs(); |
550 | 645 |
551 // Set up start and end dates and promo line in a Dictionary as if parsed | 646 // Set up start and end dates and promo line in a Dictionary as if parsed |
552 // from the service. | 647 // from the service. |
553 delegate.Init(¬ification_promo, | 648 delegate.Init(notification_promo, |
554 "{ " | 649 "{ " |
555 " \"topic\": {" | 650 " \"topic\": {" |
556 " \"answers\": [" | 651 " \"answers\": [" |
557 " {" | 652 " {" |
558 " \"name\": \"promo_start\"," | 653 " \"name\": \"promo_start\"," |
559 " \"question\": \"3:2:5:10:15\"," | 654 " \"question\": \"3:2:5:10:15:0\"," |
560 " \"tooltip\": \"Eat more pie!\"," | 655 " \"tooltip\": \"Eat more pie!\"," |
561 " \"inproduct\": \"31/01/10 01:00 GMT\"" | 656 " \"inproduct\": \"31/01/10 01:00 GMT\"" |
562 " }," | 657 " }," |
563 " {" | 658 " {" |
564 " \"name\": \"promo_end\"," | 659 " \"name\": \"promo_end\"," |
565 " \"inproduct\": \"31/01/12 01:00 GMT\"" | 660 " \"inproduct\": \"31/01/14 01:00 GMT\"" |
566 " }" | 661 " }" |
567 " ]" | 662 " ]" |
568 " }" | 663 " }" |
569 "}", | 664 "}", |
570 1264899600, // unix epoch for Jan 31 2010 0100 GMT. | 665 1264899600, // unix epoch for Jan 31 2010 0100 GMT. |
571 1327971600, // unix epoch for Jan 31 2012 0100 GMT. | 666 1391130000, // unix epoch for Jan 31 2012 0100 GMT. |
572 3, 2, 5, 10, 15, | 667 3, 2, 5, 10, 15, 0, |
573 "Eat more pie!", false); | 668 "Eat more pie!", false, false); |
574 | 669 |
575 delegate.InitPromoFromJson(true); | 670 delegate.InitPromoFromJson(true); |
576 | 671 |
577 // Second time should not trigger a notification. | 672 // Second time should not trigger a notification. |
578 delegate.InitPromoFromJson(false); | 673 delegate.InitPromoFromJson(false); |
579 | 674 |
580 delegate.TestInitFromPrefs(); | 675 delegate.TestInitFromPrefs(); |
581 | 676 |
582 // Test various conditions of CanShow. | 677 // Test various conditions of CanShow. |
583 // TestGroup Has the side effect of setting us to a passing group. | 678 // TestGroup Has the side effect of setting us to a passing group. |
584 delegate.TestGroup(); | 679 delegate.TestGroup(); |
585 delegate.TestViews(); | 680 delegate.TestViews(); |
586 delegate.TestBuild(); | 681 delegate.TestBuild(); |
587 delegate.TestClosed(); | 682 delegate.TestClosed(); |
588 delegate.TestText(); | 683 delegate.TestText(); |
589 delegate.TestTime(); | 684 delegate.TestTime(); |
685 delegate.TestFeatureMask(); | |
590 delegate.TestPlatforms(); | 686 delegate.TestPlatforms(); |
687 delegate.TestGPlus(); | |
591 } | 688 } |
592 | 689 |
593 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) { | 690 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) { |
594 // Check that prefs are set correctly. | 691 // Check that prefs are set correctly. |
595 PrefService* prefs = profile_.GetPrefs(); | 692 PrefService* prefs = profile_.GetPrefs(); |
596 ASSERT_TRUE(prefs != NULL); | 693 ASSERT_TRUE(prefs != NULL); |
597 | 694 |
598 NotificationPromoTestDelegate delegate(prefs); | 695 NotificationPromoTestDelegate delegate(&profile_); |
599 NotificationPromo notification_promo(prefs, &delegate); | 696 scoped_refptr<NotificationPromo> notification_promo = |
697 NotificationPromo::Create(&profile_, &delegate); | |
600 | 698 |
601 // Set up start and end dates and promo line in a Dictionary as if parsed | 699 // Set up start and end dates and promo line in a Dictionary as if parsed |
602 // from the service. | 700 // from the service. |
603 delegate.Init(¬ification_promo, | 701 delegate.Init(notification_promo, |
604 "{ " | 702 "{ " |
605 " \"topic\": {" | 703 " \"topic\": {" |
606 " \"answers\": [" | 704 " \"answers\": [" |
607 " {" | 705 " {" |
608 " \"name\": \"promo_start\"," | 706 " \"name\": \"promo_start\"," |
609 " \"question\": \"12:8:10:20:15\"," | 707 " \"question\": \"12:8:10:20:15:0\"," |
610 " \"tooltip\": \"Happy 3rd Birthday!\"," | 708 " \"tooltip\": \"Happy 3rd Birthday!\"," |
611 " \"inproduct\": \"09/15/10 05:00 PDT\"" | 709 " \"inproduct\": \"09/15/10 05:00 PDT\"" |
612 " }," | 710 " }," |
613 " {" | 711 " {" |
614 " \"name\": \"promo_end\"," | 712 " \"name\": \"promo_end\"," |
615 " \"inproduct\": \"09/30/10 05:00 PDT\"" | 713 " \"inproduct\": \"09/30/10 05:00 PDT\"" |
616 " }" | 714 " }" |
617 " ]" | 715 " ]" |
618 " }" | 716 " }" |
619 "}", | 717 "}", |
620 1284552000, // unix epoch for Sep 15 2010 0500 PDT. | 718 1284552000, // unix epoch for Sep 15 2010 0500 PDT. |
621 1285848000, // unix epoch for Sep 30 2010 0500 PDT. | 719 1285848000, // unix epoch for Sep 30 2010 0500 PDT. |
622 12, 8, 10, 20, 15, | 720 12, 8, 10, 20, 15, 0, |
623 "Happy 3rd Birthday!", false); | 721 "Happy 3rd Birthday!", false, false); |
624 | 722 |
625 delegate.InitPromoFromJson(true); | 723 delegate.InitPromoFromJson(true); |
626 | 724 |
627 // Second time should not trigger a notification. | 725 // Second time should not trigger a notification. |
628 delegate.InitPromoFromJson(false); | 726 delegate.InitPromoFromJson(false); |
629 | 727 |
630 delegate.TestInitFromPrefs(); | 728 delegate.TestInitFromPrefs(); |
631 | 729 |
632 // Should fail because out of time bounds. | 730 // Should fail because out of time bounds. |
633 EXPECT_FALSE(notification_promo.CanShow()); | 731 EXPECT_FALSE(notification_promo->CanShow()); |
634 } | 732 } |
635 | 733 |
636 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) { | 734 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) { |
637 const std::string question("0:-100:2048:0:2a"); | 735 const std::string question("0:-100:2048:0:0:0:2a"); |
638 const int question_vec[] = { 0, -100, 2048, 0 }; | 736 const int question_vec[] = { 0, -100, 2048, 0, 0, 0}; |
639 size_t index = 0; | 737 size_t index = 0; |
640 bool err = false; | 738 bool err = false; |
641 | 739 |
642 for (size_t i = 0; i < arraysize(question_vec); ++i) { | 740 for (size_t i = 0; i < arraysize(question_vec); ++i) { |
643 EXPECT_EQ(question_vec[i], | 741 EXPECT_EQ(question_vec[i], |
644 NotificationPromo::GetNextQuestionValue(question, &index, &err)); | 742 NotificationPromo::GetNextQuestionValue(question, &index, &err)); |
645 EXPECT_FALSE(err); | 743 EXPECT_FALSE(err); |
646 } | 744 } |
647 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0); | 745 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0); |
648 EXPECT_TRUE(err); | 746 EXPECT_TRUE(err); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); | 1138 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); |
1041 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); | 1139 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); |
1042 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); | 1140 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); |
1043 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); | 1141 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); |
1044 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); | 1142 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); |
1045 | 1143 |
1046 // invalid | 1144 // invalid |
1047 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); | 1145 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); |
1048 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); | 1146 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); |
1049 } | 1147 } |
OLD | NEW |