| OLD | NEW |
| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prefs/browser_prefs.h" | 14 #include "chrome/browser/prefs/browser_prefs.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/web_resource/notification_promo.h" | 16 #include "chrome/browser/web_resource/notification_promo.h" |
| 17 #include "chrome/browser/web_resource/promo_resource_service.h" | 17 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_pref_service.h" | 22 #include "chrome/test/base/testing_pref_service.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 25 #include "net/url_request/test_url_fetcher_factory.h" | 26 #include "net/url_request/test_url_fetcher_factory.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 class PromoResourceServiceTest : public testing::Test { | 29 class PromoResourceServiceTest : public testing::Test { |
| 29 public: | 30 public: |
| 30 PromoResourceServiceTest() | 31 PromoResourceServiceTest() |
| 31 : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)), | 32 : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)), |
| 32 web_resource_service_(new PromoResourceService(&profile_)) { | 33 web_resource_service_(new PromoResourceService(local_state_.Get())) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 protected: | 36 protected: |
| 36 TestingProfile profile_; | |
| 37 ScopedTestingLocalState local_state_; | 37 ScopedTestingLocalState local_state_; |
| 38 scoped_refptr<PromoResourceService> web_resource_service_; | 38 scoped_refptr<PromoResourceService> web_resource_service_; |
| 39 MessageLoop loop_; | 39 MessageLoop loop_; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class NotificationPromoTest { | 42 class NotificationPromoTest { |
| 43 public: | 43 public: |
| 44 explicit NotificationPromoTest(Profile* profile) | 44 explicit NotificationPromoTest(PrefServiceSimple* prefs) |
| 45 : profile_(profile), | 45 : prefs_(prefs), |
| 46 prefs_(profile->GetPrefs()), | 46 notification_promo_(prefs), |
| 47 notification_promo_(profile), | |
| 48 received_notification_(false), | 47 received_notification_(false), |
| 49 start_(0.0), | 48 start_(0.0), |
| 50 end_(0.0), | 49 end_(0.0), |
| 51 num_groups_(0), | 50 num_groups_(0), |
| 52 initial_segment_(0), | 51 initial_segment_(0), |
| 53 increment_(1), | 52 increment_(1), |
| 54 time_slice_(0), | 53 time_slice_(0), |
| 55 max_group_(0), | 54 max_group_(0), |
| 56 max_views_(0), | 55 max_views_(0), |
| 57 closed_(false), | 56 closed_(false) { |
| 58 gplus_required_(false) { | |
| 59 } | 57 } |
| 60 | 58 |
| 61 void Init(const std::string& json, | 59 void Init(const std::string& json, |
| 62 const std::string& promo_text, | 60 const std::string& promo_text, |
| 63 double start, double end, | 61 double start, double end, |
| 64 int num_groups, int initial_segment, int increment, | 62 int num_groups, int initial_segment, int increment, |
| 65 int time_slice, int max_group, int max_views, | 63 int time_slice, int max_group, int max_views) { |
| 66 bool gplus_required) { | |
| 67 Value* value(base::JSONReader::Read(json)); | 64 Value* value(base::JSONReader::Read(json)); |
| 68 ASSERT_TRUE(value); | 65 ASSERT_TRUE(value); |
| 69 DictionaryValue* dict = NULL; | 66 DictionaryValue* dict = NULL; |
| 70 value->GetAsDictionary(&dict); | 67 value->GetAsDictionary(&dict); |
| 71 ASSERT_TRUE(dict); | 68 ASSERT_TRUE(dict); |
| 72 test_json_.reset(dict); | 69 test_json_.reset(dict); |
| 73 | 70 |
| 74 promo_type_ = NotificationPromo::NTP_NOTIFICATION_PROMO; | 71 promo_type_ = NotificationPromo::NTP_NOTIFICATION_PROMO; |
| 75 promo_text_ = promo_text; | 72 promo_text_ = promo_text; |
| 76 | 73 |
| 77 start_ = start; | 74 start_ = start; |
| 78 end_ = end; | 75 end_ = end; |
| 79 | 76 |
| 80 num_groups_ = num_groups; | 77 num_groups_ = num_groups; |
| 81 initial_segment_ = initial_segment; | 78 initial_segment_ = initial_segment; |
| 82 increment_ = increment; | 79 increment_ = increment; |
| 83 time_slice_ = time_slice; | 80 time_slice_ = time_slice; |
| 84 max_group_ = max_group; | 81 max_group_ = max_group; |
| 85 | 82 |
| 86 max_views_ = max_views; | 83 max_views_ = max_views; |
| 87 | 84 |
| 88 gplus_required_ = gplus_required; | |
| 89 | |
| 90 closed_ = false; | 85 closed_ = false; |
| 91 received_notification_ = false; | 86 received_notification_ = false; |
| 92 } | 87 } |
| 93 | 88 |
| 94 void InitPromoFromJson(bool should_receive_notification) { | 89 void InitPromoFromJson(bool should_receive_notification) { |
| 95 notification_promo_.InitFromJson(*test_json_, promo_type_); | 90 notification_promo_.InitFromJson(*test_json_, promo_type_); |
| 96 EXPECT_EQ(should_receive_notification, | 91 EXPECT_EQ(should_receive_notification, |
| 97 notification_promo_.new_notification()); | 92 notification_promo_.new_notification()); |
| 98 | 93 |
| 99 // Test the fields. | 94 // Test the fields. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 115 | 110 |
| 116 EXPECT_EQ(notification_promo_.max_views_, max_views_); | 111 EXPECT_EQ(notification_promo_.max_views_, max_views_); |
| 117 EXPECT_EQ(notification_promo_.closed_, closed_); | 112 EXPECT_EQ(notification_promo_.closed_, closed_); |
| 118 | 113 |
| 119 // Check group within bounds. | 114 // Check group within bounds. |
| 120 EXPECT_GE(notification_promo_.group_, 0); | 115 EXPECT_GE(notification_promo_.group_, 0); |
| 121 EXPECT_LT(notification_promo_.group_, num_groups_); | 116 EXPECT_LT(notification_promo_.group_, num_groups_); |
| 122 | 117 |
| 123 // Views should be 0 for now. | 118 // Views should be 0 for now. |
| 124 EXPECT_EQ(notification_promo_.views_, 0); | 119 EXPECT_EQ(notification_promo_.views_, 0); |
| 125 | |
| 126 EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_); | |
| 127 } | 120 } |
| 128 | 121 |
| 129 // Create a new NotificationPromo from prefs and compare to current | 122 // Create a new NotificationPromo from prefs and compare to current |
| 130 // notification. | 123 // notification. |
| 131 void TestInitFromPrefs() { | 124 void TestInitFromPrefs() { |
| 132 NotificationPromo prefs_notification_promo(profile_); | 125 NotificationPromo prefs_notification_promo(prefs_); |
| 133 prefs_notification_promo.InitFromPrefs(promo_type_); | 126 prefs_notification_promo.InitFromPrefs(promo_type_); |
| 134 | 127 |
| 135 EXPECT_EQ(notification_promo_.prefs_, | 128 EXPECT_EQ(notification_promo_.prefs_, |
| 136 prefs_notification_promo.prefs_); | 129 prefs_notification_promo.prefs_); |
| 137 EXPECT_EQ(notification_promo_.promo_text_, | 130 EXPECT_EQ(notification_promo_.promo_text_, |
| 138 prefs_notification_promo.promo_text_); | 131 prefs_notification_promo.promo_text_); |
| 139 EXPECT_EQ(notification_promo_.start_, | 132 EXPECT_EQ(notification_promo_.start_, |
| 140 prefs_notification_promo.start_); | 133 prefs_notification_promo.start_); |
| 141 EXPECT_EQ(notification_promo_.end_, | 134 EXPECT_EQ(notification_promo_.end_, |
| 142 prefs_notification_promo.end_); | 135 prefs_notification_promo.end_); |
| 143 EXPECT_EQ(notification_promo_.num_groups_, | 136 EXPECT_EQ(notification_promo_.num_groups_, |
| 144 prefs_notification_promo.num_groups_); | 137 prefs_notification_promo.num_groups_); |
| 145 EXPECT_EQ(notification_promo_.initial_segment_, | 138 EXPECT_EQ(notification_promo_.initial_segment_, |
| 146 prefs_notification_promo.initial_segment_); | 139 prefs_notification_promo.initial_segment_); |
| 147 EXPECT_EQ(notification_promo_.increment_, | 140 EXPECT_EQ(notification_promo_.increment_, |
| 148 prefs_notification_promo.increment_); | 141 prefs_notification_promo.increment_); |
| 149 EXPECT_EQ(notification_promo_.time_slice_, | 142 EXPECT_EQ(notification_promo_.time_slice_, |
| 150 prefs_notification_promo.time_slice_); | 143 prefs_notification_promo.time_slice_); |
| 151 EXPECT_EQ(notification_promo_.max_group_, | 144 EXPECT_EQ(notification_promo_.max_group_, |
| 152 prefs_notification_promo.max_group_); | 145 prefs_notification_promo.max_group_); |
| 153 EXPECT_EQ(notification_promo_.max_views_, | 146 EXPECT_EQ(notification_promo_.max_views_, |
| 154 prefs_notification_promo.max_views_); | 147 prefs_notification_promo.max_views_); |
| 155 EXPECT_EQ(notification_promo_.group_, | 148 EXPECT_EQ(notification_promo_.group_, |
| 156 prefs_notification_promo.group_); | 149 prefs_notification_promo.group_); |
| 157 EXPECT_EQ(notification_promo_.views_, | 150 EXPECT_EQ(notification_promo_.views_, |
| 158 prefs_notification_promo.views_); | 151 prefs_notification_promo.views_); |
| 159 EXPECT_EQ(notification_promo_.closed_, | 152 EXPECT_EQ(notification_promo_.closed_, |
| 160 prefs_notification_promo.closed_); | 153 prefs_notification_promo.closed_); |
| 161 EXPECT_EQ(notification_promo_.gplus_required_, | |
| 162 prefs_notification_promo.gplus_required_); | |
| 163 } | 154 } |
| 164 | 155 |
| 165 void TestGroup() { | 156 void TestGroup() { |
| 166 // Test out of range groups. | 157 // Test out of range groups. |
| 167 const int incr = num_groups_ / 20; | 158 const int incr = num_groups_ / 20; |
| 168 for (int i = max_group_; i < num_groups_; i += incr) { | 159 for (int i = max_group_; i < num_groups_; i += incr) { |
| 169 notification_promo_.group_ = i; | 160 notification_promo_.group_ = i; |
| 170 EXPECT_FALSE(notification_promo_.CanShow()); | 161 EXPECT_FALSE(notification_promo_.CanShow()); |
| 171 } | 162 } |
| 172 | 163 |
| 173 // Test in-range groups. | 164 // Test in-range groups. |
| 174 for (int i = 0; i < max_group_; i += incr) { | 165 for (int i = 0; i < max_group_; i += incr) { |
| 175 notification_promo_.group_ = i; | 166 notification_promo_.group_ = i; |
| 176 EXPECT_TRUE(notification_promo_.CanShow()); | 167 EXPECT_TRUE(notification_promo_.CanShow()); |
| 177 } | 168 } |
| 178 | 169 |
| 179 // When max_group_ is 0, all groups pass. | 170 // When max_group_ is 0, all groups pass. |
| 180 notification_promo_.max_group_ = 0; | 171 notification_promo_.max_group_ = 0; |
| 181 for (int i = 0; i < num_groups_; i += incr) { | 172 for (int i = 0; i < num_groups_; i += incr) { |
| 182 notification_promo_.group_ = i; | 173 notification_promo_.group_ = i; |
| 183 EXPECT_TRUE(notification_promo_.CanShow()); | 174 EXPECT_TRUE(notification_promo_.CanShow()); |
| 184 } | 175 } |
| 185 notification_promo_.WritePrefs(); | 176 notification_promo_.WritePrefs(); |
| 186 } | 177 } |
| 187 | 178 |
| 188 void TestViews() { | 179 void TestViews() { |
| 189 notification_promo_.views_ = notification_promo_.max_views_ - 2; | 180 notification_promo_.views_ = notification_promo_.max_views_ - 2; |
| 190 notification_promo_.WritePrefs(); | 181 notification_promo_.WritePrefs(); |
| 191 | 182 |
| 192 NotificationPromo::HandleViewed(profile_, promo_type_); | 183 NotificationPromo::HandleViewed(prefs_, promo_type_); |
| 193 NotificationPromo new_promo(profile_); | 184 NotificationPromo new_promo(prefs_); |
| 194 new_promo.InitFromPrefs(promo_type_); | 185 new_promo.InitFromPrefs(promo_type_); |
| 195 EXPECT_EQ(new_promo.max_views_ - 1, new_promo.views_); | 186 EXPECT_EQ(new_promo.max_views_ - 1, new_promo.views_); |
| 196 EXPECT_TRUE(new_promo.CanShow()); | 187 EXPECT_TRUE(new_promo.CanShow()); |
| 197 NotificationPromo::HandleViewed(profile_, promo_type_); | 188 NotificationPromo::HandleViewed(prefs_, promo_type_); |
| 198 new_promo.InitFromPrefs(promo_type_); | 189 new_promo.InitFromPrefs(promo_type_); |
| 199 EXPECT_EQ(new_promo.max_views_, new_promo.views_); | 190 EXPECT_EQ(new_promo.max_views_, new_promo.views_); |
| 200 EXPECT_FALSE(new_promo.CanShow()); | 191 EXPECT_FALSE(new_promo.CanShow()); |
| 201 | 192 |
| 202 // Test out of range views. | 193 // Test out of range views. |
| 203 for (int i = max_views_; i < max_views_ * 2; ++i) { | 194 for (int i = max_views_; i < max_views_ * 2; ++i) { |
| 204 new_promo.views_ = i; | 195 new_promo.views_ = i; |
| 205 EXPECT_FALSE(new_promo.CanShow()); | 196 EXPECT_FALSE(new_promo.CanShow()); |
| 206 } | 197 } |
| 207 | 198 |
| 208 // Test in range views. | 199 // Test in range views. |
| 209 for (int i = 0; i < max_views_; ++i) { | 200 for (int i = 0; i < max_views_; ++i) { |
| 210 new_promo.views_ = i; | 201 new_promo.views_ = i; |
| 211 EXPECT_TRUE(new_promo.CanShow()); | 202 EXPECT_TRUE(new_promo.CanShow()); |
| 212 } | 203 } |
| 213 new_promo.WritePrefs(); | 204 new_promo.WritePrefs(); |
| 214 } | 205 } |
| 215 | 206 |
| 216 void TestClosed() { | 207 void TestClosed() { |
| 217 NotificationPromo new_promo(profile_); | 208 NotificationPromo new_promo(prefs_); |
| 218 new_promo.InitFromPrefs(promo_type_); | 209 new_promo.InitFromPrefs(promo_type_); |
| 219 EXPECT_FALSE(new_promo.closed_); | 210 EXPECT_FALSE(new_promo.closed_); |
| 220 EXPECT_TRUE(new_promo.CanShow()); | 211 EXPECT_TRUE(new_promo.CanShow()); |
| 221 | 212 |
| 222 NotificationPromo::HandleClosed(profile_, promo_type_); | 213 NotificationPromo::HandleClosed(prefs_, promo_type_); |
| 223 new_promo.InitFromPrefs(promo_type_); | 214 new_promo.InitFromPrefs(promo_type_); |
| 224 EXPECT_TRUE(new_promo.closed_); | 215 EXPECT_TRUE(new_promo.closed_); |
| 225 EXPECT_FALSE(new_promo.CanShow()); | 216 EXPECT_FALSE(new_promo.CanShow()); |
| 226 | 217 |
| 227 new_promo.closed_ = false; | 218 new_promo.closed_ = false; |
| 228 EXPECT_TRUE(new_promo.CanShow()); | 219 EXPECT_TRUE(new_promo.CanShow()); |
| 229 new_promo.WritePrefs(); | 220 new_promo.WritePrefs(); |
| 230 } | 221 } |
| 231 | 222 |
| 232 void TestPromoText() { | 223 void TestPromoText() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 notification_promo_.group_ = 16; | 290 notification_promo_.group_ = 16; |
| 300 EXPECT_TRUE(notification_promo_.CanShow()); | 291 EXPECT_TRUE(notification_promo_.CanShow()); |
| 301 notification_promo_.group_ = 17; | 292 notification_promo_.group_ = 17; |
| 302 EXPECT_FALSE(notification_promo_.CanShow()); | 293 EXPECT_FALSE(notification_promo_.CanShow()); |
| 303 | 294 |
| 304 // Test last increment. | 295 // Test last increment. |
| 305 notification_promo_.start_ -= slice; | 296 notification_promo_.start_ -= slice; |
| 306 EXPECT_TRUE(notification_promo_.CanShow()); | 297 EXPECT_TRUE(notification_promo_.CanShow()); |
| 307 } | 298 } |
| 308 | 299 |
| 309 void TestGplus() { | |
| 310 notification_promo_.gplus_required_ = true; | |
| 311 | |
| 312 // Test G+ required. | |
| 313 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, true); | |
| 314 EXPECT_TRUE(notification_promo_.CanShow()); | |
| 315 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, false); | |
| 316 EXPECT_FALSE(notification_promo_.CanShow()); | |
| 317 | |
| 318 notification_promo_.gplus_required_ = false; | |
| 319 | |
| 320 // Test G+ not required. | |
| 321 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, true); | |
| 322 EXPECT_TRUE(notification_promo_.CanShow()); | |
| 323 notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, false); | |
| 324 EXPECT_TRUE(notification_promo_.CanShow()); | |
| 325 } | |
| 326 | |
| 327 private: | 300 private: |
| 328 Profile* profile_; | 301 PrefServiceSimple* prefs_; |
| 329 PrefService* prefs_; | |
| 330 NotificationPromo notification_promo_; | 302 NotificationPromo notification_promo_; |
| 331 bool received_notification_; | 303 bool received_notification_; |
| 332 scoped_ptr<DictionaryValue> test_json_; | 304 scoped_ptr<DictionaryValue> test_json_; |
| 333 | 305 |
| 334 NotificationPromo::PromoType promo_type_; | 306 NotificationPromo::PromoType promo_type_; |
| 335 std::string promo_text_; | 307 std::string promo_text_; |
| 336 | 308 |
| 337 double start_; | 309 double start_; |
| 338 double end_; | 310 double end_; |
| 339 | 311 |
| 340 int num_groups_; | 312 int num_groups_; |
| 341 int initial_segment_; | 313 int initial_segment_; |
| 342 int increment_; | 314 int increment_; |
| 343 int time_slice_; | 315 int time_slice_; |
| 344 int max_group_; | 316 int max_group_; |
| 345 | 317 |
| 346 int max_views_; | 318 int max_views_; |
| 347 | 319 |
| 348 bool closed_; | 320 bool closed_; |
| 349 | |
| 350 bool gplus_required_; | |
| 351 }; | 321 }; |
| 352 | 322 |
| 353 // Test that everything gets parsed correctly, notifications are sent, | 323 // Test that everything gets parsed correctly, notifications are sent, |
| 354 // and CanShow() is handled correctly under variety of conditions. | 324 // and CanShow() is handled correctly under variety of conditions. |
| 355 // Additionally, test that the first string in |strings| is used if | 325 // Additionally, test that the first string in |strings| is used if |
| 356 // no payload.promo_short_message is specified in the JSON response. | 326 // no payload.promo_short_message is specified in the JSON response. |
| 357 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { | 327 TEST_F(PromoResourceServiceTest, NotificationPromoTest) { |
| 358 // Check that prefs are set correctly. | 328 // Check that prefs are set correctly. |
| 359 PrefService* prefs = profile_.GetPrefs(); | 329 NotificationPromoTest promo_test(local_state_.Get()); |
| 360 ASSERT_TRUE(prefs != NULL); | |
| 361 | |
| 362 NotificationPromoTest promo_test(&profile_); | |
| 363 | 330 |
| 364 // Set up start and end dates and promo line in a Dictionary as if parsed | 331 // Set up start and end dates and promo line in a Dictionary as if parsed |
| 365 // from the service. | 332 // from the service. |
| 366 promo_test.Init("{" | 333 promo_test.Init("{" |
| 367 " \"ntp_notification_promo\": [" | 334 " \"ntp_notification_promo\": [" |
| 368 " {" | 335 " {" |
| 369 " \"date\":" | 336 " \"date\":" |
| 370 " [" | 337 " [" |
| 371 " {" | 338 " {" |
| 372 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | 339 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
| 373 " \"end\":\"7 Jan 2013 5:40:75 PST\"" | 340 " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
| 374 " }" | 341 " }" |
| 375 " ]," | 342 " ]," |
| 376 " \"strings\":" | 343 " \"strings\":" |
| 377 " {" | 344 " {" |
| 378 " \"NTP4_HOW_DO_YOU_FEEL_ABOUT_CHROME\":" | 345 " \"NTP4_HOW_DO_YOU_FEEL_ABOUT_CHROME\":" |
| 379 " \"What do you think of Chrome?\"" | 346 " \"What do you think of Chrome?\"" |
| 380 " }," | 347 " }," |
| 381 " \"grouping\":" | 348 " \"grouping\":" |
| 382 " {" | 349 " {" |
| 383 " \"buckets\":1000," | 350 " \"buckets\":1000," |
| 384 " \"segment\":200," | 351 " \"segment\":200," |
| 385 " \"increment\":100," | 352 " \"increment\":100," |
| 386 " \"increment_frequency\":3600," | 353 " \"increment_frequency\":3600," |
| 387 " \"increment_max\":400" | 354 " \"increment_max\":400" |
| 388 " }," | 355 " }," |
| 389 " \"payload\":" | 356 " \"payload\":" |
| 390 " {" | 357 " {" |
| 391 " \"days_active\":7," | 358 " \"days_active\":7," |
| 392 " \"install_age_days\":21," | 359 " \"install_age_days\":21" |
| 393 " \"gplus_required\":false" | |
| 394 " }," | 360 " }," |
| 395 " \"max_views\":30" | 361 " \"max_views\":30" |
| 396 " }" | 362 " }" |
| 397 " ]" | 363 " ]" |
| 398 "}", | 364 "}", |
| 399 "What do you think of Chrome?", | 365 "What do you think of Chrome?", |
| 400 // The starting date is in 1999 to make tests pass | 366 // The starting date is in 1999 to make tests pass |
| 401 // on Android devices with incorrect or unset date/time. | 367 // on Android devices with incorrect or unset date/time. |
| 402 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 368 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
| 403 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. | 369 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
| 404 1000, 200, 100, 3600, 400, 30, false); | 370 1000, 200, 100, 3600, 400, 30); |
| 405 | 371 |
| 406 promo_test.InitPromoFromJson(true); | 372 promo_test.InitPromoFromJson(true); |
| 407 | 373 |
| 408 // Second time should not trigger a notification. | 374 // Second time should not trigger a notification. |
| 409 promo_test.InitPromoFromJson(false); | 375 promo_test.InitPromoFromJson(false); |
| 410 | 376 |
| 411 promo_test.TestInitFromPrefs(); | 377 promo_test.TestInitFromPrefs(); |
| 412 | 378 |
| 413 // Test various conditions of CanShow. | 379 // Test various conditions of CanShow. |
| 414 // TestGroup Has the side effect of setting us to a passing group. | 380 // TestGroup Has the side effect of setting us to a passing group. |
| 415 promo_test.TestGroup(); | 381 promo_test.TestGroup(); |
| 416 promo_test.TestViews(); | 382 promo_test.TestViews(); |
| 417 promo_test.TestClosed(); | 383 promo_test.TestClosed(); |
| 418 promo_test.TestPromoText(); | 384 promo_test.TestPromoText(); |
| 419 promo_test.TestTime(); | 385 promo_test.TestTime(); |
| 420 promo_test.TestIncrement(); | 386 promo_test.TestIncrement(); |
| 421 promo_test.TestGplus(); | |
| 422 } | 387 } |
| 423 | 388 |
| 424 // Test that payload.promo_message_short is used if present. | 389 // Test that payload.promo_message_short is used if present. |
| 425 TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { | 390 TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { |
| 426 // Check that prefs are set correctly. | 391 // Check that prefs are set correctly. |
| 427 PrefService* prefs = profile_.GetPrefs(); | 392 NotificationPromoTest promo_test(local_state_.Get()); |
| 428 ASSERT_TRUE(prefs != NULL); | |
| 429 | |
| 430 NotificationPromoTest promo_test(&profile_); | |
| 431 | 393 |
| 432 // Set up start and end dates and promo line in a Dictionary as if parsed | 394 // Set up start and end dates and promo line in a Dictionary as if parsed |
| 433 // from the service. | 395 // from the service. |
| 434 promo_test.Init("{" | 396 promo_test.Init("{" |
| 435 " \"ntp_notification_promo\": [" | 397 " \"ntp_notification_promo\": [" |
| 436 " {" | 398 " {" |
| 437 " \"date\":" | 399 " \"date\":" |
| 438 " [" | 400 " [" |
| 439 " {" | 401 " {" |
| 440 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | 402 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
| 441 " \"end\":\"7 Jan 2013 5:40:75 PST\"" | 403 " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
| 442 " }" | 404 " }" |
| 443 " ]," | 405 " ]," |
| 444 " \"grouping\":" | 406 " \"grouping\":" |
| 445 " {" | 407 " {" |
| 446 " \"buckets\":1000," | 408 " \"buckets\":1000," |
| 447 " \"segment\":200," | 409 " \"segment\":200," |
| 448 " \"increment\":100," | 410 " \"increment\":100," |
| 449 " \"increment_frequency\":3600," | 411 " \"increment_frequency\":3600," |
| 450 " \"increment_max\":400" | 412 " \"increment_max\":400" |
| 451 " }," | 413 " }," |
| 452 " \"payload\":" | 414 " \"payload\":" |
| 453 " {" | 415 " {" |
| 454 " \"promo_message_short\":" | 416 " \"promo_message_short\":" |
| 455 " \"What do you think of Chrome?\"," | 417 " \"What do you think of Chrome?\"," |
| 456 " \"days_active\":7," | 418 " \"days_active\":7," |
| 457 " \"install_age_days\":21," | 419 " \"install_age_days\":21" |
| 458 " \"gplus_required\":false" | |
| 459 " }," | 420 " }," |
| 460 " \"max_views\":30" | 421 " \"max_views\":30" |
| 461 " }" | 422 " }" |
| 462 " ]" | 423 " ]" |
| 463 "}", | 424 "}", |
| 464 "What do you think of Chrome?", | 425 "What do you think of Chrome?", |
| 465 // The starting date is in 1999 to make tests pass | 426 // The starting date is in 1999 to make tests pass |
| 466 // on Android devices with incorrect or unset date/time. | 427 // on Android devices with incorrect or unset date/time. |
| 467 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 428 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
| 468 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. | 429 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
| 469 1000, 200, 100, 3600, 400, 30, false); | 430 1000, 200, 100, 3600, 400, 30); |
| 470 | 431 |
| 471 promo_test.InitPromoFromJson(true); | 432 promo_test.InitPromoFromJson(true); |
| 472 // Second time should not trigger a notification. | 433 // Second time should not trigger a notification. |
| 473 promo_test.InitPromoFromJson(false); | 434 promo_test.InitPromoFromJson(false); |
| 474 promo_test.TestInitFromPrefs(); | 435 promo_test.TestInitFromPrefs(); |
| 475 } | 436 } |
| 476 | 437 |
| 477 // Test that strings.|payload.promo_message_short| is used if present. | 438 // Test that strings.|payload.promo_message_short| is used if present. |
| 478 TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { | 439 TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { |
| 479 // Check that prefs are set correctly. | 440 // Check that prefs are set correctly. |
| 480 PrefService* prefs = profile_.GetPrefs(); | 441 NotificationPromoTest promo_test(local_state_.Get()); |
| 481 ASSERT_TRUE(prefs != NULL); | |
| 482 | |
| 483 NotificationPromoTest promo_test(&profile_); | |
| 484 | 442 |
| 485 // Set up start and end dates and promo line in a Dictionary as if parsed | 443 // Set up start and end dates and promo line in a Dictionary as if parsed |
| 486 // from the service. | 444 // from the service. |
| 487 promo_test.Init("{" | 445 promo_test.Init("{" |
| 488 " \"ntp_notification_promo\": [" | 446 " \"ntp_notification_promo\": [" |
| 489 " {" | 447 " {" |
| 490 " \"date\":" | 448 " \"date\":" |
| 491 " [" | 449 " [" |
| 492 " {" | 450 " {" |
| 493 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | 451 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
| (...skipping 12 matching lines...) Expand all Loading... |
| 506 " {" | 464 " {" |
| 507 " \"bogus\":\"string\"," | 465 " \"bogus\":\"string\"," |
| 508 " \"GOOD_STRING\":" | 466 " \"GOOD_STRING\":" |
| 509 " \"What do you think of Chrome?\"" | 467 " \"What do you think of Chrome?\"" |
| 510 " }," | 468 " }," |
| 511 " \"payload\":" | 469 " \"payload\":" |
| 512 " {" | 470 " {" |
| 513 " \"promo_message_short\":" | 471 " \"promo_message_short\":" |
| 514 " \"GOOD_STRING\"," | 472 " \"GOOD_STRING\"," |
| 515 " \"days_active\":7," | 473 " \"days_active\":7," |
| 516 " \"install_age_days\":21," | 474 " \"install_age_days\":21" |
| 517 " \"gplus_required\":false" | |
| 518 " }," | 475 " }," |
| 519 " \"max_views\":30" | 476 " \"max_views\":30" |
| 520 " }" | 477 " }" |
| 521 " ]" | 478 " ]" |
| 522 "}", | 479 "}", |
| 523 "What do you think of Chrome?", | 480 "What do you think of Chrome?", |
| 524 // The starting date is in 1999 to make tests pass | 481 // The starting date is in 1999 to make tests pass |
| 525 // on Android devices with incorrect or unset date/time. | 482 // on Android devices with incorrect or unset date/time. |
| 526 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 483 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
| 527 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. | 484 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
| 528 1000, 200, 100, 3600, 400, 30, false); | 485 1000, 200, 100, 3600, 400, 30); |
| 529 | 486 |
| 530 promo_test.InitPromoFromJson(true); | 487 promo_test.InitPromoFromJson(true); |
| 531 // Second time should not trigger a notification. | 488 // Second time should not trigger a notification. |
| 532 promo_test.InitPromoFromJson(false); | 489 promo_test.InitPromoFromJson(false); |
| 533 promo_test.TestInitFromPrefs(); | 490 promo_test.TestInitFromPrefs(); |
| 534 } | 491 } |
| 535 | 492 |
| 536 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { | 493 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { |
| 537 GURL promo_server_url = NotificationPromo::PromoServerURL(); | 494 GURL promo_server_url = NotificationPromo::PromoServerURL(); |
| 538 EXPECT_FALSE(promo_server_url.is_empty()); | 495 EXPECT_FALSE(promo_server_url.is_empty()); |
| 539 EXPECT_TRUE(promo_server_url.SchemeIs("https")); | 496 EXPECT_TRUE(promo_server_url.is_valid()); |
| 497 EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme)); |
| 540 // TODO(achuith): Test this better. | 498 // TODO(achuith): Test this better. |
| 541 } | 499 } |
| OLD | NEW |