| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 base::Closure run_loop_quit_; | 78 base::Closure run_loop_quit_; |
| 79 std::unique_ptr<ContentHashFetcherResult> result_; | 79 std::unique_ptr<ContentHashFetcherResult> result_; |
| 80 base::WeakPtrFactory<ContentHashFetcherWaiter> weak_factory_; | 80 base::WeakPtrFactory<ContentHashFetcherWaiter> weak_factory_; |
| 81 | 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(ContentHashFetcherWaiter); | 82 DISALLOW_COPY_AND_ASSIGN(ContentHashFetcherWaiter); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // Used in setting up the behavior of our ContentHashFetcher. | 85 // Used in setting up the behavior of our ContentHashFetcher. |
| 86 class MockDelegate : public ContentVerifierDelegate { | 86 class MockDelegate : public ContentVerifierDelegate { |
| 87 public: | 87 public: |
| 88 MockDelegate() {} |
| 89 ~MockDelegate() override {} |
| 90 |
| 88 ContentVerifierDelegate::Mode ShouldBeVerified( | 91 ContentVerifierDelegate::Mode ShouldBeVerified( |
| 89 const Extension& extension) override { | 92 const Extension& extension) override { |
| 90 return ContentVerifierDelegate::ENFORCE_STRICT; | 93 return ContentVerifierDelegate::ENFORCE_STRICT; |
| 91 } | 94 } |
| 92 | 95 |
| 93 ContentVerifierKey GetPublicKey() override { | 96 ContentVerifierKey GetPublicKey() override { |
| 94 return ContentVerifierKey(kWebstoreSignaturesPublicKey, | 97 return ContentVerifierKey(kWebstoreSignaturesPublicKey, |
| 95 kWebstoreSignaturesPublicKeySize); | 98 kWebstoreSignaturesPublicKeySize); |
| 96 } | 99 } |
| 97 | 100 |
| 98 GURL GetSignatureFetchUrl(const std::string& extension_id, | 101 GURL GetSignatureFetchUrl(const std::string& extension_id, |
| 99 const base::Version& version) override { | 102 const base::Version& version) override { |
| 100 std::string url = | 103 std::string url = |
| 101 base::StringPrintf("http://localhost/getsignature?id=%s&version=%s", | 104 base::StringPrintf("http://localhost/getsignature?id=%s&version=%s", |
| 102 extension_id.c_str(), version.GetString().c_str()); | 105 extension_id.c_str(), version.GetString().c_str()); |
| 103 return GURL(url); | 106 return GURL(url); |
| 104 } | 107 } |
| 105 | 108 |
| 106 std::set<base::FilePath> GetBrowserImagePaths( | 109 std::set<base::FilePath> GetBrowserImagePaths( |
| 107 const extensions::Extension* extension) override { | 110 const extensions::Extension* extension) override { |
| 108 ADD_FAILURE() << "Unexpected call for this test"; | 111 ADD_FAILURE() << "Unexpected call for this test"; |
| 109 return std::set<base::FilePath>(); | 112 return std::set<base::FilePath>(); |
| 110 } | 113 } |
| 111 | 114 |
| 112 void VerifyFailed(const std::string& extension_id, | 115 void VerifyFailed(const std::string& extension_id, |
| 113 ContentVerifyJob::FailureReason reason) override { | 116 ContentVerifyJob::FailureReason reason) override { |
| 114 ADD_FAILURE() << "Unexpected call for this test"; | 117 ADD_FAILURE() << "Unexpected call for this test"; |
| 115 } | 118 } |
| 119 |
| 120 void Shutdown() override {} |
| 121 |
| 122 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(MockDelegate); |
| 116 }; | 124 }; |
| 117 | 125 |
| 118 class ContentHashFetcherTest : public ExtensionsTest { | 126 class ContentHashFetcherTest : public ExtensionsTest { |
| 119 public: | 127 public: |
| 120 ContentHashFetcherTest() {} | 128 ContentHashFetcherTest() {} |
| 121 ~ContentHashFetcherTest() override {} | 129 ~ContentHashFetcherTest() override {} |
| 122 | 130 |
| 123 void SetUp() override { | 131 void SetUp() override { |
| 124 ExtensionsTest::SetUp(); | 132 ExtensionsTest::SetUp(); |
| 125 // We need a real IO thread to be able to intercept the network request | 133 // We need a real IO thread to be able to intercept the network request |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 EXPECT_TRUE( | 268 EXPECT_TRUE( |
| 261 base::ContainsKey(result->mismatch_paths, script_path.BaseName())); | 269 base::ContainsKey(result->mismatch_paths, script_path.BaseName())); |
| 262 | 270 |
| 263 // Make sure the verified_contents.json file was written into the extension's | 271 // Make sure the verified_contents.json file was written into the extension's |
| 264 // install dir. | 272 // install dir. |
| 265 EXPECT_TRUE( | 273 EXPECT_TRUE( |
| 266 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); | 274 base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
| 267 } | 275 } |
| 268 | 276 |
| 269 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |