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

Side by Side Diff: chrome/browser/extensions/content_verifier_browsertest.cc

Issue 2771953003: Fix content verification code for undreadable and deleted files. (Closed)
Patch Set: Fix deleted file case and also make sure crbug 404802 does not regress Created 3 years, 8 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 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 <list> 5 #include <list>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 // Helper for forcing ContentVerifyJob's to return an error. 120 // Helper for forcing ContentVerifyJob's to return an error.
121 class JobDelegate : public ContentVerifyJob::TestDelegate { 121 class JobDelegate : public ContentVerifyJob::TestDelegate {
122 public: 122 public:
123 JobDelegate() 123 JobDelegate()
124 : fail_next_read_(false), 124 : fail_next_read_(false),
125 fail_next_done_(false), 125 fail_next_done_(false),
126 bytes_read_failed_(0), 126 bytes_read_failed_(0),
127 done_reading_failed_(0) {} 127 done_reading_failed_(0) {}
128 128
129 virtual ~JobDelegate() {} 129 ~JobDelegate() override {}
130 130
131 void set_id(const ExtensionId& id) { id_ = id; } 131 void set_id(const ExtensionId& id) { id_ = id; }
132 void fail_next_read() { fail_next_read_ = true; } 132 void fail_next_read() { fail_next_read_ = true; }
133 void fail_next_done() { fail_next_done_ = true; } 133 void fail_next_done() { fail_next_done_ = true; }
134 134
135 // Return the number of BytesRead/DoneReading calls we actually failed, 135 // Return the number of BytesRead/DoneReading calls we actually failed,
136 // respectively. 136 // respectively.
137 int bytes_read_failed() { return bytes_read_failed_; } 137 int bytes_read_failed() { return bytes_read_failed_; }
138 int done_reading_failed() { return done_reading_failed_; } 138 int done_reading_failed() { return done_reading_failed_; }
139 139
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Wait to see expected jobs. Returns true when we've seen all expected jobs 182 // Wait to see expected jobs. Returns true when we've seen all expected jobs
183 // finish, or false if there was an error or timeout. 183 // finish, or false if there was an error or timeout.
184 bool WaitForExpectedJobs(); 184 bool WaitForExpectedJobs();
185 185
186 // ContentVerifyJob::TestObserver interface 186 // ContentVerifyJob::TestObserver interface
187 void JobStarted(const std::string& extension_id, 187 void JobStarted(const std::string& extension_id,
188 const base::FilePath& relative_path) override; 188 const base::FilePath& relative_path) override;
189 189
190 void JobFinished(const std::string& extension_id, 190 void JobFinished(const std::string& extension_id,
191 const base::FilePath& relative_path, 191 const base::FilePath& relative_path,
192 bool failed) override; 192 ContentVerifyJob::FailureReason failure_reason) override;
193 193
194 private: 194 private:
195 struct ExpectedResult { 195 struct ExpectedResult {
196 public: 196 public:
197 std::string extension_id; 197 std::string extension_id;
198 base::FilePath path; 198 base::FilePath path;
199 Result result; 199 Result result;
200 200
201 ExpectedResult(const std::string& extension_id, const base::FilePath& path, 201 ExpectedResult(const std::string& extension_id, const base::FilePath& path,
202 Result result) { 202 Result result) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 234 }
235 return expectations_.empty(); 235 return expectations_.empty();
236 } 236 }
237 237
238 void JobObserver::JobStarted(const std::string& extension_id, 238 void JobObserver::JobStarted(const std::string& extension_id,
239 const base::FilePath& relative_path) { 239 const base::FilePath& relative_path) {
240 } 240 }
241 241
242 void JobObserver::JobFinished(const std::string& extension_id, 242 void JobObserver::JobFinished(const std::string& extension_id,
243 const base::FilePath& relative_path, 243 const base::FilePath& relative_path,
244 bool failed) { 244 ContentVerifyJob::FailureReason failure_reason) {
245 if (!content::BrowserThread::CurrentlyOn(creation_thread_)) { 245 if (!content::BrowserThread::CurrentlyOn(creation_thread_)) {
246 content::BrowserThread::PostTask( 246 content::BrowserThread::PostTask(
247 creation_thread_, FROM_HERE, 247 creation_thread_, FROM_HERE,
248 base::Bind(&JobObserver::JobFinished, base::Unretained(this), 248 base::Bind(&JobObserver::JobFinished, base::Unretained(this),
249 extension_id, relative_path, failed)); 249 extension_id, relative_path, failure_reason));
250 return; 250 return;
251 } 251 }
252 Result result = failed ? Result::FAILURE : Result::SUCCESS; 252 Result result = failure_reason == ContentVerifyJob::NONE ? Result::SUCCESS
253 : Result::SUCCESS;
Devlin 2017/03/29 15:51:56 Result::FAILURE?
lazyboy 2017/03/29 17:12:50 Done, thanks.
253 bool found = false; 254 bool found = false;
254 for (std::list<ExpectedResult>::iterator i = expectations_.begin(); 255 for (std::list<ExpectedResult>::iterator i = expectations_.begin();
255 i != expectations_.end(); ++i) { 256 i != expectations_.end(); ++i) {
256 if (i->extension_id == extension_id && i->path == relative_path && 257 if (i->extension_id == extension_id && i->path == relative_path &&
257 i->result == result) { 258 i->result == result) {
258 found = true; 259 found = true;
259 expectations_.erase(i); 260 expectations_.erase(i);
260 break; 261 break;
261 } 262 }
262 } 263 }
263 if (found) { 264 if (found) {
264 if (expectations_.empty() && loop_runner_.get()) 265 if (expectations_.empty() && loop_runner_.get())
265 loop_runner_->Quit(); 266 loop_runner_->Quit();
266 } else { 267 } else {
267 LOG(WARNING) << "Ignoring unexpected JobFinished " << extension_id << "/" 268 LOG(WARNING) << "Ignoring unexpected JobFinished " << extension_id << "/"
268 << relative_path.value() << " failed:" << failed; 269 << relative_path.value()
270 << " failure_reason:" << failure_reason;
269 } 271 }
270 } 272 }
271 273
272 class VerifierObserver : public ContentVerifier::TestObserver { 274 class VerifierObserver : public ContentVerifier::TestObserver {
273 public: 275 public:
274 VerifierObserver(); 276 VerifierObserver();
275 virtual ~VerifierObserver(); 277 virtual ~VerifierObserver();
276 278
277 const std::set<std::string>& completed_fetches() { 279 const std::set<std::string>& completed_fetches() {
278 return completed_fetches_; 280 return completed_fetches_;
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 // Assert that the first reinstall action happened with a delay of 0, and 829 // Assert that the first reinstall action happened with a delay of 0, and
828 // then kept growing each additional time. 830 // then kept growing each additional time.
829 ASSERT_EQ(iterations, calls.size()); 831 ASSERT_EQ(iterations, calls.size());
830 EXPECT_EQ(base::TimeDelta(), delay_tracker.calls()[0]); 832 EXPECT_EQ(base::TimeDelta(), delay_tracker.calls()[0]);
831 for (size_t i = 1; i < delay_tracker.calls().size(); i++) { 833 for (size_t i = 1; i < delay_tracker.calls().size(); i++) {
832 EXPECT_LT(calls[i - 1], calls[i]); 834 EXPECT_LT(calls[i - 1], calls[i]);
833 } 835 }
834 } 836 }
835 837
836 } // namespace extensions 838 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698