Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/time.h" | 6 #include "base/time.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/apps_promo.h" | 10 #include "chrome/browser/extensions/apps_promo.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 base::JSONReader::Read(json, false))); | 104 base::JSONReader::Read(json, false))); |
| 105 | 105 |
| 106 // Check that prefs are set correctly. | 106 // Check that prefs are set correctly. |
| 107 web_resource_service_->UnpackLogoSignal(*(test_json.get())); | 107 web_resource_service_->UnpackLogoSignal(*(test_json.get())); |
| 108 logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); | 108 logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); |
| 109 EXPECT_EQ(logo_start, 0); // date value reset to 0; | 109 EXPECT_EQ(logo_start, 0); // date value reset to 0; |
| 110 logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); | 110 logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); |
| 111 EXPECT_EQ(logo_end, 0); // date value reset to 0; | 111 EXPECT_EQ(logo_end, 0); // date value reset to 0; |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { | 114 TEST_F(PromoResourceServiceTest, UnpackNotificationSignal) { |
| 115 // Set up start and end dates and promo line in a Dictionary as if parsed | 115 // Set up start and end dates and promo line in a Dictionary as if parsed |
| 116 // from the service. | 116 // from the service. |
| 117 std::string json = "{ " | 117 std::string json = "{ " |
| 118 " \"topic\": {" | 118 " \"topic\": {" |
| 119 " \"answers\": [" | 119 " \"answers\": [" |
| 120 " {" | 120 " {" |
| 121 " \"name\": \"promo_start\"," | 121 " \"name\": \"promo_start\"," |
| 122 " \"question\": \"3:2\"," | 122 " \"question\": \"3:2:5\"," |
| 123 " \"tooltip\": \"Eat more pie!\"," | 123 " \"tooltip\": \"Eat more pie!\"," |
| 124 " \"inproduct\": \"31/01/10 01:00 GMT\"" | 124 " \"inproduct\": \"31/01/10 01:00 GMT\"" |
| 125 " }," | 125 " }," |
| 126 " {" | 126 " {" |
| 127 " \"name\": \"promo_end\"," | 127 " \"name\": \"promo_end\"," |
| 128 " \"inproduct\": \"31/01/12 01:00 GMT\"" | 128 " \"inproduct\": \"31/01/12 01:00 GMT\"" |
| 129 " }" | 129 " }" |
| 130 " ]" | 130 " ]" |
| 131 " }" | 131 " }" |
| 132 "}"; | 132 "}"; |
| 133 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 133 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
| 134 base::JSONReader::Read(json, false))); | 134 base::JSONReader::Read(json, false))); |
| 135 | 135 |
| 136 // Check that prefs are set correctly. | 136 // Check that prefs are set correctly. |
| 137 web_resource_service_->UnpackPromoSignal(*(test_json.get())); | 137 web_resource_service_->UnpackNotificationSignal(*(test_json.get())); |
| 138 PrefService* prefs = profile_.GetPrefs(); | 138 PrefService* prefs = profile_.GetPrefs(); |
| 139 ASSERT_TRUE(prefs != NULL); | 139 ASSERT_TRUE(prefs != NULL); |
| 140 | 140 |
| 141 std::string promo_line = prefs->GetString(prefs::kNTPPromoLine); | 141 std::string promo_line = prefs->GetString(prefs::kNTPPromoLine); |
| 142 EXPECT_EQ(promo_line, "Eat more pie!"); | 142 EXPECT_EQ(promo_line, "Eat more pie!"); |
| 143 | 143 |
| 144 int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup); | 144 int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup); |
| 145 EXPECT_GE(promo_group, 0); | 145 EXPECT_GE(promo_group, 0); |
| 146 EXPECT_LT(promo_group, 16); | 146 EXPECT_LT(promo_group, 100); |
| 147 | 147 |
| 148 int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild); | 148 int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild); |
| 149 EXPECT_EQ(promo_build_type & PromoResourceService::DEV_BUILD, | 149 EXPECT_EQ(promo_build_type & PromoResourceService::DEV_BUILD, |
| 150 PromoResourceService::DEV_BUILD); | 150 PromoResourceService::DEV_BUILD); |
| 151 EXPECT_EQ(promo_build_type & PromoResourceService::BETA_BUILD, | 151 EXPECT_EQ(promo_build_type & PromoResourceService::BETA_BUILD, |
| 152 PromoResourceService::BETA_BUILD); | 152 PromoResourceService::BETA_BUILD); |
| 153 EXPECT_EQ(promo_build_type & PromoResourceService::STABLE_BUILD, 0); | 153 EXPECT_EQ(promo_build_type & PromoResourceService::STABLE_BUILD, 0); |
| 154 | 154 |
| 155 int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice); | 155 int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice); |
| 156 EXPECT_EQ(promo_time_slice, 2); | 156 EXPECT_EQ(promo_time_slice, 2); |
| 157 | 157 |
| 158 double promo_start = | 158 int promo_group_max = prefs->GetInteger(prefs::kNTPPromoGroupMax); |
| 159 prefs->GetDouble(prefs::kNTPPromoStart); | 159 EXPECT_EQ(promo_group_max, 5); |
| 160 int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT. | 160 |
| 161 promo_group * 2 * 60 * 60; | 161 double promo_start = prefs->GetDouble(prefs::kNTPPromoStart); |
| 162 double actual_start = 1264899600; // unix epoch for Jan 31 2010 0100 GMT. | |
| 162 EXPECT_EQ(promo_start, actual_start); | 163 EXPECT_EQ(promo_start, actual_start); |
| 163 | 164 |
| 164 double promo_end = | 165 double modified_start = actual_start + promo_group * 2 * 60 * 60; |
| 165 prefs->GetDouble(prefs::kNTPPromoEnd); | 166 EXPECT_EQ(PromoResourceService::GetNotificationStartTime(prefs), |
| 167 modified_start); | |
| 168 | |
| 169 double promo_end = prefs->GetDouble(prefs::kNTPPromoEnd); | |
| 166 EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. | 170 EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. |
| 171 | |
| 172 // Unpack the same json a second time. | |
| 173 web_resource_service_->UnpackNotificationSignal(*(test_json.get())); | |
| 174 | |
| 175 // All the data should be unchanged. | |
| 176 EXPECT_EQ(promo_line, prefs->GetString(prefs::kNTPPromoLine)); | |
| 177 EXPECT_EQ(promo_group, prefs->GetInteger(prefs::kNTPPromoGroup)); | |
| 178 EXPECT_EQ(promo_build_type, prefs->GetInteger(prefs::kNTPPromoBuild)); | |
| 179 EXPECT_EQ(promo_time_slice, | |
| 180 prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice)); | |
| 181 EXPECT_EQ(promo_group_max, prefs->GetInteger(prefs::kNTPPromoGroupMax)); | |
| 182 EXPECT_EQ(promo_start, prefs->GetDouble(prefs::kNTPPromoStart)); | |
| 183 EXPECT_EQ(modified_start, | |
| 184 PromoResourceService::GetNotificationStartTime(prefs)); | |
| 185 EXPECT_EQ(promo_end, prefs->GetDouble(prefs::kNTPPromoEnd)); | |
|
jstritar
2011/09/19 22:20:54
Maybe test CanShowNotificationPromo? You could try
achuithb
2011/09/19 22:57:56
I can't because of the build check in CanShowNotif
| |
| 167 } | 186 } |
| 168 | 187 |
| 169 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) { | 188 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) { |
| 170 web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV); | 189 web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV); |
| 171 | 190 |
| 172 std::string json = "{ " | 191 std::string json = "{ " |
| 173 " \"topic\": {" | 192 " \"topic\": {" |
| 174 " \"answers\": [" | 193 " \"answers\": [" |
| 175 " {" | 194 " {" |
| 176 " \"answer_id\": \"341252\"," | 195 " \"answer_id\": \"341252\"," |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 const chrome::VersionInfo::Channel stable = | 444 const chrome::VersionInfo::Channel stable = |
| 426 chrome::VersionInfo::CHANNEL_STABLE; | 445 chrome::VersionInfo::CHANNEL_STABLE; |
| 427 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 1)); | 446 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 1)); |
| 428 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 3)); | 447 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 3)); |
| 429 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); | 448 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); |
| 430 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); | 449 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); |
| 431 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); | 450 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); |
| 432 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); | 451 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); |
| 433 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); | 452 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); |
| 434 } | 453 } |
| OLD | NEW |