Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 829583002: Validate hash_sha256 checksum on .crx update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest build for windows. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ManifestFetchData::kNeverPinged, 138 ManifestFetchData::kNeverPinged,
139 true, 139 true,
140 0); 140 0);
141 141
142 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { 142 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate {
143 public: 143 public:
144 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, 144 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&,
145 Error, 145 Error,
146 const PingResult&, 146 const PingResult&,
147 const std::set<int>&)); 147 const std::set<int>&));
148 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&, 148 MOCK_METHOD6(OnExtensionDownloadFinished,
149 const base::FilePath&, 149 void(const extensions::CRXFileInfo&,
150 bool, 150 bool,
151 const GURL&, 151 const GURL&,
152 const std::string&, 152 const std::string&,
153 const PingResult&, 153 const PingResult&,
154 const std::set<int>&)); 154 const std::set<int>&));
155 MOCK_METHOD2(GetPingDataForExtension, 155 MOCK_METHOD2(GetPingDataForExtension,
156 bool(const std::string&, ManifestFetchData::PingData*)); 156 bool(const std::string&, ManifestFetchData::PingData*));
157 MOCK_METHOD1(GetUpdateUrlData, std::string(const std::string&)); 157 MOCK_METHOD1(GetUpdateUrlData, std::string(const std::string&));
158 MOCK_METHOD1(IsExtensionPending, bool(const std::string&)); 158 MOCK_METHOD1(IsExtensionPending, bool(const std::string&));
159 MOCK_METHOD2(GetExtensionExistingVersion, 159 MOCK_METHOD2(GetExtensionExistingVersion,
160 bool(const std::string&, std::string*)); 160 bool(const std::string&, std::string*));
161 161
162 void Wait() { 162 void Wait() {
163 scoped_refptr<content::MessageLoopRunner> runner = 163 scoped_refptr<content::MessageLoopRunner> runner =
164 new content::MessageLoopRunner; 164 new content::MessageLoopRunner;
165 quit_closure_ = runner->QuitClosure(); 165 quit_closure_ = runner->QuitClosure();
166 runner->Run(); 166 runner->Run();
167 quit_closure_.Reset(); 167 quit_closure_.Reset();
168 } 168 }
169 169
170 void Quit() { 170 void Quit() {
171 quit_closure_.Run(); 171 quit_closure_.Run();
172 } 172 }
173 173
174 void DelegateTo(ExtensionDownloaderDelegate* delegate) { 174 void DelegateTo(ExtensionDownloaderDelegate* delegate) {
175 ON_CALL(*this, OnExtensionDownloadFailed(_, _, _, _)) 175 ON_CALL(*this, OnExtensionDownloadFailed(_, _, _, _))
176 .WillByDefault(Invoke(delegate, 176 .WillByDefault(Invoke(delegate,
177 &ExtensionDownloaderDelegate::OnExtensionDownloadFailed)); 177 &ExtensionDownloaderDelegate::OnExtensionDownloadFailed));
178 ON_CALL(*this, OnExtensionDownloadFinished(_, _, _, _, _, _, _)) 178 ON_CALL(*this, OnExtensionDownloadFinished(_, _, _, _, _, _))
179 .WillByDefault(Invoke(delegate, 179 .WillByDefault(
180 &ExtensionDownloaderDelegate::OnExtensionDownloadFinished)); 180 Invoke(delegate,
181 &ExtensionDownloaderDelegate::OnExtensionDownloadFinished));
181 ON_CALL(*this, GetPingDataForExtension(_, _)) 182 ON_CALL(*this, GetPingDataForExtension(_, _))
182 .WillByDefault(Invoke(delegate, 183 .WillByDefault(Invoke(delegate,
183 &ExtensionDownloaderDelegate::GetPingDataForExtension)); 184 &ExtensionDownloaderDelegate::GetPingDataForExtension));
184 ON_CALL(*this, GetUpdateUrlData(_)) 185 ON_CALL(*this, GetUpdateUrlData(_))
185 .WillByDefault(Invoke(delegate, 186 .WillByDefault(Invoke(delegate,
186 &ExtensionDownloaderDelegate::GetUpdateUrlData)); 187 &ExtensionDownloaderDelegate::GetUpdateUrlData));
187 ON_CALL(*this, IsExtensionPending(_)) 188 ON_CALL(*this, IsExtensionPending(_))
188 .WillByDefault(Invoke(delegate, 189 .WillByDefault(Invoke(delegate,
189 &ExtensionDownloaderDelegate::IsExtensionPending)); 190 &ExtensionDownloaderDelegate::IsExtensionPending));
190 ON_CALL(*this, GetExtensionExistingVersion(_, _)) 191 ON_CALL(*this, GetExtensionExistingVersion(_, _))
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 explicit ServiceForDownloadTests(TestExtensionPrefs* prefs) 493 explicit ServiceForDownloadTests(TestExtensionPrefs* prefs)
493 : MockService(prefs) { 494 : MockService(prefs) {
494 } 495 }
495 496
496 // Add a fake crx installer to be returned by a call to UpdateExtension() 497 // Add a fake crx installer to be returned by a call to UpdateExtension()
497 // with a specific ID. Caller keeps ownership of |crx_installer|. 498 // with a specific ID. Caller keeps ownership of |crx_installer|.
498 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { 499 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) {
499 fake_crx_installers_[id] = crx_installer; 500 fake_crx_installers_[id] = crx_installer;
500 } 501 }
501 502
502 bool UpdateExtension(const std::string& id, 503 bool UpdateExtension(const CRXFileInfo& file,
503 const base::FilePath& extension_path,
504 bool file_ownership_passed, 504 bool file_ownership_passed,
505 CrxInstaller** out_crx_installer) override { 505 CrxInstaller** out_crx_installer) override {
506 extension_id_ = id; 506 extension_id_ = file.extension_id;
507 install_path_ = extension_path; 507 install_path_ = file.path;
508 508
509 if (ContainsKey(fake_crx_installers_, id)) { 509 if (ContainsKey(fake_crx_installers_, extension_id_)) {
510 *out_crx_installer = fake_crx_installers_[id]; 510 *out_crx_installer = fake_crx_installers_[extension_id_];
511 return true; 511 return true;
512 } 512 }
513 513
514 return false; 514 return false;
515 } 515 }
516 516
517 PendingExtensionManager* pending_extension_manager() override { 517 PendingExtensionManager* pending_extension_manager() override {
518 return &pending_extension_manager_; 518 return &pending_extension_manager_;
519 } 519 }
520 520
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1214
1215 fetcher->set_url(test_url); 1215 fetcher->set_url(test_url);
1216 fetcher->set_status(net::URLRequestStatus()); 1216 fetcher->set_status(net::URLRequestStatus());
1217 if (fail) { 1217 if (fail) {
1218 fetcher->set_response_code(404); 1218 fetcher->set_response_code(404);
1219 EXPECT_CALL(delegate, OnExtensionDownloadFailed(id, _, _, requests)); 1219 EXPECT_CALL(delegate, OnExtensionDownloadFailed(id, _, _, requests));
1220 } else { 1220 } else {
1221 fetcher->set_response_code(200); 1221 fetcher->set_response_code(200);
1222 fetcher->SetResponseFilePath(extension_file_path); 1222 fetcher->SetResponseFilePath(extension_file_path);
1223 EXPECT_CALL(delegate, OnExtensionDownloadFinished( 1223 EXPECT_CALL(delegate, OnExtensionDownloadFinished(
1224 id, _, _, _, version.GetString(), _, requests)); 1224 CRXFileInfo(id, extension_file_path, hash), _,
1225 _, version.GetString(), _, requests));
1225 } 1226 }
1226 fetcher->delegate()->OnURLFetchComplete(fetcher); 1227 fetcher->delegate()->OnURLFetchComplete(fetcher);
1227 1228
1228 RunUntilIdle(); 1229 RunUntilIdle();
1229 1230
1230 if (fail) { 1231 if (fail) {
1231 // Don't expect any extension to have been installed. 1232 // Don't expect any extension to have been installed.
1232 EXPECT_TRUE(service->extension_id().empty()); 1233 EXPECT_TRUE(service->extension_id().empty());
1233 } else { 1234 } else {
1234 // Expect that ExtensionUpdater asked the mock extensions service to 1235 // Expect that ExtensionUpdater asked the mock extensions service to
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 // -prodversionmin (shouldn't update if browser version too old) 2245 // -prodversionmin (shouldn't update if browser version too old)
2245 // -manifests & updates arriving out of order / interleaved 2246 // -manifests & updates arriving out of order / interleaved
2246 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2247 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
2247 // -An extension gets uninstalled while updates are in progress (so it doesn't 2248 // -An extension gets uninstalled while updates are in progress (so it doesn't
2248 // "come back from the dead") 2249 // "come back from the dead")
2249 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2250 // -An extension gets manually updated to v3 while we're downloading v2 (ie
2250 // you don't get downgraded accidentally) 2251 // you don't get downgraded accidentally)
2251 // -An update manifest mentions multiple updates 2252 // -An update manifest mentions multiple updates
2252 2253
2253 } // namespace extensions 2254 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | chrome/common/extensions/update_manifest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698