Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / customization_document_unittest.cc
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/customization_document.h"
6
7 #include "chromeos/system/mock_statistics_provider.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace {
12
13 const char kGoodStartupManifest[] =
14     "{"
15     "  \"version\": \"1.0\","
16     "  \"initial_locale\" : \"en-US\","
17     "  \"initial_timezone\" : \"US/Pacific\","
18     "  \"keyboard_layout\" : \"xkb:us::eng\","
19     "  \"registration_url\" : \"http://www.google.com\","
20     "  \"setup_content\" : {"
21     "    \"en-US\" : {"
22     "      \"help_page\" : \"file:///opt/oem/help/en-US/help.html\","
23     "      \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\","
24     "    },"
25     "    \"ru-RU\" : {"
26     "      \"help_page\" : \"file:///opt/oem/help/ru-RU/help.html\","
27     "      \"eula_page\" : \"file:///opt/oem/eula/ru-RU/eula.html\","
28     "    },"
29     "    \"default\" : {"
30     "      \"help_page\" : \"file:///opt/oem/help/en/help.html\","
31     "      \"eula_page\" : \"file:///opt/oem/eula/en/eula.html\","
32     "    },"
33     "  },"
34     "  \"hwid_map\" : ["
35     "    {"
36     "      \"hwid_mask\": \"ZGA*34\","
37     "      \"initial_locale\" : \"ja\","
38     "      \"initial_timezone\" : \"Asia/Tokyo\","
39     "      \"keyboard_layout\" : \"mozc-jp\","
40     "    },"
41     "    {"
42     "      \"hwid_mask\": \"Mario 1?3*\","
43     "      \"initial_locale\" : \"ru-RU\","
44     "      \"initial_timezone\" : \"Europe/Moscow\","
45     "      \"keyboard_layout\" : \"xkb:ru::rus\","
46     "    },"
47     "  ],"
48     "}";
49
50 const char kMultiLanguageStartupManifest[] =
51     "{\n"
52     "  \"version\": \"1.0\",\n"
53     "  \"initial_locale\" : \"en-US,de,fr,it\",\n"
54     "  \"initial_timezone\" : \"Europe/Zurich\",\n"
55     "  \"keyboard_layout\" : \"xkb:us::eng\",\n"
56     "  \"registration_url\" : \"http://www.google.com\",\n"
57     "  \"setup_content\" : {\n"
58     "    \"default\" : {\n"
59     "      \"help_page\" : \"file:///opt/oem/help/en-US/help.html\",\n"
60     "      \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\",\n"
61     "    },\n"
62     "  },"
63     "}";
64
65 const char kBadManifest[] = "{\"version\": \"1\"}";
66
67 const char kGoodServicesManifest[] =
68     "{"
69     "  \"version\": \"1.0\","
70     "  \"app_content\" : {"
71     "    \"en-US\" : {"
72     "      \"initial_start_page\": \"http://mario/promo\","
73     "      \"support_page\": \"http://mario/us\","
74     "    },"
75     "    \"ru-RU\" : {"
76     "      \"initial_start_page\": \"http://mario/ru/promo\","
77     "      \"support_page\": \"http://mario/ru\","
78     "    },"
79     "    \"default\" : {"
80     "      \"initial_start_page\": \"http://mario/global/promo\","
81     "      \"support_page\": \"http://mario/global\","
82     "    },"
83     "  },"
84     "}";
85
86 }  // anonymous namespace
87
88 namespace chromeos {
89
90 using ::testing::_;
91 using ::testing::DoAll;
92 using ::testing::NotNull;
93 using ::testing::Return;
94 using ::testing::SetArgumentPointee;
95
96 TEST(StartupCustomizationDocumentTest, Basic) {
97   system::MockStatisticsProvider mock_statistics_provider;
98   EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(_, NotNull()))
99       .WillRepeatedly(Return(false));
100   EXPECT_CALL(mock_statistics_provider,
101       GetMachineStatistic(std::string("hardware_class"), NotNull()))
102           .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")),
103                           Return(true)));
104   StartupCustomizationDocument customization(&mock_statistics_provider,
105                                              kGoodStartupManifest);
106   EXPECT_EQ("ru-RU", customization.initial_locale());
107   EXPECT_EQ("Europe/Moscow", customization.initial_timezone());
108   EXPECT_EQ("xkb:ru::rus", customization.keyboard_layout());
109   EXPECT_EQ("http://www.google.com", customization.registration_url());
110
111   EXPECT_EQ("file:///opt/oem/help/en-US/help.html",
112             customization.GetHelpPage("en-US"));
113   EXPECT_EQ("file:///opt/oem/help/ru-RU/help.html",
114             customization.GetHelpPage("ru-RU"));
115   EXPECT_EQ("file:///opt/oem/help/en/help.html",
116             customization.GetHelpPage("ja"));
117
118   EXPECT_EQ("file:///opt/oem/eula/en-US/eula.html",
119             customization.GetEULAPage("en-US"));
120   EXPECT_EQ("file:///opt/oem/eula/ru-RU/eula.html",
121             customization.GetEULAPage("ru-RU"));
122   EXPECT_EQ("file:///opt/oem/eula/en/eula.html",
123             customization.GetEULAPage("ja"));
124 }
125
126 TEST(StartupCustomizationDocumentTest, VPD) {
127   system::MockStatisticsProvider mock_statistics_provider;
128   EXPECT_CALL(mock_statistics_provider,
129       GetMachineStatistic(std::string("hardware_class"), NotNull()))
130           .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")),
131                           Return(true)));
132   EXPECT_CALL(mock_statistics_provider,
133       GetMachineStatistic(std::string("initial_locale"), NotNull()))
134           .WillOnce(DoAll(SetArgumentPointee<1>(std::string("ja")),
135                           Return(true)));
136   EXPECT_CALL(mock_statistics_provider,
137       GetMachineStatistic(std::string("initial_timezone"), NotNull()))
138           .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Asia/Tokyo")),
139                           Return(true)));
140   EXPECT_CALL(mock_statistics_provider,
141       GetMachineStatistic(std::string("keyboard_layout"), NotNull()))
142           .WillOnce(DoAll(SetArgumentPointee<1>(std::string("mozc-jp")),
143                           Return(true)));
144   StartupCustomizationDocument customization(&mock_statistics_provider,
145                                              kGoodStartupManifest);
146   EXPECT_TRUE(customization.IsReady());
147   EXPECT_EQ("ja", customization.initial_locale());
148   EXPECT_EQ("Asia/Tokyo", customization.initial_timezone());
149   EXPECT_EQ("mozc-jp", customization.keyboard_layout());
150 }
151
152 TEST(StartupCustomizationDocumentTest, BadManifest) {
153   system::MockStatisticsProvider mock_statistics_provider;
154   StartupCustomizationDocument customization(&mock_statistics_provider,
155                                              kBadManifest);
156   EXPECT_FALSE(customization.IsReady());
157 }
158
159 TEST(ServicesCustomizationDocumentTest, Basic) {
160   ServicesCustomizationDocument customization(kGoodServicesManifest);
161   EXPECT_TRUE(customization.IsReady());
162
163   EXPECT_EQ("http://mario/promo",
164             customization.GetInitialStartPage("en-US"));
165   EXPECT_EQ("http://mario/ru/promo",
166             customization.GetInitialStartPage("ru-RU"));
167   EXPECT_EQ("http://mario/global/promo",
168             customization.GetInitialStartPage("ja"));
169
170   EXPECT_EQ("http://mario/us", customization.GetSupportPage("en-US"));
171   EXPECT_EQ("http://mario/ru", customization.GetSupportPage("ru-RU"));
172   EXPECT_EQ("http://mario/global", customization.GetSupportPage("ja"));
173 }
174
175 #define EXPECT_LOCALE_ENTRY(i, value)                     \
176   if (customization.configured_locales().size() > i)      \
177   EXPECT_EQ(value, customization.configured_locales()[i]) \
178       << "Bad locale value at index " << i
179
180 TEST(ServicesCustomizationDocumentTest, MultiLanguage) {
181   system::MockStatisticsProvider mock_statistics_provider;
182   StartupCustomizationDocument customization(&mock_statistics_provider,
183                                              kMultiLanguageStartupManifest);
184   EXPECT_TRUE(customization.IsReady());
185
186   EXPECT_EQ("en-US,de,fr,it", customization.initial_locale());
187   EXPECT_EQ("en-US", customization.initial_locale_default());
188   EXPECT_EQ(4u, customization.configured_locales().size());
189
190   EXPECT_LOCALE_ENTRY(0, "en-US");
191   EXPECT_LOCALE_ENTRY(1, "de");
192   EXPECT_LOCALE_ENTRY(2, "fr");
193   EXPECT_LOCALE_ENTRY(3, "it");
194 }
195
196 TEST(ServicesCustomizationDocumentTest, BadManifest) {
197   ServicesCustomizationDocument customization(kBadManifest);
198   EXPECT_FALSE(customization.IsReady());
199 }
200
201 }  // namespace chromeos