| 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 "chrome/browser/chromeos/customization_document.h" | 5 #include "chrome/browser/chromeos/customization_document.h" |
| 6 | 6 |
| 7 #include "base/time.h" | |
| 8 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" | 7 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const char kGoodStartupManifest[] = | 13 const char kGoodStartupManifest[] = |
| 14 "{" | 14 "{" |
| 15 " \"version\": \"1.0\"," | 15 " \"version\": \"1.0\"," |
| 16 " \"initial_locale\" : \"en-US\"," | 16 " \"initial_locale\" : \"en-US\"," |
| 17 " \"initial_timezone\" : \"US/Pacific\"," | 17 " \"initial_timezone\" : \"US/Pacific\"," |
| 18 " \"keyboard_layout\" : \"xkb:us::eng\"," | 18 " \"keyboard_layout\" : \"xkb:us::eng\"," |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 " }," | 59 " }," |
| 60 " \"ru-RU\" : {" | 60 " \"ru-RU\" : {" |
| 61 " \"initial_start_page\": \"http://mario/ru/promo\"," | 61 " \"initial_start_page\": \"http://mario/ru/promo\"," |
| 62 " \"support_page\": \"http://mario/ru\"," | 62 " \"support_page\": \"http://mario/ru\"," |
| 63 " }," | 63 " }," |
| 64 " \"default\" : {" | 64 " \"default\" : {" |
| 65 " \"initial_start_page\": \"http://mario/global/promo\"," | 65 " \"initial_start_page\": \"http://mario/global/promo\"," |
| 66 " \"support_page\": \"http://mario/global\"," | 66 " \"support_page\": \"http://mario/global\"," |
| 67 " }," | 67 " }," |
| 68 " }," | 68 " }," |
| 69 " \"carrier_deals\" : {" | |
| 70 " \"Carrier (country)\" : {" | |
| 71 " \"deal_locale\" : \"en-US\"," | |
| 72 " \"top_up_url\" : \"http://www.carrier.com/\"," | |
| 73 " \"notification_count\" : 1,\n" | |
| 74 " \"expire_date\" : \"31/12/12 0:00\"," | |
| 75 " \"localized_content\" : {" | |
| 76 " \"en-US\" : {" | |
| 77 " \"notification_text\" : \"3G connectivity : Carrier.\"," | |
| 78 " }," | |
| 79 " \"default\" : {" | |
| 80 " \"notification_text\" : \"default_text.\"," | |
| 81 " }," | |
| 82 " }," | |
| 83 " }," | |
| 84 " }," | |
| 85 "}"; | |
| 86 | |
| 87 const char kOldDealServicesManifest[] = | |
| 88 "{" | |
| 89 " \"version\": \"1.0\"," | |
| 90 " \"carrier_deals\" : {" | |
| 91 " \"Carrier (country)\" : {" | |
| 92 " \"deal_locale\" : \"en-US\"," | |
| 93 " \"top_up_url\" : \"http://www.carrier.com/\"," | |
| 94 " \"notification_count\" : 1," | |
| 95 " \"expire_date\" : \"01/01/01 0:00\"," | |
| 96 " \"localized_content\" : {" | |
| 97 " \"en-US\" : {" | |
| 98 " \"notification_text\" : \"en-US text.\"," | |
| 99 " }," | |
| 100 " \"default\" : {" | |
| 101 " \"notification_text\" : \"default_text.\"," | |
| 102 " }," | |
| 103 " }," | |
| 104 " }," | |
| 105 " }," | |
| 106 "}"; | 69 "}"; |
| 107 | 70 |
| 108 } // anonymous namespace | 71 } // anonymous namespace |
| 109 | 72 |
| 110 namespace chromeos { | 73 namespace chromeos { |
| 111 | 74 |
| 112 using ::testing::_; | 75 using ::testing::_; |
| 113 using ::testing::DoAll; | 76 using ::testing::DoAll; |
| 114 using ::testing::NotNull; | 77 using ::testing::NotNull; |
| 115 using ::testing::Return; | 78 using ::testing::Return; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 135 } |
| 173 | 136 |
| 174 TEST(StartupCustomizationDocumentTest, BadManifest) { | 137 TEST(StartupCustomizationDocumentTest, BadManifest) { |
| 175 system::MockStatisticsProvider mock_statistics_provider; | 138 system::MockStatisticsProvider mock_statistics_provider; |
| 176 StartupCustomizationDocument customization(&mock_statistics_provider, | 139 StartupCustomizationDocument customization(&mock_statistics_provider, |
| 177 kBadManifest); | 140 kBadManifest); |
| 178 EXPECT_FALSE(customization.IsReady()); | 141 EXPECT_FALSE(customization.IsReady()); |
| 179 } | 142 } |
| 180 | 143 |
| 181 TEST(ServicesCustomizationDocumentTest, Basic) { | 144 TEST(ServicesCustomizationDocumentTest, Basic) { |
| 182 ServicesCustomizationDocument customization(kGoodServicesManifest, "en-US"); | 145 ServicesCustomizationDocument customization(kGoodServicesManifest); |
| 183 EXPECT_TRUE(customization.IsReady()); | 146 EXPECT_TRUE(customization.IsReady()); |
| 184 | 147 |
| 185 EXPECT_EQ("http://mario/promo", | 148 EXPECT_EQ("http://mario/promo", |
| 186 customization.GetInitialStartPage("en-US")); | 149 customization.GetInitialStartPage("en-US")); |
| 187 EXPECT_EQ("http://mario/ru/promo", | 150 EXPECT_EQ("http://mario/ru/promo", |
| 188 customization.GetInitialStartPage("ru-RU")); | 151 customization.GetInitialStartPage("ru-RU")); |
| 189 EXPECT_EQ("http://mario/global/promo", | 152 EXPECT_EQ("http://mario/global/promo", |
| 190 customization.GetInitialStartPage("ja")); | 153 customization.GetInitialStartPage("ja")); |
| 191 | 154 |
| 192 EXPECT_EQ("http://mario/us", customization.GetSupportPage("en-US")); | 155 EXPECT_EQ("http://mario/us", customization.GetSupportPage("en-US")); |
| 193 EXPECT_EQ("http://mario/ru", customization.GetSupportPage("ru-RU")); | 156 EXPECT_EQ("http://mario/ru", customization.GetSupportPage("ru-RU")); |
| 194 EXPECT_EQ("http://mario/global", customization.GetSupportPage("ja")); | 157 EXPECT_EQ("http://mario/global", customization.GetSupportPage("ja")); |
| 195 | |
| 196 const ServicesCustomizationDocument::CarrierDeal* deal; | |
| 197 deal = customization.GetCarrierDeal("Carrier (country)", true); | |
| 198 EXPECT_TRUE(deal != NULL); | |
| 199 EXPECT_EQ("en-US", deal->deal_locale()); | |
| 200 EXPECT_EQ("http://www.carrier.com/", deal->top_up_url()); | |
| 201 EXPECT_EQ(1, deal->notification_count()); | |
| 202 EXPECT_EQ("3G connectivity : Carrier.", | |
| 203 deal->GetLocalizedString("en-US", "notification_text")); | |
| 204 EXPECT_EQ("default_text.", | |
| 205 deal->GetLocalizedString("en", "notification_text")); | |
| 206 | |
| 207 base::Time reference_time; | |
| 208 base::Time::FromString("31/12/12 0:00", &reference_time); | |
| 209 EXPECT_EQ(reference_time, deal->expire_date()); | |
| 210 } | |
| 211 | |
| 212 TEST(ServicesCustomizationDocumentTest, OldDeal) { | |
| 213 ServicesCustomizationDocument customization(kOldDealServicesManifest, | |
| 214 "en-US"); | |
| 215 EXPECT_TRUE(customization.IsReady()); | |
| 216 | |
| 217 const ServicesCustomizationDocument::CarrierDeal* deal; | |
| 218 // TODO(nkostylev): Pass fixed time instead of relying on Time::Now(). | |
| 219 deal = customization.GetCarrierDeal("Carrier (country)", true); | |
| 220 EXPECT_TRUE(deal == NULL); | |
| 221 } | |
| 222 | |
| 223 TEST(ServicesCustomizationDocumentTest, DealOtherLocale) { | |
| 224 ServicesCustomizationDocument customization(kGoodServicesManifest, | |
| 225 "en-GB"); | |
| 226 EXPECT_TRUE(customization.IsReady()); | |
| 227 | |
| 228 const ServicesCustomizationDocument::CarrierDeal* deal; | |
| 229 deal = customization.GetCarrierDeal("Carrier (country)", true); | |
| 230 EXPECT_TRUE(deal == NULL); | |
| 231 } | 158 } |
| 232 | 159 |
| 233 TEST(ServicesCustomizationDocumentTest, BadManifest) { | 160 TEST(ServicesCustomizationDocumentTest, BadManifest) { |
| 234 ServicesCustomizationDocument customization(kBadManifest, "en-US"); | 161 ServicesCustomizationDocument customization(kBadManifest); |
| 235 EXPECT_FALSE(customization.IsReady()); | 162 EXPECT_FALSE(customization.IsReady()); |
| 236 } | 163 } |
| 237 | 164 |
| 238 TEST(ServicesCustomizationDocumentTest, NoDealRestrictions) { | |
| 239 ServicesCustomizationDocument customization_oth_locale(kGoodServicesManifest, | |
| 240 "en-GB"); | |
| 241 EXPECT_TRUE(customization_oth_locale.IsReady()); | |
| 242 const ServicesCustomizationDocument::CarrierDeal* deal; | |
| 243 deal = customization_oth_locale.GetCarrierDeal("Carrier (country)", false); | |
| 244 EXPECT_TRUE(deal != NULL); | |
| 245 | |
| 246 ServicesCustomizationDocument customization_old_deal(kOldDealServicesManifest, | |
| 247 "en-US"); | |
| 248 EXPECT_TRUE(customization_old_deal.IsReady()); | |
| 249 deal = customization_old_deal.GetCarrierDeal("Carrier (country)", false); | |
| 250 EXPECT_TRUE(deal != NULL); | |
| 251 } | |
| 252 | |
| 253 } // namespace chromeos | 165 } // namespace chromeos |
| OLD | NEW |