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

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
« no previous file with comments | « chrome/browser/web_resource/promo_resource_service.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 EXPECT_TRUE(received_notification_ == should_receive_notification_);
246 } 258 }
247 259
248 virtual bool IsBuildAllowed(int builds_targeted) const { 260 virtual bool IsBuildAllowed(int builds_targeted) const {
249 EXPECT_EQ(builds_targeted, build_); 261 EXPECT_EQ(builds_targeted, build_);
250 return build_targeted_; 262 return build_targeted_;
251 } 263 }
252 264
253 virtual int CurrentPlatform() const { 265 virtual int CurrentPlatform() const {
254 return current_platform_; 266 return current_platform_;
255 } 267 }
256 268
257 const base::DictionaryValue& TestJson() const { 269 const base::DictionaryValue& TestJson() const {
258 return *test_json_; 270 return *test_json_;
259 } 271 }
260 272
261 double CalcStart() const { 273 double CalcStart() const {
262 return start_ + notification_promo_->group_ * time_slice_ * 60.0 * 60.0; 274 return start_ + notification_promo_->group_ * time_slice_ * 60.0 * 60.0;
263 } 275 }
264 276
265 void InitPromoFromJson(bool should_receive_notification) { 277 void InitPromoFromJson(bool should_receive_notification) {
278 should_receive_notification_ = should_receive_notification;
266 received_notification_ = false; 279 received_notification_ = false;
267 notification_promo_->InitFromJson(TestJson()); 280 notification_promo_->InitFromJson(TestJson(), false);
268 EXPECT_TRUE(received_notification_ == should_receive_notification); 281 EXPECT_TRUE(received_notification_ == should_receive_notification);
269 282
270 // Test the fields. 283 // Test the fields.
271 TestNotification(); 284 TestNotification();
272 TestPrefs(); 285 TestPrefs();
273 } 286 }
274 287
288 void TestCookie(const std::string& cookies,
289 bool should_receive_notification, bool should_find_cookie) {
290 gplus_ = should_find_cookie;
291 should_receive_notification_ = should_receive_notification;
292 received_notification_ = false;
293
294 bool found_cookie = NotificationPromo::CheckForGPlusCookie(cookies);
295 EXPECT_TRUE(found_cookie == should_find_cookie);
296
297 notification_promo_->CheckForNewNotification(found_cookie);
298 EXPECT_TRUE(received_notification_ == should_receive_notification);
299
300 // Test the fields.
301 EXPECT_EQ(notification_promo_->gplus_, gplus_);
302 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_);
303 // Test the prefs.
304 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_);
305 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_);
306
307 // Set group_ manually to a passing group.
308 notification_promo_->group_ = max_group_ - 1;
309 // Assumes feature_mask = GPLUS_FEATURE, so whether or not the promo is
310 // is shown depends only on the value of gplus_.
311 EXPECT_TRUE(notification_promo_->CanShow() == gplus_);
312 }
313
314 void TestGPlus() {
315 feature_mask_ = NotificationPromo::FEATURE_GPLUS;
316 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS;
317 // Force a notification when gplus_ is found to be false.
318 notification_promo_->prefs_->
319 SetBoolean(prefs::kNTPPromoIsLoggedInToPlus, true);
320
321 TestCookie("WRONG=123456;", true, false);
322 // Should not trigger notification on second call.
323 TestCookie("WRONG=123456;", false, false);
324
325 TestCookie("SID=123456;", true, true);
326 // Should not trigger notification on second call.
327 TestCookie("SID=123456;", false, true);
328
329 // Reset the notification_promo to its original state.
330 feature_mask_ = NotificationPromo::NO_FEATURE;
331 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE;
332 gplus_ = false;
333 notification_promo_->prefs_->
334 SetBoolean(prefs::kNTPPromoIsLoggedInToPlus, false);
335 notification_promo_->gplus_ = false;
336 }
337
275 void TestNotification() { 338 void TestNotification() {
276 // Check values. 339 // Check values.
277 EXPECT_EQ(notification_promo_->start_, start_); 340 EXPECT_EQ(notification_promo_->start_, start_);
278 EXPECT_EQ(notification_promo_->end_, end_); 341 EXPECT_EQ(notification_promo_->end_, end_);
279 EXPECT_EQ(notification_promo_->build_, build_); 342 EXPECT_EQ(notification_promo_->build_, build_);
280 EXPECT_EQ(notification_promo_->time_slice_, time_slice_); 343 EXPECT_EQ(notification_promo_->time_slice_, time_slice_);
281 EXPECT_EQ(notification_promo_->max_group_, max_group_); 344 EXPECT_EQ(notification_promo_->max_group_, max_group_);
282 EXPECT_EQ(notification_promo_->max_views_, max_views_); 345 EXPECT_EQ(notification_promo_->max_views_, max_views_);
283 EXPECT_EQ(notification_promo_->platform_, platform_); 346 EXPECT_EQ(notification_promo_->platform_, platform_);
284 EXPECT_EQ(notification_promo_->text_, text_); 347 EXPECT_EQ(notification_promo_->text_, text_);
285 EXPECT_EQ(notification_promo_->closed_, closed_); 348 EXPECT_EQ(notification_promo_->closed_, closed_);
349 EXPECT_EQ(notification_promo_->gplus_, gplus_);
350 EXPECT_EQ(notification_promo_->feature_mask_, feature_mask_);
286 351
287 // Check group within bounds. 352 // Check group within bounds.
288 EXPECT_GE(notification_promo_->group_, 0); 353 EXPECT_GE(notification_promo_->group_, 0);
289 EXPECT_LT(notification_promo_->group_, 100); 354 EXPECT_LT(notification_promo_->group_, 100);
290 355
291 // Views should be 0 for now. 356 // Views should be 0 for now.
292 EXPECT_EQ(notification_promo_->views_, 0); 357 EXPECT_EQ(notification_promo_->views_, 0);
293 358
294 // Check calculated time. 359 // Check calculated time.
295 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart()); 360 EXPECT_EQ(notification_promo_->StartTimeWithOffset(), CalcStart());
296 } 361 }
297 362
298 void TestPrefs() { 363 void TestPrefs() {
299 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_); 364 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoStart), start_);
300 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_); 365 EXPECT_EQ(prefs_->GetDouble(prefs::kNTPPromoEnd), end_);
301 366
302 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_); 367 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoBuild), build_);
303 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_); 368 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupTimeSlice), time_slice_);
304 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_); 369 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroupMax), max_group_);
305 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_); 370 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViewsMax), max_views_);
306 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_); 371 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoPlatform), platform_);
307 372
308 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup), 373 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoGroup),
309 notification_promo_ ? notification_promo_->group_: 0); 374 notification_promo_ ? notification_promo_->group_: 0);
310 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0); 375 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoViews), 0);
311 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_); 376 EXPECT_EQ(prefs_->GetString(prefs::kNTPPromoLine), text_);
312 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_); 377 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoClosed), closed_);
378 EXPECT_EQ(prefs_->GetBoolean(prefs::kNTPPromoIsLoggedInToPlus), gplus_);
379 EXPECT_EQ(prefs_->GetInteger(prefs::kNTPPromoFeatureMask), feature_mask_);
313 } 380 }
314 381
315 // Create a new NotificationPromo from prefs and compare to current 382 // Create a new NotificationPromo from prefs and compare to current
316 // notification. 383 // notification.
317 void TestInitFromPrefs() { 384 void TestInitFromPrefs() {
318 NotificationPromo prefs_notification_promo(prefs_, this); 385 scoped_refptr<NotificationPromo> prefs_notification_promo =
319 prefs_notification_promo.InitFromPrefs(); 386 NotificationPromo::Create(profile_, this);
320 const bool is_equal = *notification_promo_ == prefs_notification_promo; 387 prefs_notification_promo->InitFromPrefs();
388 const bool is_equal = *notification_promo_ == *prefs_notification_promo;
321 EXPECT_TRUE(is_equal); 389 EXPECT_TRUE(is_equal);
322 } 390 }
323 391
324 void TestGroup() { 392 void TestGroup() {
325 // Test out of range groups. 393 // Test out of range groups.
326 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) { 394 for (int i = max_group_; i <= NotificationPromo::kMaxGroupSize; ++i) {
327 notification_promo_->group_ = i; 395 notification_promo_->group_ = i;
328 EXPECT_FALSE(notification_promo_->CanShow()); 396 EXPECT_FALSE(notification_promo_->CanShow());
329 } 397 }
330 398
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 // End time has past. 576 // End time has past.
509 notification_promo_->start_ = now - qhour; 577 notification_promo_->start_ = now - qhour;
510 notification_promo_->end_ = now - qhour; 578 notification_promo_->end_ = now - qhour;
511 EXPECT_FALSE(notification_promo_->CanShow()); 579 EXPECT_FALSE(notification_promo_->CanShow());
512 580
513 notification_promo_->start_ = start_; 581 notification_promo_->start_ = start_;
514 notification_promo_->end_ = end_; 582 notification_promo_->end_ = end_;
515 EXPECT_TRUE(notification_promo_->CanShow()); 583 EXPECT_TRUE(notification_promo_->CanShow());
516 } 584 }
517 585
586 void TestFeatureMask() {
587 // No gplus cookie, feature mask in use.
588 notification_promo_->gplus_ = false;
589 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS;
590 EXPECT_FALSE(notification_promo_->CanShow());
591
592 // Gplus cookie, feature mask in use.
593 notification_promo_->gplus_ = true;
594 notification_promo_->feature_mask_ = NotificationPromo::FEATURE_GPLUS;
595 EXPECT_TRUE(notification_promo_->CanShow());
596
597 // If no feature mask, gplus_ value is ignored.
598 notification_promo_->gplus_ = true;
599 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE;
600 EXPECT_TRUE(notification_promo_->CanShow());
601
602 notification_promo_->gplus_ = false;
603 notification_promo_->feature_mask_ = NotificationPromo::NO_FEATURE;
604 EXPECT_TRUE(notification_promo_->CanShow());
605 }
606
518 private: 607 private:
608 Profile* profile_;
519 PrefService* prefs_; 609 PrefService* prefs_;
520 NotificationPromo* notification_promo_; 610 NotificationPromo* notification_promo_;
521 bool received_notification_; 611 bool received_notification_;
612 bool should_receive_notification_;
522 bool build_targeted_; 613 bool build_targeted_;
523 scoped_ptr<DictionaryValue> test_json_; 614 scoped_ptr<DictionaryValue> test_json_;
524 615
525 double start_; 616 double start_;
526 double end_; 617 double end_;
527 618
528 int build_; 619 int build_;
529 int time_slice_; 620 int time_slice_;
530 int max_group_; 621 int max_group_;
531 int max_views_; 622 int max_views_;
532 int platform_; 623 int platform_;
624 int feature_mask_;
533 625
534 std::string text_; 626 std::string text_;
535 bool closed_; 627 bool closed_;
536 628
629 bool gplus_;
537 int current_platform_; 630 int current_platform_;
538 }; 631 };
539 632
540 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { 633 TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
541 // Check that prefs are set correctly. 634 // Check that prefs are set correctly.
542 PrefService* prefs = profile_.GetPrefs(); 635 PrefService* prefs = profile_.GetPrefs();
543 ASSERT_TRUE(prefs != NULL); 636 ASSERT_TRUE(prefs != NULL);
544 637
545 NotificationPromoTestDelegate delegate(prefs); 638 NotificationPromoTestDelegate delegate(&profile_);
546 NotificationPromo notification_promo(prefs, &delegate); 639 scoped_refptr<NotificationPromo> notification_promo =
640 NotificationPromo::Create(&profile_, &delegate);
547 641
548 // Make sure prefs are unset. 642 // Make sure prefs are unset.
549 delegate.TestPrefs(); 643 delegate.TestPrefs();
550 644
551 // Set up start and end dates and promo line in a Dictionary as if parsed 645 // Set up start and end dates and promo line in a Dictionary as if parsed
552 // from the service. 646 // from the service.
553 delegate.Init(&notification_promo, 647 delegate.Init(notification_promo,
554 "{ " 648 "{ "
555 " \"topic\": {" 649 " \"topic\": {"
556 " \"answers\": [" 650 " \"answers\": ["
557 " {" 651 " {"
558 " \"name\": \"promo_start\"," 652 " \"name\": \"promo_start\","
559 " \"question\": \"3:2:5:10:15\"," 653 " \"question\": \"3:2:5:10:15:0\","
560 " \"tooltip\": \"Eat more pie!\"," 654 " \"tooltip\": \"Eat more pie!\","
561 " \"inproduct\": \"31/01/10 01:00 GMT\"" 655 " \"inproduct\": \"31/01/10 01:00 GMT\""
562 " }," 656 " },"
563 " {" 657 " {"
564 " \"name\": \"promo_end\"," 658 " \"name\": \"promo_end\","
565 " \"inproduct\": \"31/01/12 01:00 GMT\"" 659 " \"inproduct\": \"31/01/14 01:00 GMT\""
566 " }" 660 " }"
567 " ]" 661 " ]"
568 " }" 662 " }"
569 "}", 663 "}",
570 1264899600, // unix epoch for Jan 31 2010 0100 GMT. 664 1264899600, // unix epoch for Jan 31 2010 0100 GMT.
571 1327971600, // unix epoch for Jan 31 2012 0100 GMT. 665 1391130000, // unix epoch for Jan 31 2012 0100 GMT.
572 3, 2, 5, 10, 15, 666 3, 2, 5, 10, 15, 0,
573 "Eat more pie!", false); 667 "Eat more pie!", false, false);
574 668
575 delegate.InitPromoFromJson(true); 669 delegate.InitPromoFromJson(true);
576 670
577 // Second time should not trigger a notification. 671 // Second time should not trigger a notification.
578 delegate.InitPromoFromJson(false); 672 delegate.InitPromoFromJson(false);
579 673
580 delegate.TestInitFromPrefs(); 674 delegate.TestInitFromPrefs();
581 675
582 // Test various conditions of CanShow. 676 // Test various conditions of CanShow.
583 // TestGroup Has the side effect of setting us to a passing group. 677 // TestGroup Has the side effect of setting us to a passing group.
584 delegate.TestGroup(); 678 delegate.TestGroup();
585 delegate.TestViews(); 679 delegate.TestViews();
586 delegate.TestBuild(); 680 delegate.TestBuild();
587 delegate.TestClosed(); 681 delegate.TestClosed();
588 delegate.TestText(); 682 delegate.TestText();
589 delegate.TestTime(); 683 delegate.TestTime();
684 delegate.TestFeatureMask();
590 delegate.TestPlatforms(); 685 delegate.TestPlatforms();
686 delegate.TestGPlus();
591 } 687 }
592 688
593 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) { 689 TEST_F(PromoResourceServiceTest, NotificationPromoTestFail) {
594 // Check that prefs are set correctly. 690 // Check that prefs are set correctly.
595 PrefService* prefs = profile_.GetPrefs(); 691 PrefService* prefs = profile_.GetPrefs();
596 ASSERT_TRUE(prefs != NULL); 692 ASSERT_TRUE(prefs != NULL);
597 693
598 NotificationPromoTestDelegate delegate(prefs); 694 NotificationPromoTestDelegate delegate(&profile_);
599 NotificationPromo notification_promo(prefs, &delegate); 695 scoped_refptr<NotificationPromo> notification_promo =
696 NotificationPromo::Create(&profile_, &delegate);
600 697
601 // Set up start and end dates and promo line in a Dictionary as if parsed 698 // Set up start and end dates and promo line in a Dictionary as if parsed
602 // from the service. 699 // from the service.
603 delegate.Init(&notification_promo, 700 delegate.Init(notification_promo,
604 "{ " 701 "{ "
605 " \"topic\": {" 702 " \"topic\": {"
606 " \"answers\": [" 703 " \"answers\": ["
607 " {" 704 " {"
608 " \"name\": \"promo_start\"," 705 " \"name\": \"promo_start\","
609 " \"question\": \"12:8:10:20:15\"," 706 " \"question\": \"12:8:10:20:15:0\","
610 " \"tooltip\": \"Happy 3rd Birthday!\"," 707 " \"tooltip\": \"Happy 3rd Birthday!\","
611 " \"inproduct\": \"09/15/10 05:00 PDT\"" 708 " \"inproduct\": \"09/15/10 05:00 PDT\""
612 " }," 709 " },"
613 " {" 710 " {"
614 " \"name\": \"promo_end\"," 711 " \"name\": \"promo_end\","
615 " \"inproduct\": \"09/30/10 05:00 PDT\"" 712 " \"inproduct\": \"09/30/10 05:00 PDT\""
616 " }" 713 " }"
617 " ]" 714 " ]"
618 " }" 715 " }"
619 "}", 716 "}",
620 1284552000, // unix epoch for Sep 15 2010 0500 PDT. 717 1284552000, // unix epoch for Sep 15 2010 0500 PDT.
621 1285848000, // unix epoch for Sep 30 2010 0500 PDT. 718 1285848000, // unix epoch for Sep 30 2010 0500 PDT.
622 12, 8, 10, 20, 15, 719 12, 8, 10, 20, 15, 0,
623 "Happy 3rd Birthday!", false); 720 "Happy 3rd Birthday!", false, false);
624 721
625 delegate.InitPromoFromJson(true); 722 delegate.InitPromoFromJson(true);
626 723
627 // Second time should not trigger a notification. 724 // Second time should not trigger a notification.
628 delegate.InitPromoFromJson(false); 725 delegate.InitPromoFromJson(false);
629 726
630 delegate.TestInitFromPrefs(); 727 delegate.TestInitFromPrefs();
631 728
632 // Should fail because out of time bounds. 729 // Should fail because out of time bounds.
633 EXPECT_FALSE(notification_promo.CanShow()); 730 EXPECT_FALSE(notification_promo->CanShow());
634 } 731 }
635 732
636 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) { 733 TEST_F(PromoResourceServiceTest, GetNextQuestionValueTest) {
637 const std::string question("0:-100:2048:0:2a"); 734 const std::string question("0:-100:2048:0:0:0:2a");
638 const int question_vec[] = { 0, -100, 2048, 0 }; 735 const int question_vec[] = { 0, -100, 2048, 0, 0, 0};
639 size_t index = 0; 736 size_t index = 0;
640 bool err = false; 737 bool err = false;
641 738
642 for (size_t i = 0; i < arraysize(question_vec); ++i) { 739 for (size_t i = 0; i < arraysize(question_vec); ++i) {
643 EXPECT_EQ(question_vec[i], 740 EXPECT_EQ(question_vec[i],
644 NotificationPromo::GetNextQuestionValue(question, &index, &err)); 741 NotificationPromo::GetNextQuestionValue(question, &index, &err));
645 EXPECT_FALSE(err); 742 EXPECT_FALSE(err);
646 } 743 }
647 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0); 744 EXPECT_EQ(NotificationPromo::GetNextQuestionValue(question, &index, &err), 0);
648 EXPECT_TRUE(err); 745 EXPECT_TRUE(err);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); 1137 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7));
1041 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); 1138 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15));
1042 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); 1139 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8));
1043 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); 1140 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11));
1044 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); 1141 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12));
1045 1142
1046 // invalid 1143 // invalid
1047 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); 1144 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1));
1048 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); 1145 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX));
1049 } 1146 }
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/promo_resource_service.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698