| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/component_updater/sth_set_component_installer.h" | 5 #include "chrome/browser/component_updater/sth_set_component_installer.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class STHSetComponentInstallerTest : public PlatformTest { | 39 class STHSetComponentInstallerTest : public PlatformTest { |
| 40 public: | 40 public: |
| 41 STHSetComponentInstallerTest() {} | 41 STHSetComponentInstallerTest() {} |
| 42 void SetUp() override { | 42 void SetUp() override { |
| 43 PlatformTest::SetUp(); | 43 PlatformTest::SetUp(); |
| 44 | 44 |
| 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 46 | 46 |
| 47 std::unique_ptr<StoringSTHObserver> observer(new StoringSTHObserver()); | 47 observer_.reset(new StoringSTHObserver()); |
| 48 observer_ = observer.get(); | 48 traits_.reset(new STHSetComponentInstallerTraits(observer_.get())); |
| 49 traits_.reset(new STHSetComponentInstallerTraits(std::move(observer))); | |
| 50 } | 49 } |
| 51 | 50 |
| 52 void WriteSTHToFile(const std::string& sth_json, | 51 void WriteSTHToFile(const std::string& sth_json, |
| 53 const base::FilePath& filename) { | 52 const base::FilePath& filename) { |
| 54 ASSERT_EQ(static_cast<int32_t>(sth_json.length()), | 53 ASSERT_EQ(static_cast<int32_t>(sth_json.length()), |
| 55 base::WriteFile(filename, sth_json.data(), sth_json.length())); | 54 base::WriteFile(filename, sth_json.data(), sth_json.length())); |
| 56 } | 55 } |
| 57 | 56 |
| 58 base::FilePath GetSTHsDir() { | 57 base::FilePath GetSTHsDir() { |
| 59 return temp_dir_.path() | 58 return temp_dir_.path() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 const base::Version v("1.0"); | 74 const base::Version v("1.0"); |
| 76 traits_->LoadSTHsFromDisk(sths_dir, v); | 75 traits_->LoadSTHsFromDisk(sths_dir, v); |
| 77 // Drain the RunLoop created by the TestBrowserThreadBundle | 76 // Drain the RunLoop created by the TestBrowserThreadBundle |
| 78 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
| 79 } | 78 } |
| 80 | 79 |
| 81 protected: | 80 protected: |
| 82 content::TestBrowserThreadBundle thread_bundle_; | 81 content::TestBrowserThreadBundle thread_bundle_; |
| 83 | 82 |
| 84 base::ScopedTempDir temp_dir_; | 83 base::ScopedTempDir temp_dir_; |
| 84 std::unique_ptr<StoringSTHObserver> observer_; |
| 85 // traits_ should be destroyed before the observer_ as it holds a pointer |
| 86 // to it. |
| 85 std::unique_ptr<STHSetComponentInstallerTraits> traits_; | 87 std::unique_ptr<STHSetComponentInstallerTraits> traits_; |
| 86 StoringSTHObserver* observer_; | |
| 87 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; | 88 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(STHSetComponentInstallerTest); | 91 DISALLOW_COPY_AND_ASSIGN(STHSetComponentInstallerTest); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 // Parses valid STH JSON in a file with valid hex encoding of log id. | 94 // Parses valid STH JSON in a file with valid hex encoding of log id. |
| 94 TEST_F(STHSetComponentInstallerTest, CanLoadAllSTHs) { | 95 TEST_F(STHSetComponentInstallerTest, CanLoadAllSTHs) { |
| 95 const base::DictionaryValue manifest; | 96 const base::DictionaryValue manifest; |
| 96 const base::FilePath sths_dir(GetSTHsDir()); | 97 const base::FilePath sths_dir(GetSTHsDir()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 142 |
| 142 const base::FilePath not_hex_sth_file = | 143 const base::FilePath not_hex_sth_file = |
| 143 sths_dir.Append(FILE_PATH_LITERAL("nothex.sth")); | 144 sths_dir.Append(FILE_PATH_LITERAL("nothex.sth")); |
| 144 WriteSTHToFile(net::ct::GetSampleSTHAsJson(), not_hex_sth_file); | 145 WriteSTHToFile(net::ct::GetSampleSTHAsJson(), not_hex_sth_file); |
| 145 | 146 |
| 146 LoadSTHs(manifest, sths_dir); | 147 LoadSTHs(manifest, sths_dir); |
| 147 EXPECT_EQ(0u, observer_->sths.size()); | 148 EXPECT_EQ(0u, observer_->sths.size()); |
| 148 } | 149 } |
| 149 | 150 |
| 150 } // namespace component_updater | 151 } // namespace component_updater |
| OLD | NEW |