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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/mobile_config.h"
6
7 #include "base/time.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11
12 const char kBadManifest[] = "{\"version\": \"1\"}";
13
14 const char kGoodMobileConfig[] =
15 "{"
16 " \"version\": \"1.0\","
17 " \"carriers\" : {\n"
18 " \"carrier (country)\" : {\n"
19 " \"ids\" : [\n"
20 " {\n"
21 " \"id\": \"cr (country)\",\n"
22 " \"_comment\" : \"Based on SPN.\",\n"
23 " },\n"
24 " {\n"
25 " \"id\": \"Carrier (country)\",\n"
26 " \"_comment\" : \"Legacy ID when SPN is empty.\",\n"
27 " },\n"
28 " ],\n"
29 " \"top_up_url\" : \"http://www.carrier.com/\",\n"
30 " \"deals\" : [\n"
31 " {\n"
32 " \"deal_id\" : \"0\",\n"
33 " \"locales\" : [ \"en-US\", ],\n"
34 " \"expire_date\" : \"31/12/12 0:0\",\n"
35 " \"notification_count\" : 1,\n"
36 " \"localized_content\" : {\n"
37 " \"en-US\" : {\n"
38 " \"notification_text\" : \"3G connectivity : Carrier.\",\n"
39 " },\n"
40 " \"default\" : {\n"
41 " \"notification_text\" : \"default_text.\",\n"
42 " },\n"
43 " },\n"
44 " },\n"
45 " ],\n"
46 " },"
47 " },"
48 "}";
49
50 const char kOldDealMobileConfig[] =
51 "{"
52 " \"version\": \"1.0\","
53 " \"carriers\" : {\n"
54 " \"Carrier (country)\" : {\n"
55 " \"top_up_url\" : \"http://www.carrier.com/\",\n"
56 " \"deals\" : [\n"
57 " {\n"
58 " \"deal_id\" : \"0\",\n"
59 " \"locales\" : [ \"en-US\", ],\n"
60 " \"expire_date\" : \"01/01/01 0:0\",\n"
61 " \"notification_count\" : 1,\n"
62 " \"localized_content\" : {\n"
63 " \"en-US\" : {\n"
64 " \"notification_text\" : \"3G connectivity : Carrier.\",\n"
65 " },\n"
66 " \"default\" : {\n"
67 " \"notification_text\" : \"default_text.\",\n"
68 " },\n"
69 " },\n"
70 " },\n"
71 " ],\n"
72 " },"
73 " },"
74 "}";
75
76 } // anonymous namespace
77
78 namespace chromeos {
79
80 TEST(MobileConfigTest, Basic) {
81 MobileConfig config(kGoodMobileConfig, "en-US");
82 EXPECT_TRUE(config.IsReady());
83
84 const MobileConfig::Carrier* carrier;
85 carrier = config.GetCarrier("Carrier (country)");
86 EXPECT_TRUE(carrier != NULL);
87 carrier = config.GetCarrier("cr (country)");
88 EXPECT_TRUE(carrier != NULL);
89 EXPECT_EQ("http://www.carrier.com/", carrier->top_up_url());
90 const MobileConfig::CarrierDeal* deal;
91 deal = carrier->GetDefaultDeal();
92 EXPECT_TRUE(deal != NULL);
93 deal = carrier->GetDeal("0");
94 EXPECT_TRUE(deal != NULL);
95 EXPECT_EQ("en-US", deal->locales()[0]);
96 EXPECT_EQ(1, deal->notification_count());
97 EXPECT_EQ("3G connectivity : Carrier.",
98 deal->GetLocalizedString("en-US", "notification_text"));
99 EXPECT_EQ("default_text.",
100 deal->GetLocalizedString("en", "notification_text"));
101
102 base::Time reference_time;
103 base::Time::FromString("31/12/12 0:00", &reference_time);
104 EXPECT_EQ(reference_time, deal->expire_date());
105 }
106
107 TEST(MobileConfigTest, OldDeal) {
108 MobileConfig config(kOldDealMobileConfig, "en-US");
109 EXPECT_TRUE(config.IsReady());
110 const MobileConfig::Carrier* carrier;
111 carrier = config.GetCarrier("Carrier (country)");
112 EXPECT_TRUE(carrier != NULL);
113 const MobileConfig::CarrierDeal* deal;
114 // TODO(nkostylev): Pass fixed time instead of relying on Time::Now().
115 deal = carrier->GetDefaultDeal();
116 EXPECT_TRUE(deal == NULL);
117 }
118
119 TEST(MobileConfigTest, DealOtherLocale) {
120 MobileConfig config(kGoodMobileConfig, "en-GB");
121 EXPECT_TRUE(config.IsReady());
122 const MobileConfig::Carrier* carrier;
123 carrier = config.GetCarrier("Carrier (country)");
124 EXPECT_TRUE(carrier != NULL);
125 const MobileConfig::CarrierDeal* deal;
126 deal = carrier->GetDefaultDeal();
127 EXPECT_TRUE(deal == NULL);
128 }
129
130 TEST(MobileConfigTest, BadManifest) {
131 MobileConfig config(kBadManifest, "en-US");
132 EXPECT_FALSE(config.IsReady());
133 }
134
135 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698