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

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),
200 received_notification_(false), 201 received_notification_(false),
achuithb 2011/11/27 07:48:26 please initialize should_receive_notification_ her
Cait (Slow) 2011/11/28 19:06:25 Done.
201 build_targeted_(true), 202 build_targeted_(true),
202 start_(0.0), 203 start_(0.0),
203 end_(0.0), 204 end_(0.0),
204 build_(PromoResourceService::NO_BUILD), 205 build_(PromoResourceService::NO_BUILD),
205 time_slice_(0), 206 time_slice_(0),
206 max_group_(0), 207 max_group_(0),
207 max_views_(0), 208 max_views_(0),
208 platform_(NotificationPromo::PLATFORM_NONE), 209 platform_(NotificationPromo::PLATFORM_NONE),
209 text_(), 210 text_(),
210 closed_(false), 211 closed_(false),
211 current_platform_(NotificationPromo::CurrentPlatform()) { 212 current_platform_(NotificationPromo::CurrentPlatform()),
213 gplus_(false),
214 feature_mask_(0) {
212 } 215 }
213 216
214 void Init(NotificationPromo* notification_promo, 217 void Init(NotificationPromo* notification_promo,
215 const std::string& json, 218 const std::string& json,
216 double start, double end, 219 double start, double end,
217 int build, int time_slice, 220 int build, int time_slice,
218 int max_group, int max_views, int platform, 221 int max_group, int max_views, int platform,
219 const std::string& text, bool closed) { 222 int feature_mask, const std::string& text, bool closed,
223 bool gplus) {
220 notification_promo_ = notification_promo; 224 notification_promo_ = notification_promo;
221 225
222 test_json_.reset(static_cast<DictionaryValue*>( 226 test_json_.reset(static_cast<DictionaryValue*>(
223 base::JSONReader::Read(json, false))); 227 base::JSONReader::Read(json, false)));
224 228
225 start_ = start; 229 start_ = start;
226 end_ = end; 230 end_ = end;
227 231
228 build_ = build; 232 build_ = build;
229 time_slice_ = time_slice; 233 time_slice_ = time_slice;
230 max_group_ = max_group; 234 max_group_ = max_group;
231 max_views_ = max_views; 235 max_views_ = max_views;
232 platform_ = platform; 236 platform_ = platform;
233 237
234 text_ = text; 238 text_ = text;
235 closed_ = closed; 239 closed_ = closed;
240 gplus_ = gplus;
241 feature_mask_ = feature_mask;
236 242
237 received_notification_ = false; 243 received_notification_ = false;
238 } 244 }
239 245
240 // NotificationPromo::Delegate implementation. 246 // NotificationPromo::Delegate implementation.
241 virtual void OnNewNotification(double start, double end) { 247 virtual void OnNotificationParsed(double start, double end) {
242 EXPECT_EQ(CalcStart(), start); 248 if (should_receive_notification_) {
243 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), start); 249 EXPECT_EQ(CalcStart(), start);
244 EXPECT_EQ(notification_promo_->end_, end); 250 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), start);
245 received_notification_ = true; 251 EXPECT_EQ(notification_promo_->end_, end);
252 }
253 // If notification info needs to be updated, OnNotificationParsed is
254 // called with start and end times, if no update needed, it is called
255 // with default values (0.0, 0.0).
256 received_notification_ = !(start == 0.0 && end == 0.0);
257
258 // Test if notification received
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 ParseAndCallCookies(const DictionaryValue& json,
achuithb 2011/11/27 07:48:26 You don't need this function at all. You're mainly
Cait (Slow) 2011/11/28 19:06:25 The purpose of this code is to set the promo value
291 const std::string& cookies, bool should_receive_notification,
292 bool should_find_cookie) {
293 should_receive_notification_ = should_receive_notification;
294 received_notification_ = false;
295
296 const char kHeaderProperty[] = "topic";
297 const char kArrayProperty[] = "answers";
298
299 DictionaryValue* dict;
300 if (json.GetDictionary(kHeaderProperty, &dict)) {
301 ListValue* answers;
302 if (dict->GetList(kArrayProperty, &answers)) {
303 for (ListValue::const_iterator it = answers->begin();
304 it != answers->end();
305 ++it) {
306 if ((*it)->IsType(Value::TYPE_DICTIONARY))
307 notification_promo_->Parse(static_cast<DictionaryValue*>(*it));
308 }
309 }
310 }
311
312 bool found_cookie = notification_promo_->CheckForGPlusCookie(cookies);
313 EXPECT_TRUE(found_cookie == should_find_cookie);
314
315 notification_promo_->CheckForNewNotification(found_cookie);
316 EXPECT_TRUE(received_notification_ == should_receive_notification);
317
318 // Test the fields.
319 TestNotification();
320 TestPrefs();
321 }
322
275 void TestNotification() { 323 void TestNotification() {
276 // Check values. 324 // Check values.
277 EXPECT_EQ(notification_promo_->start_, start_); 325 EXPECT_EQ(notification_promo_->start_, start_);
278 EXPECT_EQ(notification_promo_->end_, end_); 326 EXPECT_EQ(notification_promo_->end_, end_);
279 EXPECT_EQ(notification_promo_->build_, build_); 327 EXPECT_EQ(notification_promo_->build_, build_);
280 EXPECT_EQ(notification_promo_->time_slice_, time_slice_); 328 EXPECT_EQ(notification_promo_->time_slice_, time_slice_);
281 EXPECT_EQ(notification_promo_->max_group_, max_group_); 329 EXPECT_EQ(notification_promo_->max_group_, max_group_);
282 EXPECT_EQ(notification_promo_->max_views_, max_views_); 330 EXPECT_EQ(notification_promo_->max_views_, max_views_);
283 EXPECT_EQ(notification_promo_->platform_, platform_); 331 EXPECT_EQ(notification_promo_->platform_, platform_);
284 EXPECT_EQ(notification_promo_->text_, text_); 332 EXPECT_EQ(notification_promo_->text_, text_);
285 EXPECT_EQ(notification_promo_->closed_, closed_); 333 EXPECT_EQ(notification_promo_->closed_, closed_);
334 EXPECT_EQ(notification_promo_->gplus_, gplus_);
335 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_);
286 336
287 // Check group within bounds. 337 // Check group within bounds.
288 EXPECT_GE(notification_promo_->group_, 0); 338 EXPECT_GE(notification_promo_->group_, 0);
289 EXPECT_LT(notification_promo_->group_, 100); 339 EXPECT_LT(notification_promo_->group_, 100);
290 340
291 // Views should be 0 for now. 341 // Views should be 0 for now.
292 EXPECT_EQ(notification_promo_->views_, 0); 342 EXPECT_EQ(notification_promo_->views_, 0);
293 343
294 // Check calculated time. 344 // Check calculated time.
295 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart()); 345 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart());
296 } 346 }
297 347
298 void TestPrefs() { 348 void TestPrefs() {
299 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_); 349 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_);
300 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_); 350 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_);
301 351
302 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_); 352 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_);
303 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_); 353 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_);
304 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_); 354 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_);
305 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_); 355 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_);
306 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_); 356 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_);
307 357
308 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup), 358 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup),
309 notification_promo_ ? notification_promo_->group_: 0); 359 notification_promo_ ? notification_promo_->group_: 0);
310 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0); 360 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0);
311 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_); 361 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_);
312 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_); 362 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_);
363 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_);
364 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_);
313 } 365 }
314 366
315 // Create a new NotificationPromo from prefs and compare to current 367 // Create a new NotificationPromo from prefs and compare to current
316 // notification. 368 // notification.
317 void TestInitFromPrefs() { 369 void TestInitFromPrefs() {
318 NotificationPromo prefs_notification_promo(prefs_, this); 370 scoped_refptr<NotificationPromo> prefs_notification_promo =
319 prefs_notification_promo.InitFromPrefs(); 371 NotificationPromo::Factory(profile_, this);
320 const bool is_equal = *notification_promo_ == prefs_notification_promo; 372 prefs_notification_promo->InitFromPrefs();
373 const bool is_equal = *notification_promo_ == *prefs_notification_promo;
321 EXPECT_TRUE(is_equal); 374 EXPECT_TRUE(is_equal);
322 } 375 }
323 376
324 void TestGroup() { 377 void TestGroup() {
325 // Test out of range groups. 378 // Test out of range groups.
326 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) { 379 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) {
327 notification_promo_->group_ = i; 380 notification_promo_->group_ = i;
328 EXPECT_FALSE(notification_promo_->CanShow()); 381 EXPECT_FALSE(notification_promo_->CanShow());
329 } 382 }
330 383
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 // End time has past. 561 // End time has past.
509 notification_promo_->start_ = now - qhour; 562 notification_promo_->start_ = now - qhour;
510 notification_promo_->end_ = now - qhour; 563 notification_promo_->end_ = now - qhour;
511 EXPECT_FALSE(notification_promo_->CanShow()); 564 EXPECT_FALSE(notification_promo_->CanShow());
512 565
513 notification_promo_->start_ = start_; 566 notification_promo_->start_ = start_;
514 notification_promo_->end_ = end_; 567 notification_promo_->end_ = end_;
515 EXPECT_TRUE(notification_promo_->CanShow()); 568 EXPECT_TRUE(notification_promo_->CanShow());
516 } 569 }
517 570
571 void TestFeatureMask() {
572 // If no feature mask, gplus_ value is ignored.
573 notification_promo_->gplus_ = false;
574 notification_promo_->feature_mask_ = 0;
575 EXPECT_TRUE(notification_promo_->CanShow());
576
577 notification_promo_->gplus_ = true;
578 notification_promo_->feature_mask_ = 0;
579 EXPECT_TRUE(notification_promo_->CanShow());
580
581 // No gplus cookie, feature mask in use.
582 notification_promo_->gplus_ = false;
583 notification_promo_->feature_mask_ = 1;
achuithb 2011/11/27 07:48:26 Please use the value NotificationPromo::FEATURE_GP
Cait (Slow) 2011/11/28 19:06:25 Done.
584 EXPECT_FALSE(notification_promo_->CanShow());
achuithb 2011/11/27 07:48:26 I would EXPECT_TRUE here, based on the inversion o
Cait (Slow) 2011/11/28 19:06:25 We want to show the promo if the user is already l
585
586 // Gplus cookie, feature mask in use.
587 notification_promo_->gplus_ = true;
588 notification_promo_->feature_mask_ = 1;
589 EXPECT_TRUE(notification_promo_->CanShow());
590 }
591
518 private: 592 private:
593 Profile* profile_;
519 PrefService* prefs_; 594 PrefService* prefs_;
520 NotificationPromo* notification_promo_; 595 NotificationPromo* notification_promo_;
521 bool received_notification_; 596 bool received_notification_;
597 bool should_receive_notification_;
522 bool build_targeted_; 598 bool build_targeted_;
523 scoped_ptr<DictionaryValue> test_json_; 599 scoped_ptr<DictionaryValue> test_json_;
524 600
525 double start_; 601 double start_;
526 double end_; 602 double end_;
527 603
528 int build_; 604 int build_;
529 int time_slice_; 605 int time_slice_;
530 int max_group_; 606 int max_group_;
531 int max_views_; 607 int max_views_;
532 int platform_; 608 int platform_;
609 int feature_mask_;
533 610
534 std::string text_; 611 std::string text_;
535 bool closed_; 612 bool closed_;
536 613
614 bool gplus_;
537 int current_platform_; 615 int current_platform_;
538 }; 616 };
539 617
540 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { 618 TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
541 // Check that prefs are set correctly. 619 // Check that prefs are set correctly.
542 PrefService* prefs = profile_.GetPrefs(); 620 PrefService* prefs = profile_.GetPrefs();
543 ASSERT_TRUE(prefs != NULL); 621 ASSERT_TRUE(prefs != NULL);
544 622
545 NotificationPromoTestDelegate delegate(prefs); 623 NotificationPromoTestDelegate delegate(&profile_);
546 NotificationPromo notification_promo(prefs, &delegate); 624 scoped_refptr<NotificationPromo> notification_promo =
625 NotificationPromo::Factory(&profile_, &delegate);
547 626
548 // Make sure prefs are unset. 627 // Make sure prefs are unset.
549 delegate.TestPrefs(); 628 delegate.TestPrefs();
550 629
551 // Set up start and end dates and promo line in a Dictionary as if parsed 630 // Set up start and end dates and promo line in a Dictionary as if parsed
552 // from the service. 631 // from the service.
553 delegate.Init(&notification_promo, 632 delegate.Init(notification_promo,
554 "{ " 633 "{ "
555 " \"topic\": {" 634 " \"topic\": {"
556 " \"answers\": [" 635 " \"answers\": ["
557 " {" 636 " {"
558 " \"name\": \"promo_start\"," 637 " \"name\": \"promo_start\","
559 " \"question\": \"3:2:5:10:15\"," 638 " \"question\": \"3:2:5:10:15:0\","
560 " \"tooltip\": \"Eat more pie!\"," 639 " \"tooltip\": \"Eat more pie!\","
561 " \"inproduct\": \"31/01/10 01:00 GMT\"" 640 " \"inproduct\": \"31/01/10 01:00 GMT\""
562 " }," 641 " },"
563 " {" 642 " {"
564 " \"name\": \"promo_end\"," 643 " \"name\": \"promo_end\","
565 " \"inproduct\": \"31/01/12 01:00 GMT\"" 644 " \"inproduct\": \"31/01/12 01:00 GMT\""
achuithb 2011/11/27 07:48:26 Could you please update this date? This test is go
566 " }" 645 " }"
567 " ]" 646 " ]"
568 " }" 647 " }"
569 "}", 648 "}",
570 1264899600, // unix epoch for Jan 31 2010 0100 GMT. 649 1264899600, // unix epoch for Jan 31 2010 0100 GMT.
571 1327971600, // unix epoch for Jan 31 2012 0100 GMT. 650 1327971600, // unix epoch for Jan 31 2012 0100 GMT.
572 3, 2, 5, 10, 15, 651 3, 2, 5, 10, 15, 0,
573 "Eat more pie!", false); 652 "Eat more pie!", false, false);
574 653
575 delegate.InitPromoFromJson(true); 654 delegate.InitPromoFromJson(true);
576 655
577 // Second time should not trigger a notification. 656 // Second time should not trigger a notification.
578 delegate.InitPromoFromJson(false); 657 delegate.InitPromoFromJson(false);
579 658
580 delegate.TestInitFromPrefs(); 659 delegate.TestInitFromPrefs();
581 660
582 // Test various conditions of CanShow. 661 // Test various conditions of CanShow.
583 // TestGroup Has the side effect of setting us to a passing group. 662 // TestGroup Has the side effect of setting us to a passing group.
584 delegate.TestGroup(); 663 delegate.TestGroup();
585 delegate.TestViews(); 664 delegate.TestViews();
586 delegate.TestBuild(); 665 delegate.TestBuild();
587 delegate.TestClosed(); 666 delegate.TestClosed();
588 delegate.TestText(); 667 delegate.TestText();
589 delegate.TestTime(); 668 delegate.TestTime();
669 delegate.TestFeatureMask();
590 delegate.TestPlatforms(); 670 delegate.TestPlatforms();
591 } 671 }
592 672
593 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) { 673 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) {
594 // Check that prefs are set correctly. 674 // Check that prefs are set correctly.
595 PrefService* prefs = profile_.GetPrefs(); 675 PrefService* prefs = profile_.GetPrefs();
596 ASSERT_TRUE(prefs != NULL); 676 ASSERT_TRUE(prefs != NULL);
597 677
598 NotificationPromoTestDelegate delegate(prefs); 678 NotificationPromoTestDelegate delegate(&profile_);
599 NotificationPromo notification_promo(prefs, &delegate); 679 scoped_refptr<NotificationPromo> notification_promo =
680 NotificationPromo::Factory(&profile_, &delegate);
600 681
601 // Set up start and end dates and promo line in a Dictionary as if parsed 682 // Set up start and end dates and promo line in a Dictionary as if parsed
602 // from the service. 683 // from the service.
603 delegate.Init(&notification_promo, 684 delegate.Init(notification_promo,
604 "{ " 685 "{ "
605 " \"topic\": {" 686 " \"topic\": {"
606 " \"answers\": [" 687 " \"answers\": ["
607 " {" 688 " {"
608 " \"name\": \"promo_start\"," 689 " \"name\": \"promo_start\","
609 " \"question\": \"12:8:10:20:15\"," 690 " \"question\": \"12:8:10:20:15:0\","
610 " \"tooltip\": \"Happy 3rd Birthday!\"," 691 " \"tooltip\": \"Happy 3rd Birthday!\","
611 " \"inproduct\": \"09/15/10 05:00 PDT\"" 692 " \"inproduct\": \"09/15/10 05:00 PDT\""
612 " }," 693 " },"
613 " {" 694 " {"
614 " \"name\": \"promo_end\"," 695 " \"name\": \"promo_end\","
615 " \"inproduct\": \"09/30/10 05:00 PDT\"" 696 " \"inproduct\": \"09/30/10 05:00 PDT\""
616 " }" 697 " }"
617 " ]" 698 " ]"
618 " }" 699 " }"
619 "}", 700 "}",
620 1284552000, // unix epoch for Sep 15 2010 0500 PDT. 701 1284552000, // unix epoch for Sep 15 2010 0500 PDT.
621 1285848000, // unix epoch for Sep 30 2010 0500 PDT. 702 1285848000, // unix epoch for Sep 30 2010 0500 PDT.
622 12, 8, 10, 20, 15, 703 12, 8, 10, 20, 15, 0,
623 "Happy 3rd Birthday!", false); 704 "Happy 3rd Birthday!", false, false);
624 705
625 delegate.InitPromoFromJson(true); 706 delegate.InitPromoFromJson(true);
626 707
627 // Second time should not trigger a notification. 708 // Second time should not trigger a notification.
628 delegate.InitPromoFromJson(false); 709 delegate.InitPromoFromJson(false);
629 710
630 delegate.TestInitFromPrefs(); 711 delegate.TestInitFromPrefs();
631 712
632 // Should fail because out of time bounds. 713 // Should fail because out of time bounds.
633 EXPECT_FALSE(notification_promo.CanShow()); 714 EXPECT_FALSE(notification_promo->CanShow());
634 } 715 }
635 716
717 TEST_F(PromoResourceServiceTest, NotificationPromoCookieTest) {
achuithb 2011/11/27 07:48:26 Please delete this test - it has a lot of copy/pas
718 // Check that prefs are set correctly.
719 PrefService* prefs = profile_.GetPrefs();
720 ASSERT_TRUE(prefs != NULL);
721
722 NotificationPromoTestDelegate delegate(&profile_);
723 scoped_refptr<NotificationPromo> notification_promo =
724 NotificationPromo::Factory(&profile_, &delegate);
725
726 // Make sure prefs are unset.
727 delegate.TestPrefs();
728
729 // Set up start and end dates and promo line in a Dictionary as if parsed
730 // from the service.
731 delegate.Init(notification_promo,
732 "{ "
733 " \"topic\": {"
734 " \"answers\": ["
735 " {"
736 " \"name\": \"promo_start\","
737 " \"question\": \"3:2:5:10:15:1\","
738 " \"tooltip\": \"Eat more pie!\","
739 " \"inproduct\": \"31/01/10 01:00 GMT\""
740 " },"
741 " {"
742 " \"name\": \"promo_end\","
743 " \"inproduct\": \"31/01/12 01:00 GMT\""
744 " }"
745 " ]"
746 " }"
747 "}",
748 1264899600, // unix epoch for Jan 31 2010 0100 GMT.
749 1327971600, // unix epoch for Jan 31 2012 0100 GMT.
750 3, 2, 5, 10, 15, 1,
751 "Eat more pie!", false, true);
752
753 delegate.ParseAndCallCookies(delegate.TestJson(), "SID=123456;", true, true);
754 delegate.ParseAndCallCookies(delegate.TestJson(), "SID=123456;", false, true);
755
756 delegate.TestInitFromPrefs();
757
758 // Test various conditions of CanShow.
759 // TestGroup Has the side effect of setting us to a passing group.
760 delegate.TestGroup();
761 delegate.TestViews();
762 delegate.TestBuild();
763 delegate.TestClosed();
764 delegate.TestText();
765 delegate.TestTime();
766 delegate.TestFeatureMask();
767 delegate.TestPlatforms();
768 }
achuithb 2011/11/27 07:48:26 Delete this test too. It's a bit difficult to main
769 TEST_F(PromoResourceServiceTest, NotificationPromoCookieTestFail) {
770 // Check that prefs are set correctly.
771 PrefService* prefs = profile_.GetPrefs();
772 ASSERT_TRUE(prefs != NULL);
773
774 NotificationPromoTestDelegate delegate(&profile_);
775 scoped_refptr<NotificationPromo> notification_promo =
776 NotificationPromo::Factory(&profile_, &delegate);
777
778 // Make sure prefs are unset.
779 delegate.TestPrefs();
780
781 // Set up start and end dates and promo line in a Dictionary as if parsed
782 // from the service.
783 delegate.Init(notification_promo,
784 "{ "
785 " \"topic\": {"
786 " \"answers\": ["
787 " {"
788 " \"name\": \"promo_start\","
789 " \"question\": \"3:2:5:10:15:1\","
790 " \"tooltip\": \"Eat more pie!\","
791 " \"inproduct\": \"31/01/10 01:00 GMT\""
792 " },"
793 " {"
794 " \"name\": \"promo_end\","
795 " \"inproduct\": \"31/01/12 01:00 GMT\""
796 " }"
797 " ]"
798 " }"
799 "}",
800 1264899600, // unix epoch for Jan 31 2010 0100 GMT.
801 1327971600, // unix epoch for Jan 31 2012 0100 GMT.
802 3, 2, 5, 10, 15, 1,
803 "Eat more pie!", false, false);
804
805 delegate.ParseAndCallCookies(delegate.TestJson(), "WRONG=123456;",
806 true, false);
807 // Should not trigger notification on second call.
808 delegate.ParseAndCallCookies(delegate.TestJson(), "WRONG=123456;",
809 false, false);
810
811 delegate.TestInitFromPrefs();
812
813 // Should fail because cookie is required but was not set.
814 EXPECT_FALSE(notification_promo->CanShow());
815 }
636 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) { 816 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) {
637 const std::string question("0:-100:2048:0:2a"); 817 const std::string question("0:-100:2048:0:0:0:2a");
638 const int question_vec[] = { 0, -100, 2048, 0 }; 818 const int question_vec[] = { 0, -100, 2048, 0, 0, 0};
639 size_t index = 0; 819 size_t index = 0;
640 bool err = false; 820 bool err = false;
641 821
642 for (size_t i = 0; i < arraysize(question_vec); ++i) { 822 for (size_t i = 0; i < arraysize(question_vec); ++i) {
643 EXPECT_EQ(question_vec[i], 823 EXPECT_EQ(question_vec[i],
644 NotificationPromo::GetNextQuestionValue(question, &index, &err)); 824 NotificationPromo::GetNextQuestionValue(question, &index, &err));
645 EXPECT_FALSE(err); 825 EXPECT_FALSE(err);
646 } 826 }
647 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0); 827 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0);
648 EXPECT_TRUE(err); 828 EXPECT_TRUE(err);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); 1220 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7));
1041 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); 1221 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15));
1042 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); 1222 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8));
1043 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); 1223 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11));
1044 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); 1224 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12));
1045 1225
1046 // invalid 1226 // invalid
1047 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); 1227 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1));
1048 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); 1228 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX));
1049 } 1229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698