OLD | NEW |
1 // Copyright (c) 2010 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 "chrome/browser/chromeos/mock_system_access.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 | 9 |
9 namespace { | 10 namespace { |
10 | 11 |
11 const char kGoodStartupManifest[] = | 12 const char kGoodStartupManifest[] = |
12 "{" | 13 "{" |
13 " \"version\": \"1.0\"," | 14 " \"version\": \"1.0\"," |
14 " \"initial_locale\" : \"en-US\"," | 15 " \"initial_locale\" : \"en-US\"," |
15 " \"initial_timezone\" : \"US/Pacific\"," | 16 " \"initial_timezone\" : \"US/Pacific\"," |
16 " \"keyboard_layout\" : \"xkb:us::eng\"," | 17 " \"keyboard_layout\" : \"xkb:us::eng\"," |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 " \"initial_start_page\": \"http://mario/ru/promo\"," | 60 " \"initial_start_page\": \"http://mario/ru/promo\"," |
60 " \"support_page\": \"http://mario/ru\"," | 61 " \"support_page\": \"http://mario/ru\"," |
61 " }," | 62 " }," |
62 " \"default\" : {" | 63 " \"default\" : {" |
63 " \"initial_start_page\": \"http://mario/global/promo\"," | 64 " \"initial_start_page\": \"http://mario/global/promo\"," |
64 " \"support_page\": \"http://mario/global\"," | 65 " \"support_page\": \"http://mario/global\"," |
65 " }," | 66 " }," |
66 " }," | 67 " }," |
67 "}"; | 68 "}"; |
68 | 69 |
69 const char kHWID[] = "Mario 123-456"; | |
70 | |
71 const char kVPD[] = | |
72 "\"initial_locale\"=\"ja\"\n" | |
73 "\"initial_timezone\"=\"Asia/Tokyo\"\n" | |
74 "\"keyboard_layout\"=\"mozc-jp\"\n"; | |
75 | |
76 class TestDocument : public chromeos::StartupCustomizationDocument { | |
77 public: | |
78 TestDocument() : hwid_(kHWID), vpd_() { | |
79 } | |
80 | |
81 void set_hwid(const std::string& hwid) { hwid_ = hwid; } | |
82 void set_vpd(const std::string& vpd) { vpd_ = vpd; } | |
83 | |
84 private: | |
85 virtual std::string GetHWID() const { | |
86 return hwid_; | |
87 } | |
88 | |
89 virtual std::string GetVPD() const { | |
90 return vpd_; | |
91 } | |
92 | |
93 std::string hwid_; | |
94 std::string vpd_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(TestDocument); | |
97 }; | |
98 | |
99 } // anonymous namespace | 70 } // anonymous namespace |
100 | 71 |
101 // StartupCustomizationDocumentTest implementation. | 72 namespace chromeos { |
102 class StartupCustomizationDocumentTest : public testing::Test { | |
103 protected: | |
104 TestDocument customization_; | |
105 }; | |
106 | 73 |
107 TEST_F(StartupCustomizationDocumentTest, Basic) { | 74 using ::testing::_; |
108 EXPECT_TRUE(customization_.LoadManifestFromString(kGoodStartupManifest)); | 75 using ::testing::DoAll; |
109 EXPECT_EQ(customization_.initial_locale(), "ru-RU"); | 76 using ::testing::NotNull; |
110 EXPECT_EQ(customization_.initial_timezone(), "Europe/Moscow"); | 77 using ::testing::Return; |
111 EXPECT_EQ(customization_.keyboard_layout(), "xkb:ru::rus"); | 78 using ::testing::SetArgumentPointee; |
112 EXPECT_EQ(customization_.registration_url(), "http://www.google.com"); | |
113 | 79 |
114 EXPECT_EQ(customization_.GetHelpPage("en-US"), | 80 TEST(StartupCustomizationDocumentTest, Basic) { |
| 81 MockSystemAccess mock_system_access; |
| 82 EXPECT_CALL(mock_system_access, GetMachineStatistic(_, NotNull())) |
| 83 .WillRepeatedly(Return(false)); |
| 84 EXPECT_CALL(mock_system_access, |
| 85 GetMachineStatistic(std::string("hwid"), NotNull())) |
| 86 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), |
| 87 Return(true))); |
| 88 StartupCustomizationDocument customization(&mock_system_access, |
| 89 kGoodStartupManifest); |
| 90 EXPECT_EQ(customization.initial_locale(), "ru-RU"); |
| 91 EXPECT_EQ(customization.initial_timezone(), "Europe/Moscow"); |
| 92 EXPECT_EQ(customization.keyboard_layout(), "xkb:ru::rus"); |
| 93 EXPECT_EQ(customization.registration_url(), "http://www.google.com"); |
| 94 |
| 95 EXPECT_EQ(customization.GetHelpPage("en-US"), |
115 "file:///opt/oem/help/en-US/help.html"); | 96 "file:///opt/oem/help/en-US/help.html"); |
116 EXPECT_EQ(customization_.GetHelpPage("ru-RU"), | 97 EXPECT_EQ(customization.GetHelpPage("ru-RU"), |
117 "file:///opt/oem/help/ru-RU/help.html"); | 98 "file:///opt/oem/help/ru-RU/help.html"); |
118 EXPECT_EQ(customization_.GetHelpPage("ja"), | 99 EXPECT_EQ(customization.GetHelpPage("ja"), |
119 "file:///opt/oem/help/en/help.html"); | 100 "file:///opt/oem/help/en/help.html"); |
120 | 101 |
121 EXPECT_EQ(customization_.GetEULAPage("en-US"), | 102 EXPECT_EQ(customization.GetEULAPage("en-US"), |
122 "file:///opt/oem/eula/en-US/eula.html"); | 103 "file:///opt/oem/eula/en-US/eula.html"); |
123 EXPECT_EQ(customization_.GetEULAPage("ru-RU"), | 104 EXPECT_EQ(customization.GetEULAPage("ru-RU"), |
124 "file:///opt/oem/eula/ru-RU/eula.html"); | 105 "file:///opt/oem/eula/ru-RU/eula.html"); |
125 EXPECT_EQ(customization_.GetEULAPage("ja"), | 106 EXPECT_EQ(customization.GetEULAPage("ja"), |
126 "file:///opt/oem/eula/en/eula.html"); | 107 "file:///opt/oem/eula/en/eula.html"); |
127 } | 108 } |
128 | 109 |
129 TEST_F(StartupCustomizationDocumentTest, VPD) { | 110 TEST(StartupCustomizationDocumentTest, VPD) { |
130 customization_.set_vpd(kVPD); | 111 MockSystemAccess mock_system_access; |
131 EXPECT_TRUE(customization_.LoadManifestFromString(kGoodStartupManifest)); | 112 EXPECT_CALL(mock_system_access, |
132 EXPECT_EQ(customization_.initial_locale(), "ja"); | 113 GetMachineStatistic(std::string("hwid"), NotNull())) |
133 EXPECT_EQ(customization_.initial_timezone(), "Asia/Tokyo"); | 114 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), |
134 EXPECT_EQ(customization_.keyboard_layout(), "mozc-jp"); | 115 Return(true))); |
| 116 EXPECT_CALL(mock_system_access, |
| 117 GetMachineStatistic(std::string("initial_locale"), NotNull())) |
| 118 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("ja")), |
| 119 Return(true))); |
| 120 EXPECT_CALL(mock_system_access, |
| 121 GetMachineStatistic(std::string("initial_timezone"), NotNull())) |
| 122 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Asia/Tokyo")), |
| 123 Return(true))); |
| 124 EXPECT_CALL(mock_system_access, |
| 125 GetMachineStatistic(std::string("keyboard_layout"), NotNull())) |
| 126 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("mozc-jp")), |
| 127 Return(true))); |
| 128 StartupCustomizationDocument customization(&mock_system_access, |
| 129 kGoodStartupManifest); |
| 130 EXPECT_TRUE(customization.IsReady()); |
| 131 EXPECT_EQ(customization.initial_locale(), "ja"); |
| 132 EXPECT_EQ(customization.initial_timezone(), "Asia/Tokyo"); |
| 133 EXPECT_EQ(customization.keyboard_layout(), "mozc-jp"); |
135 } | 134 } |
136 | 135 |
137 TEST_F(StartupCustomizationDocumentTest, BadManifest) { | 136 TEST(StartupCustomizationDocumentTest, BadManifest) { |
138 EXPECT_FALSE(customization_.LoadManifestFromString(kBadManifest)); | 137 MockSystemAccess mock_system_access; |
| 138 StartupCustomizationDocument customization(&mock_system_access, kBadManifest); |
| 139 EXPECT_FALSE(customization.IsReady()); |
139 } | 140 } |
140 | 141 |
141 // ServicesCustomizationDocumentTest implementation. | 142 TEST(ServicesCustomizationDocumentTest, Basic) { |
142 class ServicesCustomizationDocumentTest : public testing::Test { | 143 ServicesCustomizationDocument customization(kGoodServicesManifest); |
143 protected: | 144 EXPECT_TRUE(customization.IsReady()); |
144 chromeos::ServicesCustomizationDocument customization_; | |
145 }; | |
146 | 145 |
147 TEST_F(ServicesCustomizationDocumentTest, Basic) { | 146 EXPECT_EQ(customization.GetInitialStartPage("en-US"), |
148 EXPECT_TRUE(customization_.LoadManifestFromString(kGoodServicesManifest)); | |
149 | |
150 EXPECT_EQ(customization_.GetInitialStartPage("en-US"), | |
151 "http://mario/promo"); | 147 "http://mario/promo"); |
152 EXPECT_EQ(customization_.GetInitialStartPage("ru-RU"), | 148 EXPECT_EQ(customization.GetInitialStartPage("ru-RU"), |
153 "http://mario/ru/promo"); | 149 "http://mario/ru/promo"); |
154 EXPECT_EQ(customization_.GetInitialStartPage("ja"), | 150 EXPECT_EQ(customization.GetInitialStartPage("ja"), |
155 "http://mario/global/promo"); | 151 "http://mario/global/promo"); |
156 | 152 |
157 | 153 EXPECT_EQ(customization.GetSupportPage("en-US"), |
158 EXPECT_EQ(customization_.GetSupportPage("en-US"), | |
159 "http://mario/us"); | 154 "http://mario/us"); |
160 EXPECT_EQ(customization_.GetSupportPage("ru-RU"), | 155 EXPECT_EQ(customization.GetSupportPage("ru-RU"), |
161 "http://mario/ru"); | 156 "http://mario/ru"); |
162 EXPECT_EQ(customization_.GetSupportPage("ja"), | 157 EXPECT_EQ(customization.GetSupportPage("ja"), |
163 "http://mario/global"); | 158 "http://mario/global"); |
164 } | 159 } |
165 | 160 |
166 TEST_F(ServicesCustomizationDocumentTest, BadManifest) { | 161 TEST(ServicesCustomizationDocumentTest, BadManifest) { |
167 EXPECT_FALSE(customization_.LoadManifestFromString(kBadManifest)); | 162 ServicesCustomizationDocument customization(kBadManifest); |
| 163 EXPECT_FALSE(customization.IsReady()); |
168 } | 164 } |
| 165 |
| 166 } // namespace chromeos |
OLD | NEW |