Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / appcache / appcache_update_job_unittest.cc
blob569532a2078d8a770caafd32bccb3be824126e96
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
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/stl_util.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/thread.h"
13 #include "content/browser/appcache/appcache_group.h"
14 #include "content/browser/appcache/appcache_host.h"
15 #include "content/browser/appcache/appcache_response.h"
16 #include "content/browser/appcache/appcache_update_job.h"
17 #include "content/browser/appcache/mock_appcache_service.h"
18 #include "net/base/net_errors.h"
19 #include "net/http/http_response_headers.h"
20 #include "net/url_request/url_request_error_job.h"
21 #include "net/url_request/url_request_job_factory_impl.h"
22 #include "net/url_request/url_request_test_job.h"
23 #include "net/url_request/url_request_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h"
26 namespace content {
27 class AppCacheUpdateJobTest;
29 namespace {
31 // Values should match values used in appcache_update_job.cc.
32 const base::TimeDelta kFullUpdateInterval =
33 base::TimeDelta::FromHours(24);
34 const base::TimeDelta kMaxEvictableErrorDuration =
35 base::TimeDelta::FromDays(14);
36 const base::TimeDelta kOneHour =
37 base::TimeDelta::FromHours(1);
39 const char kManifest1Contents[] =
40 "CACHE MANIFEST\n"
41 "explicit1\n"
42 "FALLBACK:\n"
43 "fallback1 fallback1a\n"
44 "NETWORK:\n"
45 "*\n";
47 // There are a handful of http accessible resources that we need to conduct
48 // these tests. Instead of running a seperate server to host these resources,
49 // we mock them up.
50 class MockHttpServer {
51 public:
52 static GURL GetMockUrl(const std::string& path) {
53 return GURL("http://mockhost/" + path);
56 static GURL GetMockHttpsUrl(const std::string& path) {
57 return GURL("https://mockhost/" + path);
60 static GURL GetMockCrossOriginHttpsUrl(const std::string& path) {
61 return GURL("https://cross_origin_host/" + path);
64 static net::URLRequestJob* JobFactory(
65 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
66 if (request->url().host() != "mockhost" &&
67 request->url().host() != "cross_origin_host")
68 return new net::URLRequestErrorJob(request, network_delegate, -100);
70 std::string headers, body;
71 GetMockResponse(request->url().path(), &headers, &body);
72 return new net::URLRequestTestJob(
73 request, network_delegate, headers, body, true);
76 private:
77 static void GetMockResponse(const std::string& path,
78 std::string* headers,
79 std::string* body) {
80 const char ok_headers[] =
81 "HTTP/1.1 200 OK\0"
82 "\0";
83 const char error_headers[] =
84 "HTTP/1.1 500 BOO HOO\0"
85 "\0";
86 const char manifest_headers[] =
87 "HTTP/1.1 200 OK\0"
88 "Content-type: text/cache-manifest\0"
89 "\0";
90 const char not_modified_headers[] =
91 "HTTP/1.1 304 NOT MODIFIED\0"
92 "\0";
93 const char gone_headers[] =
94 "HTTP/1.1 410 GONE\0"
95 "\0";
96 const char not_found_headers[] =
97 "HTTP/1.1 404 NOT FOUND\0"
98 "\0";
99 const char no_store_headers[] =
100 "HTTP/1.1 200 OK\0"
101 "Cache-Control: no-store\0"
102 "\0";
104 if (path == "/files/missing-mime-manifest") {
105 (*headers) = std::string(ok_headers, arraysize(ok_headers));
106 (*body) = "CACHE MANIFEST\n";
107 } else if (path == "/files/bad-manifest") {
108 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
109 (*body) = "BAD CACHE MANIFEST";
110 } else if (path == "/files/empty1") {
111 (*headers) = std::string(ok_headers, arraysize(ok_headers));
112 (*body) = "";
113 } else if (path == "/files/empty-file-manifest") {
114 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
115 (*body) = "CACHE MANIFEST\n"
116 "empty1\n";
117 } else if (path == "/files/empty-manifest") {
118 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
119 (*body) = "CACHE MANIFEST\n";
120 } else if (path == "/files/explicit1") {
121 (*headers) = std::string(ok_headers, arraysize(ok_headers));
122 (*body) = "explicit1";
123 } else if (path == "/files/explicit2") {
124 (*headers) = std::string(ok_headers, arraysize(ok_headers));
125 (*body) = "explicit2";
126 } else if (path == "/files/fallback1a") {
127 (*headers) = std::string(ok_headers, arraysize(ok_headers));
128 (*body) = "fallback1a";
129 } else if (path == "/files/intercept1a") {
130 (*headers) = std::string(ok_headers, arraysize(ok_headers));
131 (*body) = "intercept1a";
132 } else if (path == "/files/gone") {
133 (*headers) = std::string(gone_headers, arraysize(gone_headers));
134 (*body) = "";
135 } else if (path == "/files/manifest1") {
136 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
137 (*body) = kManifest1Contents;
138 } else if (path == "/files/manifest1-with-notmodified") {
139 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
140 (*body) = kManifest1Contents;
141 (*body).append("CACHE:\n"
142 "notmodified\n");
143 } else if (path == "/files/manifest-fb-404") {
144 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
145 (*body) = "CACHE MANIFEST\n"
146 "explicit1\n"
147 "FALLBACK:\n"
148 "fallback1 fallback1a\n"
149 "fallback404 fallback-404\n"
150 "NETWORK:\n"
151 "online1\n";
152 } else if (path == "/files/manifest-merged-types") {
153 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
154 (*body) = "CACHE MANIFEST\n"
155 "explicit1\n"
156 "# manifest is also an explicit entry\n"
157 "manifest-merged-types\n"
158 "FALLBACK:\n"
159 "# fallback is also explicit entry\n"
160 "fallback1 explicit1\n"
161 "NETWORK:\n"
162 "online1\n";
163 } else if (path == "/files/manifest-with-404") {
164 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
165 (*body) = "CACHE MANIFEST\n"
166 "explicit-404\n"
167 "explicit1\n"
168 "explicit2\n"
169 "explicit3\n"
170 "FALLBACK:\n"
171 "fallback1 fallback1a\n"
172 "NETWORK:\n"
173 "online1\n";
174 } else if (path == "/files/manifest-with-intercept") {
175 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
176 (*body) = "CACHE MANIFEST\n"
177 "CHROMIUM-INTERCEPT:\n"
178 "intercept1 return intercept1a\n";
179 } else if (path == "/files/notmodified") {
180 (*headers) = std::string(not_modified_headers,
181 arraysize(not_modified_headers));
182 (*body) = "";
183 } else if (path == "/files/servererror") {
184 (*headers) = std::string(error_headers,
185 arraysize(error_headers));
186 (*body) = "error";
187 } else if (path == "/files/valid_cross_origin_https_manifest") {
188 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
189 (*body) = "CACHE MANIFEST\n"
190 "https://cross_origin_host/files/explicit1\n";
191 } else if (path == "/files/invalid_cross_origin_https_manifest") {
192 (*headers) = std::string(manifest_headers, arraysize(manifest_headers));
193 (*body) = "CACHE MANIFEST\n"
194 "https://cross_origin_host/files/no-store-headers\n";
195 } else if (path == "/files/no-store-headers") {
196 (*headers) = std::string(no_store_headers, arraysize(no_store_headers));
197 (*body) = "no-store";
198 } else {
199 (*headers) = std::string(not_found_headers,
200 arraysize(not_found_headers));
201 (*body) = "";
206 class MockHttpServerJobFactory
207 : public net::URLRequestJobFactory::ProtocolHandler {
208 public:
209 net::URLRequestJob* MaybeCreateJob(
210 net::URLRequest* request,
211 net::NetworkDelegate* network_delegate) const override {
212 return MockHttpServer::JobFactory(request, network_delegate);
216 inline bool operator==(const AppCacheNamespace& lhs,
217 const AppCacheNamespace& rhs) {
218 return lhs.type == rhs.type &&
219 lhs.namespace_url == rhs.namespace_url &&
220 lhs.target_url == rhs.target_url;
223 } // namespace
225 class MockFrontend : public AppCacheFrontend {
226 public:
227 MockFrontend()
228 : ignore_progress_events_(false), verify_progress_events_(false),
229 last_progress_total_(-1), last_progress_complete_(-1),
230 start_update_trigger_(APPCACHE_CHECKING_EVENT), update_(NULL) {
233 void OnCacheSelected(int host_id, const AppCacheInfo& info) override {}
235 void OnStatusChanged(const std::vector<int>& host_ids,
236 AppCacheStatus status) override {}
238 void OnEventRaised(const std::vector<int>& host_ids,
239 AppCacheEventID event_id) override {
240 raised_events_.push_back(RaisedEvent(host_ids, event_id));
242 // Trigger additional updates if requested.
243 if (event_id == start_update_trigger_ && update_) {
244 for (std::vector<AppCacheHost*>::iterator it = update_hosts_.begin();
245 it != update_hosts_.end(); ++it) {
246 AppCacheHost* host = *it;
247 update_->StartUpdate(host,
248 (host ? host->pending_master_entry_url() : GURL()));
250 update_hosts_.clear(); // only trigger once
254 void OnErrorEventRaised(const std::vector<int>& host_ids,
255 const AppCacheErrorDetails& details) override {
256 error_message_ = details.message;
257 OnEventRaised(host_ids, APPCACHE_ERROR_EVENT);
260 void OnProgressEventRaised(const std::vector<int>& host_ids,
261 const GURL& url,
262 int num_total,
263 int num_complete) override {
264 if (!ignore_progress_events_)
265 OnEventRaised(host_ids, APPCACHE_PROGRESS_EVENT);
267 if (verify_progress_events_) {
268 EXPECT_GE(num_total, num_complete);
269 EXPECT_GE(num_complete, 0);
271 if (last_progress_total_ == -1) {
272 // Should start at zero.
273 EXPECT_EQ(0, num_complete);
274 } else {
275 // Total should be stable and complete should bump up by one at a time.
276 EXPECT_EQ(last_progress_total_, num_total);
277 EXPECT_EQ(last_progress_complete_ + 1, num_complete);
280 // Url should be valid for all except the 'final' event.
281 if (num_total == num_complete)
282 EXPECT_TRUE(url.is_empty());
283 else
284 EXPECT_TRUE(url.is_valid());
286 last_progress_total_ = num_total;
287 last_progress_complete_ = num_complete;
291 void OnLogMessage(int host_id,
292 AppCacheLogLevel log_level,
293 const std::string& message) override {}
295 void OnContentBlocked(int host_id, const GURL& manifest_url) override {}
297 void AddExpectedEvent(const std::vector<int>& host_ids,
298 AppCacheEventID event_id) {
299 DCHECK(!ignore_progress_events_ || event_id != APPCACHE_PROGRESS_EVENT);
300 expected_events_.push_back(RaisedEvent(host_ids, event_id));
303 void SetIgnoreProgressEvents(bool ignore) {
304 // Some tests involve joining new hosts to an already running update job
305 // or intentionally failing. The timing and sequencing of the progress
306 // events generated by an update job are dependent on the behavior of
307 // an external HTTP server. For jobs that do not run fully till completion,
308 // due to either joining late or early exit, we skip monitoring the
309 // progress events to avoid flakiness.
310 ignore_progress_events_ = ignore;
313 void SetVerifyProgressEvents(bool verify) {
314 verify_progress_events_ = verify;
317 void TriggerAdditionalUpdates(AppCacheEventID trigger_event,
318 AppCacheUpdateJob* update) {
319 start_update_trigger_ = trigger_event;
320 update_ = update;
323 void AdditionalUpdateHost(AppCacheHost* host) {
324 update_hosts_.push_back(host);
327 typedef std::vector<int> HostIds;
328 typedef std::pair<HostIds, AppCacheEventID> RaisedEvent;
329 typedef std::vector<RaisedEvent> RaisedEvents;
330 RaisedEvents raised_events_;
331 std::string error_message_;
333 // Set the expected events if verification needs to happen asynchronously.
334 RaisedEvents expected_events_;
335 std::string expected_error_message_;
337 bool ignore_progress_events_;
339 bool verify_progress_events_;
340 int last_progress_total_;
341 int last_progress_complete_;
343 // Add ability for frontend to add master entries to an inprogress update.
344 AppCacheEventID start_update_trigger_;
345 AppCacheUpdateJob* update_;
346 std::vector<AppCacheHost*> update_hosts_;
349 // Helper factories to simulate redirected URL responses for tests.
350 class RedirectFactory : public net::URLRequestJobFactory::ProtocolHandler {
351 public:
352 net::URLRequestJob* MaybeCreateJob(
353 net::URLRequest* request,
354 net::NetworkDelegate* network_delegate) const override {
355 return new net::URLRequestTestJob(
356 request,
357 network_delegate,
358 net::URLRequestTestJob::test_redirect_headers(),
359 net::URLRequestTestJob::test_data_1(),
360 true);
364 // Helper class to simulate a URL that returns retry or success.
365 class RetryRequestTestJob : public net::URLRequestTestJob {
366 public:
367 enum RetryHeader {
368 NO_RETRY_AFTER,
369 NONZERO_RETRY_AFTER,
370 RETRY_AFTER_0,
373 static const GURL kRetryUrl;
375 // Call this at the start of each retry test.
376 static void Initialize(int num_retry_responses, RetryHeader header,
377 int expected_requests) {
378 num_requests_ = 0;
379 num_retries_ = num_retry_responses;
380 retry_after_ = header;
381 expected_requests_ = expected_requests;
384 // Verifies results at end of test and resets counters.
385 static void Verify() {
386 EXPECT_EQ(expected_requests_, num_requests_);
387 num_requests_ = 0;
388 expected_requests_ = 0;
391 static net::URLRequestJob* RetryFactory(
392 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
393 ++num_requests_;
394 if (num_retries_ > 0 && request->original_url() == kRetryUrl) {
395 --num_retries_;
396 return new RetryRequestTestJob(
397 request, network_delegate, RetryRequestTestJob::retry_headers(), 503);
398 } else {
399 return new RetryRequestTestJob(
400 request,
401 network_delegate,
402 RetryRequestTestJob::manifest_headers(), 200);
406 int GetResponseCode() const override { return response_code_; }
408 private:
409 ~RetryRequestTestJob() override {}
411 static std::string retry_headers() {
412 const char no_retry_after[] =
413 "HTTP/1.1 503 BOO HOO\0"
414 "\0";
415 const char nonzero[] =
416 "HTTP/1.1 503 BOO HOO\0"
417 "Retry-After: 60\0"
418 "\0";
419 const char retry_after_0[] =
420 "HTTP/1.1 503 BOO HOO\0"
421 "Retry-After: 0\0"
422 "\0";
424 switch (retry_after_) {
425 case NO_RETRY_AFTER:
426 return std::string(no_retry_after, arraysize(no_retry_after));
427 case NONZERO_RETRY_AFTER:
428 return std::string(nonzero, arraysize(nonzero));
429 case RETRY_AFTER_0:
430 default:
431 return std::string(retry_after_0, arraysize(retry_after_0));
435 static std::string manifest_headers() {
436 const char headers[] =
437 "HTTP/1.1 200 OK\0"
438 "Content-type: text/cache-manifest\0"
439 "\0";
440 return std::string(headers, arraysize(headers));
443 static std::string data() {
444 return std::string("CACHE MANIFEST\r"
445 "http://retry\r"); // must be same as kRetryUrl
448 RetryRequestTestJob(net::URLRequest* request,
449 net::NetworkDelegate* network_delegate,
450 const std::string& headers,
451 int response_code)
452 : net::URLRequestTestJob(
453 request, network_delegate, headers, data(), true),
454 response_code_(response_code) {
457 int response_code_;
459 static int num_requests_;
460 static int num_retries_;
461 static RetryHeader retry_after_;
462 static int expected_requests_;
465 class RetryRequestTestJobFactory
466 : public net::URLRequestJobFactory::ProtocolHandler {
467 public:
468 net::URLRequestJob* MaybeCreateJob(
469 net::URLRequest* request,
470 net::NetworkDelegate* network_delegate) const override {
471 return RetryRequestTestJob::RetryFactory(request, network_delegate);
475 // static
476 const GURL RetryRequestTestJob::kRetryUrl("http://retry");
477 int RetryRequestTestJob::num_requests_ = 0;
478 int RetryRequestTestJob::num_retries_;
479 RetryRequestTestJob::RetryHeader RetryRequestTestJob::retry_after_;
480 int RetryRequestTestJob::expected_requests_ = 0;
482 // Helper class to check for certain HTTP headers.
483 class HttpHeadersRequestTestJob : public net::URLRequestTestJob {
484 public:
485 // Call this at the start of each HTTP header-related test.
486 static void Initialize(const std::string& expect_if_modified_since,
487 const std::string& expect_if_none_match) {
488 expect_if_modified_since_ = expect_if_modified_since;
489 expect_if_none_match_ = expect_if_none_match;
492 // Verifies results at end of test and resets class.
493 static void Verify() {
494 if (!expect_if_modified_since_.empty())
495 EXPECT_TRUE(saw_if_modified_since_);
496 if (!expect_if_none_match_.empty())
497 EXPECT_TRUE(saw_if_none_match_);
499 // Reset.
500 expect_if_modified_since_.clear();
501 saw_if_modified_since_ = false;
502 expect_if_none_match_.clear();
503 saw_if_none_match_ = false;
504 already_checked_ = false;
507 static net::URLRequestJob* IfModifiedSinceFactory(
508 net::URLRequest* request, net::NetworkDelegate* network_delegate) {
509 if (!already_checked_) {
510 already_checked_ = true; // only check once for a test
511 const net::HttpRequestHeaders& extra_headers =
512 request->extra_request_headers();
513 std::string header_value;
514 saw_if_modified_since_ =
515 extra_headers.GetHeader(
516 net::HttpRequestHeaders::kIfModifiedSince, &header_value) &&
517 header_value == expect_if_modified_since_;
519 saw_if_none_match_ =
520 extra_headers.GetHeader(
521 net::HttpRequestHeaders::kIfNoneMatch, &header_value) &&
522 header_value == expect_if_none_match_;
524 return MockHttpServer::JobFactory(request, network_delegate);
527 protected:
528 ~HttpHeadersRequestTestJob() override {}
530 private:
531 static std::string expect_if_modified_since_;
532 static bool saw_if_modified_since_;
533 static std::string expect_if_none_match_;
534 static bool saw_if_none_match_;
535 static bool already_checked_;
538 // static
539 std::string HttpHeadersRequestTestJob::expect_if_modified_since_;
540 bool HttpHeadersRequestTestJob::saw_if_modified_since_ = false;
541 std::string HttpHeadersRequestTestJob::expect_if_none_match_;
542 bool HttpHeadersRequestTestJob::saw_if_none_match_ = false;
543 bool HttpHeadersRequestTestJob::already_checked_ = false;
545 class IfModifiedSinceJobFactory
546 : public net::URLRequestJobFactory::ProtocolHandler {
547 public:
548 net::URLRequestJob* MaybeCreateJob(
549 net::URLRequest* request,
550 net::NetworkDelegate* network_delegate) const override {
551 return HttpHeadersRequestTestJob::IfModifiedSinceFactory(
552 request, network_delegate);
556 class IOThread : public base::Thread {
557 public:
558 explicit IOThread(const char* name)
559 : base::Thread(name) {
562 ~IOThread() override { Stop(); }
564 net::URLRequestContext* request_context() {
565 return request_context_.get();
568 void SetNewJobFactory(net::URLRequestJobFactory* job_factory) {
569 DCHECK(job_factory);
570 job_factory_.reset(job_factory);
571 request_context_->set_job_factory(job_factory_.get());
574 void Init() override {
575 scoped_ptr<net::URLRequestJobFactoryImpl> factory(
576 new net::URLRequestJobFactoryImpl());
577 factory->SetProtocolHandler("http",
578 make_scoped_ptr(new MockHttpServerJobFactory));
579 factory->SetProtocolHandler("https",
580 make_scoped_ptr(new MockHttpServerJobFactory));
581 job_factory_ = factory.Pass();
582 request_context_.reset(new net::TestURLRequestContext());
583 request_context_->set_job_factory(job_factory_.get());
586 void CleanUp() override {
587 request_context_.reset();
588 job_factory_.reset();
591 private:
592 scoped_ptr<net::URLRequestJobFactory> job_factory_;
593 scoped_ptr<net::URLRequestContext> request_context_;
596 class AppCacheUpdateJobTest : public testing::Test,
597 public AppCacheGroup::UpdateObserver {
598 public:
599 AppCacheUpdateJobTest()
600 : do_checks_after_update_finished_(false),
601 expect_group_obsolete_(false),
602 expect_group_has_cache_(false),
603 expect_group_is_being_deleted_(false),
604 expect_evictable_error_(false),
605 expect_eviction_(false),
606 expect_old_cache_(NULL),
607 expect_newest_cache_(NULL),
608 expect_non_null_update_time_(false),
609 tested_manifest_(NONE),
610 tested_manifest_path_override_(NULL) {
611 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread"));
612 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
613 io_thread_->StartWithOptions(options);
616 // Use a separate IO thread to run a test. Thread will be destroyed
617 // when it goes out of scope.
618 template <class Method>
619 void RunTestOnIOThread(Method method) {
620 event_.reset(new base::WaitableEvent(false, false));
621 io_thread_->task_runner()->PostTask(
622 FROM_HERE, base::Bind(method, base::Unretained(this)));
624 // Wait until task is done before exiting the test.
625 event_->Wait();
628 void StartCacheAttemptTest() {
629 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
631 MakeService();
632 group_ = new AppCacheGroup(service_->storage(), GURL("http://failme"),
633 service_->storage()->NewGroupId());
635 AppCacheUpdateJob* update =
636 new AppCacheUpdateJob(service_.get(), group_.get());
637 group_->update_job_ = update;
639 MockFrontend mock_frontend;
640 AppCacheHost host(1, &mock_frontend, service_.get());
642 update->StartUpdate(&host, GURL());
644 // Verify state.
645 EXPECT_EQ(AppCacheUpdateJob::CACHE_ATTEMPT, update->update_type_);
646 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST, update->internal_state_);
647 EXPECT_EQ(AppCacheGroup::CHECKING, group_->update_status());
648 EXPECT_TRUE(update->doing_full_update_check_);
650 // Verify notifications.
651 MockFrontend::RaisedEvents& events = mock_frontend.raised_events_;
652 size_t expected = 1;
653 EXPECT_EQ(expected, events.size());
654 EXPECT_EQ(expected, events[0].first.size());
655 EXPECT_EQ(host.host_id(), events[0].first[0]);
656 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second);
658 // Abort as we're not testing actual URL fetches in this test.
659 delete update;
660 UpdateFinished();
663 void StartUpgradeAttemptTest() {
664 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
667 MakeService();
668 group_ = new AppCacheGroup(service_->storage(), GURL("http://failme"),
669 service_->storage()->NewGroupId());
671 // Give the group some existing caches.
672 AppCache* cache1 = MakeCacheForGroup(1, 111);
673 AppCache* cache2 = MakeCacheForGroup(2, 222);
675 // Associate some hosts with caches in the group.
676 MockFrontend mock_frontend1;
677 MockFrontend mock_frontend2;
678 MockFrontend mock_frontend3;
680 AppCacheHost host1(1, &mock_frontend1, service_.get());
681 host1.AssociateCompleteCache(cache1);
683 AppCacheHost host2(2, &mock_frontend2, service_.get());
684 host2.AssociateCompleteCache(cache2);
686 AppCacheHost host3(3, &mock_frontend1, service_.get());
687 host3.AssociateCompleteCache(cache1);
689 AppCacheHost host4(4, &mock_frontend3, service_.get());
691 AppCacheUpdateJob* update =
692 new AppCacheUpdateJob(service_.get(), group_.get());
693 group_->update_job_ = update;
694 update->StartUpdate(&host4, GURL());
696 // Verify state after starting an update.
697 EXPECT_EQ(AppCacheUpdateJob::UPGRADE_ATTEMPT, update->update_type_);
698 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST, update->internal_state_);
699 EXPECT_EQ(AppCacheGroup::CHECKING, group_->update_status());
700 EXPECT_FALSE(update->doing_full_update_check_);
702 // Verify notifications.
703 MockFrontend::RaisedEvents& events = mock_frontend1.raised_events_;
704 size_t expected = 1;
705 EXPECT_EQ(expected, events.size());
706 expected = 2; // 2 hosts using frontend1
707 EXPECT_EQ(expected, events[0].first.size());
708 MockFrontend::HostIds& host_ids = events[0].first;
709 EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host1.host_id())
710 != host_ids.end());
711 EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host3.host_id())
712 != host_ids.end());
713 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second);
715 events = mock_frontend2.raised_events_;
716 expected = 1;
717 EXPECT_EQ(expected, events.size());
718 EXPECT_EQ(expected, events[0].first.size()); // 1 host using frontend2
719 EXPECT_EQ(host2.host_id(), events[0].first[0]);
720 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second);
722 events = mock_frontend3.raised_events_;
723 EXPECT_TRUE(events.empty());
725 // Abort as we're not testing actual URL fetches in this test.
726 delete update;
728 UpdateFinished();
731 void CacheAttemptFetchManifestFailTest() {
732 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
734 MakeService();
735 group_ = new AppCacheGroup(service_->storage(), GURL("http://failme"),
736 service_->storage()->NewGroupId());
737 AppCacheUpdateJob* update =
738 new AppCacheUpdateJob(service_.get(), group_.get());
739 group_->update_job_ = update;
741 MockFrontend* frontend = MakeMockFrontend();
742 AppCacheHost* host = MakeHost(1, frontend);
743 update->StartUpdate(host, GURL());
745 // Set up checks for when update job finishes.
746 do_checks_after_update_finished_ = true;
747 expect_group_obsolete_ = false;
748 expect_group_has_cache_ = false;
749 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
750 APPCACHE_CHECKING_EVENT);
752 WaitForUpdateToFinish();
755 void UpgradeFetchManifestFailTest() {
756 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
758 MakeService();
759 group_ = new AppCacheGroup(service_->storage(),
760 MockHttpServer::GetMockUrl("files/servererror"),
761 service_->storage()->NewGroupId());
762 AppCacheUpdateJob* update =
763 new AppCacheUpdateJob(service_.get(), group_.get());
764 group_->update_job_ = update;
766 AppCache* cache = MakeCacheForGroup(1, 111);
767 MockFrontend* frontend1 = MakeMockFrontend();
768 MockFrontend* frontend2 = MakeMockFrontend();
769 AppCacheHost* host1 = MakeHost(1, frontend1);
770 AppCacheHost* host2 = MakeHost(2, frontend2);
771 host1->AssociateCompleteCache(cache);
772 host2->AssociateCompleteCache(cache);
774 group_->set_last_full_update_check_time(
775 base::Time::Now() - kFullUpdateInterval - kOneHour);
776 update->StartUpdate(NULL, GURL());
777 EXPECT_TRUE(update->doing_full_update_check_);
779 // Set up checks for when update job finishes.
780 do_checks_after_update_finished_ = true;
781 expect_group_obsolete_ = false;
782 expect_group_has_cache_ = true;
783 expect_evictable_error_ = true;
784 expect_newest_cache_ = cache; // newest cache unaffected by update
785 expect_full_update_time_equal_to_ = group_->last_full_update_check_time();
786 MockFrontend::HostIds ids1(1, host1->host_id());
787 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
788 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
789 MockFrontend::HostIds ids2(1, host2->host_id());
790 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
791 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
793 WaitForUpdateToFinish();
796 void ManifestRedirectTest() {
797 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
799 net::URLRequestJobFactoryImpl* new_factory(
800 new net::URLRequestJobFactoryImpl);
801 new_factory->SetProtocolHandler("http",
802 make_scoped_ptr(new RedirectFactory));
803 io_thread_->SetNewJobFactory(new_factory);
805 MakeService();
806 group_ = new AppCacheGroup(service_->storage(), GURL("http://testme"),
807 service_->storage()->NewGroupId());
808 AppCacheUpdateJob* update =
809 new AppCacheUpdateJob(service_.get(), group_.get());
810 group_->update_job_ = update;
812 MockFrontend* frontend = MakeMockFrontend();
813 AppCacheHost* host = MakeHost(1, frontend);
814 update->StartUpdate(host, GURL());
816 // Set up checks for when update job finishes.
817 do_checks_after_update_finished_ = true;
818 expect_group_obsolete_ = false;
819 expect_group_has_cache_ = false; // redirect is like a failed request
820 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
821 APPCACHE_CHECKING_EVENT);
823 WaitForUpdateToFinish();
826 void ManifestMissingMimeTypeTest() {
827 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
829 MakeService();
830 group_ = new AppCacheGroup(
831 service_->storage(),
832 MockHttpServer::GetMockUrl("files/missing-mime-manifest"),
833 service_->storage()->NewGroupId());
834 AppCacheUpdateJob* update =
835 new AppCacheUpdateJob(service_.get(), group_.get());
836 group_->update_job_ = update;
838 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 33);
839 MockFrontend* frontend = MakeMockFrontend();
840 AppCacheHost* host = MakeHost(1, frontend);
841 host->AssociateCompleteCache(cache);
843 frontend->SetVerifyProgressEvents(true);
845 update->StartUpdate(NULL, GURL());
847 // Set up checks for when update job finishes.
848 do_checks_after_update_finished_ = true;
849 expect_group_obsolete_ = false;
850 expect_group_has_cache_ = true;
851 expect_old_cache_ = cache;
852 tested_manifest_ = EMPTY_MANIFEST;
853 tested_manifest_path_override_ = "files/missing-mime-manifest";
854 MockFrontend::HostIds ids(1, host->host_id());
855 frontend->AddExpectedEvent(ids, APPCACHE_CHECKING_EVENT);
856 frontend->AddExpectedEvent(ids, APPCACHE_DOWNLOADING_EVENT);
857 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); // final
858 frontend->AddExpectedEvent(ids, APPCACHE_UPDATE_READY_EVENT);
860 WaitForUpdateToFinish();
863 void ManifestNotFoundTest() {
864 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
866 MakeService();
867 group_ = new AppCacheGroup(
868 service_->storage(), MockHttpServer::GetMockUrl("files/nosuchfile"),
869 service_->storage()->NewGroupId());
870 AppCacheUpdateJob* update =
871 new AppCacheUpdateJob(service_.get(), group_.get());
872 group_->update_job_ = update;
874 AppCache* cache = MakeCacheForGroup(1, 111);
875 MockFrontend* frontend1 = MakeMockFrontend();
876 MockFrontend* frontend2 = MakeMockFrontend();
877 AppCacheHost* host1 = MakeHost(1, frontend1);
878 AppCacheHost* host2 = MakeHost(2, frontend2);
879 host1->AssociateCompleteCache(cache);
880 host2->AssociateCompleteCache(cache);
882 update->StartUpdate(NULL, GURL());
884 // Set up checks for when update job finishes.
885 do_checks_after_update_finished_ = true;
886 expect_group_obsolete_ = true;
887 expect_group_has_cache_ = true;
888 expect_newest_cache_ = cache; // newest cache unaffected by update
889 MockFrontend::HostIds ids1(1, host1->host_id());
890 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
891 frontend1->AddExpectedEvent(ids1, APPCACHE_OBSOLETE_EVENT);
892 MockFrontend::HostIds ids2(1, host2->host_id());
893 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
894 frontend2->AddExpectedEvent(ids2, APPCACHE_OBSOLETE_EVENT);
896 WaitForUpdateToFinish();
899 void ManifestGoneTest() {
900 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
902 MakeService();
903 group_ = new AppCacheGroup(
904 service_->storage(), MockHttpServer::GetMockUrl("files/gone"),
905 service_->storage()->NewGroupId());
906 AppCacheUpdateJob* update =
907 new AppCacheUpdateJob(service_.get(), group_.get());
908 group_->update_job_ = update;
910 MockFrontend* frontend = MakeMockFrontend();
911 AppCacheHost* host = MakeHost(1, frontend);
912 update->StartUpdate(host, GURL());
914 // Set up checks for when update job finishes.
915 do_checks_after_update_finished_ = true;
916 expect_group_obsolete_ = false;
917 expect_group_has_cache_ = false;
918 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
919 APPCACHE_CHECKING_EVENT);
921 WaitForUpdateToFinish();
924 void CacheAttemptNotModifiedTest() {
925 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
927 MakeService();
928 group_ = new AppCacheGroup(
929 service_->storage(), MockHttpServer::GetMockUrl("files/notmodified"),
930 service_->storage()->NewGroupId());
931 AppCacheUpdateJob* update =
932 new AppCacheUpdateJob(service_.get(), group_.get());
933 group_->update_job_ = update;
935 MockFrontend* frontend = MakeMockFrontend();
936 AppCacheHost* host = MakeHost(1, frontend);
937 update->StartUpdate(host, GURL());
939 // Set up checks for when update job finishes.
940 do_checks_after_update_finished_ = true;
941 expect_group_obsolete_ = false;
942 expect_group_has_cache_ = false; // treated like cache failure
943 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
944 APPCACHE_CHECKING_EVENT);
946 WaitForUpdateToFinish();
949 void UpgradeNotModifiedTest() {
950 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
952 MakeService();
953 group_ = new AppCacheGroup(
954 service_->storage(), MockHttpServer::GetMockUrl("files/notmodified"),
955 service_->storage()->NewGroupId());
956 AppCacheUpdateJob* update =
957 new AppCacheUpdateJob(service_.get(), group_.get());
958 group_->update_job_ = update;
960 AppCache* cache = MakeCacheForGroup(1, 111);
961 MockFrontend* frontend1 = MakeMockFrontend();
962 MockFrontend* frontend2 = MakeMockFrontend();
963 AppCacheHost* host1 = MakeHost(1, frontend1);
964 AppCacheHost* host2 = MakeHost(2, frontend2);
965 host1->AssociateCompleteCache(cache);
966 host2->AssociateCompleteCache(cache);
968 group_->set_last_full_update_check_time(
969 base::Time::Now() - kFullUpdateInterval - kOneHour);
970 group_->set_first_evictable_error_time(base::Time::Now());
971 update->StartUpdate(NULL, GURL());
972 EXPECT_TRUE(update->doing_full_update_check_);
974 // Set up checks for when update job finishes.
975 do_checks_after_update_finished_ = true;
976 expect_group_obsolete_ = false;
977 expect_group_has_cache_ = true;
978 expect_newest_cache_ = cache; // newest cache unaffected by update
979 expect_evictable_error_ = false; // should be reset
980 expect_full_update_time_newer_than_ = group_->last_full_update_check_time();
981 MockFrontend::HostIds ids1(1, host1->host_id());
982 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
983 frontend1->AddExpectedEvent(ids1, APPCACHE_NO_UPDATE_EVENT);
984 MockFrontend::HostIds ids2(1, host2->host_id());
985 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
986 frontend2->AddExpectedEvent(ids2, APPCACHE_NO_UPDATE_EVENT);
988 WaitForUpdateToFinish();
991 void UpgradeManifestDataUnchangedTest() {
992 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
994 MakeService();
995 group_ = new AppCacheGroup(
996 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
997 service_->storage()->NewGroupId());
998 AppCacheUpdateJob* update =
999 new AppCacheUpdateJob(service_.get(), group_.get());
1000 group_->update_job_ = update;
1002 // Create response writer to get a response id.
1003 response_writer_.reset(
1004 service_->storage()->CreateResponseWriter(group_->manifest_url(),
1005 group_->group_id()));
1007 AppCache* cache = MakeCacheForGroup(1, response_writer_->response_id());
1008 MockFrontend* frontend1 = MakeMockFrontend();
1009 MockFrontend* frontend2 = MakeMockFrontend();
1010 AppCacheHost* host1 = MakeHost(1, frontend1);
1011 AppCacheHost* host2 = MakeHost(2, frontend2);
1012 host1->AssociateCompleteCache(cache);
1013 host2->AssociateCompleteCache(cache);
1015 // Set up checks for when update job finishes.
1016 do_checks_after_update_finished_ = true;
1017 expect_group_obsolete_ = false;
1018 expect_group_has_cache_ = true;
1019 expect_newest_cache_ = cache; // newest cache unaffected by update
1020 MockFrontend::HostIds ids1(1, host1->host_id());
1021 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1022 frontend1->AddExpectedEvent(ids1, APPCACHE_NO_UPDATE_EVENT);
1023 MockFrontend::HostIds ids2(1, host2->host_id());
1024 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1025 frontend2->AddExpectedEvent(ids2, APPCACHE_NO_UPDATE_EVENT);
1027 // Seed storage with expected manifest data.
1028 const std::string seed_data(kManifest1Contents);
1029 scoped_refptr<net::StringIOBuffer> io_buffer(
1030 new net::StringIOBuffer(seed_data));
1031 response_writer_->WriteData(
1032 io_buffer.get(),
1033 seed_data.length(),
1034 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1035 base::Unretained(this)));
1037 // Start update after data write completes asynchronously.
1040 // See http://code.google.com/p/chromium/issues/detail?id=95101
1041 void Bug95101Test() {
1042 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1044 MakeService();
1045 group_ = new AppCacheGroup(
1046 service_->storage(), MockHttpServer::GetMockUrl("files/empty-manifest"),
1047 service_->storage()->NewGroupId());
1048 AppCacheUpdateJob* update =
1049 new AppCacheUpdateJob(service_.get(), group_.get());
1050 group_->update_job_ = update;
1052 // Create a malformed cache with a missing manifest entry.
1053 GURL wrong_manifest_url =
1054 MockHttpServer::GetMockUrl("files/missing-mime-manifest");
1055 AppCache* cache = MakeCacheForGroup(1, wrong_manifest_url, 111);
1056 MockFrontend* frontend = MakeMockFrontend();
1057 AppCacheHost* host = MakeHost(1, frontend);
1058 host->AssociateCompleteCache(cache);
1060 update->StartUpdate(NULL, GURL());
1062 // Set up checks for when update job finishes.
1063 do_checks_after_update_finished_ = true;
1064 expect_group_is_being_deleted_ = true;
1065 expect_group_has_cache_ = true;
1066 expect_newest_cache_ = cache; // newest cache unaffected by update
1067 MockFrontend::HostIds id(1, host->host_id());
1068 frontend->AddExpectedEvent(id, APPCACHE_CHECKING_EVENT);
1069 frontend->AddExpectedEvent(id, APPCACHE_ERROR_EVENT);
1070 frontend->expected_error_message_ =
1071 "Manifest entry not found in existing cache";
1072 WaitForUpdateToFinish();
1075 void StartUpdateAfterSeedingStorageData(int result) {
1076 ASSERT_GT(result, 0);
1077 response_writer_.reset();
1079 AppCacheUpdateJob* update = group_->update_job_;
1080 update->StartUpdate(NULL, GURL());
1082 WaitForUpdateToFinish();
1085 void BasicCacheAttemptSuccessTest() {
1086 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1088 GURL manifest_url = MockHttpServer::GetMockUrl("files/manifest1");
1090 MakeService();
1091 group_ = new AppCacheGroup(
1092 service_->storage(), manifest_url,
1093 service_->storage()->NewGroupId());
1094 ASSERT_TRUE(group_->last_full_update_check_time().is_null());
1095 AppCacheUpdateJob* update =
1096 new AppCacheUpdateJob(service_.get(), group_.get());
1097 group_->update_job_ = update;
1099 MockFrontend* frontend = MakeMockFrontend();
1100 AppCacheHost* host = MakeHost(1, frontend);
1101 update->StartUpdate(host, GURL());
1103 // Set up checks for when update job finishes.
1104 do_checks_after_update_finished_ = true;
1105 expect_group_obsolete_ = false;
1106 expect_group_has_cache_ = true;
1107 expect_full_update_time_newer_than_ = base::Time::Now() - kOneHour;
1108 tested_manifest_ = MANIFEST1;
1109 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1110 APPCACHE_CHECKING_EVENT);
1112 WaitForUpdateToFinish();
1115 void DownloadInterceptEntriesTest() {
1116 // Ensures we download intercept entries too.
1117 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1118 GURL manifest_url =
1119 MockHttpServer::GetMockUrl("files/manifest-with-intercept");
1120 MakeService();
1121 group_ = new AppCacheGroup(
1122 service_->storage(), manifest_url,
1123 service_->storage()->NewGroupId());
1124 AppCacheUpdateJob* update =
1125 new AppCacheUpdateJob(service_.get(), group_.get());
1126 group_->update_job_ = update;
1128 MockFrontend* frontend = MakeMockFrontend();
1129 AppCacheHost* host = MakeHost(1, frontend);
1130 update->StartUpdate(host, GURL());
1132 // Set up checks for when update job finishes.
1133 do_checks_after_update_finished_ = true;
1134 expect_group_obsolete_ = false;
1135 expect_group_has_cache_ = true;
1136 tested_manifest_ = MANIFEST_WITH_INTERCEPT;
1137 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1138 APPCACHE_CHECKING_EVENT);
1140 WaitForUpdateToFinish();
1143 void BasicUpgradeSuccessTest() {
1144 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1146 MakeService();
1147 group_ = new AppCacheGroup(
1148 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1149 service_->storage()->NewGroupId());
1150 AppCacheUpdateJob* update =
1151 new AppCacheUpdateJob(service_.get(), group_.get());
1152 group_->update_job_ = update;
1154 // Create a response writer to get a response id.
1155 response_writer_.reset(
1156 service_->storage()->CreateResponseWriter(group_->manifest_url(),
1157 group_->group_id()));
1159 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(),
1160 response_writer_->response_id());
1161 MockFrontend* frontend1 = MakeMockFrontend();
1162 MockFrontend* frontend2 = MakeMockFrontend();
1163 AppCacheHost* host1 = MakeHost(1, frontend1);
1164 AppCacheHost* host2 = MakeHost(2, frontend2);
1165 host1->AssociateCompleteCache(cache);
1166 host2->AssociateCompleteCache(cache);
1167 frontend1->SetVerifyProgressEvents(true);
1168 frontend2->SetVerifyProgressEvents(true);
1169 group_->set_last_full_update_check_time(
1170 base::Time::Now() - kFullUpdateInterval - kOneHour);
1172 // Set up checks for when update job finishes.
1173 do_checks_after_update_finished_ = true;
1174 expect_group_obsolete_ = false;
1175 expect_group_has_cache_ = true;
1176 expect_old_cache_ = cache;
1177 tested_manifest_ = MANIFEST1;
1178 expect_full_update_time_newer_than_ = group_->last_full_update_check_time();
1179 MockFrontend::HostIds ids1(1, host1->host_id());
1180 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1181 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1182 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
1183 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
1184 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
1185 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
1186 MockFrontend::HostIds ids2(1, host2->host_id());
1187 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1188 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
1189 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
1190 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
1191 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // final
1192 frontend2->AddExpectedEvent(ids2, APPCACHE_UPDATE_READY_EVENT);
1194 // Seed storage with expected manifest data different from manifest1.
1195 const std::string seed_data("different");
1196 scoped_refptr<net::StringIOBuffer> io_buffer(
1197 new net::StringIOBuffer(seed_data));
1198 response_writer_->WriteData(
1199 io_buffer.get(),
1200 seed_data.length(),
1201 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1202 base::Unretained(this)));
1204 // Start update after data write completes asynchronously.
1207 void UpgradeLoadFromNewestCacheTest() {
1208 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1210 MakeService();
1211 group_ = new AppCacheGroup(
1212 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1213 service_->storage()->NewGroupId());
1214 AppCacheUpdateJob* update =
1215 new AppCacheUpdateJob(service_.get(), group_.get());
1216 group_->update_job_ = update;
1218 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
1219 MockFrontend* frontend = MakeMockFrontend();
1220 AppCacheHost* host = MakeHost(1, frontend);
1221 host->AssociateCompleteCache(cache);
1223 // Give the newest cache an entry that is in storage.
1224 response_writer_.reset(
1225 service_->storage()->CreateResponseWriter(group_->manifest_url(),
1226 group_->group_id()));
1227 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1228 AppCacheEntry(AppCacheEntry::EXPLICIT,
1229 response_writer_->response_id()));
1231 // Set up checks for when update job finishes.
1232 do_checks_after_update_finished_ = true;
1233 expect_group_obsolete_ = false;
1234 expect_group_has_cache_ = true;
1235 expect_old_cache_ = cache;
1236 expect_response_ids_.insert(
1237 std::map<GURL, int64>::value_type(
1238 MockHttpServer::GetMockUrl("files/explicit1"),
1239 response_writer_->response_id()));
1240 tested_manifest_ = MANIFEST1;
1241 MockFrontend::HostIds ids(1, host->host_id());
1242 frontend->AddExpectedEvent(ids, APPCACHE_CHECKING_EVENT);
1243 frontend->AddExpectedEvent(ids, APPCACHE_DOWNLOADING_EVENT);
1244 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT);
1245 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT);
1246 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); // final
1247 frontend->AddExpectedEvent(ids, APPCACHE_UPDATE_READY_EVENT);
1249 // Seed storage with expected http response info for entry. Allow reuse.
1250 const char data[] =
1251 "HTTP/1.1 200 OK\0"
1252 "Cache-Control: max-age=8675309\0"
1253 "\0";
1254 net::HttpResponseHeaders* headers =
1255 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
1256 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
1257 response_info->request_time = base::Time::Now();
1258 response_info->response_time = base::Time::Now();
1259 response_info->headers = headers; // adds ref to headers
1260 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
1261 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
1262 response_writer_->WriteInfo(
1263 io_buffer.get(),
1264 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1265 base::Unretained(this)));
1267 // Start update after data write completes asynchronously.
1270 void UpgradeNoLoadFromNewestCacheTest() {
1271 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1273 MakeService();
1274 group_ = new AppCacheGroup(
1275 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1276 service_->storage()->NewGroupId());
1277 AppCacheUpdateJob* update =
1278 new AppCacheUpdateJob(service_.get(), group_.get());
1279 group_->update_job_ = update;
1281 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
1282 MockFrontend* frontend = MakeMockFrontend();
1283 AppCacheHost* host = MakeHost(1, frontend);
1284 host->AssociateCompleteCache(cache);
1286 // Give the newest cache an entry that is in storage.
1287 response_writer_.reset(
1288 service_->storage()->CreateResponseWriter(group_->manifest_url(),
1289 group_->group_id()));
1290 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1291 AppCacheEntry(AppCacheEntry::EXPLICIT,
1292 response_writer_->response_id()));
1294 // Set up checks for when update job finishes.
1295 do_checks_after_update_finished_ = true;
1296 expect_group_obsolete_ = false;
1297 expect_group_has_cache_ = true;
1298 expect_old_cache_ = cache;
1299 tested_manifest_ = MANIFEST1;
1300 MockFrontend::HostIds ids(1, host->host_id());
1301 frontend->AddExpectedEvent(ids, APPCACHE_CHECKING_EVENT);
1302 frontend->AddExpectedEvent(ids, APPCACHE_DOWNLOADING_EVENT);
1303 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT);
1304 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT);
1305 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); // final
1306 frontend->AddExpectedEvent(ids, APPCACHE_UPDATE_READY_EVENT);
1308 // Seed storage with expected http response info for entry. Do NOT
1309 // allow reuse by setting an expires header in the past.
1310 const char data[] =
1311 "HTTP/1.1 200 OK\0"
1312 "Expires: Thu, 01 Dec 1994 16:00:00 GMT\0"
1313 "\0";
1314 net::HttpResponseHeaders* headers =
1315 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
1316 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
1317 response_info->request_time = base::Time::Now();
1318 response_info->response_time = base::Time::Now();
1319 response_info->headers = headers; // adds ref to headers
1320 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
1321 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
1322 response_writer_->WriteInfo(
1323 io_buffer.get(),
1324 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1325 base::Unretained(this)));
1327 // Start update after data write completes asynchronously.
1330 void UpgradeLoadFromNewestCacheVaryHeaderTest() {
1331 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1333 MakeService();
1334 group_ = new AppCacheGroup(
1335 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1336 service_->storage()->NewGroupId());
1337 AppCacheUpdateJob* update =
1338 new AppCacheUpdateJob(service_.get(), group_.get());
1339 group_->update_job_ = update;
1341 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
1342 MockFrontend* frontend = MakeMockFrontend();
1343 AppCacheHost* host = MakeHost(1, frontend);
1344 host->AssociateCompleteCache(cache);
1346 // Give the newest cache an entry that is in storage.
1347 response_writer_.reset(
1348 service_->storage()->CreateResponseWriter(group_->manifest_url(),
1349 group_->group_id()));
1350 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1351 AppCacheEntry(AppCacheEntry::EXPLICIT,
1352 response_writer_->response_id()));
1354 // Set up checks for when update job finishes.
1355 do_checks_after_update_finished_ = true;
1356 expect_group_obsolete_ = false;
1357 expect_group_has_cache_ = true;
1358 expect_old_cache_ = cache;
1359 tested_manifest_ = MANIFEST1;
1360 MockFrontend::HostIds ids(1, host->host_id());
1361 frontend->AddExpectedEvent(ids, APPCACHE_CHECKING_EVENT);
1362 frontend->AddExpectedEvent(ids, APPCACHE_DOWNLOADING_EVENT);
1363 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT);
1364 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT);
1365 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); // final
1366 frontend->AddExpectedEvent(ids, APPCACHE_UPDATE_READY_EVENT);
1368 // Seed storage with expected http response info for entry: a vary header.
1369 const char data[] =
1370 "HTTP/1.1 200 OK\0"
1371 "Cache-Control: max-age=8675309\0"
1372 "Vary: blah\0"
1373 "\0";
1374 net::HttpResponseHeaders* headers =
1375 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
1376 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
1377 response_info->request_time = base::Time::Now();
1378 response_info->response_time = base::Time::Now();
1379 response_info->headers = headers; // adds ref to headers
1380 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
1381 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
1382 response_writer_->WriteInfo(
1383 io_buffer.get(),
1384 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1385 base::Unretained(this)));
1387 // Start update after data write completes asynchronously.
1390 void UpgradeSuccessMergedTypesTest() {
1391 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1393 MakeService();
1394 group_ = new AppCacheGroup(service_->storage(),
1395 MockHttpServer::GetMockUrl("files/manifest-merged-types"),
1396 service_->storage()->NewGroupId());
1397 AppCacheUpdateJob* update =
1398 new AppCacheUpdateJob(service_.get(), group_.get());
1399 group_->update_job_ = update;
1401 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
1402 MockFrontend* frontend1 = MakeMockFrontend();
1403 MockFrontend* frontend2 = MakeMockFrontend();
1404 AppCacheHost* host1 = MakeHost(1, frontend1);
1405 AppCacheHost* host2 = MakeHost(2, frontend2);
1406 host1->AssociateCompleteCache(cache);
1407 host2->AssociateCompleteCache(cache);
1409 // Give the newest cache a master entry that is also one of the explicit
1410 // entries in the manifest.
1411 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1412 AppCacheEntry(AppCacheEntry::MASTER, 111));
1414 update->StartUpdate(NULL, GURL());
1416 // Set up checks for when update job finishes.
1417 do_checks_after_update_finished_ = true;
1418 expect_group_obsolete_ = false;
1419 expect_group_has_cache_ = true;
1420 expect_old_cache_ = cache;
1421 tested_manifest_ = MANIFEST_MERGED_TYPES;
1422 MockFrontend::HostIds ids1(1, host1->host_id());
1423 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1424 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1425 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit1
1426 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // manifest
1427 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
1428 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
1429 MockFrontend::HostIds ids2(1, host2->host_id());
1430 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1431 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
1432 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
1433 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
1434 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // final
1435 frontend2->AddExpectedEvent(ids2, APPCACHE_UPDATE_READY_EVENT);
1437 WaitForUpdateToFinish();
1440 void CacheAttemptFailUrlFetchTest() {
1441 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1443 MakeService();
1444 group_ = new AppCacheGroup(service_->storage(),
1445 MockHttpServer::GetMockUrl("files/manifest-with-404"),
1446 service_->storage()->NewGroupId());
1447 AppCacheUpdateJob* update =
1448 new AppCacheUpdateJob(service_.get(), group_.get());
1449 group_->update_job_ = update;
1451 MockFrontend* frontend = MakeMockFrontend();
1452 AppCacheHost* host = MakeHost(1, frontend);
1453 update->StartUpdate(host, GURL());
1455 // Set up checks for when update job finishes.
1456 do_checks_after_update_finished_ = true;
1457 expect_group_obsolete_ = false;
1458 expect_group_has_cache_ = false; // 404 explicit url is cache failure
1459 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1460 APPCACHE_CHECKING_EVENT);
1462 WaitForUpdateToFinish();
1465 void UpgradeFailUrlFetchTest() {
1466 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1468 MakeService();
1469 group_ = new AppCacheGroup(service_->storage(),
1470 MockHttpServer::GetMockUrl("files/manifest-fb-404"),
1471 service_->storage()->NewGroupId());
1472 AppCacheUpdateJob* update =
1473 new AppCacheUpdateJob(service_.get(), group_.get());
1474 group_->update_job_ = update;
1476 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 99);
1477 group_->set_first_evictable_error_time(
1478 base::Time::Now() - kMaxEvictableErrorDuration - kOneHour);
1479 MockFrontend* frontend1 = MakeMockFrontend();
1480 MockFrontend* frontend2 = MakeMockFrontend();
1481 frontend1->SetIgnoreProgressEvents(true);
1482 frontend2->SetIgnoreProgressEvents(true);
1483 AppCacheHost* host1 = MakeHost(1, frontend1);
1484 AppCacheHost* host2 = MakeHost(2, frontend2);
1485 host1->AssociateCompleteCache(cache);
1486 host2->AssociateCompleteCache(cache);
1488 update->StartUpdate(NULL, GURL());
1490 // Set up checks for when update job finishes.
1491 do_checks_after_update_finished_ = true;
1492 expect_group_obsolete_ = false;
1493 expect_group_has_cache_ = true;
1494 expect_newest_cache_ = cache; // newest cache unaffectd by failed update
1495 expect_eviction_ = true;
1496 MockFrontend::HostIds ids1(1, host1->host_id());
1497 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1498 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1499 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
1500 MockFrontend::HostIds ids2(1, host2->host_id());
1501 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1502 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
1503 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
1505 WaitForUpdateToFinish();
1508 void UpgradeFailMasterUrlFetchTest() {
1509 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1511 tested_manifest_path_override_ = "files/manifest1-with-notmodified";
1513 MakeService();
1514 const GURL kManifestUrl =
1515 MockHttpServer::GetMockUrl(tested_manifest_path_override_);
1516 group_ = new AppCacheGroup(
1517 service_->storage(), kManifestUrl,
1518 service_->storage()->NewGroupId());
1519 AppCacheUpdateJob* update =
1520 new AppCacheUpdateJob(service_.get(), group_.get());
1521 group_->update_job_ = update;
1523 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 25);
1524 MockFrontend* frontend1 = MakeMockFrontend();
1525 MockFrontend* frontend2 = MakeMockFrontend();
1526 AppCacheHost* host1 = MakeHost(1, frontend1);
1527 AppCacheHost* host2 = MakeHost(2, frontend2);
1528 host1->AssociateCompleteCache(cache);
1529 host2->AssociateCompleteCache(cache);
1531 // Give the newest cache some existing entries; one will fail with a 404.
1532 cache->AddEntry(
1533 MockHttpServer::GetMockUrl("files/notfound"),
1534 AppCacheEntry(AppCacheEntry::MASTER, 222));
1535 cache->AddEntry(
1536 MockHttpServer::GetMockUrl("files/explicit2"),
1537 AppCacheEntry(AppCacheEntry::MASTER | AppCacheEntry::FOREIGN, 333));
1538 cache->AddEntry(
1539 MockHttpServer::GetMockUrl("files/servererror"),
1540 AppCacheEntry(AppCacheEntry::MASTER, 444));
1541 cache->AddEntry(
1542 MockHttpServer::GetMockUrl("files/notmodified"),
1543 AppCacheEntry(AppCacheEntry::EXPLICIT, 555));
1545 // Seed the response_info working set with canned data for
1546 // files/servererror and for files/notmodified to test that the
1547 // existing entries for those resource are reused by the update job.
1548 const char kData[] =
1549 "HTTP/1.1 200 OK\0"
1550 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
1551 "\0";
1552 const std::string kRawHeaders(kData, arraysize(kData));
1553 MakeAppCacheResponseInfo(kManifestUrl, 444, kRawHeaders);
1554 MakeAppCacheResponseInfo(kManifestUrl, 555, kRawHeaders);
1556 update->StartUpdate(NULL, GURL());
1558 // Set up checks for when update job finishes.
1559 do_checks_after_update_finished_ = true;
1560 expect_group_obsolete_ = false;
1561 expect_group_has_cache_ = true;
1562 expect_old_cache_ = cache;
1563 tested_manifest_ = MANIFEST1;
1564 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
1565 MockHttpServer::GetMockUrl("files/explicit2"),
1566 AppCacheEntry(AppCacheEntry::MASTER))); // foreign flag is dropped
1567 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
1568 MockHttpServer::GetMockUrl("files/servererror"),
1569 AppCacheEntry(AppCacheEntry::MASTER)));
1570 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
1571 MockHttpServer::GetMockUrl("files/notmodified"),
1572 AppCacheEntry(AppCacheEntry::EXPLICIT)));
1573 expect_response_ids_.insert(std::map<GURL, int64>::value_type(
1574 MockHttpServer::GetMockUrl("files/servererror"), 444)); // copied
1575 expect_response_ids_.insert(std::map<GURL, int64>::value_type(
1576 MockHttpServer::GetMockUrl("files/notmodified"), 555)); // copied
1577 MockFrontend::HostIds ids1(1, host1->host_id());
1578 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1579 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1580 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit1
1581 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // fallback1a
1582 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // notfound
1583 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit2
1584 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // servererror
1585 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // notmodified
1586 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
1587 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
1588 MockFrontend::HostIds ids2(1, host2->host_id());
1589 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1590 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
1591 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // explicit1
1592 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // fallback1a
1593 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // notfound
1594 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // explicit2
1595 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // servererror
1596 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // notmodified
1597 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // final
1598 frontend2->AddExpectedEvent(ids2, APPCACHE_UPDATE_READY_EVENT);
1600 WaitForUpdateToFinish();
1603 void EmptyManifestTest() {
1604 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1606 MakeService();
1607 group_ = new AppCacheGroup(
1608 service_->storage(), MockHttpServer::GetMockUrl("files/empty-manifest"),
1609 service_->storage()->NewGroupId());
1610 AppCacheUpdateJob* update =
1611 new AppCacheUpdateJob(service_.get(), group_.get());
1612 group_->update_job_ = update;
1614 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 33);
1615 MockFrontend* frontend1 = MakeMockFrontend();
1616 MockFrontend* frontend2 = MakeMockFrontend();
1617 AppCacheHost* host1 = MakeHost(1, frontend1);
1618 AppCacheHost* host2 = MakeHost(2, frontend2);
1619 host1->AssociateCompleteCache(cache);
1620 host2->AssociateCompleteCache(cache);
1622 frontend1->SetVerifyProgressEvents(true);
1624 update->StartUpdate(NULL, GURL());
1626 // Set up checks for when update job finishes.
1627 do_checks_after_update_finished_ = true;
1628 expect_group_obsolete_ = false;
1629 expect_group_has_cache_ = true;
1630 expect_old_cache_ = cache;
1631 tested_manifest_ = EMPTY_MANIFEST;
1632 MockFrontend::HostIds ids1(1, host1->host_id());
1633 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1634 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1635 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
1636 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
1637 MockFrontend::HostIds ids2(1, host2->host_id());
1638 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1639 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
1640 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // final
1641 frontend2->AddExpectedEvent(ids2, APPCACHE_UPDATE_READY_EVENT);
1643 WaitForUpdateToFinish();
1646 void EmptyFileTest() {
1647 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1649 MakeService();
1650 group_ = new AppCacheGroup(service_->storage(),
1651 MockHttpServer::GetMockUrl("files/empty-file-manifest"),
1652 service_->storage()->NewGroupId());
1653 AppCacheUpdateJob* update =
1654 new AppCacheUpdateJob(service_.get(), group_.get());
1655 group_->update_job_ = update;
1657 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 22);
1658 MockFrontend* frontend = MakeMockFrontend();
1659 AppCacheHost* host = MakeHost(1, frontend);
1660 host->AssociateCompleteCache(cache);
1661 frontend->SetVerifyProgressEvents(true);
1663 update->StartUpdate(host, GURL());
1665 // Set up checks for when update job finishes.
1666 do_checks_after_update_finished_ = true;
1667 expect_group_obsolete_ = false;
1668 expect_group_has_cache_ = true;
1669 tested_manifest_ = EMPTY_FILE_MANIFEST;
1670 MockFrontend::HostIds ids1(1, host->host_id());
1671 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1672 frontend->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1673 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
1674 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
1675 frontend->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
1677 WaitForUpdateToFinish();
1680 void RetryRequestTest() {
1681 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1683 // Set some large number of times to return retry.
1684 // Expect 1 manifest fetch and 3 retries.
1685 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0, 4);
1686 net::URLRequestJobFactoryImpl* new_factory(
1687 new net::URLRequestJobFactoryImpl);
1688 new_factory->SetProtocolHandler(
1689 "http", make_scoped_ptr(new RetryRequestTestJobFactory));
1690 io_thread_->SetNewJobFactory(new_factory);
1692 MakeService();
1693 group_ = new AppCacheGroup(service_->storage(),
1694 RetryRequestTestJob::kRetryUrl,
1695 service_->storage()->NewGroupId());
1696 AppCacheUpdateJob* update =
1697 new AppCacheUpdateJob(service_.get(), group_.get());
1698 group_->update_job_ = update;
1700 MockFrontend* frontend = MakeMockFrontend();
1701 AppCacheHost* host = MakeHost(1, frontend);
1702 update->StartUpdate(host, GURL());
1704 // Set up checks for when update job finishes.
1705 do_checks_after_update_finished_ = true;
1706 expect_group_obsolete_ = false;
1707 expect_group_has_cache_ = false;
1708 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1709 APPCACHE_CHECKING_EVENT);
1711 WaitForUpdateToFinish();
1714 void RetryNoRetryAfterTest() {
1715 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1717 // Set some large number of times to return retry.
1718 // Expect 1 manifest fetch and 0 retries.
1719 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER, 1);
1720 net::URLRequestJobFactoryImpl* new_factory(
1721 new net::URLRequestJobFactoryImpl);
1722 new_factory->SetProtocolHandler(
1723 "http", make_scoped_ptr(new RetryRequestTestJobFactory));
1724 io_thread_->SetNewJobFactory(new_factory);
1726 MakeService();
1727 group_ = new AppCacheGroup(service_->storage(),
1728 RetryRequestTestJob::kRetryUrl,
1729 service_->storage()->NewGroupId());
1730 AppCacheUpdateJob* update =
1731 new AppCacheUpdateJob(service_.get(), group_.get());
1732 group_->update_job_ = update;
1734 MockFrontend* frontend = MakeMockFrontend();
1735 AppCacheHost* host = MakeHost(1, frontend);
1736 update->StartUpdate(host, GURL());
1738 // Set up checks for when update job finishes.
1739 do_checks_after_update_finished_ = true;
1740 expect_group_obsolete_ = false;
1741 expect_group_has_cache_ = false;
1742 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1743 APPCACHE_CHECKING_EVENT);
1745 WaitForUpdateToFinish();
1748 void RetryNonzeroRetryAfterTest() {
1749 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1751 // Set some large number of times to return retry.
1752 // Expect 1 request and 0 retry attempts.
1753 RetryRequestTestJob::Initialize(
1754 5, RetryRequestTestJob::NONZERO_RETRY_AFTER, 1);
1755 net::URLRequestJobFactoryImpl* new_factory(
1756 new net::URLRequestJobFactoryImpl);
1757 new_factory->SetProtocolHandler(
1758 "http", make_scoped_ptr(new RetryRequestTestJobFactory));
1759 io_thread_->SetNewJobFactory(new_factory);
1761 MakeService();
1762 group_ = new AppCacheGroup(service_->storage(),
1763 RetryRequestTestJob::kRetryUrl,
1764 service_->storage()->NewGroupId());
1765 AppCacheUpdateJob* update =
1766 new AppCacheUpdateJob(service_.get(), group_.get());
1767 group_->update_job_ = update;
1769 MockFrontend* frontend = MakeMockFrontend();
1770 AppCacheHost* host = MakeHost(1, frontend);
1771 update->StartUpdate(host, GURL());
1773 // Set up checks for when update job finishes.
1774 do_checks_after_update_finished_ = true;
1775 expect_group_obsolete_ = false;
1776 expect_group_has_cache_ = false;
1777 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1778 APPCACHE_CHECKING_EVENT);
1780 WaitForUpdateToFinish();
1783 void RetrySuccessTest() {
1784 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1786 // Set 2 as the retry limit (does not exceed the max).
1787 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch.
1788 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0, 5);
1789 net::URLRequestJobFactoryImpl* new_factory(
1790 new net::URLRequestJobFactoryImpl);
1791 new_factory->SetProtocolHandler(
1792 "http", make_scoped_ptr(new RetryRequestTestJobFactory));
1793 io_thread_->SetNewJobFactory(new_factory);
1795 MakeService();
1796 group_ = new AppCacheGroup(service_->storage(),
1797 RetryRequestTestJob::kRetryUrl,
1798 service_->storage()->NewGroupId());
1799 AppCacheUpdateJob* update =
1800 new AppCacheUpdateJob(service_.get(), group_.get());
1801 group_->update_job_ = update;
1803 MockFrontend* frontend = MakeMockFrontend();
1804 AppCacheHost* host = MakeHost(1, frontend);
1805 update->StartUpdate(host, GURL());
1807 // Set up checks for when update job finishes.
1808 do_checks_after_update_finished_ = true;
1809 expect_group_obsolete_ = false;
1810 expect_group_has_cache_ = true;
1811 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1812 APPCACHE_CHECKING_EVENT);
1814 WaitForUpdateToFinish();
1817 void RetryUrlTest() {
1818 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1820 // Set 1 as the retry limit (does not exceed the max).
1821 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch.
1822 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0, 4);
1823 net::URLRequestJobFactoryImpl* new_factory(
1824 new net::URLRequestJobFactoryImpl);
1825 new_factory->SetProtocolHandler(
1826 "http", make_scoped_ptr(new RetryRequestTestJobFactory));
1827 io_thread_->SetNewJobFactory(new_factory);
1829 MakeService();
1830 group_ = new AppCacheGroup(service_->storage(), GURL("http://retryurl"),
1831 service_->storage()->NewGroupId());
1832 AppCacheUpdateJob* update =
1833 new AppCacheUpdateJob(service_.get(), group_.get());
1834 group_->update_job_ = update;
1836 MockFrontend* frontend = MakeMockFrontend();
1837 AppCacheHost* host = MakeHost(1, frontend);
1838 update->StartUpdate(host, GURL());
1840 // Set up checks for when update job finishes.
1841 do_checks_after_update_finished_ = true;
1842 expect_group_obsolete_ = false;
1843 expect_group_has_cache_ = true;
1844 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1845 APPCACHE_CHECKING_EVENT);
1847 WaitForUpdateToFinish();
1850 void FailStoreNewestCacheTest() {
1851 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1853 MakeService();
1854 MockAppCacheStorage* storage =
1855 reinterpret_cast<MockAppCacheStorage*>(service_->storage());
1856 storage->SimulateStoreGroupAndNewestCacheFailure();
1858 group_ = new AppCacheGroup(
1859 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1860 service_->storage()->NewGroupId());
1861 AppCacheUpdateJob* update =
1862 new AppCacheUpdateJob(service_.get(), group_.get());
1863 group_->update_job_ = update;
1865 MockFrontend* frontend = MakeMockFrontend();
1866 AppCacheHost* host = MakeHost(1, frontend);
1867 update->StartUpdate(host, GURL());
1869 // Set up checks for when update job finishes.
1870 do_checks_after_update_finished_ = true;
1871 expect_group_obsolete_ = false;
1872 expect_group_has_cache_ = false; // storage failed
1873 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()),
1874 APPCACHE_CHECKING_EVENT);
1876 WaitForUpdateToFinish();
1879 void UpgradeFailStoreNewestCacheTest() {
1880 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1882 MakeService();
1883 MockAppCacheStorage* storage =
1884 reinterpret_cast<MockAppCacheStorage*>(service_->storage());
1885 storage->SimulateStoreGroupAndNewestCacheFailure();
1887 group_ = new AppCacheGroup(
1888 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1889 service_->storage()->NewGroupId());
1890 AppCacheUpdateJob* update =
1891 new AppCacheUpdateJob(service_.get(), group_.get());
1892 group_->update_job_ = update;
1894 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 11);
1895 MockFrontend* frontend1 = MakeMockFrontend();
1896 MockFrontend* frontend2 = MakeMockFrontend();
1897 AppCacheHost* host1 = MakeHost(1, frontend1);
1898 AppCacheHost* host2 = MakeHost(2, frontend2);
1899 host1->AssociateCompleteCache(cache);
1900 host2->AssociateCompleteCache(cache);
1902 update->StartUpdate(NULL, GURL());
1904 // Set up checks for when update job finishes.
1905 do_checks_after_update_finished_ = true;
1906 expect_group_obsolete_ = false;
1907 expect_group_has_cache_ = true;
1908 expect_newest_cache_ = cache; // unchanged
1909 MockFrontend::HostIds ids1(1, host1->host_id());
1910 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
1911 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
1912 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
1913 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
1914 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
1915 MockFrontend::HostIds ids2(1, host2->host_id());
1916 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
1917 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
1918 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
1919 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
1920 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
1922 WaitForUpdateToFinish();
1925 void MasterEntryFailStoreNewestCacheTest() {
1926 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1928 MakeService();
1929 MockAppCacheStorage* storage =
1930 reinterpret_cast<MockAppCacheStorage*>(service_->storage());
1931 storage->SimulateStoreGroupAndNewestCacheFailure();
1933 const GURL kManifestUrl = MockHttpServer::GetMockUrl("files/notmodified");
1934 const int64 kManifestResponseId = 11;
1936 // Seed the response_info working set with canned data for
1937 // files/servererror and for files/notmodified to test that the
1938 // existing entries for those resource are reused by the update job.
1939 const char kData[] =
1940 "HTTP/1.1 200 OK\0"
1941 "Content-type: text/cache-manifest\0"
1942 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
1943 "\0";
1944 const std::string kRawHeaders(kData, arraysize(kData));
1945 MakeAppCacheResponseInfo(kManifestUrl, kManifestResponseId, kRawHeaders);
1947 group_ = new AppCacheGroup(
1948 service_->storage(), kManifestUrl,
1949 service_->storage()->NewGroupId());
1950 scoped_refptr<AppCache> cache(
1951 MakeCacheForGroup(service_->storage()->NewCacheId(),
1952 kManifestResponseId));
1954 MockFrontend* frontend = MakeMockFrontend();
1955 AppCacheHost* host = MakeHost(1, frontend);
1956 host->first_party_url_ = kManifestUrl;
1957 host->SelectCache(MockHttpServer::GetMockUrl("files/empty1"),
1958 kAppCacheNoCacheId, kManifestUrl);
1960 // Set up checks for when update job finishes.
1961 do_checks_after_update_finished_ = true;
1962 tested_manifest_ = EMPTY_MANIFEST;
1963 tested_manifest_path_override_ = "files/notmodified";
1964 expect_group_obsolete_ = false;
1965 expect_group_has_cache_ = true;
1966 expect_newest_cache_ = cache.get(); // unchanged
1967 MockFrontend::HostIds ids1(1, host->host_id());
1968 frontend->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
1969 frontend->expected_error_message_ =
1970 "Failed to commit new cache to storage";
1972 WaitForUpdateToFinish();
1975 void UpgradeFailMakeGroupObsoleteTest() {
1976 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1978 MakeService();
1979 MockAppCacheStorage* storage =
1980 reinterpret_cast<MockAppCacheStorage*>(service_->storage());
1981 storage->SimulateMakeGroupObsoleteFailure();
1983 group_ = new AppCacheGroup(
1984 service_->storage(), MockHttpServer::GetMockUrl("files/nosuchfile"),
1985 service_->storage()->NewGroupId());
1986 AppCacheUpdateJob* update =
1987 new AppCacheUpdateJob(service_.get(), group_.get());
1988 group_->update_job_ = update;
1990 AppCache* cache = MakeCacheForGroup(1, 111);
1991 MockFrontend* frontend1 = MakeMockFrontend();
1992 MockFrontend* frontend2 = MakeMockFrontend();
1993 AppCacheHost* host1 = MakeHost(1, frontend1);
1994 AppCacheHost* host2 = MakeHost(2, frontend2);
1995 host1->AssociateCompleteCache(cache);
1996 host2->AssociateCompleteCache(cache);
1998 update->StartUpdate(NULL, GURL());
2000 // Set up checks for when update job finishes.
2001 do_checks_after_update_finished_ = true;
2002 expect_group_obsolete_ = false;
2003 expect_group_has_cache_ = true;
2004 expect_newest_cache_ = cache; // newest cache unaffected by update
2005 MockFrontend::HostIds ids1(1, host1->host_id());
2006 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2007 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2008 MockFrontend::HostIds ids2(1, host2->host_id());
2009 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
2010 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
2012 WaitForUpdateToFinish();
2015 void MasterEntryFetchManifestFailTest() {
2016 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2018 MakeService();
2019 group_ = new AppCacheGroup(service_->storage(), GURL("http://failme"), 111);
2020 AppCacheUpdateJob* update =
2021 new AppCacheUpdateJob(service_.get(), group_.get());
2022 group_->update_job_ = update;
2024 MockFrontend* frontend = MakeMockFrontend();
2025 AppCacheHost* host = MakeHost(1, frontend);
2026 host->new_master_entry_url_ = GURL("http://failme/blah");
2027 update->StartUpdate(host, host->new_master_entry_url_);
2029 // Set up checks for when update job finishes.
2030 do_checks_after_update_finished_ = true;
2031 expect_group_obsolete_ = false;
2032 expect_group_has_cache_ = false;
2033 MockFrontend::HostIds ids1(1, host->host_id());
2034 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2035 frontend->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2037 WaitForUpdateToFinish();
2040 void MasterEntryBadManifestTest() {
2041 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2043 MakeService();
2044 group_ = new AppCacheGroup(service_->storage(),
2045 MockHttpServer::GetMockUrl("files/bad-manifest"), 111);
2046 AppCacheUpdateJob* update =
2047 new AppCacheUpdateJob(service_.get(), group_.get());
2048 group_->update_job_ = update;
2050 MockFrontend* frontend = MakeMockFrontend();
2051 AppCacheHost* host = MakeHost(1, frontend);
2052 host->new_master_entry_url_ = MockHttpServer::GetMockUrl("files/blah");
2053 update->StartUpdate(host, host->new_master_entry_url_);
2055 // Set up checks for when update job finishes.
2056 do_checks_after_update_finished_ = true;
2057 expect_group_obsolete_ = false;
2058 expect_group_has_cache_ = false;
2059 MockFrontend::HostIds ids1(1, host->host_id());
2060 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2061 frontend->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2063 WaitForUpdateToFinish();
2066 void MasterEntryManifestNotFoundTest() {
2067 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2069 MakeService();
2070 group_ = new AppCacheGroup(
2071 service_->storage(),
2072 MockHttpServer::GetMockUrl("files/nosuchfile"),
2073 111);
2074 AppCacheUpdateJob* update =
2075 new AppCacheUpdateJob(service_.get(), group_.get());
2076 group_->update_job_ = update;
2078 MockFrontend* frontend = MakeMockFrontend();
2079 AppCacheHost* host = MakeHost(1, frontend);
2080 host->new_master_entry_url_ = MockHttpServer::GetMockUrl("files/blah");
2082 update->StartUpdate(host, host->new_master_entry_url_);
2084 // Set up checks for when update job finishes.
2085 do_checks_after_update_finished_ = true;
2086 expect_group_obsolete_ = false;
2087 expect_group_has_cache_ = false;
2088 MockFrontend::HostIds ids1(1, host->host_id());
2089 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2090 frontend->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2092 WaitForUpdateToFinish();
2095 void MasterEntryFailUrlFetchTest() {
2096 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2098 MakeService();
2099 group_ = new AppCacheGroup(service_->storage(),
2100 MockHttpServer::GetMockUrl("files/manifest-fb-404"), 111);
2101 AppCacheUpdateJob* update =
2102 new AppCacheUpdateJob(service_.get(), group_.get());
2103 group_->update_job_ = update;
2105 MockFrontend* frontend = MakeMockFrontend();
2106 frontend->SetIgnoreProgressEvents(true);
2107 AppCacheHost* host = MakeHost(1, frontend);
2108 host->new_master_entry_url_ =
2109 MockHttpServer::GetMockUrl("files/explicit1");
2111 update->StartUpdate(host, host->new_master_entry_url_);
2113 // Set up checks for when update job finishes.
2114 do_checks_after_update_finished_ = true;
2115 expect_group_obsolete_ = false;
2116 expect_group_has_cache_ = false; // 404 fallback url is cache failure
2117 MockFrontend::HostIds ids1(1, host->host_id());
2118 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2119 frontend->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2120 frontend->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2122 WaitForUpdateToFinish();
2125 void MasterEntryAllFailTest() {
2126 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2128 MakeService();
2129 group_ = new AppCacheGroup(
2130 service_->storage(),
2131 MockHttpServer::GetMockUrl("files/manifest1"),
2132 111);
2133 AppCacheUpdateJob* update =
2134 new AppCacheUpdateJob(service_.get(), group_.get());
2135 group_->update_job_ = update;
2137 MockFrontend* frontend1 = MakeMockFrontend();
2138 frontend1->SetIgnoreProgressEvents(true);
2139 AppCacheHost* host1 = MakeHost(1, frontend1);
2140 host1->new_master_entry_url_ =
2141 MockHttpServer::GetMockUrl("files/nosuchfile");
2142 update->StartUpdate(host1, host1->new_master_entry_url_);
2144 MockFrontend* frontend2 = MakeMockFrontend();
2145 frontend2->SetIgnoreProgressEvents(true);
2146 AppCacheHost* host2 = MakeHost(2, frontend2);
2147 host2->new_master_entry_url_ =
2148 MockHttpServer::GetMockUrl("files/servererror");
2149 update->StartUpdate(host2, host2->new_master_entry_url_);
2151 // Set up checks for when update job finishes.
2152 do_checks_after_update_finished_ = true;
2153 expect_group_obsolete_ = false;
2154 expect_group_has_cache_ = false; // all pending masters failed
2155 MockFrontend::HostIds ids1(1, host1->host_id());
2156 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2157 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2158 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2159 MockFrontend::HostIds ids2(1, host2->host_id());
2160 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
2161 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
2162 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
2164 WaitForUpdateToFinish();
2167 void UpgradeMasterEntryAllFailTest() {
2168 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2170 MakeService();
2171 group_ = new AppCacheGroup(
2172 service_->storage(),
2173 MockHttpServer::GetMockUrl("files/manifest1"),
2174 111);
2175 AppCacheUpdateJob* update =
2176 new AppCacheUpdateJob(service_.get(), group_.get());
2177 group_->update_job_ = update;
2179 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
2180 MockFrontend* frontend1 = MakeMockFrontend();
2181 AppCacheHost* host1 = MakeHost(1, frontend1);
2182 host1->AssociateCompleteCache(cache);
2184 MockFrontend* frontend2 = MakeMockFrontend();
2185 frontend2->SetIgnoreProgressEvents(true);
2186 AppCacheHost* host2 = MakeHost(2, frontend2);
2187 host2->new_master_entry_url_ =
2188 MockHttpServer::GetMockUrl("files/nosuchfile");
2189 update->StartUpdate(host2, host2->new_master_entry_url_);
2191 MockFrontend* frontend3 = MakeMockFrontend();
2192 frontend3->SetIgnoreProgressEvents(true);
2193 AppCacheHost* host3 = MakeHost(3, frontend3);
2194 host3->new_master_entry_url_ =
2195 MockHttpServer::GetMockUrl("files/servererror");
2196 update->StartUpdate(host3, host3->new_master_entry_url_);
2198 // Set up checks for when update job finishes.
2199 do_checks_after_update_finished_ = true;
2200 expect_group_obsolete_ = false;
2201 expect_group_has_cache_ = true;
2202 expect_old_cache_ = cache;
2203 tested_manifest_ = MANIFEST1;
2204 MockFrontend::HostIds ids1(1, host1->host_id());
2205 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2206 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2207 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2208 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2209 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2210 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
2211 MockFrontend::HostIds ids2(1, host2->host_id());
2212 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
2213 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
2214 MockFrontend::HostIds ids3(1, host3->host_id());
2215 frontend3->AddExpectedEvent(ids3, APPCACHE_CHECKING_EVENT);
2216 frontend3->AddExpectedEvent(ids3, APPCACHE_DOWNLOADING_EVENT);
2217 frontend3->AddExpectedEvent(ids3, APPCACHE_ERROR_EVENT);
2219 WaitForUpdateToFinish();
2222 void MasterEntrySomeFailTest() {
2223 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2225 MakeService();
2226 group_ = new AppCacheGroup(
2227 service_->storage(),
2228 MockHttpServer::GetMockUrl("files/manifest1"),
2229 111);
2230 AppCacheUpdateJob* update =
2231 new AppCacheUpdateJob(service_.get(), group_.get());
2232 group_->update_job_ = update;
2234 MockFrontend* frontend1 = MakeMockFrontend();
2235 frontend1->SetIgnoreProgressEvents(true);
2236 AppCacheHost* host1 = MakeHost(1, frontend1);
2237 host1->new_master_entry_url_ =
2238 MockHttpServer::GetMockUrl("files/nosuchfile");
2239 update->StartUpdate(host1, host1->new_master_entry_url_);
2241 MockFrontend* frontend2 = MakeMockFrontend();
2242 AppCacheHost* host2 = MakeHost(2, frontend2);
2243 host2->new_master_entry_url_ =
2244 MockHttpServer::GetMockUrl("files/explicit2");
2245 update->StartUpdate(host2, host2->new_master_entry_url_);
2247 // Set up checks for when update job finishes.
2248 do_checks_after_update_finished_ = true;
2249 expect_group_obsolete_ = false;
2250 expect_group_has_cache_ = true; // as long as one pending master succeeds
2251 tested_manifest_ = MANIFEST1;
2252 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
2253 MockHttpServer::GetMockUrl("files/explicit2"),
2254 AppCacheEntry(AppCacheEntry::MASTER)));
2255 MockFrontend::HostIds ids1(1, host1->host_id());
2256 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2257 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2258 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT);
2259 MockFrontend::HostIds ids2(1, host2->host_id());
2260 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
2261 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
2262 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
2263 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
2264 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // final
2265 frontend2->AddExpectedEvent(ids2, APPCACHE_CACHED_EVENT);
2267 WaitForUpdateToFinish();
2270 void UpgradeMasterEntrySomeFailTest() {
2271 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2273 MakeService();
2274 group_ = new AppCacheGroup(
2275 service_->storage(),
2276 MockHttpServer::GetMockUrl("files/manifest1"),
2277 111);
2278 AppCacheUpdateJob* update =
2279 new AppCacheUpdateJob(service_.get(), group_.get());
2280 group_->update_job_ = update;
2282 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
2283 MockFrontend* frontend1 = MakeMockFrontend();
2284 AppCacheHost* host1 = MakeHost(1, frontend1);
2285 host1->AssociateCompleteCache(cache);
2287 MockFrontend* frontend2 = MakeMockFrontend();
2288 frontend2->SetIgnoreProgressEvents(true);
2289 AppCacheHost* host2 = MakeHost(2, frontend2);
2290 host2->new_master_entry_url_ =
2291 MockHttpServer::GetMockUrl("files/nosuchfile");
2292 update->StartUpdate(host2, host2->new_master_entry_url_);
2294 MockFrontend* frontend3 = MakeMockFrontend();
2295 AppCacheHost* host3 = MakeHost(3, frontend3);
2296 host3->new_master_entry_url_ =
2297 MockHttpServer::GetMockUrl("files/explicit2");
2298 update->StartUpdate(host3, host3->new_master_entry_url_);
2300 // Set up checks for when update job finishes.
2301 do_checks_after_update_finished_ = true;
2302 expect_group_obsolete_ = false;
2303 expect_group_has_cache_ = true;
2304 expect_old_cache_ = cache;
2305 tested_manifest_ = MANIFEST1;
2306 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
2307 MockHttpServer::GetMockUrl("files/explicit2"),
2308 AppCacheEntry(AppCacheEntry::MASTER)));
2309 MockFrontend::HostIds ids1(1, host1->host_id());
2310 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2311 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2312 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2313 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2314 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2315 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
2316 MockFrontend::HostIds ids2(1, host2->host_id());
2317 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
2318 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
2319 MockFrontend::HostIds ids3(1, host3->host_id());
2320 frontend3->AddExpectedEvent(ids3, APPCACHE_CHECKING_EVENT);
2321 frontend3->AddExpectedEvent(ids3, APPCACHE_DOWNLOADING_EVENT);
2322 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT);
2323 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT);
2324 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT); // final
2325 frontend3->AddExpectedEvent(ids3, APPCACHE_UPDATE_READY_EVENT);
2327 WaitForUpdateToFinish();
2330 void MasterEntryNoUpdateTest() {
2331 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2333 MakeService();
2334 group_ = new AppCacheGroup(service_->storage(),
2335 MockHttpServer::GetMockUrl("files/notmodified"), 111);
2336 AppCacheUpdateJob* update =
2337 new AppCacheUpdateJob(service_.get(), group_.get());
2338 group_->update_job_ = update;
2340 AppCache* cache = MakeCacheForGroup(1, 111);
2341 MockFrontend* frontend1 = MakeMockFrontend();
2342 AppCacheHost* host1 = MakeHost(1, frontend1);
2343 host1->AssociateCompleteCache(cache);
2345 // Give cache an existing entry that can also be fetched.
2346 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit2"),
2347 AppCacheEntry(AppCacheEntry::EXPLICIT, 222));
2349 // Reset the update time to null so we can verify it gets
2350 // modified in this test case by the UpdateJob.
2351 cache->set_update_time(base::Time());
2353 MockFrontend* frontend2 = MakeMockFrontend();
2354 AppCacheHost* host2 = MakeHost(2, frontend2);
2355 host2->new_master_entry_url_ =
2356 MockHttpServer::GetMockUrl("files/explicit1");
2357 update->StartUpdate(host2, host2->new_master_entry_url_);
2359 AppCacheHost* host3 = MakeHost(3, frontend2); // same frontend as host2
2360 host3->new_master_entry_url_ =
2361 MockHttpServer::GetMockUrl("files/explicit2");
2362 update->StartUpdate(host3, host3->new_master_entry_url_);
2364 // Set up checks for when update job finishes.
2365 do_checks_after_update_finished_ = true;
2366 expect_group_obsolete_ = false;
2367 expect_group_has_cache_ = true;
2368 expect_newest_cache_ = cache; // newest cache still the same cache
2369 expect_non_null_update_time_ = true;
2370 tested_manifest_ = PENDING_MASTER_NO_UPDATE;
2371 MockFrontend::HostIds ids1(1, host1->host_id());
2372 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2373 frontend1->AddExpectedEvent(ids1, APPCACHE_NO_UPDATE_EVENT);
2374 MockFrontend::HostIds ids3(1, host3->host_id());
2375 frontend2->AddExpectedEvent(ids3, APPCACHE_CHECKING_EVENT);
2376 MockFrontend::HostIds ids2and3;
2377 ids2and3.push_back(host2->host_id());
2378 ids2and3.push_back(host3->host_id());
2379 frontend2->AddExpectedEvent(ids2and3, APPCACHE_NO_UPDATE_EVENT);
2381 WaitForUpdateToFinish();
2384 void StartUpdateMidCacheAttemptTest() {
2385 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2387 MakeService();
2388 group_ = new AppCacheGroup(
2389 service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
2390 service_->storage()->NewGroupId());
2391 AppCacheUpdateJob* update =
2392 new AppCacheUpdateJob(service_.get(), group_.get());
2393 group_->update_job_ = update;
2395 MockFrontend* frontend1 = MakeMockFrontend();
2396 AppCacheHost* host1 = MakeHost(1, frontend1);
2397 host1->new_master_entry_url_ =
2398 MockHttpServer::GetMockUrl("files/explicit2");
2399 update->StartUpdate(host1, host1->new_master_entry_url_);
2401 // Set up additional updates to be started while update is in progress.
2402 MockFrontend* frontend2 = MakeMockFrontend();
2403 frontend2->SetIgnoreProgressEvents(true);
2404 AppCacheHost* host2 = MakeHost(2, frontend2);
2405 host2->new_master_entry_url_ =
2406 MockHttpServer::GetMockUrl("files/nosuchfile");
2408 MockFrontend* frontend3 = MakeMockFrontend();
2409 AppCacheHost* host3 = MakeHost(3, frontend3);
2410 host3->new_master_entry_url_ =
2411 MockHttpServer::GetMockUrl("files/explicit1");
2413 MockFrontend* frontend4 = MakeMockFrontend();
2414 AppCacheHost* host4 = MakeHost(4, frontend4);
2415 host4->new_master_entry_url_ =
2416 MockHttpServer::GetMockUrl("files/explicit2");
2418 MockFrontend* frontend5 = MakeMockFrontend();
2419 AppCacheHost* host5 = MakeHost(5, frontend5); // no master entry url
2421 frontend1->TriggerAdditionalUpdates(APPCACHE_DOWNLOADING_EVENT, update);
2422 frontend1->AdditionalUpdateHost(host2); // fetch will fail
2423 frontend1->AdditionalUpdateHost(host3); // same as an explicit entry
2424 frontend1->AdditionalUpdateHost(host4); // same as another master entry
2425 frontend1->AdditionalUpdateHost(NULL); // no host
2426 frontend1->AdditionalUpdateHost(host5); // no master entry url
2428 // Set up checks for when update job finishes.
2429 do_checks_after_update_finished_ = true;
2430 expect_group_obsolete_ = false;
2431 expect_group_has_cache_ = true;
2432 tested_manifest_ = MANIFEST1;
2433 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
2434 MockHttpServer::GetMockUrl("files/explicit2"),
2435 AppCacheEntry(AppCacheEntry::MASTER)));
2436 MockFrontend::HostIds ids1(1, host1->host_id());
2437 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2438 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2439 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2440 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2441 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2442 frontend1->AddExpectedEvent(ids1, APPCACHE_CACHED_EVENT);
2443 MockFrontend::HostIds ids2(1, host2->host_id());
2444 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
2445 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
2446 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
2447 MockFrontend::HostIds ids3(1, host3->host_id());
2448 frontend3->AddExpectedEvent(ids3, APPCACHE_CHECKING_EVENT);
2449 frontend3->AddExpectedEvent(ids3, APPCACHE_DOWNLOADING_EVENT);
2450 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT);
2451 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT);
2452 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT); // final
2453 frontend3->AddExpectedEvent(ids3, APPCACHE_CACHED_EVENT);
2454 MockFrontend::HostIds ids4(1, host4->host_id());
2455 frontend4->AddExpectedEvent(ids4, APPCACHE_CHECKING_EVENT);
2456 frontend4->AddExpectedEvent(ids4, APPCACHE_DOWNLOADING_EVENT);
2457 frontend4->AddExpectedEvent(ids4, APPCACHE_PROGRESS_EVENT);
2458 frontend4->AddExpectedEvent(ids4, APPCACHE_PROGRESS_EVENT);
2459 frontend4->AddExpectedEvent(ids4, APPCACHE_PROGRESS_EVENT); // final
2460 frontend4->AddExpectedEvent(ids4, APPCACHE_CACHED_EVENT);
2462 // Host 5 is not associated with cache so no progress/cached events.
2463 MockFrontend::HostIds ids5(1, host5->host_id());
2464 frontend5->AddExpectedEvent(ids5, APPCACHE_CHECKING_EVENT);
2465 frontend5->AddExpectedEvent(ids5, APPCACHE_DOWNLOADING_EVENT);
2467 WaitForUpdateToFinish();
2470 void StartUpdateMidNoUpdateTest() {
2471 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2473 MakeService();
2474 group_ = new AppCacheGroup(
2475 service_->storage(), MockHttpServer::GetMockUrl("files/notmodified"),
2476 service_->storage()->NewGroupId());
2477 AppCacheUpdateJob* update =
2478 new AppCacheUpdateJob(service_.get(), group_.get());
2479 group_->update_job_ = update;
2481 AppCache* cache = MakeCacheForGroup(1, 111);
2482 MockFrontend* frontend1 = MakeMockFrontend();
2483 AppCacheHost* host1 = MakeHost(1, frontend1);
2484 host1->AssociateCompleteCache(cache);
2486 // Give cache an existing entry.
2487 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit2"),
2488 AppCacheEntry(AppCacheEntry::EXPLICIT, 222));
2490 // Start update with a pending master entry that will fail to give us an
2491 // event to trigger other updates.
2492 MockFrontend* frontend2 = MakeMockFrontend();
2493 AppCacheHost* host2 = MakeHost(2, frontend2);
2494 host2->new_master_entry_url_ =
2495 MockHttpServer::GetMockUrl("files/nosuchfile");
2496 update->StartUpdate(host2, host2->new_master_entry_url_);
2498 // Set up additional updates to be started while update is in progress.
2499 MockFrontend* frontend3 = MakeMockFrontend();
2500 AppCacheHost* host3 = MakeHost(3, frontend3);
2501 host3->new_master_entry_url_ =
2502 MockHttpServer::GetMockUrl("files/explicit1");
2504 MockFrontend* frontend4 = MakeMockFrontend();
2505 AppCacheHost* host4 = MakeHost(4, frontend4); // no master entry url
2507 MockFrontend* frontend5 = MakeMockFrontend();
2508 AppCacheHost* host5 = MakeHost(5, frontend5);
2509 host5->new_master_entry_url_ =
2510 MockHttpServer::GetMockUrl("files/explicit2"); // existing entry
2512 MockFrontend* frontend6 = MakeMockFrontend();
2513 AppCacheHost* host6 = MakeHost(6, frontend6);
2514 host6->new_master_entry_url_ =
2515 MockHttpServer::GetMockUrl("files/explicit1");
2517 frontend2->TriggerAdditionalUpdates(APPCACHE_ERROR_EVENT, update);
2518 frontend2->AdditionalUpdateHost(host3);
2519 frontend2->AdditionalUpdateHost(NULL); // no host
2520 frontend2->AdditionalUpdateHost(host4); // no master entry url
2521 frontend2->AdditionalUpdateHost(host5); // same as existing cache entry
2522 frontend2->AdditionalUpdateHost(host6); // same as another master entry
2524 // Set up checks for when update job finishes.
2525 do_checks_after_update_finished_ = true;
2526 expect_group_obsolete_ = false;
2527 expect_group_has_cache_ = true;
2528 expect_newest_cache_ = cache; // newest cache unaffected by update
2529 tested_manifest_ = PENDING_MASTER_NO_UPDATE;
2530 MockFrontend::HostIds ids1(1, host1->host_id()); // prior associated host
2531 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2532 frontend1->AddExpectedEvent(ids1, APPCACHE_NO_UPDATE_EVENT);
2533 MockFrontend::HostIds ids2(1, host2->host_id());
2534 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT);
2535 MockFrontend::HostIds ids3(1, host3->host_id());
2536 frontend3->AddExpectedEvent(ids3, APPCACHE_CHECKING_EVENT);
2537 frontend3->AddExpectedEvent(ids3, APPCACHE_NO_UPDATE_EVENT);
2538 MockFrontend::HostIds ids4(1, host4->host_id()); // unassociated w/cache
2539 frontend4->AddExpectedEvent(ids4, APPCACHE_CHECKING_EVENT);
2540 MockFrontend::HostIds ids5(1, host5->host_id());
2541 frontend5->AddExpectedEvent(ids5, APPCACHE_CHECKING_EVENT);
2542 frontend5->AddExpectedEvent(ids5, APPCACHE_NO_UPDATE_EVENT);
2543 MockFrontend::HostIds ids6(1, host6->host_id());
2544 frontend6->AddExpectedEvent(ids6, APPCACHE_CHECKING_EVENT);
2545 frontend6->AddExpectedEvent(ids6, APPCACHE_NO_UPDATE_EVENT);
2547 WaitForUpdateToFinish();
2550 void StartUpdateMidDownloadTest() {
2551 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2553 MakeService();
2554 group_ = new AppCacheGroup(
2555 service_->storage(),
2556 MockHttpServer::GetMockUrl("files/manifest1"),
2557 111);
2558 AppCacheUpdateJob* update =
2559 new AppCacheUpdateJob(service_.get(), group_.get());
2560 group_->update_job_ = update;
2562 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 42);
2563 MockFrontend* frontend1 = MakeMockFrontend();
2564 AppCacheHost* host1 = MakeHost(1, frontend1);
2565 host1->AssociateCompleteCache(cache);
2567 update->StartUpdate(NULL, GURL());
2569 // Set up additional updates to be started while update is in progress.
2570 MockFrontend* frontend2 = MakeMockFrontend();
2571 AppCacheHost* host2 = MakeHost(2, frontend2);
2572 host2->new_master_entry_url_ =
2573 MockHttpServer::GetMockUrl("files/explicit1");
2575 MockFrontend* frontend3 = MakeMockFrontend();
2576 AppCacheHost* host3 = MakeHost(3, frontend3);
2577 host3->new_master_entry_url_ =
2578 MockHttpServer::GetMockUrl("files/explicit2");
2580 MockFrontend* frontend4 = MakeMockFrontend();
2581 AppCacheHost* host4 = MakeHost(4, frontend4); // no master entry url
2583 MockFrontend* frontend5 = MakeMockFrontend();
2584 AppCacheHost* host5 = MakeHost(5, frontend5);
2585 host5->new_master_entry_url_ =
2586 MockHttpServer::GetMockUrl("files/explicit2");
2588 frontend1->TriggerAdditionalUpdates(APPCACHE_PROGRESS_EVENT, update);
2589 frontend1->AdditionalUpdateHost(host2); // same as entry in manifest
2590 frontend1->AdditionalUpdateHost(NULL); // no host
2591 frontend1->AdditionalUpdateHost(host3); // new master entry
2592 frontend1->AdditionalUpdateHost(host4); // no master entry url
2593 frontend1->AdditionalUpdateHost(host5); // same as another master entry
2595 // Set up checks for when update job finishes.
2596 do_checks_after_update_finished_ = true;
2597 expect_group_obsolete_ = false;
2598 expect_group_has_cache_ = true;
2599 tested_manifest_ = MANIFEST1;
2600 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
2601 MockHttpServer::GetMockUrl("files/explicit2"),
2602 AppCacheEntry(AppCacheEntry::MASTER)));
2603 MockFrontend::HostIds ids1(1, host1->host_id()); // prior associated host
2604 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2605 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2606 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2607 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2608 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2609 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
2610 MockFrontend::HostIds ids2(1, host2->host_id());
2611 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT);
2612 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT);
2613 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT);
2614 frontend2->AddExpectedEvent(ids2, APPCACHE_PROGRESS_EVENT); // final
2615 frontend2->AddExpectedEvent(ids2, APPCACHE_UPDATE_READY_EVENT);
2616 MockFrontend::HostIds ids3(1, host3->host_id());
2617 frontend3->AddExpectedEvent(ids3, APPCACHE_CHECKING_EVENT);
2618 frontend3->AddExpectedEvent(ids3, APPCACHE_DOWNLOADING_EVENT);
2619 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT);
2620 frontend3->AddExpectedEvent(ids3, APPCACHE_PROGRESS_EVENT); // final
2621 frontend3->AddExpectedEvent(ids3, APPCACHE_UPDATE_READY_EVENT);
2622 MockFrontend::HostIds ids4(1, host4->host_id()); // unassociated w/cache
2623 frontend4->AddExpectedEvent(ids4, APPCACHE_CHECKING_EVENT);
2624 frontend4->AddExpectedEvent(ids4, APPCACHE_DOWNLOADING_EVENT);
2625 MockFrontend::HostIds ids5(1, host5->host_id());
2626 frontend5->AddExpectedEvent(ids5, APPCACHE_CHECKING_EVENT);
2627 frontend5->AddExpectedEvent(ids5, APPCACHE_DOWNLOADING_EVENT);
2628 frontend5->AddExpectedEvent(ids5, APPCACHE_PROGRESS_EVENT);
2629 frontend5->AddExpectedEvent(ids5, APPCACHE_PROGRESS_EVENT); // final
2630 frontend5->AddExpectedEvent(ids5, APPCACHE_UPDATE_READY_EVENT);
2632 WaitForUpdateToFinish();
2635 void QueueMasterEntryTest() {
2636 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2638 MakeService();
2639 group_ = new AppCacheGroup(
2640 service_->storage(),
2641 MockHttpServer::GetMockUrl("files/manifest1"),
2642 111);
2643 AppCacheUpdateJob* update =
2644 new AppCacheUpdateJob(service_.get(), group_.get());
2645 group_->update_job_ = update;
2647 // Pretend update job has been running and is about to terminate.
2648 group_->update_status_ = AppCacheGroup::DOWNLOADING;
2649 update->internal_state_ = AppCacheUpdateJob::REFETCH_MANIFEST;
2650 EXPECT_TRUE(update->IsTerminating());
2652 // Start an update. Should be queued.
2653 MockFrontend* frontend = MakeMockFrontend();
2654 AppCacheHost* host = MakeHost(1, frontend);
2655 host->new_master_entry_url_ =
2656 MockHttpServer::GetMockUrl("files/explicit2");
2657 update->StartUpdate(host, host->new_master_entry_url_);
2658 EXPECT_TRUE(update->pending_master_entries_.empty());
2659 EXPECT_FALSE(group_->queued_updates_.empty());
2661 // Delete update, causing it to finish, which should trigger a new update
2662 // for the queued host and master entry after a delay.
2663 delete update;
2664 EXPECT_FALSE(group_->restart_update_task_.IsCancelled());
2666 // Set up checks for when queued update job finishes.
2667 do_checks_after_update_finished_ = true;
2668 expect_group_obsolete_ = false;
2669 expect_group_has_cache_ = true;
2670 tested_manifest_ = MANIFEST1;
2671 expect_extra_entries_.insert(AppCache::EntryMap::value_type(
2672 host->new_master_entry_url_, AppCacheEntry(AppCacheEntry::MASTER)));
2673 MockFrontend::HostIds ids1(1, host->host_id());
2674 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2675 frontend->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2676 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2677 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2678 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2679 frontend->AddExpectedEvent(ids1, APPCACHE_CACHED_EVENT);
2681 // Group status will be APPCACHE_STATUS_IDLE so cannot call
2682 // WaitForUpdateToFinish.
2683 group_->AddUpdateObserver(this);
2686 void IfModifiedSinceTest() {
2687 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2689 net::URLRequestJobFactoryImpl* new_factory(
2690 new net::URLRequestJobFactoryImpl);
2691 new_factory->SetProtocolHandler(
2692 "http", make_scoped_ptr(new IfModifiedSinceJobFactory));
2693 io_thread_->SetNewJobFactory(new_factory);
2695 MakeService();
2696 group_ = new AppCacheGroup(
2697 service_->storage(), GURL("http://headertest"), 111);
2698 AppCacheUpdateJob* update =
2699 new AppCacheUpdateJob(service_.get(), group_.get());
2700 group_->update_job_ = update;
2702 // First test against a cache attempt. Will start manifest fetch
2703 // synchronously.
2704 HttpHeadersRequestTestJob::Initialize(std::string(), std::string());
2705 MockFrontend mock_frontend;
2706 AppCacheHost host(1, &mock_frontend, service_.get());
2707 update->StartUpdate(&host, GURL());
2708 HttpHeadersRequestTestJob::Verify();
2709 delete update;
2711 // Now simulate a refetch manifest request. Will start fetch request
2712 // synchronously.
2713 const char data[] =
2714 "HTTP/1.1 200 OK\0"
2715 "\0";
2716 net::HttpResponseHeaders* headers =
2717 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2718 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2719 response_info->headers = headers; // adds ref to headers
2721 HttpHeadersRequestTestJob::Initialize(std::string(), std::string());
2722 update = new AppCacheUpdateJob(service_.get(), group_.get());
2723 group_->update_job_ = update;
2724 group_->update_status_ = AppCacheGroup::DOWNLOADING;
2725 update->manifest_response_info_.reset(response_info);
2726 update->internal_state_ = AppCacheUpdateJob::REFETCH_MANIFEST;
2727 update->FetchManifest(false); // not first request
2728 HttpHeadersRequestTestJob::Verify();
2729 delete update;
2731 // Change the headers to include a Last-Modified header. Manifest refetch
2732 // should include If-Modified-Since header.
2733 const char data2[] =
2734 "HTTP/1.1 200 OK\0"
2735 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2736 "\0";
2737 net::HttpResponseHeaders* headers2 =
2738 new net::HttpResponseHeaders(std::string(data2, arraysize(data2)));
2739 response_info = new net::HttpResponseInfo();
2740 response_info->headers = headers2;
2742 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT",
2743 std::string());
2744 update = new AppCacheUpdateJob(service_.get(), group_.get());
2745 group_->update_job_ = update;
2746 group_->update_status_ = AppCacheGroup::DOWNLOADING;
2747 update->manifest_response_info_.reset(response_info);
2748 update->internal_state_ = AppCacheUpdateJob::REFETCH_MANIFEST;
2749 update->FetchManifest(false); // not first request
2750 HttpHeadersRequestTestJob::Verify();
2751 delete update;
2753 UpdateFinished();
2756 void IfModifiedSinceUpgradeTest() {
2757 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2759 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT",
2760 std::string());
2761 net::URLRequestJobFactoryImpl* new_factory(
2762 new net::URLRequestJobFactoryImpl);
2763 new_factory->SetProtocolHandler(
2764 "http", make_scoped_ptr(new IfModifiedSinceJobFactory));
2765 io_thread_->SetNewJobFactory(new_factory);
2767 MakeService();
2768 group_ = new AppCacheGroup(
2769 service_->storage(),
2770 MockHttpServer::GetMockUrl("files/manifest1"),
2771 111);
2772 AppCacheUpdateJob* update =
2773 new AppCacheUpdateJob(service_.get(), group_.get());
2774 group_->update_job_ = update;
2776 // Give the newest cache a manifest enry that is in storage.
2777 response_writer_.reset(
2778 service_->storage()->CreateResponseWriter(group_->manifest_url(),
2779 group_->group_id()));
2781 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(),
2782 response_writer_->response_id());
2783 MockFrontend* frontend = MakeMockFrontend();
2784 AppCacheHost* host = MakeHost(1, frontend);
2785 host->AssociateCompleteCache(cache);
2787 // Set up checks for when update job finishes.
2788 do_checks_after_update_finished_ = true;
2789 expect_group_obsolete_ = false;
2790 expect_group_has_cache_ = true;
2791 expect_old_cache_ = cache;
2792 tested_manifest_ = MANIFEST1;
2793 MockFrontend::HostIds ids1(1, host->host_id());
2794 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2795 frontend->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2796 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2797 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2798 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2799 frontend->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
2801 // Seed storage with expected manifest response info that will cause
2802 // an If-Modified-Since header to be put in the manifest fetch request.
2803 const char data[] =
2804 "HTTP/1.1 200 OK\0"
2805 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2806 "\0";
2807 net::HttpResponseHeaders* headers =
2808 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2809 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2810 response_info->headers = headers; // adds ref to headers
2811 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
2812 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
2813 response_writer_->WriteInfo(
2814 io_buffer.get(),
2815 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
2816 base::Unretained(this)));
2818 // Start update after data write completes asynchronously.
2821 void IfNoneMatchUpgradeTest() {
2822 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2824 HttpHeadersRequestTestJob::Initialize(std::string(), "\"LadeDade\"");
2825 net::URLRequestJobFactoryImpl* new_factory(
2826 new net::URLRequestJobFactoryImpl);
2827 new_factory->SetProtocolHandler(
2828 "http", make_scoped_ptr(new IfModifiedSinceJobFactory));
2829 io_thread_->SetNewJobFactory(new_factory);
2831 MakeService();
2832 group_ = new AppCacheGroup(
2833 service_->storage(),
2834 MockHttpServer::GetMockUrl("files/manifest1"),
2835 111);
2836 AppCacheUpdateJob* update =
2837 new AppCacheUpdateJob(service_.get(), group_.get());
2838 group_->update_job_ = update;
2840 // Give the newest cache a manifest enry that is in storage.
2841 response_writer_.reset(
2842 service_->storage()->CreateResponseWriter(group_->manifest_url(),
2843 group_->group_id()));
2845 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(),
2846 response_writer_->response_id());
2847 MockFrontend* frontend = MakeMockFrontend();
2848 AppCacheHost* host = MakeHost(1, frontend);
2849 host->AssociateCompleteCache(cache);
2851 // Set up checks for when update job finishes.
2852 do_checks_after_update_finished_ = true;
2853 expect_group_obsolete_ = false;
2854 expect_group_has_cache_ = true;
2855 expect_old_cache_ = cache;
2856 tested_manifest_ = MANIFEST1;
2857 MockFrontend::HostIds ids1(1, host->host_id());
2858 frontend->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT);
2859 frontend->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT);
2860 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2861 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT);
2862 frontend->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final
2863 frontend->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT);
2865 // Seed storage with expected manifest response info that will cause
2866 // an If-None-Match header to be put in the manifest fetch request.
2867 const char data[] =
2868 "HTTP/1.1 200 OK\0"
2869 "ETag: \"LadeDade\"\0"
2870 "\0";
2871 net::HttpResponseHeaders* headers =
2872 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2873 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2874 response_info->headers = headers; // adds ref to headers
2875 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
2876 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
2877 response_writer_->WriteInfo(
2878 io_buffer.get(),
2879 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
2880 base::Unretained(this)));
2882 // Start update after data write completes asynchronously.
2885 void IfNoneMatchRefetchTest() {
2886 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2888 HttpHeadersRequestTestJob::Initialize(std::string(), "\"LadeDade\"");
2889 net::URLRequestJobFactoryImpl* new_factory(
2890 new net::URLRequestJobFactoryImpl);
2891 new_factory->SetProtocolHandler(
2892 "http", make_scoped_ptr(new IfModifiedSinceJobFactory));
2893 io_thread_->SetNewJobFactory(new_factory);
2895 MakeService();
2896 group_ = new AppCacheGroup(
2897 service_->storage(), GURL("http://headertest"), 111);
2898 AppCacheUpdateJob* update =
2899 new AppCacheUpdateJob(service_.get(), group_.get());
2900 group_->update_job_ = update;
2902 // Simulate a refetch manifest request that uses an ETag header.
2903 const char data[] =
2904 "HTTP/1.1 200 OK\0"
2905 "ETag: \"LadeDade\"\0"
2906 "\0";
2907 net::HttpResponseHeaders* headers =
2908 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2909 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2910 response_info->headers = headers; // adds ref to headers
2912 group_->update_status_ = AppCacheGroup::DOWNLOADING;
2913 update->manifest_response_info_.reset(response_info);
2914 update->internal_state_ = AppCacheUpdateJob::REFETCH_MANIFEST;
2915 update->FetchManifest(false); // not first request
2916 HttpHeadersRequestTestJob::Verify();
2917 delete update;
2919 UpdateFinished();
2922 void MultipleHeadersRefetchTest() {
2923 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2925 // Verify that code is correct when building multiple extra headers.
2926 HttpHeadersRequestTestJob::Initialize(
2927 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\"");
2928 net::URLRequestJobFactoryImpl* new_factory(
2929 new net::URLRequestJobFactoryImpl);
2930 new_factory->SetProtocolHandler(
2931 "http", make_scoped_ptr(new IfModifiedSinceJobFactory));
2932 io_thread_->SetNewJobFactory(new_factory);
2934 MakeService();
2935 group_ = new AppCacheGroup(
2936 service_->storage(), GURL("http://headertest"), 111);
2937 AppCacheUpdateJob* update =
2938 new AppCacheUpdateJob(service_.get(), group_.get());
2939 group_->update_job_ = update;
2941 // Simulate a refetch manifest request that uses an ETag header.
2942 const char data[] =
2943 "HTTP/1.1 200 OK\0"
2944 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2945 "ETag: \"LadeDade\"\0"
2946 "\0";
2947 net::HttpResponseHeaders* headers =
2948 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2949 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2950 response_info->headers = headers; // adds ref to headers
2952 group_->update_status_ = AppCacheGroup::DOWNLOADING;
2953 update->manifest_response_info_.reset(response_info);
2954 update->internal_state_ = AppCacheUpdateJob::REFETCH_MANIFEST;
2955 update->FetchManifest(false); // not first request
2956 HttpHeadersRequestTestJob::Verify();
2957 delete update;
2959 UpdateFinished();
2962 void CrossOriginHttpsSuccessTest() {
2963 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2965 GURL manifest_url = MockHttpServer::GetMockHttpsUrl(
2966 "files/valid_cross_origin_https_manifest");
2968 MakeService();
2969 group_ = new AppCacheGroup(
2970 service_->storage(), manifest_url, service_->storage()->NewGroupId());
2971 AppCacheUpdateJob* update =
2972 new AppCacheUpdateJob(service_.get(), group_.get());
2973 group_->update_job_ = update;
2975 MockFrontend* frontend = MakeMockFrontend();
2976 AppCacheHost* host = MakeHost(1, frontend);
2977 update->StartUpdate(host, GURL());
2979 // Set up checks for when update job finishes.
2980 do_checks_after_update_finished_ = true;
2981 expect_group_obsolete_ = false;
2982 expect_group_has_cache_ = true;
2983 tested_manifest_ = NONE;
2984 MockFrontend::HostIds host_ids(1, host->host_id());
2985 frontend->AddExpectedEvent(host_ids, APPCACHE_CHECKING_EVENT);
2987 WaitForUpdateToFinish();
2990 void CrossOriginHttpsDeniedTest() {
2991 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2993 GURL manifest_url = MockHttpServer::GetMockHttpsUrl(
2994 "files/invalid_cross_origin_https_manifest");
2996 MakeService();
2997 group_ = new AppCacheGroup(
2998 service_->storage(), manifest_url, service_->storage()->NewGroupId());
2999 AppCacheUpdateJob* update =
3000 new AppCacheUpdateJob(service_.get(), group_.get());
3001 group_->update_job_ = update;
3003 MockFrontend* frontend = MakeMockFrontend();
3004 AppCacheHost* host = MakeHost(1, frontend);
3005 update->StartUpdate(host, GURL());
3007 // Set up checks for when update job finishes.
3008 do_checks_after_update_finished_ = true;
3009 expect_group_obsolete_ = false;
3010 expect_group_has_cache_ = false;
3011 tested_manifest_ = NONE;
3012 MockFrontend::HostIds host_ids(1, host->host_id());
3013 frontend->AddExpectedEvent(host_ids, APPCACHE_CHECKING_EVENT);
3015 WaitForUpdateToFinish();
3018 void WaitForUpdateToFinish() {
3019 if (group_->update_status() == AppCacheGroup::IDLE)
3020 UpdateFinished();
3021 else
3022 group_->AddUpdateObserver(this);
3025 void OnUpdateComplete(AppCacheGroup* group) override {
3026 ASSERT_EQ(group_.get(), group);
3027 protect_newest_cache_ = group->newest_complete_cache();
3028 UpdateFinished();
3031 void UpdateFinished() {
3032 // We unwind the stack prior to finishing up to let stack-based objects
3033 // get deleted.
3034 base::ThreadTaskRunnerHandle::Get()->PostTask(
3035 FROM_HERE, base::Bind(&AppCacheUpdateJobTest::UpdateFinishedUnwound,
3036 base::Unretained(this)));
3039 void UpdateFinishedUnwound() {
3040 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status());
3041 EXPECT_TRUE(group_->update_job() == NULL);
3042 if (do_checks_after_update_finished_)
3043 VerifyExpectations();
3045 // Clean up everything that was created on the IO thread.
3046 protect_newest_cache_ = NULL;
3047 group_ = NULL;
3048 STLDeleteContainerPointers(hosts_.begin(), hosts_.end());
3049 STLDeleteContainerPointers(frontends_.begin(), frontends_.end());
3050 response_infos_.clear();
3051 service_.reset(NULL);
3053 event_->Signal();
3056 void MakeService() {
3057 service_.reset(new MockAppCacheService());
3058 service_->set_request_context(io_thread_->request_context());
3061 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) {
3062 return MakeCacheForGroup(cache_id, group_->manifest_url(),
3063 manifest_response_id);
3066 AppCache* MakeCacheForGroup(int64 cache_id, const GURL& manifest_entry_url,
3067 int64 manifest_response_id) {
3068 AppCache* cache = new AppCache(service_->storage(), cache_id);
3069 cache->set_complete(true);
3070 cache->set_update_time(base::Time::Now() - kOneHour);
3071 group_->AddCache(cache);
3072 group_->set_last_full_update_check_time(cache->update_time());
3074 // Add manifest entry to cache.
3075 cache->AddEntry(manifest_entry_url,
3076 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id));
3078 // Specific tests that expect a newer time should set
3079 // expect_full_update_time_newer_than_ which causes this
3080 // equality expectation to be ignored.
3081 expect_full_update_time_equal_to_ = cache->update_time();
3083 return cache;
3086 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) {
3087 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get());
3088 hosts_.push_back(host);
3089 return host;
3092 AppCacheResponseInfo* MakeAppCacheResponseInfo(
3093 const GURL& manifest_url, int64 response_id,
3094 const std::string& raw_headers) {
3095 net::HttpResponseInfo* http_info = new net::HttpResponseInfo();
3096 http_info->headers = new net::HttpResponseHeaders(raw_headers);
3097 scoped_refptr<AppCacheResponseInfo> info(
3098 new AppCacheResponseInfo(service_->storage(), manifest_url,
3099 response_id, http_info, 0));
3100 response_infos_.push_back(info);
3101 return info.get();
3104 MockFrontend* MakeMockFrontend() {
3105 MockFrontend* frontend = new MockFrontend();
3106 frontends_.push_back(frontend);
3107 return frontend;
3110 // Verifies conditions about the group and notifications after an update
3111 // has finished. Cannot verify update job internals as update is deleted.
3112 void VerifyExpectations() {
3113 RetryRequestTestJob::Verify();
3114 HttpHeadersRequestTestJob::Verify();
3116 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete());
3117 EXPECT_EQ(expect_group_is_being_deleted_ || expect_eviction_,
3118 group_->is_being_deleted());
3120 if (!expect_eviction_) {
3121 EXPECT_EQ(expect_evictable_error_,
3122 !group_->first_evictable_error_time().is_null());
3123 if (expect_evictable_error_) {
3124 MockAppCacheStorage* storage =
3125 reinterpret_cast<MockAppCacheStorage*>(service_->storage());
3126 EXPECT_EQ(group_->first_evictable_error_time(),
3127 storage->stored_eviction_times_[group_->group_id()].second);
3131 if (!expect_full_update_time_newer_than_.is_null()) {
3132 EXPECT_LT(expect_full_update_time_newer_than_,
3133 group_->last_full_update_check_time());
3134 } else if (!expect_full_update_time_equal_to_.is_null()) {
3135 EXPECT_EQ(expect_full_update_time_equal_to_,
3136 group_->last_full_update_check_time());
3139 if (expect_group_has_cache_) {
3140 EXPECT_TRUE(group_->newest_complete_cache() != NULL);
3142 if (expect_non_null_update_time_)
3143 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null());
3145 if (expect_old_cache_) {
3146 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache());
3147 EXPECT_TRUE(group_->old_caches().end() !=
3148 std::find(group_->old_caches().begin(),
3149 group_->old_caches().end(), expect_old_cache_));
3151 if (expect_newest_cache_) {
3152 EXPECT_EQ(expect_newest_cache_, group_->newest_complete_cache());
3153 EXPECT_TRUE(group_->old_caches().end() ==
3154 std::find(group_->old_caches().begin(),
3155 group_->old_caches().end(), expect_newest_cache_));
3156 } else {
3157 // Tests that don't know which newest cache to expect contain updates
3158 // that succeed (because the update creates a new cache whose pointer
3159 // is unknown to the test). Check group and newest cache were stored
3160 // when update succeeds.
3161 MockAppCacheStorage* storage =
3162 reinterpret_cast<MockAppCacheStorage*>(service_->storage());
3163 EXPECT_TRUE(storage->IsGroupStored(group_.get()));
3164 EXPECT_TRUE(storage->IsCacheStored(group_->newest_complete_cache()));
3166 // Check that all entries in the newest cache were stored.
3167 const AppCache::EntryMap& entries =
3168 group_->newest_complete_cache()->entries();
3169 for (AppCache::EntryMap::const_iterator it = entries.begin();
3170 it != entries.end(); ++it) {
3171 EXPECT_NE(kAppCacheNoResponseId, it->second.response_id());
3173 // Check that any copied entries have the expected response id
3174 // and that entries that are not copied have a different response id.
3175 std::map<GURL, int64>::iterator found =
3176 expect_response_ids_.find(it->first);
3177 if (found != expect_response_ids_.end()) {
3178 EXPECT_EQ(found->second, it->second.response_id());
3179 } else if (expect_old_cache_) {
3180 AppCacheEntry* old_entry = expect_old_cache_->GetEntry(it->first);
3181 if (old_entry)
3182 EXPECT_NE(old_entry->response_id(), it->second.response_id());
3186 } else {
3187 EXPECT_TRUE(group_->newest_complete_cache() == NULL);
3190 // Check expected events.
3191 for (size_t i = 0; i < frontends_.size(); ++i) {
3192 MockFrontend* frontend = frontends_[i];
3194 MockFrontend::RaisedEvents& expected_events = frontend->expected_events_;
3195 MockFrontend::RaisedEvents& actual_events = frontend->raised_events_;
3196 EXPECT_EQ(expected_events.size(), actual_events.size());
3198 // Check each expected event.
3199 for (size_t j = 0;
3200 j < expected_events.size() && j < actual_events.size(); ++j) {
3201 EXPECT_EQ(expected_events[j].second, actual_events[j].second);
3203 MockFrontend::HostIds& expected_ids = expected_events[j].first;
3204 MockFrontend::HostIds& actual_ids = actual_events[j].first;
3205 EXPECT_EQ(expected_ids.size(), actual_ids.size());
3207 for (size_t k = 0; k < expected_ids.size(); ++k) {
3208 int id = expected_ids[k];
3209 EXPECT_TRUE(std::find(actual_ids.begin(), actual_ids.end(), id) !=
3210 actual_ids.end());
3214 if (!frontend->expected_error_message_.empty()) {
3215 EXPECT_EQ(frontend->expected_error_message_,
3216 frontend->error_message_);
3220 // Verify expected cache contents last as some checks are asserts
3221 // and will abort the test if they fail.
3222 if (tested_manifest_) {
3223 AppCache* cache = group_->newest_complete_cache();
3224 ASSERT_TRUE(cache != NULL);
3225 EXPECT_EQ(group_.get(), cache->owning_group());
3226 EXPECT_TRUE(cache->is_complete());
3228 switch (tested_manifest_) {
3229 case MANIFEST1:
3230 VerifyManifest1(cache);
3231 break;
3232 case MANIFEST_MERGED_TYPES:
3233 VerifyManifestMergedTypes(cache);
3234 break;
3235 case EMPTY_MANIFEST:
3236 VerifyEmptyManifest(cache);
3237 break;
3238 case EMPTY_FILE_MANIFEST:
3239 VerifyEmptyFileManifest(cache);
3240 break;
3241 case PENDING_MASTER_NO_UPDATE:
3242 VerifyMasterEntryNoUpdate(cache);
3243 break;
3244 case MANIFEST_WITH_INTERCEPT:
3245 VerifyManifestWithIntercept(cache);
3246 break;
3247 case NONE:
3248 default:
3249 break;
3254 void VerifyManifest1(AppCache* cache) {
3255 size_t expected = 3 + expect_extra_entries_.size();
3256 EXPECT_EQ(expected, cache->entries().size());
3257 const char* kManifestPath = tested_manifest_path_override_ ?
3258 tested_manifest_path_override_ :
3259 "files/manifest1";
3260 AppCacheEntry* entry =
3261 cache->GetEntry(MockHttpServer::GetMockUrl(kManifestPath));
3262 ASSERT_TRUE(entry);
3263 EXPECT_EQ(AppCacheEntry::MANIFEST, entry->types());
3264 entry = cache->GetEntry(MockHttpServer::GetMockUrl("files/explicit1"));
3265 ASSERT_TRUE(entry);
3266 EXPECT_TRUE(entry->IsExplicit());
3267 entry = cache->GetEntry(
3268 MockHttpServer::GetMockUrl("files/fallback1a"));
3269 ASSERT_TRUE(entry);
3270 EXPECT_EQ(AppCacheEntry::FALLBACK, entry->types());
3272 for (AppCache::EntryMap::iterator i = expect_extra_entries_.begin();
3273 i != expect_extra_entries_.end(); ++i) {
3274 entry = cache->GetEntry(i->first);
3275 ASSERT_TRUE(entry);
3276 EXPECT_EQ(i->second.types(), entry->types());
3279 expected = 1;
3280 ASSERT_EQ(expected, cache->fallback_namespaces_.size());
3281 EXPECT_TRUE(cache->fallback_namespaces_[0] ==
3282 AppCacheNamespace(
3283 APPCACHE_FALLBACK_NAMESPACE,
3284 MockHttpServer::GetMockUrl("files/fallback1"),
3285 MockHttpServer::GetMockUrl("files/fallback1a"),
3286 false));
3288 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty());
3289 EXPECT_TRUE(cache->online_whitelist_all_);
3291 EXPECT_TRUE(cache->update_time_ > base::Time());
3294 void VerifyManifestMergedTypes(AppCache* cache) {
3295 size_t expected = 2;
3296 EXPECT_EQ(expected, cache->entries().size());
3297 AppCacheEntry* entry = cache->GetEntry(
3298 MockHttpServer::GetMockUrl("files/manifest-merged-types"));
3299 ASSERT_TRUE(entry);
3300 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::MANIFEST,
3301 entry->types());
3302 entry = cache->GetEntry(MockHttpServer::GetMockUrl("files/explicit1"));
3303 ASSERT_TRUE(entry);
3304 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::FALLBACK |
3305 AppCacheEntry::MASTER, entry->types());
3307 expected = 1;
3308 ASSERT_EQ(expected, cache->fallback_namespaces_.size());
3309 EXPECT_TRUE(cache->fallback_namespaces_[0] ==
3310 AppCacheNamespace(
3311 APPCACHE_FALLBACK_NAMESPACE,
3312 MockHttpServer::GetMockUrl("files/fallback1"),
3313 MockHttpServer::GetMockUrl("files/explicit1"),
3314 false));
3316 EXPECT_EQ(expected, cache->online_whitelist_namespaces_.size());
3317 EXPECT_TRUE(cache->online_whitelist_namespaces_[0] ==
3318 AppCacheNamespace(
3319 APPCACHE_NETWORK_NAMESPACE,
3320 MockHttpServer::GetMockUrl("files/online1"),
3321 GURL(), false));
3322 EXPECT_FALSE(cache->online_whitelist_all_);
3324 EXPECT_TRUE(cache->update_time_ > base::Time());
3327 void VerifyEmptyManifest(AppCache* cache) {
3328 const char* kManifestPath = tested_manifest_path_override_ ?
3329 tested_manifest_path_override_ :
3330 "files/empty-manifest";
3331 size_t expected = 1;
3332 EXPECT_EQ(expected, cache->entries().size());
3333 AppCacheEntry* entry = cache->GetEntry(
3334 MockHttpServer::GetMockUrl(kManifestPath));
3335 ASSERT_TRUE(entry);
3336 EXPECT_EQ(AppCacheEntry::MANIFEST, entry->types());
3338 EXPECT_TRUE(cache->fallback_namespaces_.empty());
3339 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty());
3340 EXPECT_FALSE(cache->online_whitelist_all_);
3342 EXPECT_TRUE(cache->update_time_ > base::Time());
3345 void VerifyEmptyFileManifest(AppCache* cache) {
3346 EXPECT_EQ(size_t(2), cache->entries().size());
3347 AppCacheEntry* entry = cache->GetEntry(
3348 MockHttpServer::GetMockUrl("files/empty-file-manifest"));
3349 ASSERT_TRUE(entry);
3350 EXPECT_EQ(AppCacheEntry::MANIFEST, entry->types());
3352 entry = cache->GetEntry(
3353 MockHttpServer::GetMockUrl("files/empty1"));
3354 ASSERT_TRUE(entry);
3355 EXPECT_EQ(AppCacheEntry::EXPLICIT, entry->types());
3356 EXPECT_TRUE(entry->has_response_id());
3358 EXPECT_TRUE(cache->fallback_namespaces_.empty());
3359 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty());
3360 EXPECT_FALSE(cache->online_whitelist_all_);
3362 EXPECT_TRUE(cache->update_time_ > base::Time());
3365 void VerifyMasterEntryNoUpdate(AppCache* cache) {
3366 EXPECT_EQ(size_t(3), cache->entries().size());
3367 AppCacheEntry* entry = cache->GetEntry(
3368 MockHttpServer::GetMockUrl("files/notmodified"));
3369 ASSERT_TRUE(entry);
3370 EXPECT_EQ(AppCacheEntry::MANIFEST, entry->types());
3372 entry = cache->GetEntry(
3373 MockHttpServer::GetMockUrl("files/explicit1"));
3374 ASSERT_TRUE(entry);
3375 EXPECT_EQ(AppCacheEntry::MASTER, entry->types());
3376 EXPECT_TRUE(entry->has_response_id());
3378 entry = cache->GetEntry(
3379 MockHttpServer::GetMockUrl("files/explicit2"));
3380 ASSERT_TRUE(entry);
3381 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::MASTER, entry->types());
3382 EXPECT_TRUE(entry->has_response_id());
3384 EXPECT_TRUE(cache->fallback_namespaces_.empty());
3385 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty());
3386 EXPECT_FALSE(cache->online_whitelist_all_);
3388 EXPECT_TRUE(cache->update_time_ > base::Time());
3391 void VerifyManifestWithIntercept(AppCache* cache) {
3392 EXPECT_EQ(2u, cache->entries().size());
3393 const char* kManifestPath = "files/manifest-with-intercept";
3394 AppCacheEntry* entry =
3395 cache->GetEntry(MockHttpServer::GetMockUrl(kManifestPath));
3396 ASSERT_TRUE(entry);
3397 EXPECT_EQ(AppCacheEntry::MANIFEST, entry->types());
3398 entry = cache->GetEntry(MockHttpServer::GetMockUrl("files/intercept1a"));
3399 ASSERT_TRUE(entry);
3400 EXPECT_TRUE(entry->IsIntercept());
3401 EXPECT_TRUE(cache->online_whitelist_namespaces_.empty());
3402 EXPECT_FALSE(cache->online_whitelist_all_);
3403 EXPECT_TRUE(cache->update_time_ > base::Time());
3406 private:
3407 // Various manifest files used in this test.
3408 enum TestedManifest {
3409 NONE,
3410 MANIFEST1,
3411 MANIFEST_MERGED_TYPES,
3412 EMPTY_MANIFEST,
3413 EMPTY_FILE_MANIFEST,
3414 PENDING_MASTER_NO_UPDATE,
3415 MANIFEST_WITH_INTERCEPT
3418 scoped_ptr<IOThread> io_thread_;
3420 scoped_ptr<MockAppCacheService> service_;
3421 scoped_refptr<AppCacheGroup> group_;
3422 scoped_refptr<AppCache> protect_newest_cache_;
3423 scoped_ptr<base::WaitableEvent> event_;
3425 scoped_ptr<AppCacheResponseWriter> response_writer_;
3427 // Hosts used by an async test that need to live until update job finishes.
3428 // Otherwise, test can put host on the stack instead of here.
3429 std::vector<AppCacheHost*> hosts_;
3431 // Response infos used by an async test that need to live until update job
3432 // finishes.
3433 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_;
3435 // Flag indicating if test cares to verify the update after update finishes.
3436 bool do_checks_after_update_finished_;
3437 bool expect_group_obsolete_;
3438 bool expect_group_has_cache_;
3439 bool expect_group_is_being_deleted_;
3440 bool expect_evictable_error_;
3441 bool expect_eviction_;
3442 base::Time expect_full_update_time_newer_than_;
3443 base::Time expect_full_update_time_equal_to_;
3444 AppCache* expect_old_cache_;
3445 AppCache* expect_newest_cache_;
3446 bool expect_non_null_update_time_;
3447 std::vector<MockFrontend*> frontends_; // to check expected events
3448 TestedManifest tested_manifest_;
3449 const char* tested_manifest_path_override_;
3450 AppCache::EntryMap expect_extra_entries_;
3451 std::map<GURL, int64> expect_response_ids_;
3454 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) {
3455 MockAppCacheService service;
3456 scoped_refptr<AppCacheGroup> group(
3457 new AppCacheGroup(service.storage(), GURL("http://manifesturl.com"),
3458 service.storage()->NewGroupId()));
3460 AppCacheUpdateJob update(&service, group.get());
3462 // Pretend group is in checking state.
3463 group->update_job_ = &update;
3464 group->update_status_ = AppCacheGroup::CHECKING;
3466 update.StartUpdate(NULL, GURL());
3467 EXPECT_EQ(AppCacheGroup::CHECKING, group->update_status());
3469 MockFrontend mock_frontend;
3470 AppCacheHost host(1, &mock_frontend, &service);
3471 update.StartUpdate(&host, GURL());
3473 MockFrontend::RaisedEvents events = mock_frontend.raised_events_;
3474 size_t expected = 1;
3475 EXPECT_EQ(expected, events.size());
3476 EXPECT_EQ(expected, events[0].first.size());
3477 EXPECT_EQ(host.host_id(), events[0].first[0]);
3478 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second);
3479 EXPECT_EQ(AppCacheGroup::CHECKING, group->update_status());
3482 TEST_F(AppCacheUpdateJobTest, AlreadyDownloading) {
3483 MockAppCacheService service;
3484 scoped_refptr<AppCacheGroup> group(
3485 new AppCacheGroup(service.storage(), GURL("http://manifesturl.com"),
3486 service.storage()->NewGroupId()));
3488 AppCacheUpdateJob update(&service, group.get());
3490 // Pretend group is in downloading state.
3491 group->update_job_ = &update;
3492 group->update_status_ = AppCacheGroup::DOWNLOADING;
3494 update.StartUpdate(NULL, GURL());
3495 EXPECT_EQ(AppCacheGroup::DOWNLOADING, group->update_status());
3497 MockFrontend mock_frontend;
3498 AppCacheHost host(1, &mock_frontend, &service);
3499 update.StartUpdate(&host, GURL());
3501 MockFrontend::RaisedEvents events = mock_frontend.raised_events_;
3502 size_t expected = 2;
3503 EXPECT_EQ(expected, events.size());
3504 expected = 1;
3505 EXPECT_EQ(expected, events[0].first.size());
3506 EXPECT_EQ(host.host_id(), events[0].first[0]);
3507 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second);
3509 EXPECT_EQ(expected, events[1].first.size());
3510 EXPECT_EQ(host.host_id(), events[1].first[0]);
3511 EXPECT_EQ(APPCACHE_DOWNLOADING_EVENT, events[1].second);
3513 EXPECT_EQ(AppCacheGroup::DOWNLOADING, group->update_status());
3516 TEST_F(AppCacheUpdateJobTest, StartCacheAttempt) {
3517 RunTestOnIOThread(&AppCacheUpdateJobTest::StartCacheAttemptTest);
3520 TEST_F(AppCacheUpdateJobTest, StartUpgradeAttempt) {
3521 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpgradeAttemptTest);
3524 TEST_F(AppCacheUpdateJobTest, CacheAttemptFetchManifestFail) {
3525 RunTestOnIOThread(&AppCacheUpdateJobTest::CacheAttemptFetchManifestFailTest);
3528 TEST_F(AppCacheUpdateJobTest, UpgradeFetchManifestFail) {
3529 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFetchManifestFailTest);
3532 TEST_F(AppCacheUpdateJobTest, ManifestRedirect) {
3533 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest);
3536 TEST_F(AppCacheUpdateJobTest, ManifestMissingMimeTypeTest) {
3537 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestMissingMimeTypeTest);
3540 TEST_F(AppCacheUpdateJobTest, ManifestNotFound) {
3541 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestNotFoundTest);
3544 TEST_F(AppCacheUpdateJobTest, ManifestGone) {
3545 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestGoneTest);
3548 TEST_F(AppCacheUpdateJobTest, CacheAttemptNotModified) {
3549 RunTestOnIOThread(&AppCacheUpdateJobTest::CacheAttemptNotModifiedTest);
3552 TEST_F(AppCacheUpdateJobTest, UpgradeNotModified) {
3553 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNotModifiedTest);
3556 TEST_F(AppCacheUpdateJobTest, UpgradeManifestDataUnchanged) {
3557 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeManifestDataUnchangedTest);
3560 TEST_F(AppCacheUpdateJobTest, Bug95101Test) {
3561 RunTestOnIOThread(&AppCacheUpdateJobTest::Bug95101Test);
3564 TEST_F(AppCacheUpdateJobTest, BasicCacheAttemptSuccess) {
3565 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicCacheAttemptSuccessTest);
3568 TEST_F(AppCacheUpdateJobTest, DownloadInterceptEntriesTest) {
3569 RunTestOnIOThread(&AppCacheUpdateJobTest::DownloadInterceptEntriesTest);
3572 TEST_F(AppCacheUpdateJobTest, BasicUpgradeSuccess) {
3573 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicUpgradeSuccessTest);
3576 TEST_F(AppCacheUpdateJobTest, UpgradeLoadFromNewestCache) {
3577 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeLoadFromNewestCacheTest);
3580 TEST_F(AppCacheUpdateJobTest, UpgradeNoLoadFromNewestCache) {
3581 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNoLoadFromNewestCacheTest);
3584 TEST_F(AppCacheUpdateJobTest, UpgradeLoadFromNewestCacheVaryHeader) {
3585 RunTestOnIOThread(
3586 &AppCacheUpdateJobTest::UpgradeLoadFromNewestCacheVaryHeaderTest);
3589 TEST_F(AppCacheUpdateJobTest, UpgradeSuccessMergedTypes) {
3590 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeSuccessMergedTypesTest);
3593 TEST_F(AppCacheUpdateJobTest, CacheAttemptFailUrlFetch) {
3594 RunTestOnIOThread(&AppCacheUpdateJobTest::CacheAttemptFailUrlFetchTest);
3597 TEST_F(AppCacheUpdateJobTest, UpgradeFailUrlFetch) {
3598 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailUrlFetchTest);
3601 TEST_F(AppCacheUpdateJobTest, UpgradeFailMasterUrlFetch) {
3602 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailMasterUrlFetchTest);
3605 TEST_F(AppCacheUpdateJobTest, EmptyManifest) {
3606 RunTestOnIOThread(&AppCacheUpdateJobTest::EmptyManifestTest);
3609 TEST_F(AppCacheUpdateJobTest, EmptyFile) {
3610 RunTestOnIOThread(&AppCacheUpdateJobTest::EmptyFileTest);
3613 TEST_F(AppCacheUpdateJobTest, RetryRequest) {
3614 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryRequestTest);
3617 TEST_F(AppCacheUpdateJobTest, RetryNoRetryAfter) {
3618 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryNoRetryAfterTest);
3621 TEST_F(AppCacheUpdateJobTest, RetryNonzeroRetryAfter) {
3622 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryNonzeroRetryAfterTest);
3625 TEST_F(AppCacheUpdateJobTest, RetrySuccess) {
3626 RunTestOnIOThread(&AppCacheUpdateJobTest::RetrySuccessTest);
3629 TEST_F(AppCacheUpdateJobTest, RetryUrl) {
3630 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryUrlTest);
3633 TEST_F(AppCacheUpdateJobTest, FailStoreNewestCache) {
3634 RunTestOnIOThread(&AppCacheUpdateJobTest::FailStoreNewestCacheTest);
3637 TEST_F(AppCacheUpdateJobTest, MasterEntryFailStoreNewestCacheTest) {
3638 RunTestOnIOThread(
3639 &AppCacheUpdateJobTest::MasterEntryFailStoreNewestCacheTest);
3642 TEST_F(AppCacheUpdateJobTest, UpgradeFailStoreNewestCache) {
3643 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailStoreNewestCacheTest);
3646 TEST_F(AppCacheUpdateJobTest, UpgradeFailMakeGroupObsolete) {
3647 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailMakeGroupObsoleteTest);
3650 TEST_F(AppCacheUpdateJobTest, MasterEntryFetchManifestFail) {
3651 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryFetchManifestFailTest);
3654 TEST_F(AppCacheUpdateJobTest, MasterEntryBadManifest) {
3655 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryBadManifestTest);
3658 TEST_F(AppCacheUpdateJobTest, MasterEntryManifestNotFound) {
3659 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryManifestNotFoundTest);
3662 TEST_F(AppCacheUpdateJobTest, MasterEntryFailUrlFetch) {
3663 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryFailUrlFetchTest);
3666 TEST_F(AppCacheUpdateJobTest, MasterEntryAllFail) {
3667 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryAllFailTest);
3670 TEST_F(AppCacheUpdateJobTest, UpgradeMasterEntryAllFail) {
3671 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeMasterEntryAllFailTest);
3674 TEST_F(AppCacheUpdateJobTest, MasterEntrySomeFail) {
3675 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntrySomeFailTest);
3678 TEST_F(AppCacheUpdateJobTest, UpgradeMasterEntrySomeFail) {
3679 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeMasterEntrySomeFailTest);
3682 TEST_F(AppCacheUpdateJobTest, MasterEntryNoUpdate) {
3683 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryNoUpdateTest);
3686 TEST_F(AppCacheUpdateJobTest, StartUpdateMidCacheAttempt) {
3687 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpdateMidCacheAttemptTest);
3690 TEST_F(AppCacheUpdateJobTest, StartUpdateMidNoUpdate) {
3691 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpdateMidNoUpdateTest);
3694 TEST_F(AppCacheUpdateJobTest, StartUpdateMidDownload) {
3695 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpdateMidDownloadTest);
3698 TEST_F(AppCacheUpdateJobTest, QueueMasterEntry) {
3699 RunTestOnIOThread(&AppCacheUpdateJobTest::QueueMasterEntryTest);
3702 TEST_F(AppCacheUpdateJobTest, IfModifiedSince) {
3703 RunTestOnIOThread(&AppCacheUpdateJobTest::IfModifiedSinceTest);
3706 TEST_F(AppCacheUpdateJobTest, IfModifiedSinceUpgrade) {
3707 RunTestOnIOThread(&AppCacheUpdateJobTest::IfModifiedSinceUpgradeTest);
3710 TEST_F(AppCacheUpdateJobTest, IfNoneMatchUpgrade) {
3711 RunTestOnIOThread(&AppCacheUpdateJobTest::IfNoneMatchUpgradeTest);
3714 TEST_F(AppCacheUpdateJobTest, IfNoneMatchRefetch) {
3715 RunTestOnIOThread(&AppCacheUpdateJobTest::IfNoneMatchRefetchTest);
3718 TEST_F(AppCacheUpdateJobTest, MultipleHeadersRefetch) {
3719 RunTestOnIOThread(&AppCacheUpdateJobTest::MultipleHeadersRefetchTest);
3722 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) {
3723 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest);
3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest);
3730 } // namespace content