Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3722)

Unified Diff: chrome/browser/chromeos/mobile_config_unittest.cc

Issue 7778043: [cros] Support global carrier config. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/mobile_config_unittest.cc
diff --git a/chrome/browser/chromeos/mobile_config_unittest.cc b/chrome/browser/chromeos/mobile_config_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4500a290ca443e0d2762daad7bfe9ca3ff6aa2fc
--- /dev/null
+++ b/chrome/browser/chromeos/mobile_config_unittest.cc
@@ -0,0 +1,135 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/mobile_config.h"
+
+#include "base/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kBadManifest[] = "{\"version\": \"1\"}";
+
+const char kGoodMobileConfig[] =
+ "{"
+ " \"version\": \"1.0\","
+ " \"carriers\" : {\n"
+ " \"carrier (country)\" : {\n"
+ " \"ids\" : [\n"
+ " {\n"
+ " \"id\": \"cr (country)\",\n"
+ " \"_comment\" : \"Based on SPN.\",\n"
+ " },\n"
+ " {\n"
+ " \"id\": \"Carrier (country)\",\n"
+ " \"_comment\" : \"Legacy ID when SPN is empty.\",\n"
+ " },\n"
+ " ],\n"
+ " \"top_up_url\" : \"http://www.carrier.com/\",\n"
+ " \"deals\" : [\n"
+ " {\n"
+ " \"deal_id\" : \"0\",\n"
+ " \"locales\" : [ \"en-US\", ],\n"
+ " \"expire_date\" : \"31/12/12 0:0\",\n"
+ " \"notification_count\" : 1,\n"
+ " \"localized_content\" : {\n"
+ " \"en-US\" : {\n"
+ " \"notification_text\" : \"3G connectivity : Carrier.\",\n"
+ " },\n"
+ " \"default\" : {\n"
+ " \"notification_text\" : \"default_text.\",\n"
+ " },\n"
+ " },\n"
+ " },\n"
+ " ],\n"
+ " },"
+ " },"
+ "}";
+
+const char kOldDealMobileConfig[] =
+ "{"
+ " \"version\": \"1.0\","
+ " \"carriers\" : {\n"
+ " \"Carrier (country)\" : {\n"
+ " \"top_up_url\" : \"http://www.carrier.com/\",\n"
+ " \"deals\" : [\n"
+ " {\n"
+ " \"deal_id\" : \"0\",\n"
+ " \"locales\" : [ \"en-US\", ],\n"
+ " \"expire_date\" : \"01/01/01 0:0\",\n"
+ " \"notification_count\" : 1,\n"
+ " \"localized_content\" : {\n"
+ " \"en-US\" : {\n"
+ " \"notification_text\" : \"3G connectivity : Carrier.\",\n"
+ " },\n"
+ " \"default\" : {\n"
+ " \"notification_text\" : \"default_text.\",\n"
+ " },\n"
+ " },\n"
+ " },\n"
+ " ],\n"
+ " },"
+ " },"
+ "}";
+
+} // anonymous namespace
+
+namespace chromeos {
+
+TEST(MobileConfigTest, Basic) {
+ MobileConfig config(kGoodMobileConfig, "en-US");
+ EXPECT_TRUE(config.IsReady());
+
+ const MobileConfig::Carrier* carrier;
+ carrier = config.GetCarrier("Carrier (country)");
+ EXPECT_TRUE(carrier != NULL);
+ carrier = config.GetCarrier("cr (country)");
+ EXPECT_TRUE(carrier != NULL);
+ EXPECT_EQ("http://www.carrier.com/", carrier->top_up_url());
+ const MobileConfig::CarrierDeal* deal;
+ deal = carrier->GetDefaultDeal();
+ EXPECT_TRUE(deal != NULL);
+ deal = carrier->GetDeal("0");
+ EXPECT_TRUE(deal != NULL);
+ EXPECT_EQ("en-US", deal->locales()[0]);
+ EXPECT_EQ(1, deal->notification_count());
+ EXPECT_EQ("3G connectivity : Carrier.",
+ deal->GetLocalizedString("en-US", "notification_text"));
+ EXPECT_EQ("default_text.",
+ deal->GetLocalizedString("en", "notification_text"));
+
+ base::Time reference_time;
+ base::Time::FromString("31/12/12 0:00", &reference_time);
+ EXPECT_EQ(reference_time, deal->expire_date());
+}
+
+TEST(MobileConfigTest, OldDeal) {
+ MobileConfig config(kOldDealMobileConfig, "en-US");
+ EXPECT_TRUE(config.IsReady());
+ const MobileConfig::Carrier* carrier;
+ carrier = config.GetCarrier("Carrier (country)");
+ EXPECT_TRUE(carrier != NULL);
+ const MobileConfig::CarrierDeal* deal;
+ // TODO(nkostylev): Pass fixed time instead of relying on Time::Now().
+ deal = carrier->GetDefaultDeal();
+ EXPECT_TRUE(deal == NULL);
+}
+
+TEST(MobileConfigTest, DealOtherLocale) {
+ MobileConfig config(kGoodMobileConfig, "en-GB");
+ EXPECT_TRUE(config.IsReady());
+ const MobileConfig::Carrier* carrier;
+ carrier = config.GetCarrier("Carrier (country)");
+ EXPECT_TRUE(carrier != NULL);
+ const MobileConfig::CarrierDeal* deal;
+ deal = carrier->GetDefaultDeal();
+ EXPECT_TRUE(deal == NULL);
+}
+
+TEST(MobileConfigTest, BadManifest) {
+ MobileConfig config(kBadManifest, "en-US");
+ EXPECT_FALSE(config.IsReady());
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698