Chromium Code Reviews| Index: ios/chrome/browser/notification_promo_unittest.cc |
| diff --git a/ios/chrome/browser/notification_promo_unittest.cc b/ios/chrome/browser/notification_promo_unittest.cc |
| index 642836a3d3478d7e1e1bd10159b019e49fc5d491..6040f2a9d08cf3cc3e299315a7358d8a80d29e6e 100644 |
| --- a/ios/chrome/browser/notification_promo_unittest.cc |
| +++ b/ios/chrome/browser/notification_promo_unittest.cc |
| @@ -288,6 +288,40 @@ class NotificationPromoTest : public testing::Test { |
| notification_promo_.WritePrefs(); |
| } |
| + // Tests that if data is saved in the old pref structure, it is successfully |
| + // migrated to the new structure that supports saving multiple promos. |
| + void TestMigrationOfOldPrefs() { |
| + NotificationPromo promo(&local_state_); |
| + promo.InitFromVariations(); |
| + |
| + // Pick values for each variable that is saved into old prefs structure. |
| + double first_view_time = 2.0; |
| + int views = max_views_ + 1; |
| + bool closed = true; |
| + |
| + // Save data into old prefs structure. |
| + base::DictionaryValue* ntp_promo = new base::DictionaryValue; |
| + ntp_promo->SetInteger("id", promo.promo_id_); |
| + ntp_promo->SetDouble("first_view_time", first_view_time); |
| + ntp_promo->SetInteger("views", views); |
| + ntp_promo->SetBoolean("closed", true); |
| + |
| + base::ListValue* promo_list = new base::ListValue; |
| + promo_list->Set(0, ntp_promo); |
| + |
| + base::DictionaryValue promo_dict; |
| + promo_dict.Set("mobile_ntp_whats_new_promo", promo_list); |
| + local_state_.Set("ios.ntppromo", promo_dict); |
| + |
| + // 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.
|
| + // saved in the old structure. |
| + promo.InitFromPrefs(promo_type_); |
| + EXPECT_EQ(first_view_time, promo.first_view_time_); |
| + EXPECT_EQ(views, promo.views_); |
| + EXPECT_EQ(closed, promo.closed_); |
| + EXPECT_FALSE(promo.CanShow()); |
| + } |
| + |
| const NotificationPromo& promo() const { return notification_promo_; } |
| protected: |
| @@ -375,4 +409,26 @@ TEST_F(NotificationPromoTest, NotificationPromoFinchTest) { |
| TestFirstViewTimeRecorded(); |
| } |
| +TEST_F(NotificationPromoTest, NotificationPromoPrefMigrationTest) { |
| + Init( |
| + "{" |
| + " \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
| + " \"end\":\"$1\"," |
| + " \"promo_text\":\"What do you think of Chrome?\"," |
| + " \"payload\":" |
| + " {" |
| + " \"days_active\":7," |
| + " \"install_age_days\":21" |
| + " }," |
| + " \"max_views\":30," |
| + " \"max_seconds\":30," |
| + " \"promo_id\":0" |
| + "}", |
| + "What do you think of Chrome?", |
| + 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
| + 0, 30, 30); |
| + InitPromoFromVariations(); |
| + TestMigrationOfOldPrefs(); |
| +} |
| + |
| } // namespace ios |