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

Side by Side Diff: content/browser/appcache/appcache_update_job_unittest.cc

Issue 631773003: Replacing the OVERRIDE with override and FINAL with final in content/browser/appcache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "content/browser/appcache/appcache_group.h" 10 #include "content/browser/appcache/appcache_group.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 (*body) = ""; 190 (*body) = "";
191 } 191 }
192 } 192 }
193 }; 193 };
194 194
195 class MockHttpServerJobFactory 195 class MockHttpServerJobFactory
196 : public net::URLRequestJobFactory::ProtocolHandler { 196 : public net::URLRequestJobFactory::ProtocolHandler {
197 public: 197 public:
198 virtual net::URLRequestJob* MaybeCreateJob( 198 virtual net::URLRequestJob* MaybeCreateJob(
199 net::URLRequest* request, 199 net::URLRequest* request,
200 net::NetworkDelegate* network_delegate) const OVERRIDE { 200 net::NetworkDelegate* network_delegate) const override {
201 return MockHttpServer::JobFactory(request, network_delegate); 201 return MockHttpServer::JobFactory(request, network_delegate);
202 } 202 }
203 }; 203 };
204 204
205 inline bool operator==(const AppCacheNamespace& lhs, 205 inline bool operator==(const AppCacheNamespace& lhs,
206 const AppCacheNamespace& rhs) { 206 const AppCacheNamespace& rhs) {
207 return lhs.type == rhs.type && 207 return lhs.type == rhs.type &&
208 lhs.namespace_url == rhs.namespace_url && 208 lhs.namespace_url == rhs.namespace_url &&
209 lhs.target_url == rhs.target_url; 209 lhs.target_url == rhs.target_url;
210 } 210 }
211 211
212 } // namespace 212 } // namespace
213 213
214 class MockFrontend : public AppCacheFrontend { 214 class MockFrontend : public AppCacheFrontend {
215 public: 215 public:
216 MockFrontend() 216 MockFrontend()
217 : ignore_progress_events_(false), verify_progress_events_(false), 217 : ignore_progress_events_(false), verify_progress_events_(false),
218 last_progress_total_(-1), last_progress_complete_(-1), 218 last_progress_total_(-1), last_progress_complete_(-1),
219 start_update_trigger_(APPCACHE_CHECKING_EVENT), update_(NULL) { 219 start_update_trigger_(APPCACHE_CHECKING_EVENT), update_(NULL) {
220 } 220 }
221 221
222 virtual void OnCacheSelected( 222 virtual void OnCacheSelected(
223 int host_id, const AppCacheInfo& info) OVERRIDE { 223 int host_id, const AppCacheInfo& info) override {
224 } 224 }
225 225
226 virtual void OnStatusChanged(const std::vector<int>& host_ids, 226 virtual void OnStatusChanged(const std::vector<int>& host_ids,
227 AppCacheStatus status) OVERRIDE { 227 AppCacheStatus status) override {
228 } 228 }
229 229
230 virtual void OnEventRaised(const std::vector<int>& host_ids, 230 virtual void OnEventRaised(const std::vector<int>& host_ids,
231 AppCacheEventID event_id) OVERRIDE { 231 AppCacheEventID event_id) override {
232 raised_events_.push_back(RaisedEvent(host_ids, event_id)); 232 raised_events_.push_back(RaisedEvent(host_ids, event_id));
233 233
234 // Trigger additional updates if requested. 234 // Trigger additional updates if requested.
235 if (event_id == start_update_trigger_ && update_) { 235 if (event_id == start_update_trigger_ && update_) {
236 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin(); 236 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin();
237 it != update_hosts_.end(); ++it) { 237 it != update_hosts_.end(); ++it) {
238 AppCacheHost* host = *it; 238 AppCacheHost* host = *it;
239 update_->StartUpdate(host, 239 update_->StartUpdate(host,
240 (host ? host->pending_master_entry_url() : GURL())); 240 (host ? host->pending_master_entry_url() : GURL()));
241 } 241 }
242 update_hosts_.clear(); // only trigger once 242 update_hosts_.clear(); // only trigger once
243 } 243 }
244 } 244 }
245 245
246 virtual void OnErrorEventRaised(const std::vector<int>& host_ids, 246 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
247 const AppCacheErrorDetails& details) 247 const AppCacheErrorDetails& details)
248 OVERRIDE { 248 override {
249 error_message_ = details.message; 249 error_message_ = details.message;
250 OnEventRaised(host_ids, APPCACHE_ERROR_EVENT); 250 OnEventRaised(host_ids, APPCACHE_ERROR_EVENT);
251 } 251 }
252 252
253 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, 253 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
254 const GURL& url, 254 const GURL& url,
255 int num_total, 255 int num_total,
256 int num_complete) OVERRIDE { 256 int num_complete) override {
257 if (!ignore_progress_events_) 257 if (!ignore_progress_events_)
258 OnEventRaised(host_ids, APPCACHE_PROGRESS_EVENT); 258 OnEventRaised(host_ids, APPCACHE_PROGRESS_EVENT);
259 259
260 if (verify_progress_events_) { 260 if (verify_progress_events_) {
261 EXPECT_GE(num_total, num_complete); 261 EXPECT_GE(num_total, num_complete);
262 EXPECT_GE(num_complete, 0); 262 EXPECT_GE(num_complete, 0);
263 263
264 if (last_progress_total_ == -1) { 264 if (last_progress_total_ == -1) {
265 // Should start at zero. 265 // Should start at zero.
266 EXPECT_EQ(0, num_complete); 266 EXPECT_EQ(0, num_complete);
267 } else { 267 } else {
268 // Total should be stable and complete should bump up by one at a time. 268 // Total should be stable and complete should bump up by one at a time.
269 EXPECT_EQ(last_progress_total_, num_total); 269 EXPECT_EQ(last_progress_total_, num_total);
270 EXPECT_EQ(last_progress_complete_ + 1, num_complete); 270 EXPECT_EQ(last_progress_complete_ + 1, num_complete);
271 } 271 }
272 272
273 // Url should be valid for all except the 'final' event. 273 // Url should be valid for all except the 'final' event.
274 if (num_total == num_complete) 274 if (num_total == num_complete)
275 EXPECT_TRUE(url.is_empty()); 275 EXPECT_TRUE(url.is_empty());
276 else 276 else
277 EXPECT_TRUE(url.is_valid()); 277 EXPECT_TRUE(url.is_valid());
278 278
279 last_progress_total_ = num_total; 279 last_progress_total_ = num_total;
280 last_progress_complete_ = num_complete; 280 last_progress_complete_ = num_complete;
281 } 281 }
282 } 282 }
283 283
284 virtual void OnLogMessage(int host_id, 284 virtual void OnLogMessage(int host_id,
285 AppCacheLogLevel log_level, 285 AppCacheLogLevel log_level,
286 const std::string& message) OVERRIDE { 286 const std::string& message) override {
287 } 287 }
288 288
289 virtual void OnContentBlocked(int host_id, 289 virtual void OnContentBlocked(int host_id,
290 const GURL& manifest_url) OVERRIDE { 290 const GURL& manifest_url) override {
291 } 291 }
292 292
293 void AddExpectedEvent(const std::vector<int>& host_ids, 293 void AddExpectedEvent(const std::vector<int>& host_ids,
294 AppCacheEventID event_id) { 294 AppCacheEventID event_id) {
295 DCHECK(!ignore_progress_events_ || event_id != APPCACHE_PROGRESS_EVENT); 295 DCHECK(!ignore_progress_events_ || event_id != APPCACHE_PROGRESS_EVENT);
296 expected_events_.push_back(RaisedEvent(host_ids, event_id)); 296 expected_events_.push_back(RaisedEvent(host_ids, event_id));
297 } 297 }
298 298
299 void SetIgnoreProgressEvents(bool ignore) { 299 void SetIgnoreProgressEvents(bool ignore) {
300 // Some tests involve joining new hosts to an already running update job 300 // Some tests involve joining new hosts to an already running update job
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 AppCacheEventID start_update_trigger_; 340 AppCacheEventID start_update_trigger_;
341 AppCacheUpdateJob* update_; 341 AppCacheUpdateJob* update_;
342 std::vector<AppCacheHost*> update_hosts_; 342 std::vector<AppCacheHost*> update_hosts_;
343 }; 343 };
344 344
345 // Helper factories to simulate redirected URL responses for tests. 345 // Helper factories to simulate redirected URL responses for tests.
346 class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler { 346 class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler {
347 public: 347 public:
348 virtual net::URLRequestJob* MaybeCreateJob( 348 virtual net::URLRequestJob* MaybeCreateJob(
349 net::URLRequest* request, 349 net::URLRequest* request,
350 net::NetworkDelegate* network_delegate) const OVERRIDE { 350 net::NetworkDelegate* network_delegate) const override {
351 return new net::URLRequestTestJob( 351 return new net::URLRequestTestJob(
352 request, 352 request,
353 network_delegate, 353 network_delegate,
354 net::URLRequestTestJob::test_redirect_headers(), 354 net::URLRequestTestJob::test_redirect_headers(),
355 net::URLRequestTestJob::test_data_1(), 355 net::URLRequestTestJob::test_data_1(),
356 true); 356 true);
357 } 357 }
358 }; 358 };
359 359
360 // Helper class to simulate a URL that returns retry or success. 360 // Helper class to simulate a URL that returns retry or success.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 return new RetryRequestTestJob( 392 return new RetryRequestTestJob(
393 request, network_delegate, RetryRequestTestJob::retry_headers(), 503); 393 request, network_delegate, RetryRequestTestJob::retry_headers(), 503);
394 } else { 394 } else {
395 return new RetryRequestTestJob( 395 return new RetryRequestTestJob(
396 request, 396 request,
397 network_delegate, 397 network_delegate,
398 RetryRequestTestJob::manifest_headers(), 200); 398 RetryRequestTestJob::manifest_headers(), 200);
399 } 399 }
400 } 400 }
401 401
402 virtual int GetResponseCode() const OVERRIDE { return response_code_; } 402 virtual int GetResponseCode() const override { return response_code_; }
403 403
404 private: 404 private:
405 virtual ~RetryRequestTestJob() {} 405 virtual ~RetryRequestTestJob() {}
406 406
407 static std::string retry_headers() { 407 static std::string retry_headers() {
408 const char no_retry_after[] = 408 const char no_retry_after[] =
409 "HTTP/1.1 503 BOO HOO\0" 409 "HTTP/1.1 503 BOO HOO\0"
410 "\0"; 410 "\0";
411 const char nonzero[] = 411 const char nonzero[] =
412 "HTTP/1.1 503 BOO HOO\0" 412 "HTTP/1.1 503 BOO HOO\0"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 static int num_retries_; 456 static int num_retries_;
457 static RetryHeader retry_after_; 457 static RetryHeader retry_after_;
458 static int expected_requests_; 458 static int expected_requests_;
459 }; 459 };
460 460
461 class RetryRequestTestJobFactory 461 class RetryRequestTestJobFactory
462 : public net::URLRequestJobFactory::ProtocolHandler { 462 : public net::URLRequestJobFactory::ProtocolHandler {
463 public: 463 public:
464 virtual net::URLRequestJob* MaybeCreateJob( 464 virtual net::URLRequestJob* MaybeCreateJob(
465 net::URLRequest* request, 465 net::URLRequest* request,
466 net::NetworkDelegate* network_delegate) const OVERRIDE { 466 net::NetworkDelegate* network_delegate) const override {
467 return RetryRequestTestJob::RetryFactory(request, network_delegate); 467 return RetryRequestTestJob::RetryFactory(request, network_delegate);
468 } 468 }
469 }; 469 };
470 470
471 // static 471 // static
472 const GURL RetryRequestTestJob::kRetryUrl("http://retry"); 472 const GURL RetryRequestTestJob::kRetryUrl("http://retry");
473 int RetryRequestTestJob::num_requests_ = 0; 473 int RetryRequestTestJob::num_requests_ = 0;
474 int RetryRequestTestJob::num_retries_; 474 int RetryRequestTestJob::num_retries_;
475 RetryRequestTestJob::RetryHeader RetryRequestTestJob::retry_after_; 475 RetryRequestTestJob::RetryHeader RetryRequestTestJob::retry_after_;
476 int RetryRequestTestJob::expected_requests_ = 0; 476 int RetryRequestTestJob::expected_requests_ = 0;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 bool HttpHeadersRequestTestJob::saw_if_modified_since_ = false; 536 bool HttpHeadersRequestTestJob::saw_if_modified_since_ = false;
537 std::string HttpHeadersRequestTestJob::expect_if_none_match_; 537 std::string HttpHeadersRequestTestJob::expect_if_none_match_;
538 bool HttpHeadersRequestTestJob::saw_if_none_match_ = false; 538 bool HttpHeadersRequestTestJob::saw_if_none_match_ = false;
539 bool HttpHeadersRequestTestJob::already_checked_ = false; 539 bool HttpHeadersRequestTestJob::already_checked_ = false;
540 540
541 class IfModifiedSinceJobFactory 541 class IfModifiedSinceJobFactory
542 : public net::URLRequestJobFactory::ProtocolHandler { 542 : public net::URLRequestJobFactory::ProtocolHandler {
543 public: 543 public:
544 virtual net::URLRequestJob* MaybeCreateJob( 544 virtual net::URLRequestJob* MaybeCreateJob(
545 net::URLRequest* request, 545 net::URLRequest* request,
546 net::NetworkDelegate* network_delegate) const OVERRIDE { 546 net::NetworkDelegate* network_delegate) const override {
547 return HttpHeadersRequestTestJob::IfModifiedSinceFactory( 547 return HttpHeadersRequestTestJob::IfModifiedSinceFactory(
548 request, network_delegate); 548 request, network_delegate);
549 } 549 }
550 }; 550 };
551 551
552 class IOThread : public base::Thread { 552 class IOThread : public base::Thread {
553 public: 553 public:
554 explicit IOThread(const char* name) 554 explicit IOThread(const char* name)
555 : base::Thread(name) { 555 : base::Thread(name) {
556 } 556 }
557 557
558 virtual ~IOThread() { 558 virtual ~IOThread() {
559 Stop(); 559 Stop();
560 } 560 }
561 561
562 net::URLRequestContext* request_context() { 562 net::URLRequestContext* request_context() {
563 return request_context_.get(); 563 return request_context_.get();
564 } 564 }
565 565
566 void SetNewJobFactory(net::URLRequestJobFactory* job_factory) { 566 void SetNewJobFactory(net::URLRequestJobFactory* job_factory) {
567 DCHECK(job_factory); 567 DCHECK(job_factory);
568 job_factory_.reset(job_factory); 568 job_factory_.reset(job_factory);
569 request_context_->set_job_factory(job_factory_.get()); 569 request_context_->set_job_factory(job_factory_.get());
570 } 570 }
571 571
572 virtual void Init() OVERRIDE { 572 virtual void Init() override {
573 scoped_ptr<net::URLRequestJobFactoryImpl> factory( 573 scoped_ptr<net::URLRequestJobFactoryImpl> factory(
574 new net::URLRequestJobFactoryImpl()); 574 new net::URLRequestJobFactoryImpl());
575 factory->SetProtocolHandler("http", new MockHttpServerJobFactory); 575 factory->SetProtocolHandler("http", new MockHttpServerJobFactory);
576 factory->SetProtocolHandler("https", new MockHttpServerJobFactory); 576 factory->SetProtocolHandler("https", new MockHttpServerJobFactory);
577 job_factory_ = factory.Pass(); 577 job_factory_ = factory.Pass();
578 request_context_.reset(new net::TestURLRequestContext()); 578 request_context_.reset(new net::TestURLRequestContext());
579 request_context_->set_job_factory(job_factory_.get()); 579 request_context_->set_job_factory(job_factory_.get());
580 } 580 }
581 581
582 virtual void CleanUp() OVERRIDE { 582 virtual void CleanUp() override {
583 request_context_.reset(); 583 request_context_.reset();
584 job_factory_.reset(); 584 job_factory_.reset();
585 } 585 }
586 586
587 private: 587 private:
588 scoped_ptr<net::URLRequestJobFactory> job_factory_; 588 scoped_ptr<net::URLRequestJobFactory> job_factory_;
589 scoped_ptr<net::URLRequestContext> request_context_; 589 scoped_ptr<net::URLRequestContext> request_context_;
590 }; 590 };
591 591
592 class AppCacheUpdateJobTest : public testing::Test, 592 class AppCacheUpdateJobTest : public testing::Test,
(...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after
3010 WaitForUpdateToFinish(); 3010 WaitForUpdateToFinish();
3011 } 3011 }
3012 3012
3013 void WaitForUpdateToFinish() { 3013 void WaitForUpdateToFinish() {
3014 if (group_->update_status() == AppCacheGroup::IDLE) 3014 if (group_->update_status() == AppCacheGroup::IDLE)
3015 UpdateFinished(); 3015 UpdateFinished();
3016 else 3016 else
3017 group_->AddUpdateObserver(this); 3017 group_->AddUpdateObserver(this);
3018 } 3018 }
3019 3019
3020 virtual void OnUpdateComplete(AppCacheGroup* group) OVERRIDE { 3020 virtual void OnUpdateComplete(AppCacheGroup* group) override {
3021 ASSERT_EQ(group_.get(), group); 3021 ASSERT_EQ(group_.get(), group);
3022 protect_newest_cache_ = group->newest_complete_cache(); 3022 protect_newest_cache_ = group->newest_complete_cache();
3023 UpdateFinished(); 3023 UpdateFinished();
3024 } 3024 }
3025 3025
3026 void UpdateFinished() { 3026 void UpdateFinished() {
3027 // We unwind the stack prior to finishing up to let stack-based objects 3027 // We unwind the stack prior to finishing up to let stack-based objects
3028 // get deleted. 3028 // get deleted.
3029 base::MessageLoop::current()->PostTask( 3029 base::MessageLoop::current()->PostTask(
3030 FROM_HERE, 3030 FROM_HERE,
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
3687 3687
3688 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { 3688 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) {
3689 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); 3689 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest);
3690 } 3690 }
3691 3691
3692 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { 3692 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
3693 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); 3693 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest);
3694 } 3694 }
3695 3695
3696 } // namespace content 3696 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_update_job.h ('k') | content/browser/appcache/appcache_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698