| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/policy/device_local_account.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <map> | 9 #include <map> |
| 10 #include <memory> |
| 9 #include <set> | 11 #include <set> |
| 10 #include <string> | 12 #include <string> |
| 11 #include <utility> | 13 #include <utility> |
| 12 #include <vector> | 14 #include <vector> |
| 13 | 15 |
| 14 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 15 #include "ash/system/chromeos/session/logout_confirmation_controller.h" | 17 #include "ash/system/chromeos/session/logout_confirmation_controller.h" |
| 16 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" | 18 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" |
| 17 #include "base/bind.h" | 19 #include "base/bind.h" |
| 18 #include "base/bind_helpers.h" | 20 #include "base/bind_helpers.h" |
| 19 #include "base/callback.h" | 21 #include "base/callback.h" |
| 20 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 21 #include "base/files/file_path.h" | 23 #include "base/files/file_path.h" |
| 22 #include "base/files/file_util.h" | 24 #include "base/files/file_util.h" |
| 23 #include "base/json/json_reader.h" | 25 #include "base/json/json_reader.h" |
| 24 #include "base/json/json_writer.h" | 26 #include "base/json/json_writer.h" |
| 25 #include "base/location.h" | 27 #include "base/location.h" |
| 26 #include "base/macros.h" | 28 #include "base/macros.h" |
| 29 #include "base/memory/ptr_util.h" |
| 27 #include "base/memory/ref_counted.h" | 30 #include "base/memory/ref_counted.h" |
| 28 #include "base/memory/scoped_ptr.h" | |
| 29 #include "base/message_loop/message_loop.h" | 31 #include "base/message_loop/message_loop.h" |
| 30 #include "base/path_service.h" | 32 #include "base/path_service.h" |
| 31 #include "base/run_loop.h" | 33 #include "base/run_loop.h" |
| 32 #include "base/sequenced_task_runner.h" | 34 #include "base/sequenced_task_runner.h" |
| 33 #include "base/strings/string_number_conversions.h" | 35 #include "base/strings/string_number_conversions.h" |
| 34 #include "base/strings/string_util.h" | 36 #include "base/strings/string_util.h" |
| 35 #include "base/strings/stringprintf.h" | 37 #include "base/strings/stringprintf.h" |
| 36 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
| 37 #include "base/synchronization/lock.h" | 39 #include "base/synchronization/lock.h" |
| 38 #include "base/thread_task_runner_handle.h" | 40 #include "base/thread_task_runner_handle.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 const std::string& relative_update_url); | 228 const std::string& relative_update_url); |
| 227 | 229 |
| 228 // When an update manifest is requested for the given extension |id|, indicate | 230 // When an update manifest is requested for the given extension |id|, indicate |
| 229 // that |version| of the extension can be downloaded at |crx_url|. | 231 // that |version| of the extension can be downloaded at |crx_url|. |
| 230 void AddUpdate(const std::string& id, | 232 void AddUpdate(const std::string& id, |
| 231 const std::string& version, | 233 const std::string& version, |
| 232 const GURL& crx_url); | 234 const GURL& crx_url); |
| 233 | 235 |
| 234 // This method must be registered with the test's EmbeddedTestServer to start | 236 // This method must be registered with the test's EmbeddedTestServer to start |
| 235 // serving update manifests. | 237 // serving update manifests. |
| 236 scoped_ptr<net::test_server::HttpResponse> HandleRequest( | 238 std::unique_ptr<net::test_server::HttpResponse> HandleRequest( |
| 237 const net::test_server::HttpRequest& request); | 239 const net::test_server::HttpRequest& request); |
| 238 | 240 |
| 239 private: | 241 private: |
| 240 struct Update { | 242 struct Update { |
| 241 public: | 243 public: |
| 242 Update(const std::string& version, const GURL& crx_url); | 244 Update(const std::string& version, const GURL& crx_url); |
| 243 Update(); | 245 Update(); |
| 244 | 246 |
| 245 std::string version; | 247 std::string version; |
| 246 GURL crx_url; | 248 GURL crx_url; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 : relative_update_url_(relative_update_url) { | 300 : relative_update_url_(relative_update_url) { |
| 299 } | 301 } |
| 300 | 302 |
| 301 void TestingUpdateManifestProvider::AddUpdate(const std::string& id, | 303 void TestingUpdateManifestProvider::AddUpdate(const std::string& id, |
| 302 const std::string& version, | 304 const std::string& version, |
| 303 const GURL& crx_url) { | 305 const GURL& crx_url) { |
| 304 base::AutoLock auto_lock(lock_); | 306 base::AutoLock auto_lock(lock_); |
| 305 updates_[id] = Update(version, crx_url); | 307 updates_[id] = Update(version, crx_url); |
| 306 } | 308 } |
| 307 | 309 |
| 308 scoped_ptr<net::test_server::HttpResponse> | 310 std::unique_ptr<net::test_server::HttpResponse> |
| 309 TestingUpdateManifestProvider::HandleRequest( | 311 TestingUpdateManifestProvider::HandleRequest( |
| 310 const net::test_server::HttpRequest& request) { | 312 const net::test_server::HttpRequest& request) { |
| 311 base::AutoLock auto_lock(lock_); | 313 base::AutoLock auto_lock(lock_); |
| 312 const GURL url("http://localhost" + request.relative_url); | 314 const GURL url("http://localhost" + request.relative_url); |
| 313 if (url.path() != relative_update_url_) | 315 if (url.path() != relative_update_url_) |
| 314 return scoped_ptr<net::test_server::HttpResponse>(); | 316 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 315 | 317 |
| 316 std::string content = kUpdateManifestHeader; | 318 std::string content = kUpdateManifestHeader; |
| 317 for (net::QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { | 319 for (net::QueryIterator it(url); !it.IsAtEnd(); it.Advance()) { |
| 318 if (it.GetKey() != "x") | 320 if (it.GetKey() != "x") |
| 319 continue; | 321 continue; |
| 320 // Extract the extension id from the subquery. Since GetValueForKeyInQuery() | 322 // Extract the extension id from the subquery. Since GetValueForKeyInQuery() |
| 321 // expects a complete URL, dummy scheme and host must be prepended. | 323 // expects a complete URL, dummy scheme and host must be prepended. |
| 322 std::string id; | 324 std::string id; |
| 323 net::GetValueForKeyInQuery(GURL("http://dummy?" + it.GetUnescapedValue()), | 325 net::GetValueForKeyInQuery(GURL("http://dummy?" + it.GetUnescapedValue()), |
| 324 "id", &id); | 326 "id", &id); |
| 325 UpdateMap::const_iterator entry = updates_.find(id); | 327 UpdateMap::const_iterator entry = updates_.find(id); |
| 326 if (entry != updates_.end()) { | 328 if (entry != updates_.end()) { |
| 327 content += base::StringPrintf(kUpdateManifestTemplate, | 329 content += base::StringPrintf(kUpdateManifestTemplate, |
| 328 id.c_str(), | 330 id.c_str(), |
| 329 entry->second.crx_url.spec().c_str(), | 331 entry->second.crx_url.spec().c_str(), |
| 330 entry->second.version.c_str()); | 332 entry->second.version.c_str()); |
| 331 } | 333 } |
| 332 } | 334 } |
| 333 content += kUpdateManifestFooter; | 335 content += kUpdateManifestFooter; |
| 334 scoped_ptr<net::test_server::BasicHttpResponse> | 336 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 335 http_response(new net::test_server::BasicHttpResponse); | 337 new net::test_server::BasicHttpResponse); |
| 336 http_response->set_code(net::HTTP_OK); | 338 http_response->set_code(net::HTTP_OK); |
| 337 http_response->set_content(content); | 339 http_response->set_content(content); |
| 338 http_response->set_content_type("text/xml"); | 340 http_response->set_content_type("text/xml"); |
| 339 return std::move(http_response); | 341 return std::move(http_response); |
| 340 } | 342 } |
| 341 | 343 |
| 342 TestingUpdateManifestProvider::~TestingUpdateManifestProvider() { | 344 TestingUpdateManifestProvider::~TestingUpdateManifestProvider() { |
| 343 } | 345 } |
| 344 | 346 |
| 345 DictionaryPrefValueWaiter::DictionaryPrefValueWaiter( | 347 DictionaryPrefValueWaiter::DictionaryPrefValueWaiter( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 376 } | 378 } |
| 377 | 379 |
| 378 bool DoesInstallFailureReferToId(const std::string& id, | 380 bool DoesInstallFailureReferToId(const std::string& id, |
| 379 const content::NotificationSource& source, | 381 const content::NotificationSource& source, |
| 380 const content::NotificationDetails& details) { | 382 const content::NotificationDetails& details) { |
| 381 return content::Details<const extensions::CrxInstallError>(details) | 383 return content::Details<const extensions::CrxInstallError>(details) |
| 382 ->message() | 384 ->message() |
| 383 .find(base::UTF8ToUTF16(id)) != base::string16::npos; | 385 .find(base::UTF8ToUTF16(id)) != base::string16::npos; |
| 384 } | 386 } |
| 385 | 387 |
| 386 scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher( | 388 std::unique_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher( |
| 387 scoped_refptr<base::SequencedTaskRunner> task_runner, | 389 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 388 const base::Closure& callback, | 390 const base::Closure& callback, |
| 389 const GURL& url, | 391 const GURL& url, |
| 390 net::URLFetcherDelegate* delegate, | 392 net::URLFetcherDelegate* delegate, |
| 391 const std::string& response_data, | 393 const std::string& response_data, |
| 392 net::HttpStatusCode response_code, | 394 net::HttpStatusCode response_code, |
| 393 net::URLRequestStatus::Status status) { | 395 net::URLRequestStatus::Status status) { |
| 394 task_runner->PostTask(FROM_HERE, callback); | 396 task_runner->PostTask(FROM_HERE, callback); |
| 395 return make_scoped_ptr(new net::FakeURLFetcher( | 397 return base::WrapUnique(new net::FakeURLFetcher(url, delegate, response_data, |
| 396 url, delegate, response_data, response_code, status)); | 398 response_code, status)); |
| 397 } | 399 } |
| 398 | 400 |
| 399 bool IsSessionStarted() { | 401 bool IsSessionStarted() { |
| 400 return user_manager::UserManager::Get()->IsSessionStarted(); | 402 return user_manager::UserManager::Get()->IsSessionStarted(); |
| 401 } | 403 } |
| 402 | 404 |
| 403 void PolicyChangedCallback(const base::Closure& callback, | 405 void PolicyChangedCallback(const base::Closure& callback, |
| 404 const base::Value* old_value, | 406 const base::Value* old_value, |
| 405 const base::Value* new_value) { | 407 const base::Value* new_value) { |
| 406 callback.Run(); | 408 callback.Run(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 418 base::StringPrintf(kPublicSessionInputMethodIDTemplate, | 420 base::StringPrintf(kPublicSessionInputMethodIDTemplate, |
| 419 chromeos::extension_ime_util::kXkbExtensionId)), | 421 chromeos::extension_ime_util::kXkbExtensionId)), |
| 420 contents_(NULL) { | 422 contents_(NULL) { |
| 421 set_exit_when_last_browser_closes(false); | 423 set_exit_when_last_browser_closes(false); |
| 422 } | 424 } |
| 423 | 425 |
| 424 ~DeviceLocalAccountTest() override {} | 426 ~DeviceLocalAccountTest() override {} |
| 425 | 427 |
| 426 void SetUp() override { | 428 void SetUp() override { |
| 427 // Configure and start the test server. | 429 // Configure and start the test server. |
| 428 scoped_ptr<crypto::RSAPrivateKey> signing_key( | 430 std::unique_ptr<crypto::RSAPrivateKey> signing_key( |
| 429 PolicyBuilder::CreateTestSigningKey()); | 431 PolicyBuilder::CreateTestSigningKey()); |
| 430 ASSERT_TRUE(test_server_.SetSigningKeyAndSignature( | 432 ASSERT_TRUE(test_server_.SetSigningKeyAndSignature( |
| 431 signing_key.get(), PolicyBuilder::GetTestSigningKeySignature())); | 433 signing_key.get(), PolicyBuilder::GetTestSigningKeySignature())); |
| 432 signing_key.reset(); | 434 signing_key.reset(); |
| 433 test_server_.RegisterClient(PolicyBuilder::kFakeToken, | 435 test_server_.RegisterClient(PolicyBuilder::kFakeToken, |
| 434 PolicyBuilder::kFakeDeviceId); | 436 PolicyBuilder::kFakeDeviceId); |
| 435 ASSERT_TRUE(test_server_.Start()); | 437 ASSERT_TRUE(test_server_.Start()); |
| 436 | 438 |
| 437 BrowserList::AddObserver(this); | 439 BrowserList::AddObserver(this); |
| 438 | 440 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 DeviceLocalAccount::TYPE_PUBLIC_SESSION)); | 784 DeviceLocalAccount::TYPE_PUBLIC_SESSION)); |
| 783 const AccountId account_id_2_ = | 785 const AccountId account_id_2_ = |
| 784 AccountId::FromUserEmail(GenerateDeviceLocalAccountUserId( | 786 AccountId::FromUserEmail(GenerateDeviceLocalAccountUserId( |
| 785 kAccountId2, | 787 kAccountId2, |
| 786 DeviceLocalAccount::TYPE_PUBLIC_SESSION)); | 788 DeviceLocalAccount::TYPE_PUBLIC_SESSION)); |
| 787 const std::string public_session_input_method_id_; | 789 const std::string public_session_input_method_id_; |
| 788 | 790 |
| 789 std::string initial_locale_; | 791 std::string initial_locale_; |
| 790 std::string initial_language_; | 792 std::string initial_language_; |
| 791 | 793 |
| 792 scoped_ptr<base::RunLoop> run_loop_; | 794 std::unique_ptr<base::RunLoop> run_loop_; |
| 793 | 795 |
| 794 UserPolicyBuilder device_local_account_policy_; | 796 UserPolicyBuilder device_local_account_policy_; |
| 795 LocalPolicyTestServer test_server_; | 797 LocalPolicyTestServer test_server_; |
| 796 | 798 |
| 797 content::WebContents* contents_; | 799 content::WebContents* contents_; |
| 798 | 800 |
| 799 private: | 801 private: |
| 800 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountTest); | 802 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountTest); |
| 801 }; | 803 }; |
| 802 | 804 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 ->browser_policy_connector_chromeos() | 1222 ->browser_policy_connector_chromeos() |
| 1221 ->GetDeviceLocalAccountPolicyService() | 1223 ->GetDeviceLocalAccountPolicyService() |
| 1222 ->GetBrokerForUser(account_id_1_.GetUserEmail()); | 1224 ->GetBrokerForUser(account_id_1_.GetUserEmail()); |
| 1223 ASSERT_TRUE(broker); | 1225 ASSERT_TRUE(broker); |
| 1224 chromeos::ExternalCache* cache = | 1226 chromeos::ExternalCache* cache = |
| 1225 broker->extension_loader()->GetExternalCacheForTesting(); | 1227 broker->extension_loader()->GetExternalCacheForTesting(); |
| 1226 ASSERT_TRUE(cache); | 1228 ASSERT_TRUE(cache); |
| 1227 EXPECT_FALSE(cache->GetExtension(kGoodExtensionID, NULL, NULL)); | 1229 EXPECT_FALSE(cache->GetExtension(kGoodExtensionID, NULL, NULL)); |
| 1228 } | 1230 } |
| 1229 | 1231 |
| 1230 static void OnPutExtension(scoped_ptr<base::RunLoop>* run_loop, | 1232 static void OnPutExtension(std::unique_ptr<base::RunLoop>* run_loop, |
| 1231 const base::FilePath& file_path, | 1233 const base::FilePath& file_path, |
| 1232 bool file_ownership_passed) { | 1234 bool file_ownership_passed) { |
| 1233 ASSERT_TRUE(*run_loop); | 1235 ASSERT_TRUE(*run_loop); |
| 1234 (*run_loop)->Quit(); | 1236 (*run_loop)->Quit(); |
| 1235 } | 1237 } |
| 1236 | 1238 |
| 1237 static void OnExtensionCacheImplInitialized( | 1239 static void OnExtensionCacheImplInitialized( |
| 1238 scoped_ptr<base::RunLoop>* run_loop) { | 1240 std::unique_ptr<base::RunLoop>* run_loop) { |
| 1239 ASSERT_TRUE(*run_loop); | 1241 ASSERT_TRUE(*run_loop); |
| 1240 (*run_loop)->Quit(); | 1242 (*run_loop)->Quit(); |
| 1241 } | 1243 } |
| 1242 | 1244 |
| 1243 static void CreateFile(const base::FilePath& file, | 1245 static void CreateFile(const base::FilePath& file, |
| 1244 size_t size, | 1246 size_t size, |
| 1245 const base::Time& timestamp) { | 1247 const base::Time& timestamp) { |
| 1246 std::string data(size, 0); | 1248 std::string data(size, 0); |
| 1247 EXPECT_EQ(base::WriteFile(file, data.data(), data.size()), int(size)); | 1249 EXPECT_EQ(base::WriteFile(file, data.data(), data.size()), int(size)); |
| 1248 EXPECT_TRUE(base::TouchFile(file, timestamp, timestamp)); | 1250 EXPECT_TRUE(base::TouchFile(file, timestamp, timestamp)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1263 base::Bind(&TestingUpdateManifestProvider::HandleRequest, | 1265 base::Bind(&TestingUpdateManifestProvider::HandleRequest, |
| 1264 testing_update_manifest_provider)); | 1266 testing_update_manifest_provider)); |
| 1265 // Create and initialize local cache. | 1267 // Create and initialize local cache. |
| 1266 base::ScopedTempDir cache_dir; | 1268 base::ScopedTempDir cache_dir; |
| 1267 EXPECT_TRUE(cache_dir.CreateUniqueTempDir()); | 1269 EXPECT_TRUE(cache_dir.CreateUniqueTempDir()); |
| 1268 const base::FilePath impl_path = cache_dir.path(); | 1270 const base::FilePath impl_path = cache_dir.path(); |
| 1269 EXPECT_TRUE(base::CreateDirectory(impl_path)); | 1271 EXPECT_TRUE(base::CreateDirectory(impl_path)); |
| 1270 CreateFile(impl_path.Append( | 1272 CreateFile(impl_path.Append( |
| 1271 extensions::LocalExtensionCache::kCacheReadyFlagFileName), | 1273 extensions::LocalExtensionCache::kCacheReadyFlagFileName), |
| 1272 0, base::Time::Now()); | 1274 0, base::Time::Now()); |
| 1273 extensions::ExtensionCacheImpl cache_impl(make_scoped_ptr( | 1275 extensions::ExtensionCacheImpl cache_impl(base::WrapUnique( |
| 1274 new extensions::ChromeOSExtensionCacheDelegate(impl_path))); | 1276 new extensions::ChromeOSExtensionCacheDelegate(impl_path))); |
| 1275 scoped_ptr<base::RunLoop> run_loop; | 1277 std::unique_ptr<base::RunLoop> run_loop; |
| 1276 run_loop.reset(new base::RunLoop); | 1278 run_loop.reset(new base::RunLoop); |
| 1277 cache_impl.Start(base::Bind(&OnExtensionCacheImplInitialized, &run_loop)); | 1279 cache_impl.Start(base::Bind(&OnExtensionCacheImplInitialized, &run_loop)); |
| 1278 run_loop->Run(); | 1280 run_loop->Run(); |
| 1279 | 1281 |
| 1280 // Put extension in the local cache. | 1282 // Put extension in the local cache. |
| 1281 base::ScopedTempDir temp_dir; | 1283 base::ScopedTempDir temp_dir; |
| 1282 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | 1284 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1283 const base::FilePath temp_path = temp_dir.path(); | 1285 const base::FilePath temp_path = temp_dir.path(); |
| 1284 EXPECT_TRUE(base::CreateDirectory(temp_path)); | 1286 EXPECT_TRUE(base::CreateDirectory(temp_path)); |
| 1285 const base::FilePath temp_file = | 1287 const base::FilePath temp_file = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 // prevented from seeing the policy change. | 1348 // prevented from seeing the policy change. |
| 1347 reinterpret_cast<chromeos::ChromeUserManagerImpl*>( | 1349 reinterpret_cast<chromeos::ChromeUserManagerImpl*>( |
| 1348 user_manager::UserManager::Get())->StopPolicyObserverForTesting(); | 1350 user_manager::UserManager::Get())->StopPolicyObserverForTesting(); |
| 1349 | 1351 |
| 1350 UploadDeviceLocalAccountPolicy(); | 1352 UploadDeviceLocalAccountPolicy(); |
| 1351 AddPublicSessionToDevicePolicy(kAccountId1); | 1353 AddPublicSessionToDevicePolicy(kAccountId1); |
| 1352 | 1354 |
| 1353 WaitForPolicy(); | 1355 WaitForPolicy(); |
| 1354 | 1356 |
| 1355 // Start serving external data at |kExternalDataURL|. | 1357 // Start serving external data at |kExternalDataURL|. |
| 1356 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop); | 1358 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop); |
| 1357 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory( | 1359 std::unique_ptr<net::FakeURLFetcherFactory> fetcher_factory( |
| 1358 new net::FakeURLFetcherFactory( | 1360 new net::FakeURLFetcherFactory( |
| 1359 NULL, base::Bind(&RunCallbackAndReturnFakeURLFetcher, | 1361 NULL, base::Bind(&RunCallbackAndReturnFakeURLFetcher, |
| 1360 base::ThreadTaskRunnerHandle::Get(), | 1362 base::ThreadTaskRunnerHandle::Get(), |
| 1361 run_loop->QuitClosure()))); | 1363 run_loop->QuitClosure()))); |
| 1362 fetcher_factory->SetFakeResponse(GURL(kExternalDataURL), | 1364 fetcher_factory->SetFakeResponse(GURL(kExternalDataURL), |
| 1363 kExternalData, | 1365 kExternalData, |
| 1364 net::HTTP_OK, | 1366 net::HTTP_OK, |
| 1365 net::URLRequestStatus::SUCCESS); | 1367 net::URLRequestStatus::SUCCESS); |
| 1366 | 1368 |
| 1367 // Specify an external data reference for the key::kUserAvatarImage policy. | 1369 // Specify an external data reference for the key::kUserAvatarImage policy. |
| 1368 scoped_ptr<base::DictionaryValue> metadata = | 1370 std::unique_ptr<base::DictionaryValue> metadata = |
| 1369 test::ConstructExternalDataReference(kExternalDataURL, kExternalData); | 1371 test::ConstructExternalDataReference(kExternalDataURL, kExternalData); |
| 1370 std::string policy; | 1372 std::string policy; |
| 1371 base::JSONWriter::Write(*metadata, &policy); | 1373 base::JSONWriter::Write(*metadata, &policy); |
| 1372 device_local_account_policy_.payload().mutable_useravatarimage()->set_value( | 1374 device_local_account_policy_.payload().mutable_useravatarimage()->set_value( |
| 1373 policy); | 1375 policy); |
| 1374 UploadAndInstallDeviceLocalAccountPolicy(); | 1376 UploadAndInstallDeviceLocalAccountPolicy(); |
| 1375 policy::BrowserPolicyConnectorChromeOS* connector = | 1377 policy::BrowserPolicyConnectorChromeOS* connector = |
| 1376 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 1378 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 1377 DeviceLocalAccountPolicyBroker* broker = | 1379 DeviceLocalAccountPolicyBroker* broker = |
| 1378 connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( | 1380 connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1389 | 1391 |
| 1390 const PolicyMap::Entry* policy_entry = | 1392 const PolicyMap::Entry* policy_entry = |
| 1391 broker->core()->store()->policy_map().Get(key::kUserAvatarImage); | 1393 broker->core()->store()->policy_map().Get(key::kUserAvatarImage); |
| 1392 ASSERT_TRUE(policy_entry); | 1394 ASSERT_TRUE(policy_entry); |
| 1393 ASSERT_TRUE(policy_entry->external_data_fetcher); | 1395 ASSERT_TRUE(policy_entry->external_data_fetcher); |
| 1394 | 1396 |
| 1395 // Retrieve the external data. Although the data is no longer being served at | 1397 // Retrieve the external data. Although the data is no longer being served at |
| 1396 // |kExternalDataURL|, the retrieval should succeed because the data has been | 1398 // |kExternalDataURL|, the retrieval should succeed because the data has been |
| 1397 // cached. | 1399 // cached. |
| 1398 run_loop.reset(new base::RunLoop); | 1400 run_loop.reset(new base::RunLoop); |
| 1399 scoped_ptr<std::string> fetched_external_data; | 1401 std::unique_ptr<std::string> fetched_external_data; |
| 1400 policy_entry->external_data_fetcher->Fetch(base::Bind( | 1402 policy_entry->external_data_fetcher->Fetch(base::Bind( |
| 1401 &test::ExternalDataFetchCallback, | 1403 &test::ExternalDataFetchCallback, |
| 1402 &fetched_external_data, | 1404 &fetched_external_data, |
| 1403 run_loop->QuitClosure())); | 1405 run_loop->QuitClosure())); |
| 1404 run_loop->Run(); | 1406 run_loop->Run(); |
| 1405 | 1407 |
| 1406 ASSERT_TRUE(fetched_external_data); | 1408 ASSERT_TRUE(fetched_external_data); |
| 1407 EXPECT_EQ(kExternalData, *fetched_external_data); | 1409 EXPECT_EQ(kExternalData, *fetched_external_data); |
| 1408 | 1410 |
| 1409 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); | 1411 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( | 1470 connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( |
| 1469 account_id_1_.GetUserEmail()); | 1471 account_id_1_.GetUserEmail()); |
| 1470 ASSERT_TRUE(broker); | 1472 ASSERT_TRUE(broker); |
| 1471 | 1473 |
| 1472 run_loop_.reset(new base::RunLoop); | 1474 run_loop_.reset(new base::RunLoop); |
| 1473 user_manager::UserManager::Get()->AddObserver(this); | 1475 user_manager::UserManager::Get()->AddObserver(this); |
| 1474 broker->core()->store()->Load(); | 1476 broker->core()->store()->Load(); |
| 1475 run_loop_->Run(); | 1477 run_loop_->Run(); |
| 1476 user_manager::UserManager::Get()->RemoveObserver(this); | 1478 user_manager::UserManager::Get()->RemoveObserver(this); |
| 1477 | 1479 |
| 1478 scoped_ptr<gfx::ImageSkia> policy_image = chromeos::test::ImageLoader( | 1480 std::unique_ptr<gfx::ImageSkia> policy_image = |
| 1479 test_dir.Append(chromeos::test::kUserAvatarImage1RelativePath)).Load(); | 1481 chromeos::test::ImageLoader( |
| 1482 test_dir.Append(chromeos::test::kUserAvatarImage1RelativePath)) |
| 1483 .Load(); |
| 1480 ASSERT_TRUE(policy_image); | 1484 ASSERT_TRUE(policy_image); |
| 1481 | 1485 |
| 1482 const user_manager::User* user = | 1486 const user_manager::User* user = |
| 1483 user_manager::UserManager::Get()->FindUser(account_id_1_); | 1487 user_manager::UserManager::Get()->FindUser(account_id_1_); |
| 1484 ASSERT_TRUE(user); | 1488 ASSERT_TRUE(user); |
| 1485 | 1489 |
| 1486 base::FilePath user_data_dir; | 1490 base::FilePath user_data_dir; |
| 1487 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 1491 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 1488 const base::FilePath saved_image_path = | 1492 const base::FilePath saved_image_path = |
| 1489 user_data_dir.Append(account_id_1_.GetUserEmail()).AddExtension("jpg"); | 1493 user_data_dir.Append(account_id_1_.GetUserEmail()).AddExtension("jpg"); |
| 1490 | 1494 |
| 1491 EXPECT_FALSE(user->HasDefaultImage()); | 1495 EXPECT_FALSE(user->HasDefaultImage()); |
| 1492 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); | 1496 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, user->image_index()); |
| 1493 EXPECT_TRUE(chromeos::test::AreImagesEqual(*policy_image, user->GetImage())); | 1497 EXPECT_TRUE(chromeos::test::AreImagesEqual(*policy_image, user->GetImage())); |
| 1494 const base::DictionaryValue* images_pref = | 1498 const base::DictionaryValue* images_pref = |
| 1495 g_browser_process->local_state()->GetDictionary("user_image_info"); | 1499 g_browser_process->local_state()->GetDictionary("user_image_info"); |
| 1496 ASSERT_TRUE(images_pref); | 1500 ASSERT_TRUE(images_pref); |
| 1497 const base::DictionaryValue* image_properties; | 1501 const base::DictionaryValue* image_properties; |
| 1498 ASSERT_TRUE(images_pref->GetDictionaryWithoutPathExpansion( | 1502 ASSERT_TRUE(images_pref->GetDictionaryWithoutPathExpansion( |
| 1499 account_id_1_.GetUserEmail(), &image_properties)); | 1503 account_id_1_.GetUserEmail(), &image_properties)); |
| 1500 int image_index; | 1504 int image_index; |
| 1501 std::string image_path; | 1505 std::string image_path; |
| 1502 ASSERT_TRUE(image_properties->GetInteger("index", &image_index)); | 1506 ASSERT_TRUE(image_properties->GetInteger("index", &image_index)); |
| 1503 ASSERT_TRUE(image_properties->GetString("path", &image_path)); | 1507 ASSERT_TRUE(image_properties->GetString("path", &image_path)); |
| 1504 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, image_index); | 1508 EXPECT_EQ(user_manager::User::USER_IMAGE_EXTERNAL, image_index); |
| 1505 EXPECT_EQ(saved_image_path.value(), image_path); | 1509 EXPECT_EQ(saved_image_path.value(), image_path); |
| 1506 | 1510 |
| 1507 scoped_ptr<gfx::ImageSkia> saved_image = | 1511 std::unique_ptr<gfx::ImageSkia> saved_image = |
| 1508 chromeos::test::ImageLoader(saved_image_path).Load(); | 1512 chromeos::test::ImageLoader(saved_image_path).Load(); |
| 1509 ASSERT_TRUE(saved_image); | 1513 ASSERT_TRUE(saved_image); |
| 1510 | 1514 |
| 1511 // Check image dimensions. Images can't be compared since JPEG is lossy. | 1515 // Check image dimensions. Images can't be compared since JPEG is lossy. |
| 1512 EXPECT_EQ(policy_image->width(), saved_image->width()); | 1516 EXPECT_EQ(policy_image->width(), saved_image->width()); |
| 1513 EXPECT_EQ(policy_image->height(), saved_image->height()); | 1517 EXPECT_EQ(policy_image->height(), saved_image->height()); |
| 1514 } | 1518 } |
| 1515 | 1519 |
| 1516 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LastWindowClosedLogoutReminder) { | 1520 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LastWindowClosedLogoutReminder) { |
| 1517 UploadAndInstallDeviceLocalAccountPolicy(); | 1521 UploadAndInstallDeviceLocalAccountPolicy(); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 " .getPodWithUsername_('%s').querySelector('.language-select');" | 1807 " .getPodWithUsername_('%s').querySelector('.language-select');" |
| 1804 "var locales = [];" | 1808 "var locales = [];" |
| 1805 "for (var i = 0; i < languageSelect.length; ++i)" | 1809 "for (var i = 0; i < languageSelect.length; ++i)" |
| 1806 " locales.push(languageSelect.options[i].value);" | 1810 " locales.push(languageSelect.options[i].value);" |
| 1807 "domAutomationController.send(JSON.stringify(locales));", | 1811 "domAutomationController.send(JSON.stringify(locales));", |
| 1808 account_id_1_.Serialize().c_str()); | 1812 account_id_1_.Serialize().c_str()); |
| 1809 std::string json; | 1813 std::string json; |
| 1810 ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents_, | 1814 ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents_, |
| 1811 get_locale_list, | 1815 get_locale_list, |
| 1812 &json)); | 1816 &json)); |
| 1813 scoped_ptr<base::Value> value_ptr = base::JSONReader::Read(json); | 1817 std::unique_ptr<base::Value> value_ptr = base::JSONReader::Read(json); |
| 1814 const base::ListValue* locales = NULL; | 1818 const base::ListValue* locales = NULL; |
| 1815 ASSERT_TRUE(value_ptr); | 1819 ASSERT_TRUE(value_ptr); |
| 1816 ASSERT_TRUE(value_ptr->GetAsList(&locales)); | 1820 ASSERT_TRUE(value_ptr->GetAsList(&locales)); |
| 1817 EXPECT_LT(arraysize(kRecommendedLocales1), locales->GetSize()); | 1821 EXPECT_LT(arraysize(kRecommendedLocales1), locales->GetSize()); |
| 1818 | 1822 |
| 1819 // Verify that the list starts with the recommended locales, in correct order. | 1823 // Verify that the list starts with the recommended locales, in correct order. |
| 1820 for (size_t i = 0; i < arraysize(kRecommendedLocales1); ++i) { | 1824 for (size_t i = 0; i < arraysize(kRecommendedLocales1); ++i) { |
| 1821 std::string locale; | 1825 std::string locale; |
| 1822 EXPECT_TRUE(locales->GetString(i, &locale)); | 1826 EXPECT_TRUE(locales->GetString(i, &locale)); |
| 1823 EXPECT_EQ(kRecommendedLocales1[i], locale); | 1827 EXPECT_EQ(kRecommendedLocales1[i], locale); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2379 " domAutomationController.send(JSON.stringify(status));" | 2383 " domAutomationController.send(JSON.stringify(status));" |
| 2380 " observer.disconnect();" | 2384 " observer.disconnect();" |
| 2381 " return true;" | 2385 " return true;" |
| 2382 "}" | 2386 "}" |
| 2383 "var observer = new MutationObserver(SendReplyIfDownloadDone);" | 2387 "var observer = new MutationObserver(SendReplyIfDownloadDone);" |
| 2384 "if (!SendReplyIfDownloadDone()) {" | 2388 "if (!SendReplyIfDownloadDone()) {" |
| 2385 " var options = { attributes: true, attributeFilter: [ 'class' ] };" | 2389 " var options = { attributes: true, attributeFilter: [ 'class' ] };" |
| 2386 " observer.observe(screenElement, options);" | 2390 " observer.observe(screenElement, options);" |
| 2387 "}", | 2391 "}", |
| 2388 &json)); | 2392 &json)); |
| 2389 scoped_ptr<base::Value> value_ptr = base::JSONReader::Read(json); | 2393 std::unique_ptr<base::Value> value_ptr = base::JSONReader::Read(json); |
| 2390 const base::DictionaryValue* status = NULL; | 2394 const base::DictionaryValue* status = NULL; |
| 2391 ASSERT_TRUE(value_ptr); | 2395 ASSERT_TRUE(value_ptr); |
| 2392 ASSERT_TRUE(value_ptr->GetAsDictionary(&status)); | 2396 ASSERT_TRUE(value_ptr->GetAsDictionary(&status)); |
| 2393 std::string heading; | 2397 std::string heading; |
| 2394 EXPECT_TRUE(status->GetString("heading", &heading)); | 2398 EXPECT_TRUE(status->GetString("heading", &heading)); |
| 2395 std::string subheading; | 2399 std::string subheading; |
| 2396 EXPECT_TRUE(status->GetString("subheading", &subheading)); | 2400 EXPECT_TRUE(status->GetString("subheading", &subheading)); |
| 2397 std::string content_heading; | 2401 std::string content_heading; |
| 2398 EXPECT_TRUE(status->GetString("contentHeading", &content_heading)); | 2402 EXPECT_TRUE(status->GetString("contentHeading", &content_heading)); |
| 2399 std::string content; | 2403 std::string content; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2440 ASSERT_TRUE(content::ExecuteScript(contents_, | 2444 ASSERT_TRUE(content::ExecuteScript(contents_, |
| 2441 "$('tos-accept-button').click();")); | 2445 "$('tos-accept-button').click();")); |
| 2442 | 2446 |
| 2443 WaitForSessionStart(); | 2447 WaitForSessionStart(); |
| 2444 } | 2448 } |
| 2445 | 2449 |
| 2446 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance, | 2450 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance, |
| 2447 TermsOfServiceDownloadTest, testing::Bool()); | 2451 TermsOfServiceDownloadTest, testing::Bool()); |
| 2448 | 2452 |
| 2449 } // namespace policy | 2453 } // namespace policy |
| OLD | NEW |