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 | |
195 // This tests our ability to successfully fetch, parse, and validate a missing | 189 // This tests our ability to successfully fetch, parse, and validate a missing |
196 // verified_contents.json file for an extension. | 190 // verified_contents.json file for an extension. |
197 TEST_F(ContentHashFetcherTest, MAYBE_MissingVerifiedContents) { | 191 TEST_F(ContentHashFetcherTest, MissingVerifiedContents) { |
198 // We unzip the extension source to a temp directory to simulate it being | 192 // We unzip the extension source to a temp directory to simulate it being |
199 // installed there, because the ContentHashFetcher will create the _metadata/ | 193 // installed there, because the ContentHashFetcher will create the _metadata/ |
200 // directory within the extension install dir and write the fetched | 194 // directory within the extension install dir and write the fetched |
201 // verified_contents.json file there. | 195 // verified_contents.json file there. |
202 base::FilePath test_dir_base = GetTestPath( | 196 base::FilePath test_dir_base = GetTestPath( |
203 base::FilePath(FILE_PATH_LITERAL("missing_verified_contents"))); | 197 base::FilePath(FILE_PATH_LITERAL("missing_verified_contents"))); |
204 scoped_refptr<Extension> extension = | 198 scoped_refptr<Extension> extension = |
205 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); | 199 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); |
206 | 200 |
207 // Make sure there isn't already a verified_contents.json file there. | 201 // Make sure there isn't already a verified_contents.json file there. |
(...skipping 18 matching lines...) Expand all Loading... |
226 EXPECT_TRUE(result->success); | 220 EXPECT_TRUE(result->success); |
227 EXPECT_TRUE(result->force); | 221 EXPECT_TRUE(result->force); |
228 EXPECT_TRUE(result->mismatch_paths.empty()); | 222 EXPECT_TRUE(result->mismatch_paths.empty()); |
229 | 223 |
230 // Make sure the verified_contents.json file was written into the extension's | 224 // Make sure the verified_contents.json file was written into the extension's |
231 // install dir. | 225 // install dir. |
232 EXPECT_TRUE( | 226 EXPECT_TRUE( |
233 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); | 227 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
234 } | 228 } |
235 | 229 |
236 // Flaky on Linux and ChromeOS. https://crbug.com/702300 | |
237 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | |
238 #define MAYBE_MissingVerifiedContentsAndCorrupt \ | |
239 DISABLED_MissingVerifiedContentsAndCorrupt | |
240 #else | |
241 #define MAYBE_MissingVerifiedContentsAndCorrupt \ | |
242 MissingVerifiedContentsAndCorrupt | |
243 #endif | |
244 // Similar to MissingVerifiedContents, but tests the case where the extension | 230 // Similar to MissingVerifiedContents, but tests the case where the extension |
245 // actually has corruption. | 231 // actually has corruption. |
246 TEST_F(ContentHashFetcherTest, MAYBE_MissingVerifiedContentsAndCorrupt) { | 232 TEST_F(ContentHashFetcherTest, MissingVerifiedContentsAndCorrupt) { |
247 base::FilePath test_dir_base = | 233 base::FilePath test_dir_base = |
248 GetTestPath(base::FilePath()).AppendASCII("missing_verified_contents"); | 234 GetTestPath(base::FilePath()).AppendASCII("missing_verified_contents"); |
249 scoped_refptr<Extension> extension = | 235 scoped_refptr<Extension> extension = |
250 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); | 236 UnzipToTempDirAndLoad(test_dir_base.AppendASCII("source.zip")); |
251 | 237 |
252 // Tamper with a file in the extension. | 238 // Tamper with a file in the extension. |
253 base::FilePath script_path = extension->path().AppendASCII("script.js"); | 239 base::FilePath script_path = extension->path().AppendASCII("script.js"); |
254 std::string addition = "//hello world"; | 240 std::string addition = "//hello world"; |
255 ASSERT_TRUE( | 241 ASSERT_TRUE( |
256 base::AppendToFile(script_path, addition.c_str(), addition.size())); | 242 base::AppendToFile(script_path, addition.c_str(), addition.size())); |
(...skipping 17 matching lines...) Expand all Loading... |
274 EXPECT_TRUE( | 260 EXPECT_TRUE( |
275 base::ContainsKey(result->mismatch_paths, script_path.BaseName())); | 261 base::ContainsKey(result->mismatch_paths, script_path.BaseName())); |
276 | 262 |
277 // Make sure the verified_contents.json file was written into the extension's | 263 // Make sure the verified_contents.json file was written into the extension's |
278 // install dir. | 264 // install dir. |
279 EXPECT_TRUE( | 265 EXPECT_TRUE( |
280 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); | 266 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
281 } | 267 } |
282 | 268 |
283 } // namespace extensions | 269 } // namespace extensions |
OLD | NEW |