OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" | 11 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" |
12 #include "chrome/browser/extensions/external_provider_impl.h" | 12 #include "chrome/browser/extensions/external_provider_impl.h" |
13 #include "chrome/browser/prefs/browser_prefs.h" | 13 #include "chrome/browser/prefs/browser_prefs.h" |
14 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 14 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
15 #include "chrome/browser/prefs/pref_service_syncable.h" | 15 #include "chrome/browser/prefs/pref_service_syncable.h" |
16 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 16 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
17 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 17 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
20 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
21 #include "chromeos/network/network_handler.h" | 21 #include "chromeos/network/network_handler.h" |
22 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
23 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
24 #include "chromeos/system/mock_statistics_provider.h" | 24 #include "chromeos/system/fake_statistics_provider.h" |
25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
26 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
27 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
28 #include "extensions/common/manifest.h" | 28 #include "extensions/common/manifest.h" |
29 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
30 #include "net/http/http_status_code.h" | 30 #include "net/http/http_status_code.h" |
31 #include "net/url_request/test_url_fetcher_factory.h" | 31 #include "net/url_request/test_url_fetcher_factory.h" |
32 #include "net/url_request/url_request_status.h" | 32 #include "net/url_request/url_request_status.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 " }\n" | 94 " }\n" |
95 " }\n" | 95 " }\n" |
96 "}"; | 96 "}"; |
97 | 97 |
98 const char kDummyCustomizationID[] = "test-dummy"; | 98 const char kDummyCustomizationID[] = "test-dummy"; |
99 | 99 |
100 } // anonymous namespace | 100 } // anonymous namespace |
101 | 101 |
102 namespace chromeos { | 102 namespace chromeos { |
103 | 103 |
104 using ::testing::_; | |
105 using ::testing::DoAll; | 104 using ::testing::DoAll; |
106 using ::testing::NotNull; | 105 using ::testing::NotNull; |
107 using ::testing::Return; | 106 using ::testing::Return; |
108 using ::testing::SetArgumentPointee; | 107 using ::testing::SetArgumentPointee; |
108 using ::testing::_; | |
109 | 109 |
110 TEST(StartupCustomizationDocumentTest, Basic) { | 110 TEST(StartupCustomizationDocumentTest, Basic) { |
111 system::MockStatisticsProvider mock_statistics_provider; | 111 system::ScopedFakeStatisticsProvider fake_statistics_provider; |
112 EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(_, NotNull())) | 112 fake_statistics_provider.SetMachineStatistic("hardware_class", "Mario 12345"); |
113 .WillRepeatedly(Return(false)); | 113 StartupCustomizationDocument customization(&fake_statistics_provider, |
114 EXPECT_CALL(mock_statistics_provider, | |
115 GetMachineStatistic(std::string("hardware_class"), NotNull())) | |
116 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), | |
117 Return(true))); | |
118 StartupCustomizationDocument customization(&mock_statistics_provider, | |
119 kGoodStartupManifest); | 114 kGoodStartupManifest); |
120 EXPECT_EQ("ru-RU", customization.initial_locale()); | 115 EXPECT_EQ("ru-RU", customization.initial_locale()); |
121 EXPECT_EQ("Europe/Moscow", customization.initial_timezone()); | 116 EXPECT_EQ("Europe/Moscow", customization.initial_timezone()); |
122 EXPECT_EQ("xkb:ru::rus", customization.keyboard_layout()); | 117 EXPECT_EQ("xkb:ru::rus", customization.keyboard_layout()); |
123 | 118 |
124 EXPECT_EQ("file:///opt/oem/eula/en-US/eula.html", | 119 EXPECT_EQ("file:///opt/oem/eula/en-US/eula.html", |
125 customization.GetEULAPage("en-US")); | 120 customization.GetEULAPage("en-US")); |
126 EXPECT_EQ("file:///opt/oem/eula/ru-RU/eula.html", | 121 EXPECT_EQ("file:///opt/oem/eula/ru-RU/eula.html", |
127 customization.GetEULAPage("ru-RU")); | 122 customization.GetEULAPage("ru-RU")); |
128 EXPECT_EQ("file:///opt/oem/eula/en/eula.html", | 123 EXPECT_EQ("file:///opt/oem/eula/en/eula.html", |
129 customization.GetEULAPage("ja")); | 124 customization.GetEULAPage("ja")); |
130 } | 125 } |
131 | 126 |
132 TEST(StartupCustomizationDocumentTest, VPD) { | 127 TEST(StartupCustomizationDocumentTest, VPD) { |
133 system::MockStatisticsProvider mock_statistics_provider; | 128 system::ScopedFakeStatisticsProvider fake_statistics_provider; |
134 EXPECT_CALL(mock_statistics_provider, | 129 fake_statistics_provider.SetMachineStatistic("hardware_class", "Mario 12345"); |
135 GetMachineStatistic(std::string("hardware_class"), NotNull())) | 130 fake_statistics_provider.SetMachineStatistic("initial_locale", "ja"); |
136 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), | 131 fake_statistics_provider.SetMachineStatistic("initial_timezone", |
137 Return(true))); | 132 "Asia/Tokyo"); |
138 EXPECT_CALL(mock_statistics_provider, | 133 fake_statistics_provider.SetMachineStatistic("keyboard_layout", "mozc-jp"); |
139 GetMachineStatistic(std::string("initial_locale"), NotNull())) | 134 StartupCustomizationDocument customization(&fake_statistics_provider, |
140 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("ja")), | |
141 Return(true))); | |
142 EXPECT_CALL(mock_statistics_provider, | |
143 GetMachineStatistic(std::string("initial_timezone"), NotNull())) | |
144 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Asia/Tokyo")), | |
145 Return(true))); | |
146 EXPECT_CALL(mock_statistics_provider, | |
147 GetMachineStatistic(std::string("keyboard_layout"), NotNull())) | |
148 .WillOnce(DoAll(SetArgumentPointee<1>(std::string("mozc-jp")), | |
149 Return(true))); | |
150 StartupCustomizationDocument customization(&mock_statistics_provider, | |
151 kGoodStartupManifest); | 135 kGoodStartupManifest); |
152 EXPECT_TRUE(customization.IsReady()); | 136 EXPECT_TRUE(customization.IsReady()); |
153 EXPECT_EQ("ja", customization.initial_locale()); | 137 EXPECT_EQ("ja", customization.initial_locale()); |
154 EXPECT_EQ("Asia/Tokyo", customization.initial_timezone()); | 138 EXPECT_EQ("Asia/Tokyo", customization.initial_timezone()); |
155 EXPECT_EQ("mozc-jp", customization.keyboard_layout()); | 139 EXPECT_EQ("mozc-jp", customization.keyboard_layout()); |
stevenjb
2014/10/13 14:28:20
We don't appear to test 'hardware_class' or 'keybo
Mattias Nissler (ping if slow)
2014/10/13 15:01:07
Added comment for hardware_class. keyboard_layout
| |
156 } | 140 } |
157 | 141 |
158 TEST(StartupCustomizationDocumentTest, BadManifest) { | 142 TEST(StartupCustomizationDocumentTest, BadManifest) { |
159 system::MockStatisticsProvider mock_statistics_provider; | 143 system::ScopedFakeStatisticsProvider fake_statistics_provider; |
160 StartupCustomizationDocument customization(&mock_statistics_provider, | 144 StartupCustomizationDocument customization(&fake_statistics_provider, |
161 kBadManifest); | 145 kBadManifest); |
162 EXPECT_FALSE(customization.IsReady()); | 146 EXPECT_FALSE(customization.IsReady()); |
163 } | 147 } |
164 | 148 |
165 class TestURLFetcherCallback { | 149 class TestURLFetcherCallback { |
166 public: | 150 public: |
167 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( | 151 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( |
168 const GURL& url, | 152 const GURL& url, |
169 net::URLFetcherDelegate* d, | 153 net::URLFetcherDelegate* d, |
170 const std::string& response_data, | 154 const std::string& response_data, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 ServicesCustomizationDocumentTest() | 198 ServicesCustomizationDocumentTest() |
215 : factory_(NULL, | 199 : factory_(NULL, |
216 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, | 200 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, |
217 base::Unretained(&url_callback_))) { | 201 base::Unretained(&url_callback_))) { |
218 } | 202 } |
219 | 203 |
220 // testing::Test: | 204 // testing::Test: |
221 virtual void SetUp() override { | 205 virtual void SetUp() override { |
222 ServicesCustomizationDocument::InitializeForTesting(); | 206 ServicesCustomizationDocument::InitializeForTesting(); |
223 | 207 |
224 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull())) | |
225 .WillRepeatedly(Return(false)); | |
226 chromeos::system::StatisticsProvider::SetTestProvider( | |
227 &mock_statistics_provider_); | |
228 | |
229 DBusThreadManager::Initialize(); | 208 DBusThreadManager::Initialize(); |
230 NetworkHandler::Initialize(); | 209 NetworkHandler::Initialize(); |
231 RunUntilIdle(); | 210 RunUntilIdle(); |
232 const NetworkState* default_network = | 211 const NetworkState* default_network = |
233 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 212 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
234 std::string default_network_path = | 213 std::string default_network_path = |
235 default_network ? default_network->path() : ""; | 214 default_network ? default_network->path() : ""; |
236 | 215 |
237 NetworkPortalDetector::InitializeForTesting(&network_portal_detector_); | 216 NetworkPortalDetector::InitializeForTesting(&network_portal_detector_); |
238 NetworkPortalDetector::CaptivePortalState online_state; | 217 NetworkPortalDetector::CaptivePortalState online_state; |
239 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 218 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
240 online_state.response_code = 204; | 219 online_state.response_code = 204; |
241 std::string guid = | 220 std::string guid = |
242 default_network ? default_network->guid() : std::string(); | 221 default_network ? default_network->guid() : std::string(); |
243 network_portal_detector_.SetDefaultNetworkForTesting(guid); | 222 network_portal_detector_.SetDefaultNetworkForTesting(guid); |
244 if (!guid.empty()) { | 223 if (!guid.empty()) { |
245 network_portal_detector_.SetDetectionResultsForTesting( | 224 network_portal_detector_.SetDetectionResultsForTesting( |
246 guid, online_state); | 225 guid, online_state); |
247 } | 226 } |
248 | 227 |
249 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); | 228 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
250 ServicesCustomizationDocument::RegisterPrefs(local_state_.registry()); | 229 ServicesCustomizationDocument::RegisterPrefs(local_state_.registry()); |
251 } | 230 } |
252 | 231 |
253 virtual void TearDown() override { | 232 virtual void TearDown() override { |
254 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 233 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
255 NetworkHandler::Shutdown(); | 234 NetworkHandler::Shutdown(); |
256 DBusThreadManager::Shutdown(); | 235 DBusThreadManager::Shutdown(); |
257 NetworkPortalDetector::InitializeForTesting(NULL); | 236 NetworkPortalDetector::InitializeForTesting(NULL); |
258 chromeos::system::StatisticsProvider::SetTestProvider(NULL); | |
259 | 237 |
260 ServicesCustomizationDocument::ShutdownForTesting(); | 238 ServicesCustomizationDocument::ShutdownForTesting(); |
261 } | 239 } |
262 | 240 |
263 void RunUntilIdle() { | 241 void RunUntilIdle() { |
264 base::RunLoop().RunUntilIdle(); | 242 base::RunLoop().RunUntilIdle(); |
265 } | 243 } |
266 | 244 |
267 void AddCustomizationIdToVp(const std::string& id) { | 245 void AddCustomizationIdToVp(const std::string& id) { |
268 EXPECT_CALL(mock_statistics_provider_, | 246 fake_statistics_provider_.SetMachineStatistic(system::kCustomizationIdKey, |
269 GetMachineStatistic(system::kCustomizationIdKey, NotNull())) | 247 id); |
270 .WillOnce(DoAll(SetArgumentPointee<1>(id), | |
271 Return(true))); | |
272 } | 248 } |
273 | 249 |
274 void AddExpectedManifest(const std::string& id, | 250 void AddExpectedManifest(const std::string& id, |
275 const std::string& manifest) { | 251 const std::string& manifest) { |
276 GURL url(base::StringPrintf(ServicesCustomizationDocument::kManifestUrl, | 252 GURL url(base::StringPrintf(ServicesCustomizationDocument::kManifestUrl, |
277 id.c_str())); | 253 id.c_str())); |
278 factory_.SetFakeResponse(url, | 254 factory_.SetFakeResponse(url, |
279 manifest, | 255 manifest, |
280 net::HTTP_OK, | 256 net::HTTP_OK, |
281 net::URLRequestStatus::SUCCESS); | 257 net::URLRequestStatus::SUCCESS); |
(...skipping 20 matching lines...) Expand all Loading... | |
302 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | 278 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
303 new user_prefs::PrefRegistrySyncable); | 279 new user_prefs::PrefRegistrySyncable); |
304 scoped_ptr<PrefServiceSyncable> prefs( | 280 scoped_ptr<PrefServiceSyncable> prefs( |
305 factory.CreateSyncable(registry.get())); | 281 factory.CreateSyncable(registry.get())); |
306 chrome::RegisterUserProfilePrefs(registry.get()); | 282 chrome::RegisterUserProfilePrefs(registry.get()); |
307 profile_builder.SetPrefService(prefs.Pass()); | 283 profile_builder.SetPrefService(prefs.Pass()); |
308 return profile_builder.Build(); | 284 return profile_builder.Build(); |
309 } | 285 } |
310 | 286 |
311 private: | 287 private: |
312 system::MockStatisticsProvider mock_statistics_provider_; | 288 system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
313 content::TestBrowserThreadBundle thread_bundle_; | 289 content::TestBrowserThreadBundle thread_bundle_; |
314 TestingPrefServiceSimple local_state_; | 290 TestingPrefServiceSimple local_state_; |
315 TestURLFetcherCallback url_callback_; | 291 TestURLFetcherCallback url_callback_; |
316 net::FakeURLFetcherFactory factory_; | 292 net::FakeURLFetcherFactory factory_; |
317 NetworkPortalDetectorTestImpl network_portal_detector_; | 293 NetworkPortalDetectorTestImpl network_portal_detector_; |
318 }; | 294 }; |
319 | 295 |
320 TEST_F(ServicesCustomizationDocumentTest, Basic) { | 296 TEST_F(ServicesCustomizationDocumentTest, Basic) { |
321 AddCustomizationIdToVp(kDummyCustomizationID); | 297 AddCustomizationIdToVp(kDummyCustomizationID); |
322 AddExpectedManifest(kDummyCustomizationID, kGoodServicesManifest); | 298 AddExpectedManifest(kDummyCustomizationID, kGoodServicesManifest); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 EXPECT_CALL(visitor, OnExternalExtensionUpdateUrlFound(_, _, _, _, _, _)) | 452 EXPECT_CALL(visitor, OnExternalExtensionUpdateUrlFound(_, _, _, _, _, _)) |
477 .Times(0); | 453 .Times(0); |
478 EXPECT_CALL(visitor, OnExternalProviderReady(_)) | 454 EXPECT_CALL(visitor, OnExternalProviderReady(_)) |
479 .Times(1); | 455 .Times(1); |
480 | 456 |
481 RunUntilIdle(); | 457 RunUntilIdle(); |
482 EXPECT_TRUE(doc->IsReady()); | 458 EXPECT_TRUE(doc->IsReady()); |
483 } | 459 } |
484 | 460 |
485 } // namespace chromeos | 461 } // namespace chromeos |
OLD | NEW |