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

Side by Side Diff: chrome/browser/web_resource/promo_resource_service_unittest.cc

Issue 8520009: Only show G+ promo for users logged into G+ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
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
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
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
258 // Test if notification received
achuithb 2011/11/28 21:21:22 Period at the end of the comment (not sure if this
Cait (Slow) 2011/11/29 00:12:27 Done.
259 EXPECT_TRUE(received_notification_ == should_receive_notification_);
246 } 260 }
247 261
248 virtual bool IsBuildAllowed(int builds_targeted) const { 262 virtual bool IsBuildAllowed(int builds_targeted) const {
249 EXPECT_EQ(builds_targeted, build_); 263 EXPECT_EQ(builds_targeted, build_);
250 return build_targeted_; 264 return build_targeted_;
251 } 265 }
252 266
253 virtual int CurrentPlatform() const { 267 virtual int CurrentPlatform() const {
254 return current_platform_; 268 return current_platform_;
255 } 269 }
256 270
257 const base::DictionaryValue& TestJson() const { 271 const base::DictionaryValue& TestJson() const {
258 return *test_json_; 272 return *test_json_;
259 } 273 }
260 274
261 double CalcStart() const { 275 double CalcStart() const {
262 return start_ + notification_promo_->group_ * time_slice_ * 60.0 * 60.0; 276 return start_ + notification_promo_->group_ * time_slice_ * 60.0 * 60.0;
263 } 277 }
264 278
265 void InitPromoFromJson(bool should_receive_notification) { 279 void InitPromoFromJson(bool should_receive_notification) {
280 should_receive_notification_ = should_receive_notification;
266 received_notification_ = false; 281 received_notification_ = false;
267 notification_promo_->InitFromJson(TestJson()); 282 notification_promo_->InitFromJson(TestJson(), false);
268 EXPECT_TRUE(received_notification_ == should_receive_notification); 283 EXPECT_TRUE(received_notification_ == should_receive_notification);
269 284
270 // Test the fields. 285 // Test the fields.
271 TestNotification(); 286 TestNotification();
272 TestPrefs(); 287 TestPrefs();
273 } 288 }
274 289
290 void SetFeatureMaskToGPlus() {
achuithb 2011/11/28 21:21:22 I don't think this function is necessary if you cr
Cait (Slow) 2011/11/29 00:12:27 Done.
291 feature_mask_ = NotificationPromo::FEATURE_GPLUS;
292 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS;
293 }
294
295 void RunCookieTests(const DictionaryValue& json,
achuithb 2011/11/28 21:21:22 Could you rename this to TestCookie or TestGPlusCo
Cait (Slow) 2011/11/29 00:12:27 Done.
296 const std::string& cookies, bool should_receive_notification,
297 bool should_find_cookie) {
298 gplus_ = should_find_cookie;
299 should_receive_notification_ = should_receive_notification;
300 received_notification_ = false;
301
302 bool found_cookie = NotificationPromo::CheckForGPlusCookie(cookies);
303 EXPECT_TRUE(found_cookie == should_find_cookie);
304
305 notification_promo_->CheckForNewNotification(found_cookie);
306 EXPECT_TRUE(received_notification_ == should_receive_notification);
307
308 // Test the fields.
309 EXPECT_EQ(notification_promo_->gplus_, gplus_);
310 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_);
311 // Test the prefs.
312 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_);
313 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_);
achuithb 2011/11/28 21:21:22 Is there a way to also test CanShow() here? should
Cait (Slow) 2011/11/29 00:12:27 Done.
314 }
275 void TestNotification() { 315 void TestNotification() {
276 // Check values. 316 // Check values.
277 EXPECT_EQ(notification_promo_->start_, start_); 317 EXPECT_EQ(notification_promo_->start_, start_);
278 EXPECT_EQ(notification_promo_->end_, end_); 318 EXPECT_EQ(notification_promo_->end_, end_);
279 EXPECT_EQ(notification_promo_->build_, build_); 319 EXPECT_EQ(notification_promo_->build_, build_);
280 EXPECT_EQ(notification_promo_->time_slice_, time_slice_); 320 EXPECT_EQ(notification_promo_->time_slice_, time_slice_);
281 EXPECT_EQ(notification_promo_->max_group_, max_group_); 321 EXPECT_EQ(notification_promo_->max_group_, max_group_);
282 EXPECT_EQ(notification_promo_->max_views_, max_views_); 322 EXPECT_EQ(notification_promo_->max_views_, max_views_);
283 EXPECT_EQ(notification_promo_->platform_, platform_); 323 EXPECT_EQ(notification_promo_->platform_, platform_);
284 EXPECT_EQ(notification_promo_->text_, text_); 324 EXPECT_EQ(notification_promo_->text_, text_);
285 EXPECT_EQ(notification_promo_->closed_, closed_); 325 EXPECT_EQ(notification_promo_->closed_, closed_);
326 EXPECT_EQ(notification_promo_->gplus_, gplus_);
327 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_);
286 328
287 // Check group within bounds. 329 // Check group within bounds.
288 EXPECT_GE(notification_promo_->group_, 0); 330 EXPECT_GE(notification_promo_->group_, 0);
289 EXPECT_LT(notification_promo_->group_, 100); 331 EXPECT_LT(notification_promo_->group_, 100);
290 332
291 // Views should be 0 for now. 333 // Views should be 0 for now.
292 EXPECT_EQ(notification_promo_->views_, 0); 334 EXPECT_EQ(notification_promo_->views_, 0);
293 335
294 // Check calculated time. 336 // Check calculated time.
295 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart()); 337 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart());
296 } 338 }
297 339
298 void TestPrefs() { 340 void TestPrefs() {
299 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_); 341 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_);
300 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_); 342 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_);
301 343
302 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_); 344 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_);
303 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_); 345 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_);
304 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_); 346 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_);
305 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_); 347 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_);
306 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_); 348 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_);
307 349
308 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup), 350 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup),
309 notification_promo_ ? notification_promo_->group_: 0); 351 notification_promo_ ? notification_promo_->group_: 0);
310 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0); 352 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0);
311 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_); 353 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_);
312 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_); 354 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_);
355 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_);
356 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_);
313 } 357 }
314 358
315 // Create a new NotificationPromo from prefs and compare to current 359 // Create a new NotificationPromo from prefs and compare to current
316 // notification. 360 // notification.
317 void TestInitFromPrefs() { 361 void TestInitFromPrefs() {
318 NotificationPromo prefs_notification_promo(prefs_, this); 362 scoped_refptr<NotificationPromo> prefs_notification_promo =
319 prefs_notification_promo.InitFromPrefs(); 363 NotificationPromo::Create(profile_, this);
320 const bool is_equal = *notification_promo_ == prefs_notification_promo; 364 prefs_notification_promo->InitFromPrefs();
365 const bool is_equal = *notification_promo_ == *prefs_notification_promo;
321 EXPECT_TRUE(is_equal); 366 EXPECT_TRUE(is_equal);
322 } 367 }
323 368
324 void TestGroup() { 369 void TestGroup() {
325 // Test out of range groups. 370 // Test out of range groups.
326 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) { 371 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) {
327 notification_promo_->group_ = i; 372 notification_promo_->group_ = i;
328 EXPECT_FALSE(notification_promo_->CanShow()); 373 EXPECT_FALSE(notification_promo_->CanShow());
329 } 374 }
330 375
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 // End time has past. 553 // End time has past.
509 notification_promo_->start_ = now - qhour; 554 notification_promo_->start_ = now - qhour;
510 notification_promo_->end_ = now - qhour; 555 notification_promo_->end_ = now - qhour;
511 EXPECT_FALSE(notification_promo_->CanShow()); 556 EXPECT_FALSE(notification_promo_->CanShow());
512 557
513 notification_promo_->start_ = start_; 558 notification_promo_->start_ = start_;
514 notification_promo_->end_ = end_; 559 notification_promo_->end_ = end_;
515 EXPECT_TRUE(notification_promo_->CanShow()); 560 EXPECT_TRUE(notification_promo_->CanShow());
516 } 561 }
517 562
563 void TestFeatureMask() {
564 // If no feature mask, gplus_ value is ignored.
achuithb 2011/11/28 21:21:22 Could you move this sub-test (no feature mask, gpl
Cait (Slow) 2011/11/29 00:12:27 Done.
565 notification_promo_->gplus_ = false;
566 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE;
567 EXPECT_TRUE(notification_promo_->CanShow());
568
569 notification_promo_->gplus_ = true;
570 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE;
571 EXPECT_TRUE(notification_promo_->CanShow());
572
573 // No gplus cookie, feature mask in use.
574 notification_promo_->gplus_ = false;
575 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS;
576 EXPECT_FALSE(notification_promo_->CanShow());
577
578 // Gplus cookie, feature mask in use.
579 notification_promo_->gplus_ = true;
580 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS;
581 EXPECT_TRUE(notification_promo_->CanShow());
582 }
583
518 private: 584 private:
585 Profile* profile_;
519 PrefService* prefs_; 586 PrefService* prefs_;
520 NotificationPromo* notification_promo_; 587 NotificationPromo* notification_promo_;
521 bool received_notification_; 588 bool received_notification_;
589 bool should_receive_notification_;
522 bool build_targeted_; 590 bool build_targeted_;
523 scoped_ptr<DictionaryValue> test_json_; 591 scoped_ptr<DictionaryValue> test_json_;
524 592
525 double start_; 593 double start_;
526 double end_; 594 double end_;
527 595
528 int build_; 596 int build_;
529 int time_slice_; 597 int time_slice_;
530 int max_group_; 598 int max_group_;
531 int max_views_; 599 int max_views_;
532 int platform_; 600 int platform_;
601 int feature_mask_;
533 602
534 std::string text_; 603 std::string text_;
535 bool closed_; 604 bool closed_;
536 605
606 bool gplus_;
537 int current_platform_; 607 int current_platform_;
538 }; 608 };
539 609
540 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { 610 TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
541 // Check that prefs are set correctly. 611 // Check that prefs are set correctly.
542 PrefService* prefs = profile_.GetPrefs(); 612 PrefService* prefs = profile_.GetPrefs();
543 ASSERT_TRUE(prefs != NULL); 613 ASSERT_TRUE(prefs != NULL);
544 614
545 NotificationPromoTestDelegate delegate(prefs); 615 NotificationPromoTestDelegate delegate(&profile_);
546 NotificationPromo notification_promo(prefs, &delegate); 616 scoped_refptr<NotificationPromo> notification_promo =
617 NotificationPromo::Create(&profile_, &delegate);
547 618
548 // Make sure prefs are unset. 619 // Make sure prefs are unset.
549 delegate.TestPrefs(); 620 delegate.TestPrefs();
550 621
551 // Set up start and end dates and promo line in a Dictionary as if parsed 622 // Set up start and end dates and promo line in a Dictionary as if parsed
552 // from the service. 623 // from the service.
553 delegate.Init(&notification_promo, 624 delegate.Init(notification_promo,
554 "{ " 625 "{ "
555 " \"topic\": {" 626 " \"topic\": {"
556 " \"answers\": [" 627 " \"answers\": ["
557 " {" 628 " {"
558 " \"name\": \"promo_start\"," 629 " \"name\": \"promo_start\","
559 " \"question\": \"3:2:5:10:15\"," 630 " \"question\": \"3:2:5:10:15:0\","
560 " \"tooltip\": \"Eat more pie!\"," 631 " \"tooltip\": \"Eat more pie!\","
561 " \"inproduct\": \"31/01/10 01:00 GMT\"" 632 " \"inproduct\": \"31/01/10 01:00 GMT\""
562 " }," 633 " },"
563 " {" 634 " {"
564 " \"name\": \"promo_end\"," 635 " \"name\": \"promo_end\","
565 " \"inproduct\": \"31/01/12 01:00 GMT\"" 636 " \"inproduct\": \"31/01/14 01:00 GMT\""
566 " }" 637 " }"
567 " ]" 638 " ]"
568 " }" 639 " }"
569 "}", 640 "}",
570 1264899600, // unix epoch for Jan 31 2010 0100 GMT. 641 1264899600, // unix epoch for Jan 31 2010 0100 GMT.
571 1327971600, // unix epoch for Jan 31 2012 0100 GMT. 642 1391130000, // unix epoch for Jan 31 2012 0100 GMT.
572 3, 2, 5, 10, 15, 643 3, 2, 5, 10, 15, 0,
573 "Eat more pie!", false); 644 "Eat more pie!", false, false);
574 645
575 delegate.InitPromoFromJson(true); 646 delegate.InitPromoFromJson(true);
576 647
577 // Second time should not trigger a notification. 648 // Second time should not trigger a notification.
578 delegate.InitPromoFromJson(false); 649 delegate.InitPromoFromJson(false);
579 650
580 delegate.TestInitFromPrefs(); 651 delegate.TestInitFromPrefs();
581 652
582 // Test various conditions of CanShow. 653 // Test various conditions of CanShow.
583 // TestGroup Has the side effect of setting us to a passing group. 654 // TestGroup Has the side effect of setting us to a passing group.
584 delegate.TestGroup(); 655 delegate.TestGroup();
585 delegate.TestViews(); 656 delegate.TestViews();
586 delegate.TestBuild(); 657 delegate.TestBuild();
587 delegate.TestClosed(); 658 delegate.TestClosed();
588 delegate.TestText(); 659 delegate.TestText();
589 delegate.TestTime(); 660 delegate.TestTime();
661 delegate.TestFeatureMask();
590 delegate.TestPlatforms(); 662 delegate.TestPlatforms();
663
664 delegate.SetFeatureMaskToGPlus();
achuithb 2011/11/28 21:21:22 could you move lines 664-675 into a separate funct
Cait (Slow) 2011/11/29 00:12:27 Done.
665
666 delegate.RunCookieTests(delegate.TestJson(), "SID=123456;", true, true);
667 // Should not trigger notification on second call.
668 delegate.RunCookieTests(delegate.TestJson(), "SID=123456;", false, true);
669
670 delegate.RunCookieTests(delegate.TestJson(), "WRONG=123456;", true, false);
671 // Should not trigger notification on second call.
672 delegate.RunCookieTests(delegate.TestJson(), "WRONG=123456;", false, false);
673
674 // Should fail because cookie is required but was not set.
675 EXPECT_FALSE(notification_promo->CanShow());
achuithb 2011/11/28 21:21:22 Could you reverse the order so you test failing co
Cait (Slow) 2011/11/29 00:12:27 Done.
591 } 676 }
592 677
593 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) { 678 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) {
594 // Check that prefs are set correctly. 679 // Check that prefs are set correctly.
595 PrefService* prefs = profile_.GetPrefs(); 680 PrefService* prefs = profile_.GetPrefs();
596 ASSERT_TRUE(prefs != NULL); 681 ASSERT_TRUE(prefs != NULL);
597 682
598 NotificationPromoTestDelegate delegate(prefs); 683 NotificationPromoTestDelegate delegate(&profile_);
599 NotificationPromo notification_promo(prefs, &delegate); 684 scoped_refptr<NotificationPromo> notification_promo =
685 NotificationPromo::Create(&profile_, &delegate);
600 686
601 // Set up start and end dates and promo line in a Dictionary as if parsed 687 // Set up start and end dates and promo line in a Dictionary as if parsed
602 // from the service. 688 // from the service.
603 delegate.Init(&notification_promo, 689 delegate.Init(notification_promo,
604 "{ " 690 "{ "
605 " \"topic\": {" 691 " \"topic\": {"
606 " \"answers\": [" 692 " \"answers\": ["
607 " {" 693 " {"
608 " \"name\": \"promo_start\"," 694 " \"name\": \"promo_start\","
609 " \"question\": \"12:8:10:20:15\"," 695 " \"question\": \"12:8:10:20:15:0\","
610 " \"tooltip\": \"Happy 3rd Birthday!\"," 696 " \"tooltip\": \"Happy 3rd Birthday!\","
611 " \"inproduct\": \"09/15/10 05:00 PDT\"" 697 " \"inproduct\": \"09/15/10 05:00 PDT\""
612 " }," 698 " },"
613 " {" 699 " {"
614 " \"name\": \"promo_end\"," 700 " \"name\": \"promo_end\","
615 " \"inproduct\": \"09/30/10 05:00 PDT\"" 701 " \"inproduct\": \"09/30/10 05:00 PDT\""
616 " }" 702 " }"
617 " ]" 703 " ]"
618 " }" 704 " }"
619 "}", 705 "}",
620 1284552000, // unix epoch for Sep 15 2010 0500 PDT. 706 1284552000, // unix epoch for Sep 15 2010 0500 PDT.
621 1285848000, // unix epoch for Sep 30 2010 0500 PDT. 707 1285848000, // unix epoch for Sep 30 2010 0500 PDT.
622 12, 8, 10, 20, 15, 708 12, 8, 10, 20, 15, 0,
623 "Happy 3rd Birthday!", false); 709 "Happy 3rd Birthday!", false, false);
624 710
625 delegate.InitPromoFromJson(true); 711 delegate.InitPromoFromJson(true);
626 712
627 // Second time should not trigger a notification. 713 // Second time should not trigger a notification.
628 delegate.InitPromoFromJson(false); 714 delegate.InitPromoFromJson(false);
629 715
630 delegate.TestInitFromPrefs(); 716 delegate.TestInitFromPrefs();
631 717
632 // Should fail because out of time bounds. 718 // Should fail because out of time bounds.
633 EXPECT_FALSE(notification_promo.CanShow()); 719 EXPECT_FALSE(notification_promo->CanShow());
634 } 720 }
635 721
636 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) { 722 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) {
637 const std::string question("0:-100:2048:0:2a"); 723 const std::string question("0:-100:2048:0:0:0:2a");
638 const int question_vec[] = { 0, -100, 2048, 0 }; 724 const int question_vec[] = { 0, -100, 2048, 0, 0, 0};
639 size_t index = 0; 725 size_t index = 0;
640 bool err = false; 726 bool err = false;
641 727
642 for (size_t i = 0; i < arraysize(question_vec); ++i) { 728 for (size_t i = 0; i < arraysize(question_vec); ++i) {
643 EXPECT_EQ(question_vec[i], 729 EXPECT_EQ(question_vec[i],
644 NotificationPromo::GetNextQuestionValue(question, &index, &err)); 730 NotificationPromo::GetNextQuestionValue(question, &index, &err));
645 EXPECT_FALSE(err); 731 EXPECT_FALSE(err);
646 } 732 }
647 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0); 733 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0);
648 EXPECT_TRUE(err); 734 EXPECT_TRUE(err);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); 1126 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7));
1041 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); 1127 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15));
1042 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); 1128 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8));
1043 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); 1129 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11));
1044 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); 1130 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12));
1045 1131
1046 // invalid 1132 // invalid
1047 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); 1133 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1));
1048 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); 1134 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX));
1049 } 1135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698