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 "components/search_provider_logos/logo_cache.h" | 5 #include "components/search_provider_logos/logo_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // Removes 1 byte from the end of the file at |path|. | 88 // Removes 1 byte from the end of the file at |path|. |
89 void ShortenFile(base::FilePath path) { | 89 void ShortenFile(base::FilePath path) { |
90 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_WRITE); | 90 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
91 int64 file_length = file.GetLength(); | 91 int64 file_length = file.GetLength(); |
92 ASSERT_NE(file_length, 0); | 92 ASSERT_NE(file_length, 0); |
93 file.SetLength(file_length - 1); | 93 file.SetLength(file_length - 1); |
94 } | 94 } |
95 | 95 |
96 class LogoCacheTest : public ::testing::Test { | 96 class LogoCacheTest : public ::testing::Test { |
97 protected: | 97 protected: |
98 virtual void SetUp() override { | 98 void SetUp() override { |
99 ASSERT_TRUE(cache_parent_dir_.CreateUniqueTempDir()); | 99 ASSERT_TRUE(cache_parent_dir_.CreateUniqueTempDir()); |
100 InitCache(); | 100 InitCache(); |
101 } | 101 } |
102 | 102 |
103 void InitCache() { | 103 void InitCache() { |
104 cache_.reset(new LogoCache( | 104 cache_.reset(new LogoCache( |
105 cache_parent_dir_.path().Append(FILE_PATH_LITERAL("cache")))); | 105 cache_parent_dir_.path().Append(FILE_PATH_LITERAL("cache")))); |
106 } | 106 } |
107 | 107 |
108 void ExpectMetadata(const LogoMetadata* expected_metadata) { | 108 void ExpectMetadata(const LogoMetadata* expected_metadata) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 ExpectLogo(NULL); | 243 ExpectLogo(NULL); |
244 // Once the logo is noticed to be NULL, the metadata should also be cleared. | 244 // Once the logo is noticed to be NULL, the metadata should also be cleared. |
245 ExpectMetadata(NULL); | 245 ExpectMetadata(NULL); |
246 | 246 |
247 // Ensure corrupt cache files are deleted. | 247 // Ensure corrupt cache files are deleted. |
248 EXPECT_FALSE(base::PathExists(cache_->GetMetadataPath())); | 248 EXPECT_FALSE(base::PathExists(cache_->GetMetadataPath())); |
249 EXPECT_FALSE(base::PathExists(cache_->GetLogoPath())); | 249 EXPECT_FALSE(base::PathExists(cache_->GetLogoPath())); |
250 } | 250 } |
251 | 251 |
252 } // namespace search_provider_logos | 252 } // namespace search_provider_logos |
OLD | NEW |