| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const char kWhitelistFile[] = "whitelist.json"; | 44 const char kWhitelistFile[] = "whitelist.json"; |
| 45 | 45 |
| 46 std::string CrxIdToHashToCrxId(const std::string& kCrxId) { | 46 std::string CrxIdToHashToCrxId(const std::string& kCrxId) { |
| 47 CrxComponent component; | 47 CrxComponent component; |
| 48 component.pk_hash = | 48 component.pk_hash = |
| 49 SupervisedUserWhitelistInstaller::GetHashFromCrxId(kCrxId); | 49 SupervisedUserWhitelistInstaller::GetHashFromCrxId(kCrxId); |
| 50 EXPECT_EQ(16u, component.pk_hash.size()); | 50 EXPECT_EQ(16u, component.pk_hash.size()); |
| 51 return GetCrxComponentID(component); | 51 return GetCrxComponentID(component); |
| 52 } | 52 } |
| 53 | 53 |
| 54 std::string JsonToString(const base::DictionaryValue* dict) { | 54 std::string JsonToString(const base::DictionaryValue& dict) { |
| 55 std::string json; | 55 std::string json; |
| 56 base::JSONWriter::Write(dict, &json); | 56 base::JSONWriter::Write(dict, &json); |
| 57 return json; | 57 return json; |
| 58 } | 58 } |
| 59 | 59 |
| 60 class MockComponentUpdateService : public ComponentUpdateService, | 60 class MockComponentUpdateService : public ComponentUpdateService, |
| 61 public OnDemandUpdater { | 61 public OnDemandUpdater { |
| 62 public: | 62 public: |
| 63 MockComponentUpdateService( | 63 MockComponentUpdateService( |
| 64 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 64 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 component_update_service_.registered_component(); | 303 component_update_service_.registered_component(); |
| 304 ASSERT_TRUE(component); | 304 ASSERT_TRUE(component); |
| 305 ASSERT_TRUE(component->installer->Install(manifest_, unpacked_path)); | 305 ASSERT_TRUE(component->installer->Install(manifest_, unpacked_path)); |
| 306 observer.Wait(); | 306 observer.Wait(); |
| 307 EXPECT_EQ(whitelist_path_.value(), observer.whitelist_path().value()); | 307 EXPECT_EQ(whitelist_path_.value(), observer.whitelist_path().value()); |
| 308 | 308 |
| 309 std::string whitelist_contents; | 309 std::string whitelist_contents; |
| 310 ASSERT_TRUE(base::ReadFileToString(whitelist_path_, &whitelist_contents)); | 310 ASSERT_TRUE(base::ReadFileToString(whitelist_path_, &whitelist_contents)); |
| 311 EXPECT_EQ(kWhitelistContents, whitelist_contents); | 311 EXPECT_EQ(kWhitelistContents, whitelist_contents); |
| 312 | 312 |
| 313 EXPECT_EQ(JsonToString(&pref_), | 313 EXPECT_EQ(JsonToString(pref_), |
| 314 JsonToString(local_state_.GetDictionary( | 314 JsonToString(*local_state_.GetDictionary( |
| 315 prefs::kRegisteredSupervisedUserWhitelists))); | 315 prefs::kRegisteredSupervisedUserWhitelists))); |
| 316 } | 316 } |
| 317 | 317 |
| 318 TEST_F(SupervisedUserWhitelistInstallerTest, | 318 TEST_F(SupervisedUserWhitelistInstallerTest, |
| 319 RegisterAndUninstallExistingWhitelist) { | 319 RegisterAndUninstallExistingWhitelist) { |
| 320 ASSERT_TRUE(base::CreateDirectory(whitelist_version_directory_)); | 320 ASSERT_TRUE(base::CreateDirectory(whitelist_version_directory_)); |
| 321 ASSERT_NO_FATAL_FAILURE( | 321 ASSERT_NO_FATAL_FAILURE( |
| 322 PrepareWhitelistDirectory(whitelist_version_directory_)); | 322 PrepareWhitelistDirectory(whitelist_version_directory_)); |
| 323 | 323 |
| 324 // Create another whitelist directory, with an ID that is not registered. | 324 // Create another whitelist directory, with an ID that is not registered. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 { | 360 { |
| 361 base::RunLoop run_loop; | 361 base::RunLoop run_loop; |
| 362 installer_->UnregisterWhitelist(kOtherClientId, kCrxId); | 362 installer_->UnregisterWhitelist(kOtherClientId, kCrxId); |
| 363 run_loop.RunUntilIdle(); | 363 run_loop.RunUntilIdle(); |
| 364 } | 364 } |
| 365 EXPECT_FALSE(component_update_service_.registered_component()); | 365 EXPECT_FALSE(component_update_service_.registered_component()); |
| 366 EXPECT_FALSE(base::DirectoryExists(whitelist_directory_)); | 366 EXPECT_FALSE(base::DirectoryExists(whitelist_directory_)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace component_updater | 369 } // namespace component_updater |
| OLD | NEW |