OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 temp_promo.InitFromVariations(); | 281 temp_promo.InitFromVariations(); |
282 temp_promo.InitFromPrefs(promo_type_); | 282 temp_promo.InitFromPrefs(promo_type_); |
283 | 283 |
284 EXPECT_EQ(first_viewed, temp_promo.first_view_time_); | 284 EXPECT_EQ(first_viewed, temp_promo.first_view_time_); |
285 | 285 |
286 notification_promo_.views_ = 0; | 286 notification_promo_.views_ = 0; |
287 notification_promo_.first_view_time_ = 0; | 287 notification_promo_.first_view_time_ = 0; |
288 notification_promo_.WritePrefs(); | 288 notification_promo_.WritePrefs(); |
289 } | 289 } |
290 | 290 |
291 // Tests that if data is saved in the old pref structure, it is successfully | |
292 // migrated to the new structure that supports saving multiple promos. | |
293 void TestMigrationOfOldPrefs() { | |
294 NotificationPromo promo(&local_state_); | |
295 promo.InitFromVariations(); | |
296 | |
297 // Pick values for each variable that is saved into old prefs structure. | |
298 double first_view_time = 2.0; | |
299 int views = max_views_ + 1; | |
300 bool closed = true; | |
301 | |
302 // Save data into old prefs structure. | |
303 base::DictionaryValue* ntp_promo = new base::DictionaryValue; | |
304 ntp_promo->SetInteger("id", promo.promo_id_); | |
305 ntp_promo->SetDouble("first_view_time", first_view_time); | |
306 ntp_promo->SetInteger("views", views); | |
307 ntp_promo->SetBoolean("closed", true); | |
308 | |
309 base::ListValue* promo_list = new base::ListValue; | |
310 promo_list->Set(0, ntp_promo); | |
311 | |
312 base::DictionaryValue promo_dict; | |
313 promo_dict.Set("mobile_ntp_whats_new_promo", promo_list); | |
314 local_state_.Set("ios.ntppromo", promo_dict); | |
315 | |
316 // Initialize promo and verify that its instance variables match the data | |
rohitrao (ping after 24h)
2016/06/27 17:04:19
Also verify that the old prefs are gone?
gchatz
2016/06/27 23:12:22
Added check for this.
| |
317 // saved in the old structure. | |
318 promo.InitFromPrefs(promo_type_); | |
319 EXPECT_EQ(first_view_time, promo.first_view_time_); | |
320 EXPECT_EQ(views, promo.views_); | |
321 EXPECT_EQ(closed, promo.closed_); | |
322 EXPECT_FALSE(promo.CanShow()); | |
323 } | |
324 | |
291 const NotificationPromo& promo() const { return notification_promo_; } | 325 const NotificationPromo& promo() const { return notification_promo_; } |
292 | 326 |
293 protected: | 327 protected: |
294 TestingPrefServiceSimple local_state_; | 328 TestingPrefServiceSimple local_state_; |
295 | 329 |
296 private: | 330 private: |
297 NotificationPromo notification_promo_; | 331 NotificationPromo notification_promo_; |
298 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 332 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
299 bool received_notification_; | 333 bool received_notification_; |
300 std::unique_ptr<base::DictionaryValue> test_json_; | 334 std::unique_ptr<base::DictionaryValue> test_json_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 // Test various conditions of CanShow. | 402 // Test various conditions of CanShow. |
369 TestViews(); | 403 TestViews(); |
370 TestClosed(); | 404 TestClosed(); |
371 TestPromoText(); | 405 TestPromoText(); |
372 TestTime(); | 406 TestTime(); |
373 TestMaxTime(); | 407 TestMaxTime(); |
374 | 408 |
375 TestFirstViewTimeRecorded(); | 409 TestFirstViewTimeRecorded(); |
376 } | 410 } |
377 | 411 |
412 TEST_F(NotificationPromoTest, NotificationPromoPrefMigrationTest) { | |
413 Init( | |
414 "{" | |
415 " \"start\":\"3 Aug 1999 9:26:06 GMT\"," | |
416 " \"end\":\"$1\"," | |
417 " \"promo_text\":\"What do you think of Chrome?\"," | |
418 " \"payload\":" | |
419 " {" | |
420 " \"days_active\":7," | |
421 " \"install_age_days\":21" | |
422 " }," | |
423 " \"max_views\":30," | |
424 " \"max_seconds\":30," | |
425 " \"promo_id\":0" | |
426 "}", | |
427 "What do you think of Chrome?", | |
428 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | |
429 0, 30, 30); | |
430 InitPromoFromVariations(); | |
431 TestMigrationOfOldPrefs(); | |
432 } | |
433 | |
378 } // namespace ios | 434 } // namespace ios |
OLD | NEW |