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

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

Issue 10836099: Support for promo_type. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review feedback Created 8 years, 4 months 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') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 int num_groups, int initial_segment, int increment, 70 int num_groups, int initial_segment, int increment,
71 int time_slice, int max_group, int max_views, 71 int time_slice, int max_group, int max_views,
72 bool gplus_required) { 72 bool gplus_required) {
73 Value* value(base::JSONReader::Read(json)); 73 Value* value(base::JSONReader::Read(json));
74 ASSERT_TRUE(value); 74 ASSERT_TRUE(value);
75 DictionaryValue* dict = NULL; 75 DictionaryValue* dict = NULL;
76 value->GetAsDictionary(&dict); 76 value->GetAsDictionary(&dict);
77 ASSERT_TRUE(dict); 77 ASSERT_TRUE(dict);
78 test_json_.reset(dict); 78 test_json_.reset(dict);
79 79
80 promo_type_ =
81 #if !defined(OS_ANDROID)
82 NotificationPromo::NTP_NOTIFICATION_PROMO;
83 #else
84 NotificationPromo::MOBILE_NTP_SYNC_PROMO;
85 #endif
86
80 promo_text_ = promo_text; 87 promo_text_ = promo_text;
81 88
82 #if defined(OS_ANDROID) 89 #if defined(OS_ANDROID)
83 promo_text_long_ = promo_text_long; 90 promo_text_long_ = promo_text_long;
84 promo_action_type_ = promo_action_type; 91 promo_action_type_ = promo_action_type;
85 promo_action_args_.push_back(promo_action_arg0); 92 promo_action_args_.push_back(promo_action_arg0);
86 promo_action_args_.push_back(promo_action_arg1); 93 promo_action_args_.push_back(promo_action_arg1);
87 #endif // defined(OS_ANDROID) 94 #endif // defined(OS_ANDROID)
88 95
89 start_ = start; 96 start_ = start;
90 end_ = end; 97 end_ = end;
91 98
92 num_groups_ = num_groups; 99 num_groups_ = num_groups;
93 initial_segment_ = initial_segment; 100 initial_segment_ = initial_segment;
94 increment_ = increment; 101 increment_ = increment;
95 time_slice_ = time_slice; 102 time_slice_ = time_slice;
96 max_group_ = max_group; 103 max_group_ = max_group;
97 104
98 max_views_ = max_views; 105 max_views_ = max_views;
99 106
100 gplus_required_ = gplus_required; 107 gplus_required_ = gplus_required;
101 108
102 closed_ = false; 109 closed_ = false;
103 received_notification_ = false; 110 received_notification_ = false;
104 } 111 }
105 112
106 void InitPromoFromJson(bool should_receive_notification) { 113 void InitPromoFromJson(bool should_receive_notification) {
107 notification_promo_.InitFromJson(*test_json_); 114 notification_promo_.InitFromJson(*test_json_, promo_type_);
108 EXPECT_EQ(should_receive_notification, 115 EXPECT_EQ(should_receive_notification,
109 notification_promo_.new_notification()); 116 notification_promo_.new_notification());
110 117
111 // Test the fields. 118 // Test the fields.
112 TestNotification(); 119 TestNotification();
113 } 120 }
114 121
115 void TestNotification() { 122 void TestNotification() {
116 // Check values. 123 // Check values.
117 EXPECT_EQ(notification_promo_.promo_text_, promo_text_); 124 EXPECT_EQ(notification_promo_.promo_text_, promo_text_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Views should be 0 for now. 156 // Views should be 0 for now.
150 EXPECT_EQ(notification_promo_.views_, 0); 157 EXPECT_EQ(notification_promo_.views_, 0);
151 158
152 EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_); 159 EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_);
153 } 160 }
154 161
155 // Create a new NotificationPromo from prefs and compare to current 162 // Create a new NotificationPromo from prefs and compare to current
156 // notification. 163 // notification.
157 void TestInitFromPrefs() { 164 void TestInitFromPrefs() {
158 NotificationPromo prefs_notification_promo(profile_); 165 NotificationPromo prefs_notification_promo(profile_);
159 prefs_notification_promo.InitFromPrefs(); 166 prefs_notification_promo.InitFromPrefs(promo_type_);
160 167
161 EXPECT_EQ(notification_promo_.prefs_, 168 EXPECT_EQ(notification_promo_.prefs_,
162 prefs_notification_promo.prefs_); 169 prefs_notification_promo.prefs_);
163 EXPECT_EQ(notification_promo_.promo_text_, 170 EXPECT_EQ(notification_promo_.promo_text_,
164 prefs_notification_promo.promo_text_); 171 prefs_notification_promo.promo_text_);
165 #if defined(OS_ANDROID) 172 #if defined(OS_ANDROID)
166 EXPECT_EQ(notification_promo_.promo_text_long_, 173 EXPECT_EQ(notification_promo_.promo_text_long_,
167 prefs_notification_promo.promo_text_long_); 174 prefs_notification_promo.promo_text_long_);
168 EXPECT_EQ(notification_promo_.promo_action_type_, 175 EXPECT_EQ(notification_promo_.promo_action_type_,
169 prefs_notification_promo.promo_action_type_); 176 prefs_notification_promo.promo_action_type_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 notification_promo_.group_ = i; 236 notification_promo_.group_ = i;
230 EXPECT_TRUE(notification_promo_.CanShow()); 237 EXPECT_TRUE(notification_promo_.CanShow());
231 } 238 }
232 notification_promo_.WritePrefs(); 239 notification_promo_.WritePrefs();
233 } 240 }
234 241
235 void TestViews() { 242 void TestViews() {
236 notification_promo_.views_ = notification_promo_.max_views_ - 2; 243 notification_promo_.views_ = notification_promo_.max_views_ - 2;
237 notification_promo_.WritePrefs(); 244 notification_promo_.WritePrefs();
238 245
246 NotificationPromo::HandleViewed(profile_, promo_type_);
239 NotificationPromo new_promo(profile_); 247 NotificationPromo new_promo(profile_);
240 new_promo.HandleViewed(); 248 new_promo.InitFromPrefs(promo_type_);
249 EXPECT_EQ(new_promo.max_views_ - 1, new_promo.views_);
241 EXPECT_TRUE(new_promo.CanShow()); 250 EXPECT_TRUE(new_promo.CanShow());
242 new_promo.HandleViewed(); 251 NotificationPromo::HandleViewed(profile_, promo_type_);
252 new_promo.InitFromPrefs(promo_type_);
253 EXPECT_EQ(new_promo.max_views_, new_promo.views_);
243 EXPECT_FALSE(new_promo.CanShow()); 254 EXPECT_FALSE(new_promo.CanShow());
244 255
245 notification_promo_.InitFromPrefs();
246 EXPECT_FALSE(notification_promo_.CanShow());
247
248 // Test out of range views. 256 // Test out of range views.
249 for (int i = max_views_; i < max_views_ * 2; ++i) { 257 for (int i = max_views_; i < max_views_ * 2; ++i) {
250 notification_promo_.views_ = i; 258 new_promo.views_ = i;
251 EXPECT_FALSE(notification_promo_.CanShow()); 259 EXPECT_FALSE(new_promo.CanShow());
252 } 260 }
253 261
254 // Test in range views. 262 // Test in range views.
255 for (int i = 0; i < max_views_; ++i) { 263 for (int i = 0; i < max_views_; ++i) {
256 notification_promo_.views_ = i; 264 new_promo.views_ = i;
257 EXPECT_TRUE(notification_promo_.CanShow()); 265 EXPECT_TRUE(new_promo.CanShow());
258 } 266 }
259 notification_promo_.WritePrefs(); 267 new_promo.WritePrefs();
260 } 268 }
261 269
262 void TestClosed() { 270 void TestClosed() {
263 NotificationPromo new_promo(profile_); 271 NotificationPromo new_promo(profile_);
264 new_promo.InitFromPrefs(); 272 new_promo.InitFromPrefs(promo_type_);
273 EXPECT_FALSE(new_promo.closed_);
265 EXPECT_TRUE(new_promo.CanShow()); 274 EXPECT_TRUE(new_promo.CanShow());
266 new_promo.HandleClosed(); 275
267 EXPECT_FALSE(new_promo.CanShow()); 276 NotificationPromo::HandleClosed(profile_, promo_type_);
268 new_promo.InitFromPrefs(); 277 new_promo.InitFromPrefs(promo_type_);
278 EXPECT_TRUE(new_promo.closed_);
269 EXPECT_FALSE(new_promo.CanShow()); 279 EXPECT_FALSE(new_promo.CanShow());
270 280
271 notification_promo_.closed_ = true; 281 new_promo.closed_ = false;
272 EXPECT_FALSE(notification_promo_.CanShow()); 282 EXPECT_TRUE(new_promo.CanShow());
273 283 new_promo.WritePrefs();
274 notification_promo_.closed_ = false;
275 EXPECT_TRUE(notification_promo_.CanShow());
276 notification_promo_.WritePrefs();
277 } 284 }
278 285
279 void TestPromoText() { 286 void TestPromoText() {
280 notification_promo_.promo_text_.clear(); 287 notification_promo_.promo_text_.clear();
281 EXPECT_FALSE(notification_promo_.CanShow()); 288 EXPECT_FALSE(notification_promo_.CanShow());
282 289
283 notification_promo_.promo_text_ = promo_text_; 290 notification_promo_.promo_text_ = promo_text_;
284 EXPECT_TRUE(notification_promo_.CanShow()); 291 EXPECT_TRUE(notification_promo_.CanShow());
285 } 292 }
286 293
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_TRUE(notification_promo_.CanShow()); 378 EXPECT_TRUE(notification_promo_.CanShow());
372 } 379 }
373 380
374 private: 381 private:
375 Profile* profile_; 382 Profile* profile_;
376 PrefService* prefs_; 383 PrefService* prefs_;
377 NotificationPromo notification_promo_; 384 NotificationPromo notification_promo_;
378 bool received_notification_; 385 bool received_notification_;
379 scoped_ptr<DictionaryValue> test_json_; 386 scoped_ptr<DictionaryValue> test_json_;
380 387
388 NotificationPromo::PromoType promo_type_;
381 std::string promo_text_; 389 std::string promo_text_;
382 #if defined(OS_ANDROID) 390 #if defined(OS_ANDROID)
383 std::string promo_text_long_; 391 std::string promo_text_long_;
384 std::string promo_action_type_; 392 std::string promo_action_type_;
385 std::vector<std::string> promo_action_args_; 393 std::vector<std::string> promo_action_args_;
386 #endif // defined(OS_ANDROID) 394 #endif // defined(OS_ANDROID)
387 395
388 double start_; 396 double start_;
389 double end_; 397 double end_;
390 398
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 promo_test.TestIncrement(); 526 promo_test.TestIncrement();
519 promo_test.TestGplus(); 527 promo_test.TestGplus();
520 } 528 }
521 529
522 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { 530 TEST_F(PromoResourceServiceTest, PromoServerURLTest) {
523 GURL promo_server_url = NotificationPromo::PromoServerURL(); 531 GURL promo_server_url = NotificationPromo::PromoServerURL();
524 EXPECT_FALSE(promo_server_url.is_empty()); 532 EXPECT_FALSE(promo_server_url.is_empty());
525 EXPECT_TRUE(promo_server_url.SchemeIs("https")); 533 EXPECT_TRUE(promo_server_url.SchemeIs("https"));
526 // TODO(achuith): Test this better. 534 // TODO(achuith): Test this better.
527 } 535 }
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/promo_resource_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698