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.
5 #include "chrome/browser/chromeos/customization_document.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"
13 const char kGoodStartupManifest
[] =
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\" : {"
22 " \"help_page\" : \"file:///opt/oem/help/en-US/help.html\","
23 " \"eula_page\" : \"file:///opt/oem/eula/en-US/eula.html\","
26 " \"help_page\" : \"file:///opt/oem/help/ru-RU/help.html\","
27 " \"eula_page\" : \"file:///opt/oem/eula/ru-RU/eula.html\","
30 " \"help_page\" : \"file:///opt/oem/help/en/help.html\","
31 " \"eula_page\" : \"file:///opt/oem/eula/en/eula.html\","
36 " \"hwid_mask\": \"ZGA*34\","
37 " \"initial_locale\" : \"ja\","
38 " \"initial_timezone\" : \"Asia/Tokyo\","
39 " \"keyboard_layout\" : \"mozc-jp\","
42 " \"hwid_mask\": \"Mario 1?3*\","
43 " \"initial_locale\" : \"ru-RU\","
44 " \"initial_timezone\" : \"Europe/Moscow\","
45 " \"keyboard_layout\" : \"xkb:ru::rus\","
50 const char kBadManifest
[] = "{\"version\": \"1\"}";
52 const char kGoodServicesManifest
[] =
54 " \"version\": \"1.0\","
55 " \"app_content\" : {"
57 " \"initial_start_page\": \"http://mario/promo\","
58 " \"support_page\": \"http://mario/us\","
61 " \"initial_start_page\": \"http://mario/ru/promo\","
62 " \"support_page\": \"http://mario/ru\","
65 " \"initial_start_page\": \"http://mario/global/promo\","
66 " \"support_page\": \"http://mario/global\","
71 } // anonymous namespace
76 using ::testing::DoAll
;
77 using ::testing::NotNull
;
78 using ::testing::Return
;
79 using ::testing::SetArgumentPointee
;
81 TEST(StartupCustomizationDocumentTest
, Basic
) {
82 system::MockStatisticsProvider mock_statistics_provider
;
83 EXPECT_CALL(mock_statistics_provider
, GetMachineStatistic(_
, NotNull()))
84 .WillRepeatedly(Return(false));
85 EXPECT_CALL(mock_statistics_provider
,
86 GetMachineStatistic(std::string("hardware_class"), NotNull()))
87 .WillOnce(DoAll(SetArgumentPointee
<1>(std::string("Mario 12345")),
89 StartupCustomizationDocument
customization(&mock_statistics_provider
,
90 kGoodStartupManifest
);
91 EXPECT_EQ("ru-RU", customization
.initial_locale());
92 EXPECT_EQ("Europe/Moscow", customization
.initial_timezone());
93 EXPECT_EQ("xkb:ru::rus", customization
.keyboard_layout());
94 EXPECT_EQ("http://www.google.com", customization
.registration_url());
96 EXPECT_EQ("file:///opt/oem/help/en-US/help.html",
97 customization
.GetHelpPage("en-US"));
98 EXPECT_EQ("file:///opt/oem/help/ru-RU/help.html",
99 customization
.GetHelpPage("ru-RU"));
100 EXPECT_EQ("file:///opt/oem/help/en/help.html",
101 customization
.GetHelpPage("ja"));
103 EXPECT_EQ("file:///opt/oem/eula/en-US/eula.html",
104 customization
.GetEULAPage("en-US"));
105 EXPECT_EQ("file:///opt/oem/eula/ru-RU/eula.html",
106 customization
.GetEULAPage("ru-RU"));
107 EXPECT_EQ("file:///opt/oem/eula/en/eula.html",
108 customization
.GetEULAPage("ja"));
111 TEST(StartupCustomizationDocumentTest
, VPD
) {
112 system::MockStatisticsProvider mock_statistics_provider
;
113 EXPECT_CALL(mock_statistics_provider
,
114 GetMachineStatistic(std::string("hardware_class"), NotNull()))
115 .WillOnce(DoAll(SetArgumentPointee
<1>(std::string("Mario 12345")),
117 EXPECT_CALL(mock_statistics_provider
,
118 GetMachineStatistic(std::string("initial_locale"), NotNull()))
119 .WillOnce(DoAll(SetArgumentPointee
<1>(std::string("ja")),
121 EXPECT_CALL(mock_statistics_provider
,
122 GetMachineStatistic(std::string("initial_timezone"), NotNull()))
123 .WillOnce(DoAll(SetArgumentPointee
<1>(std::string("Asia/Tokyo")),
125 EXPECT_CALL(mock_statistics_provider
,
126 GetMachineStatistic(std::string("keyboard_layout"), NotNull()))
127 .WillOnce(DoAll(SetArgumentPointee
<1>(std::string("mozc-jp")),
129 StartupCustomizationDocument
customization(&mock_statistics_provider
,
130 kGoodStartupManifest
);
131 EXPECT_TRUE(customization
.IsReady());
132 EXPECT_EQ("ja", customization
.initial_locale());
133 EXPECT_EQ("Asia/Tokyo", customization
.initial_timezone());
134 EXPECT_EQ("mozc-jp", customization
.keyboard_layout());
137 TEST(StartupCustomizationDocumentTest
, BadManifest
) {
138 system::MockStatisticsProvider mock_statistics_provider
;
139 StartupCustomizationDocument
customization(&mock_statistics_provider
,
141 EXPECT_FALSE(customization
.IsReady());
144 TEST(ServicesCustomizationDocumentTest
, Basic
) {
145 ServicesCustomizationDocument
customization(kGoodServicesManifest
);
146 EXPECT_TRUE(customization
.IsReady());
148 EXPECT_EQ("http://mario/promo",
149 customization
.GetInitialStartPage("en-US"));
150 EXPECT_EQ("http://mario/ru/promo",
151 customization
.GetInitialStartPage("ru-RU"));
152 EXPECT_EQ("http://mario/global/promo",
153 customization
.GetInitialStartPage("ja"));
155 EXPECT_EQ("http://mario/us", customization
.GetSupportPage("en-US"));
156 EXPECT_EQ("http://mario/ru", customization
.GetSupportPage("ru-RU"));
157 EXPECT_EQ("http://mario/global", customization
.GetSupportPage("ja"));
160 TEST(ServicesCustomizationDocumentTest
, BadManifest
) {
161 ServicesCustomizationDocument
customization(kBadManifest
);
162 EXPECT_FALSE(customization
.IsReady());
165 } // namespace chromeos