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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 interceptor_->SetResponse(url, response_path); | 179 interceptor_->SetResponse(url, response_path); |
180 } | 180 } |
181 | 181 |
182 protected: | 182 protected: |
183 std::unique_ptr<content::TestBrowserThreadBundle> browser_threads_; | 183 std::unique_ptr<content::TestBrowserThreadBundle> browser_threads_; |
184 std::unique_ptr<net::TestURLRequestInterceptor> interceptor_; | 184 std::unique_ptr<net::TestURLRequestInterceptor> interceptor_; |
185 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 185 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
186 base::ScopedTempDir temp_dir_; | 186 base::ScopedTempDir temp_dir_; |
187 }; | 187 }; |
188 | 188 |
| 189 // Flaky on Linux and ChromeOS. https://crbug.com/702300 |
| 190 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 191 #define MAYBE_MissingVerifiedContents DISABLED_MissingVerifiedContents |
| 192 #else |
| 193 #define MAYBE_MissingVerifiedContents MissingVerifiedContents |
| 194 #endif |
189 // This tests our ability to successfully fetch, parse, and validate a missing | 195 // This tests our ability to successfully fetch, parse, and validate a missing |
190 // verified_contents.json file for an extension. | 196 // verified_contents.json file for an extension. |
191 TEST_F(ContentHashFetcherTest, MissingVerifiedContents) { | 197 TEST_F(ContentHashFetcherTest, MAYBE_MissingVerifiedContents) { |
192 // We unzip the extension source to a temp directory to simulate it being | 198 // We unzip the extension source to a temp directory to simulate it being |
193 // installed there, because the ContentHashFetcher will create the _metadata/ | 199 // installed there, because the ContentHashFetcher will create the _metadata/ |
194 // directory within the extension install dir and write the fetched | 200 // directory within the extension install dir and write the fetched |
195 // verified_contents.json file there. | 201 // verified_contents.json file there. |
196 base::FilePath test_dir_base = GetTestPath( | 202 base::FilePath test_dir_base = GetTestPath( |
197 base::FilePath(FILE_PATH_LITERAL("missing_verified_contents"))); | 203 base::FilePath(FILE_PATH_LITERAL("missing_verified_contents"))); |
198 scoped_refptr<Extension> extension = | 204 scoped_refptr<Extension> extension = |
199 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); | 205 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); |
200 | 206 |
201 // Make sure there isn't already a verified_contents.json file there. | 207 // Make sure there isn't already a verified_contents.json file there. |
(...skipping 18 matching lines...) Expand all Loading... |
220 EXPECT_TRUE(result->success); | 226 EXPECT_TRUE(result->success); |
221 EXPECT_TRUE(result->force); | 227 EXPECT_TRUE(result->force); |
222 EXPECT_TRUE(result->mismatch_paths.empty()); | 228 EXPECT_TRUE(result->mismatch_paths.empty()); |
223 | 229 |
224 // Make sure the verified_contents.json file was written into the extension's | 230 // Make sure the verified_contents.json file was written into the extension's |
225 // install dir. | 231 // install dir. |
226 EXPECT_TRUE( | 232 EXPECT_TRUE( |
227 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); | 233 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
228 } | 234 } |
229 | 235 |
230 // Similar to MissingVerifiedContents, but tests the case where the extension | 236 // Flaky on Linux and ChromeOS. https://crbug.com/702300 |
231 // actually has corruption. | |
232 // Flaky on Linux and ChromeOS. crbug.com/ | |
233 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 237 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
234 #define MAYBE_MissingVerifiedContentsAndCorrupt \ | 238 #define MAYBE_MissingVerifiedContentsAndCorrupt \ |
235 DISABLED_MissingVerifiedContentsAndCorrupt | 239 DISABLED_MissingVerifiedContentsAndCorrupt |
236 #else | 240 #else |
237 #define MAYBE_MissingVerifiedContentsAndCorrupt \ | 241 #define MAYBE_MissingVerifiedContentsAndCorrupt \ |
238 MissingVerifiedContentsAndCorrupt | 242 MissingVerifiedContentsAndCorrupt |
239 #endif | 243 #endif |
| 244 // Similar to MissingVerifiedContents, but tests the case where the extension |
| 245 // actually has corruption. |
240 TEST_F(ContentHashFetcherTest, MAYBE_MissingVerifiedContentsAndCorrupt) { | 246 TEST_F(ContentHashFetcherTest, MAYBE_MissingVerifiedContentsAndCorrupt) { |
241 base::FilePath test_dir_base = | 247 base::FilePath test_dir_base = |
242 GetTestPath(base::FilePath()).AppendASCII("missing_verified_contents"); | 248 GetTestPath(base::FilePath()).AppendASCII("missing_verified_contents"); |
243 scoped_refptr<Extension> extension = | 249 scoped_refptr<Extension> extension = |
244 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); | 250 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); |
245 | 251 |
246 // Tamper with a file in the extension. | 252 // Tamper with a file in the extension. |
247 base::FilePath script_path = extension->path().AppendASCII("script.js"); | 253 base::FilePath script_path = extension->path().AppendASCII("script.js"); |
248 std::string addition = "//hello world"; | 254 std::string addition = "//hello world"; |
249 ASSERT_TRUE( | 255 ASSERT_TRUE( |
(...skipping 18 matching lines...) Expand all Loading... |
268 EXPECT_TRUE( | 274 EXPECT_TRUE( |
269 base::ContainsKey(result->mismatch_paths, script_path.BaseName())); | 275 base::ContainsKey(result->mismatch_paths, script_path.BaseName())); |
270 | 276 |
271 // Make sure the verified_contents.json file was written into the extension's | 277 // Make sure the verified_contents.json file was written into the extension's |
272 // install dir. | 278 // install dir. |
273 EXPECT_TRUE( | 279 EXPECT_TRUE( |
274 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); | 280 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
275 } | 281 } |
276 | 282 |
277 } // namespace extensions | 283 } // namespace extensions |
OLD | NEW |