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.
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"
27 class AppCacheUpdateJobTest
;
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
[] =
43 "fallback1 fallback1a\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,
50 class MockHttpServer
{
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);
77 static void GetMockResponse(const std::string
& path
,
80 const char ok_headers
[] =
83 const char error_headers
[] =
84 "HTTP/1.1 500 BOO HOO\0"
86 const char manifest_headers
[] =
88 "Content-type: text/cache-manifest\0"
90 const char not_modified_headers
[] =
91 "HTTP/1.1 304 NOT MODIFIED\0"
93 const char gone_headers
[] =
96 const char not_found_headers
[] =
97 "HTTP/1.1 404 NOT FOUND\0"
99 const char no_store_headers
[] =
101 "Cache-Control: no-store\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
));
113 } else if (path
== "/files/empty-file-manifest") {
114 (*headers
) = std::string(manifest_headers
, arraysize(manifest_headers
));
115 (*body
) = "CACHE MANIFEST\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
));
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"
143 } else if (path
== "/files/manifest-fb-404") {
144 (*headers
) = std::string(manifest_headers
, arraysize(manifest_headers
));
145 (*body
) = "CACHE MANIFEST\n"
148 "fallback1 fallback1a\n"
149 "fallback404 fallback-404\n"
152 } else if (path
== "/files/manifest-merged-types") {
153 (*headers
) = std::string(manifest_headers
, arraysize(manifest_headers
));
154 (*body
) = "CACHE MANIFEST\n"
156 "# manifest is also an explicit entry\n"
157 "manifest-merged-types\n"
159 "# fallback is also explicit entry\n"
160 "fallback1 explicit1\n"
163 } else if (path
== "/files/manifest-with-404") {
164 (*headers
) = std::string(manifest_headers
, arraysize(manifest_headers
));
165 (*body
) = "CACHE MANIFEST\n"
171 "fallback1 fallback1a\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
));
183 } else if (path
== "/files/servererror") {
184 (*headers
) = std::string(error_headers
,
185 arraysize(error_headers
));
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";
199 (*headers
) = std::string(not_found_headers
,
200 arraysize(not_found_headers
));
206 class MockHttpServerJobFactory
207 : public net::URLRequestJobFactory::ProtocolHandler
{
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
;
225 class MockFrontend
: public AppCacheFrontend
{
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
,
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
);
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());
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
;
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
{
352 net::URLRequestJob
* MaybeCreateJob(
353 net::URLRequest
* request
,
354 net::NetworkDelegate
* network_delegate
) const override
{
355 return new net::URLRequestTestJob(
358 net::URLRequestTestJob::test_redirect_headers(),
359 net::URLRequestTestJob::test_data_1(),
364 // Helper class to simulate a URL that returns retry or success.
365 class RetryRequestTestJob
: public net::URLRequestTestJob
{
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
) {
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_
);
388 expected_requests_
= 0;
391 static net::URLRequestJob
* RetryFactory(
392 net::URLRequest
* request
, net::NetworkDelegate
* network_delegate
) {
394 if (num_retries_
> 0 && request
->original_url() == kRetryUrl
) {
396 return new RetryRequestTestJob(
397 request
, network_delegate
, RetryRequestTestJob::retry_headers(), 503);
399 return new RetryRequestTestJob(
402 RetryRequestTestJob::manifest_headers(), 200);
406 int GetResponseCode() const override
{ return response_code_
; }
409 ~RetryRequestTestJob() override
{}
411 static std::string
retry_headers() {
412 const char no_retry_after
[] =
413 "HTTP/1.1 503 BOO HOO\0"
415 const char nonzero
[] =
416 "HTTP/1.1 503 BOO HOO\0"
419 const char retry_after_0
[] =
420 "HTTP/1.1 503 BOO HOO\0"
424 switch (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
));
431 return std::string(retry_after_0
, arraysize(retry_after_0
));
435 static std::string
manifest_headers() {
436 const char headers
[] =
438 "Content-type: text/cache-manifest\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
,
452 : net::URLRequestTestJob(
453 request
, network_delegate
, headers
, data(), true),
454 response_code_(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
{
468 net::URLRequestJob
* MaybeCreateJob(
469 net::URLRequest
* request
,
470 net::NetworkDelegate
* network_delegate
) const override
{
471 return RetryRequestTestJob::RetryFactory(request
, network_delegate
);
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
{
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_
);
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_
;
520 extra_headers
.GetHeader(
521 net::HttpRequestHeaders::kIfNoneMatch
, &header_value
) &&
522 header_value
== expect_if_none_match_
;
524 return MockHttpServer::JobFactory(request
, network_delegate
);
528 ~HttpHeadersRequestTestJob() override
{}
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_
;
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
{
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
{
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
) {
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", new MockHttpServerJobFactory
);
578 factory
->SetProtocolHandler("https", new MockHttpServerJobFactory
);
579 job_factory_
= factory
.Pass();
580 request_context_
.reset(new net::TestURLRequestContext());
581 request_context_
->set_job_factory(job_factory_
.get());
584 void CleanUp() override
{
585 request_context_
.reset();
586 job_factory_
.reset();
590 scoped_ptr
<net::URLRequestJobFactory
> job_factory_
;
591 scoped_ptr
<net::URLRequestContext
> request_context_
;
594 class AppCacheUpdateJobTest
: public testing::Test
,
595 public AppCacheGroup::UpdateObserver
{
597 AppCacheUpdateJobTest()
598 : do_checks_after_update_finished_(false),
599 expect_group_obsolete_(false),
600 expect_group_has_cache_(false),
601 expect_group_is_being_deleted_(false),
602 expect_evictable_error_(false),
603 expect_eviction_(false),
604 expect_old_cache_(NULL
),
605 expect_newest_cache_(NULL
),
606 expect_non_null_update_time_(false),
607 tested_manifest_(NONE
),
608 tested_manifest_path_override_(NULL
) {
609 io_thread_
.reset(new IOThread("AppCacheUpdateJob IO test thread"));
610 base::Thread::Options
options(base::MessageLoop::TYPE_IO
, 0);
611 io_thread_
->StartWithOptions(options
);
614 // Use a separate IO thread to run a test. Thread will be destroyed
615 // when it goes out of scope.
616 template <class Method
>
617 void RunTestOnIOThread(Method method
) {
618 event_
.reset(new base::WaitableEvent(false, false));
619 io_thread_
->task_runner()->PostTask(
620 FROM_HERE
, base::Bind(method
, base::Unretained(this)));
622 // Wait until task is done before exiting the test.
626 void StartCacheAttemptTest() {
627 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
630 group_
= new AppCacheGroup(service_
->storage(), GURL("http://failme"),
631 service_
->storage()->NewGroupId());
633 AppCacheUpdateJob
* update
=
634 new AppCacheUpdateJob(service_
.get(), group_
.get());
635 group_
->update_job_
= update
;
637 MockFrontend mock_frontend
;
638 AppCacheHost
host(1, &mock_frontend
, service_
.get());
640 update
->StartUpdate(&host
, GURL());
643 EXPECT_EQ(AppCacheUpdateJob::CACHE_ATTEMPT
, update
->update_type_
);
644 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST
, update
->internal_state_
);
645 EXPECT_EQ(AppCacheGroup::CHECKING
, group_
->update_status());
646 EXPECT_TRUE(update
->doing_full_update_check_
);
648 // Verify notifications.
649 MockFrontend::RaisedEvents
& events
= mock_frontend
.raised_events_
;
651 EXPECT_EQ(expected
, events
.size());
652 EXPECT_EQ(expected
, events
[0].first
.size());
653 EXPECT_EQ(host
.host_id(), events
[0].first
[0]);
654 EXPECT_EQ(APPCACHE_CHECKING_EVENT
, events
[0].second
);
656 // Abort as we're not testing actual URL fetches in this test.
661 void StartUpgradeAttemptTest() {
662 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
666 group_
= new AppCacheGroup(service_
->storage(), GURL("http://failme"),
667 service_
->storage()->NewGroupId());
669 // Give the group some existing caches.
670 AppCache
* cache1
= MakeCacheForGroup(1, 111);
671 AppCache
* cache2
= MakeCacheForGroup(2, 222);
673 // Associate some hosts with caches in the group.
674 MockFrontend mock_frontend1
;
675 MockFrontend mock_frontend2
;
676 MockFrontend mock_frontend3
;
678 AppCacheHost
host1(1, &mock_frontend1
, service_
.get());
679 host1
.AssociateCompleteCache(cache1
);
681 AppCacheHost
host2(2, &mock_frontend2
, service_
.get());
682 host2
.AssociateCompleteCache(cache2
);
684 AppCacheHost
host3(3, &mock_frontend1
, service_
.get());
685 host3
.AssociateCompleteCache(cache1
);
687 AppCacheHost
host4(4, &mock_frontend3
, service_
.get());
689 AppCacheUpdateJob
* update
=
690 new AppCacheUpdateJob(service_
.get(), group_
.get());
691 group_
->update_job_
= update
;
692 update
->StartUpdate(&host4
, GURL());
694 // Verify state after starting an update.
695 EXPECT_EQ(AppCacheUpdateJob::UPGRADE_ATTEMPT
, update
->update_type_
);
696 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST
, update
->internal_state_
);
697 EXPECT_EQ(AppCacheGroup::CHECKING
, group_
->update_status());
698 EXPECT_FALSE(update
->doing_full_update_check_
);
700 // Verify notifications.
701 MockFrontend::RaisedEvents
& events
= mock_frontend1
.raised_events_
;
703 EXPECT_EQ(expected
, events
.size());
704 expected
= 2; // 2 hosts using frontend1
705 EXPECT_EQ(expected
, events
[0].first
.size());
706 MockFrontend::HostIds
& host_ids
= events
[0].first
;
707 EXPECT_TRUE(std::find(host_ids
.begin(), host_ids
.end(), host1
.host_id())
709 EXPECT_TRUE(std::find(host_ids
.begin(), host_ids
.end(), host3
.host_id())
711 EXPECT_EQ(APPCACHE_CHECKING_EVENT
, events
[0].second
);
713 events
= mock_frontend2
.raised_events_
;
715 EXPECT_EQ(expected
, events
.size());
716 EXPECT_EQ(expected
, events
[0].first
.size()); // 1 host using frontend2
717 EXPECT_EQ(host2
.host_id(), events
[0].first
[0]);
718 EXPECT_EQ(APPCACHE_CHECKING_EVENT
, events
[0].second
);
720 events
= mock_frontend3
.raised_events_
;
721 EXPECT_TRUE(events
.empty());
723 // Abort as we're not testing actual URL fetches in this test.
729 void CacheAttemptFetchManifestFailTest() {
730 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
733 group_
= new AppCacheGroup(service_
->storage(), GURL("http://failme"),
734 service_
->storage()->NewGroupId());
735 AppCacheUpdateJob
* update
=
736 new AppCacheUpdateJob(service_
.get(), group_
.get());
737 group_
->update_job_
= update
;
739 MockFrontend
* frontend
= MakeMockFrontend();
740 AppCacheHost
* host
= MakeHost(1, frontend
);
741 update
->StartUpdate(host
, GURL());
743 // Set up checks for when update job finishes.
744 do_checks_after_update_finished_
= true;
745 expect_group_obsolete_
= false;
746 expect_group_has_cache_
= false;
747 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
748 APPCACHE_CHECKING_EVENT
);
750 WaitForUpdateToFinish();
753 void UpgradeFetchManifestFailTest() {
754 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
757 group_
= new AppCacheGroup(service_
->storage(),
758 MockHttpServer::GetMockUrl("files/servererror"),
759 service_
->storage()->NewGroupId());
760 AppCacheUpdateJob
* update
=
761 new AppCacheUpdateJob(service_
.get(), group_
.get());
762 group_
->update_job_
= update
;
764 AppCache
* cache
= MakeCacheForGroup(1, 111);
765 MockFrontend
* frontend1
= MakeMockFrontend();
766 MockFrontend
* frontend2
= MakeMockFrontend();
767 AppCacheHost
* host1
= MakeHost(1, frontend1
);
768 AppCacheHost
* host2
= MakeHost(2, frontend2
);
769 host1
->AssociateCompleteCache(cache
);
770 host2
->AssociateCompleteCache(cache
);
772 group_
->set_last_full_update_check_time(
773 base::Time::Now() - kFullUpdateInterval
- kOneHour
);
774 update
->StartUpdate(NULL
, GURL());
775 EXPECT_TRUE(update
->doing_full_update_check_
);
777 // Set up checks for when update job finishes.
778 do_checks_after_update_finished_
= true;
779 expect_group_obsolete_
= false;
780 expect_group_has_cache_
= true;
781 expect_evictable_error_
= true;
782 expect_newest_cache_
= cache
; // newest cache unaffected by update
783 expect_full_update_time_equal_to_
= group_
->last_full_update_check_time();
784 MockFrontend::HostIds
ids1(1, host1
->host_id());
785 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
786 frontend1
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
787 MockFrontend::HostIds
ids2(1, host2
->host_id());
788 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
789 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
791 WaitForUpdateToFinish();
794 void ManifestRedirectTest() {
795 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
797 net::URLRequestJobFactoryImpl
* new_factory(
798 new net::URLRequestJobFactoryImpl
);
799 new_factory
->SetProtocolHandler("http", new RedirectFactory
);
800 io_thread_
->SetNewJobFactory(new_factory
);
803 group_
= new AppCacheGroup(service_
->storage(), GURL("http://testme"),
804 service_
->storage()->NewGroupId());
805 AppCacheUpdateJob
* update
=
806 new AppCacheUpdateJob(service_
.get(), group_
.get());
807 group_
->update_job_
= update
;
809 MockFrontend
* frontend
= MakeMockFrontend();
810 AppCacheHost
* host
= MakeHost(1, frontend
);
811 update
->StartUpdate(host
, GURL());
813 // Set up checks for when update job finishes.
814 do_checks_after_update_finished_
= true;
815 expect_group_obsolete_
= false;
816 expect_group_has_cache_
= false; // redirect is like a failed request
817 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
818 APPCACHE_CHECKING_EVENT
);
820 WaitForUpdateToFinish();
823 void ManifestMissingMimeTypeTest() {
824 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
827 group_
= new AppCacheGroup(
829 MockHttpServer::GetMockUrl("files/missing-mime-manifest"),
830 service_
->storage()->NewGroupId());
831 AppCacheUpdateJob
* update
=
832 new AppCacheUpdateJob(service_
.get(), group_
.get());
833 group_
->update_job_
= update
;
835 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 33);
836 MockFrontend
* frontend
= MakeMockFrontend();
837 AppCacheHost
* host
= MakeHost(1, frontend
);
838 host
->AssociateCompleteCache(cache
);
840 frontend
->SetVerifyProgressEvents(true);
842 update
->StartUpdate(NULL
, GURL());
844 // Set up checks for when update job finishes.
845 do_checks_after_update_finished_
= true;
846 expect_group_obsolete_
= false;
847 expect_group_has_cache_
= true;
848 expect_old_cache_
= cache
;
849 tested_manifest_
= EMPTY_MANIFEST
;
850 tested_manifest_path_override_
= "files/missing-mime-manifest";
851 MockFrontend::HostIds
ids(1, host
->host_id());
852 frontend
->AddExpectedEvent(ids
, APPCACHE_CHECKING_EVENT
);
853 frontend
->AddExpectedEvent(ids
, APPCACHE_DOWNLOADING_EVENT
);
854 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
); // final
855 frontend
->AddExpectedEvent(ids
, APPCACHE_UPDATE_READY_EVENT
);
857 WaitForUpdateToFinish();
860 void ManifestNotFoundTest() {
861 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
864 group_
= new AppCacheGroup(
865 service_
->storage(), MockHttpServer::GetMockUrl("files/nosuchfile"),
866 service_
->storage()->NewGroupId());
867 AppCacheUpdateJob
* update
=
868 new AppCacheUpdateJob(service_
.get(), group_
.get());
869 group_
->update_job_
= update
;
871 AppCache
* cache
= MakeCacheForGroup(1, 111);
872 MockFrontend
* frontend1
= MakeMockFrontend();
873 MockFrontend
* frontend2
= MakeMockFrontend();
874 AppCacheHost
* host1
= MakeHost(1, frontend1
);
875 AppCacheHost
* host2
= MakeHost(2, frontend2
);
876 host1
->AssociateCompleteCache(cache
);
877 host2
->AssociateCompleteCache(cache
);
879 update
->StartUpdate(NULL
, GURL());
881 // Set up checks for when update job finishes.
882 do_checks_after_update_finished_
= true;
883 expect_group_obsolete_
= true;
884 expect_group_has_cache_
= true;
885 expect_newest_cache_
= cache
; // newest cache unaffected by update
886 MockFrontend::HostIds
ids1(1, host1
->host_id());
887 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
888 frontend1
->AddExpectedEvent(ids1
, APPCACHE_OBSOLETE_EVENT
);
889 MockFrontend::HostIds
ids2(1, host2
->host_id());
890 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
891 frontend2
->AddExpectedEvent(ids2
, APPCACHE_OBSOLETE_EVENT
);
893 WaitForUpdateToFinish();
896 void ManifestGoneTest() {
897 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
900 group_
= new AppCacheGroup(
901 service_
->storage(), MockHttpServer::GetMockUrl("files/gone"),
902 service_
->storage()->NewGroupId());
903 AppCacheUpdateJob
* update
=
904 new AppCacheUpdateJob(service_
.get(), group_
.get());
905 group_
->update_job_
= update
;
907 MockFrontend
* frontend
= MakeMockFrontend();
908 AppCacheHost
* host
= MakeHost(1, frontend
);
909 update
->StartUpdate(host
, GURL());
911 // Set up checks for when update job finishes.
912 do_checks_after_update_finished_
= true;
913 expect_group_obsolete_
= false;
914 expect_group_has_cache_
= false;
915 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
916 APPCACHE_CHECKING_EVENT
);
918 WaitForUpdateToFinish();
921 void CacheAttemptNotModifiedTest() {
922 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
925 group_
= new AppCacheGroup(
926 service_
->storage(), MockHttpServer::GetMockUrl("files/notmodified"),
927 service_
->storage()->NewGroupId());
928 AppCacheUpdateJob
* update
=
929 new AppCacheUpdateJob(service_
.get(), group_
.get());
930 group_
->update_job_
= update
;
932 MockFrontend
* frontend
= MakeMockFrontend();
933 AppCacheHost
* host
= MakeHost(1, frontend
);
934 update
->StartUpdate(host
, GURL());
936 // Set up checks for when update job finishes.
937 do_checks_after_update_finished_
= true;
938 expect_group_obsolete_
= false;
939 expect_group_has_cache_
= false; // treated like cache failure
940 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
941 APPCACHE_CHECKING_EVENT
);
943 WaitForUpdateToFinish();
946 void UpgradeNotModifiedTest() {
947 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
950 group_
= new AppCacheGroup(
951 service_
->storage(), MockHttpServer::GetMockUrl("files/notmodified"),
952 service_
->storage()->NewGroupId());
953 AppCacheUpdateJob
* update
=
954 new AppCacheUpdateJob(service_
.get(), group_
.get());
955 group_
->update_job_
= update
;
957 AppCache
* cache
= MakeCacheForGroup(1, 111);
958 MockFrontend
* frontend1
= MakeMockFrontend();
959 MockFrontend
* frontend2
= MakeMockFrontend();
960 AppCacheHost
* host1
= MakeHost(1, frontend1
);
961 AppCacheHost
* host2
= MakeHost(2, frontend2
);
962 host1
->AssociateCompleteCache(cache
);
963 host2
->AssociateCompleteCache(cache
);
965 group_
->set_last_full_update_check_time(
966 base::Time::Now() - kFullUpdateInterval
- kOneHour
);
967 group_
->set_first_evictable_error_time(base::Time::Now());
968 update
->StartUpdate(NULL
, GURL());
969 EXPECT_TRUE(update
->doing_full_update_check_
);
971 // Set up checks for when update job finishes.
972 do_checks_after_update_finished_
= true;
973 expect_group_obsolete_
= false;
974 expect_group_has_cache_
= true;
975 expect_newest_cache_
= cache
; // newest cache unaffected by update
976 expect_evictable_error_
= false; // should be reset
977 expect_full_update_time_newer_than_
= group_
->last_full_update_check_time();
978 MockFrontend::HostIds
ids1(1, host1
->host_id());
979 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
980 frontend1
->AddExpectedEvent(ids1
, APPCACHE_NO_UPDATE_EVENT
);
981 MockFrontend::HostIds
ids2(1, host2
->host_id());
982 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
983 frontend2
->AddExpectedEvent(ids2
, APPCACHE_NO_UPDATE_EVENT
);
985 WaitForUpdateToFinish();
988 void UpgradeManifestDataUnchangedTest() {
989 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
992 group_
= new AppCacheGroup(
993 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
994 service_
->storage()->NewGroupId());
995 AppCacheUpdateJob
* update
=
996 new AppCacheUpdateJob(service_
.get(), group_
.get());
997 group_
->update_job_
= update
;
999 // Create response writer to get a response id.
1000 response_writer_
.reset(
1001 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
1002 group_
->group_id()));
1004 AppCache
* cache
= MakeCacheForGroup(1, response_writer_
->response_id());
1005 MockFrontend
* frontend1
= MakeMockFrontend();
1006 MockFrontend
* frontend2
= MakeMockFrontend();
1007 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1008 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1009 host1
->AssociateCompleteCache(cache
);
1010 host2
->AssociateCompleteCache(cache
);
1012 // Set up checks for when update job finishes.
1013 do_checks_after_update_finished_
= true;
1014 expect_group_obsolete_
= false;
1015 expect_group_has_cache_
= true;
1016 expect_newest_cache_
= cache
; // newest cache unaffected by update
1017 MockFrontend::HostIds
ids1(1, host1
->host_id());
1018 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1019 frontend1
->AddExpectedEvent(ids1
, APPCACHE_NO_UPDATE_EVENT
);
1020 MockFrontend::HostIds
ids2(1, host2
->host_id());
1021 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1022 frontend2
->AddExpectedEvent(ids2
, APPCACHE_NO_UPDATE_EVENT
);
1024 // Seed storage with expected manifest data.
1025 const std::string
seed_data(kManifest1Contents
);
1026 scoped_refptr
<net::StringIOBuffer
> io_buffer(
1027 new net::StringIOBuffer(seed_data
));
1028 response_writer_
->WriteData(
1031 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
1032 base::Unretained(this)));
1034 // Start update after data write completes asynchronously.
1037 // See http://code.google.com/p/chromium/issues/detail?id=95101
1038 void Bug95101Test() {
1039 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1042 group_
= new AppCacheGroup(
1043 service_
->storage(), MockHttpServer::GetMockUrl("files/empty-manifest"),
1044 service_
->storage()->NewGroupId());
1045 AppCacheUpdateJob
* update
=
1046 new AppCacheUpdateJob(service_
.get(), group_
.get());
1047 group_
->update_job_
= update
;
1049 // Create a malformed cache with a missing manifest entry.
1050 GURL wrong_manifest_url
=
1051 MockHttpServer::GetMockUrl("files/missing-mime-manifest");
1052 AppCache
* cache
= MakeCacheForGroup(1, wrong_manifest_url
, 111);
1053 MockFrontend
* frontend
= MakeMockFrontend();
1054 AppCacheHost
* host
= MakeHost(1, frontend
);
1055 host
->AssociateCompleteCache(cache
);
1057 update
->StartUpdate(NULL
, GURL());
1059 // Set up checks for when update job finishes.
1060 do_checks_after_update_finished_
= true;
1061 expect_group_is_being_deleted_
= true;
1062 expect_group_has_cache_
= true;
1063 expect_newest_cache_
= cache
; // newest cache unaffected by update
1064 MockFrontend::HostIds
id(1, host
->host_id());
1065 frontend
->AddExpectedEvent(id
, APPCACHE_CHECKING_EVENT
);
1066 frontend
->AddExpectedEvent(id
, APPCACHE_ERROR_EVENT
);
1067 frontend
->expected_error_message_
=
1068 "Manifest entry not found in existing cache";
1069 WaitForUpdateToFinish();
1072 void StartUpdateAfterSeedingStorageData(int result
) {
1073 ASSERT_GT(result
, 0);
1074 response_writer_
.reset();
1076 AppCacheUpdateJob
* update
= group_
->update_job_
;
1077 update
->StartUpdate(NULL
, GURL());
1079 WaitForUpdateToFinish();
1082 void BasicCacheAttemptSuccessTest() {
1083 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1085 GURL manifest_url
= MockHttpServer::GetMockUrl("files/manifest1");
1088 group_
= new AppCacheGroup(
1089 service_
->storage(), manifest_url
,
1090 service_
->storage()->NewGroupId());
1091 ASSERT_TRUE(group_
->last_full_update_check_time().is_null());
1092 AppCacheUpdateJob
* update
=
1093 new AppCacheUpdateJob(service_
.get(), group_
.get());
1094 group_
->update_job_
= update
;
1096 MockFrontend
* frontend
= MakeMockFrontend();
1097 AppCacheHost
* host
= MakeHost(1, frontend
);
1098 update
->StartUpdate(host
, GURL());
1100 // Set up checks for when update job finishes.
1101 do_checks_after_update_finished_
= true;
1102 expect_group_obsolete_
= false;
1103 expect_group_has_cache_
= true;
1104 expect_full_update_time_newer_than_
= base::Time::Now() - kOneHour
;
1105 tested_manifest_
= MANIFEST1
;
1106 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1107 APPCACHE_CHECKING_EVENT
);
1109 WaitForUpdateToFinish();
1112 void DownloadInterceptEntriesTest() {
1113 // Ensures we download intercept entries too.
1114 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1116 MockHttpServer::GetMockUrl("files/manifest-with-intercept");
1118 group_
= new AppCacheGroup(
1119 service_
->storage(), manifest_url
,
1120 service_
->storage()->NewGroupId());
1121 AppCacheUpdateJob
* update
=
1122 new AppCacheUpdateJob(service_
.get(), group_
.get());
1123 group_
->update_job_
= update
;
1125 MockFrontend
* frontend
= MakeMockFrontend();
1126 AppCacheHost
* host
= MakeHost(1, frontend
);
1127 update
->StartUpdate(host
, GURL());
1129 // Set up checks for when update job finishes.
1130 do_checks_after_update_finished_
= true;
1131 expect_group_obsolete_
= false;
1132 expect_group_has_cache_
= true;
1133 tested_manifest_
= MANIFEST_WITH_INTERCEPT
;
1134 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1135 APPCACHE_CHECKING_EVENT
);
1137 WaitForUpdateToFinish();
1140 void BasicUpgradeSuccessTest() {
1141 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1144 group_
= new AppCacheGroup(
1145 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1146 service_
->storage()->NewGroupId());
1147 AppCacheUpdateJob
* update
=
1148 new AppCacheUpdateJob(service_
.get(), group_
.get());
1149 group_
->update_job_
= update
;
1151 // Create a response writer to get a response id.
1152 response_writer_
.reset(
1153 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
1154 group_
->group_id()));
1156 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(),
1157 response_writer_
->response_id());
1158 MockFrontend
* frontend1
= MakeMockFrontend();
1159 MockFrontend
* frontend2
= MakeMockFrontend();
1160 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1161 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1162 host1
->AssociateCompleteCache(cache
);
1163 host2
->AssociateCompleteCache(cache
);
1164 frontend1
->SetVerifyProgressEvents(true);
1165 frontend2
->SetVerifyProgressEvents(true);
1166 group_
->set_last_full_update_check_time(
1167 base::Time::Now() - kFullUpdateInterval
- kOneHour
);
1169 // Set up checks for when update job finishes.
1170 do_checks_after_update_finished_
= true;
1171 expect_group_obsolete_
= false;
1172 expect_group_has_cache_
= true;
1173 expect_old_cache_
= cache
;
1174 tested_manifest_
= MANIFEST1
;
1175 expect_full_update_time_newer_than_
= group_
->last_full_update_check_time();
1176 MockFrontend::HostIds
ids1(1, host1
->host_id());
1177 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1178 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1179 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
1180 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
1181 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
1182 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
1183 MockFrontend::HostIds
ids2(1, host2
->host_id());
1184 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1185 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
1186 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
1187 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
1188 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // final
1189 frontend2
->AddExpectedEvent(ids2
, APPCACHE_UPDATE_READY_EVENT
);
1191 // Seed storage with expected manifest data different from manifest1.
1192 const std::string
seed_data("different");
1193 scoped_refptr
<net::StringIOBuffer
> io_buffer(
1194 new net::StringIOBuffer(seed_data
));
1195 response_writer_
->WriteData(
1198 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
1199 base::Unretained(this)));
1201 // Start update after data write completes asynchronously.
1204 void UpgradeLoadFromNewestCacheTest() {
1205 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1208 group_
= new AppCacheGroup(
1209 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1210 service_
->storage()->NewGroupId());
1211 AppCacheUpdateJob
* update
=
1212 new AppCacheUpdateJob(service_
.get(), group_
.get());
1213 group_
->update_job_
= update
;
1215 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
1216 MockFrontend
* frontend
= MakeMockFrontend();
1217 AppCacheHost
* host
= MakeHost(1, frontend
);
1218 host
->AssociateCompleteCache(cache
);
1220 // Give the newest cache an entry that is in storage.
1221 response_writer_
.reset(
1222 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
1223 group_
->group_id()));
1224 cache
->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1225 AppCacheEntry(AppCacheEntry::EXPLICIT
,
1226 response_writer_
->response_id()));
1228 // Set up checks for when update job finishes.
1229 do_checks_after_update_finished_
= true;
1230 expect_group_obsolete_
= false;
1231 expect_group_has_cache_
= true;
1232 expect_old_cache_
= cache
;
1233 expect_response_ids_
.insert(
1234 std::map
<GURL
, int64
>::value_type(
1235 MockHttpServer::GetMockUrl("files/explicit1"),
1236 response_writer_
->response_id()));
1237 tested_manifest_
= MANIFEST1
;
1238 MockFrontend::HostIds
ids(1, host
->host_id());
1239 frontend
->AddExpectedEvent(ids
, APPCACHE_CHECKING_EVENT
);
1240 frontend
->AddExpectedEvent(ids
, APPCACHE_DOWNLOADING_EVENT
);
1241 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
);
1242 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
);
1243 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
); // final
1244 frontend
->AddExpectedEvent(ids
, APPCACHE_UPDATE_READY_EVENT
);
1246 // Seed storage with expected http response info for entry. Allow reuse.
1249 "Cache-Control: max-age=8675309\0"
1251 net::HttpResponseHeaders
* headers
=
1252 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
1253 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
1254 response_info
->request_time
= base::Time::Now();
1255 response_info
->response_time
= base::Time::Now();
1256 response_info
->headers
= headers
; // adds ref to headers
1257 scoped_refptr
<HttpResponseInfoIOBuffer
> io_buffer(
1258 new HttpResponseInfoIOBuffer(response_info
)); // adds ref to info
1259 response_writer_
->WriteInfo(
1261 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
1262 base::Unretained(this)));
1264 // Start update after data write completes asynchronously.
1267 void UpgradeNoLoadFromNewestCacheTest() {
1268 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1271 group_
= new AppCacheGroup(
1272 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1273 service_
->storage()->NewGroupId());
1274 AppCacheUpdateJob
* update
=
1275 new AppCacheUpdateJob(service_
.get(), group_
.get());
1276 group_
->update_job_
= update
;
1278 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
1279 MockFrontend
* frontend
= MakeMockFrontend();
1280 AppCacheHost
* host
= MakeHost(1, frontend
);
1281 host
->AssociateCompleteCache(cache
);
1283 // Give the newest cache an entry that is in storage.
1284 response_writer_
.reset(
1285 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
1286 group_
->group_id()));
1287 cache
->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1288 AppCacheEntry(AppCacheEntry::EXPLICIT
,
1289 response_writer_
->response_id()));
1291 // Set up checks for when update job finishes.
1292 do_checks_after_update_finished_
= true;
1293 expect_group_obsolete_
= false;
1294 expect_group_has_cache_
= true;
1295 expect_old_cache_
= cache
;
1296 tested_manifest_
= MANIFEST1
;
1297 MockFrontend::HostIds
ids(1, host
->host_id());
1298 frontend
->AddExpectedEvent(ids
, APPCACHE_CHECKING_EVENT
);
1299 frontend
->AddExpectedEvent(ids
, APPCACHE_DOWNLOADING_EVENT
);
1300 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
);
1301 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
);
1302 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
); // final
1303 frontend
->AddExpectedEvent(ids
, APPCACHE_UPDATE_READY_EVENT
);
1305 // Seed storage with expected http response info for entry. Do NOT
1306 // allow reuse by setting an expires header in the past.
1309 "Expires: Thu, 01 Dec 1994 16:00:00 GMT\0"
1311 net::HttpResponseHeaders
* headers
=
1312 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
1313 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
1314 response_info
->request_time
= base::Time::Now();
1315 response_info
->response_time
= base::Time::Now();
1316 response_info
->headers
= headers
; // adds ref to headers
1317 scoped_refptr
<HttpResponseInfoIOBuffer
> io_buffer(
1318 new HttpResponseInfoIOBuffer(response_info
)); // adds ref to info
1319 response_writer_
->WriteInfo(
1321 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
1322 base::Unretained(this)));
1324 // Start update after data write completes asynchronously.
1327 void UpgradeLoadFromNewestCacheVaryHeaderTest() {
1328 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1331 group_
= new AppCacheGroup(
1332 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1333 service_
->storage()->NewGroupId());
1334 AppCacheUpdateJob
* update
=
1335 new AppCacheUpdateJob(service_
.get(), group_
.get());
1336 group_
->update_job_
= update
;
1338 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
1339 MockFrontend
* frontend
= MakeMockFrontend();
1340 AppCacheHost
* host
= MakeHost(1, frontend
);
1341 host
->AssociateCompleteCache(cache
);
1343 // Give the newest cache an entry that is in storage.
1344 response_writer_
.reset(
1345 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
1346 group_
->group_id()));
1347 cache
->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1348 AppCacheEntry(AppCacheEntry::EXPLICIT
,
1349 response_writer_
->response_id()));
1351 // Set up checks for when update job finishes.
1352 do_checks_after_update_finished_
= true;
1353 expect_group_obsolete_
= false;
1354 expect_group_has_cache_
= true;
1355 expect_old_cache_
= cache
;
1356 tested_manifest_
= MANIFEST1
;
1357 MockFrontend::HostIds
ids(1, host
->host_id());
1358 frontend
->AddExpectedEvent(ids
, APPCACHE_CHECKING_EVENT
);
1359 frontend
->AddExpectedEvent(ids
, APPCACHE_DOWNLOADING_EVENT
);
1360 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
);
1361 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
);
1362 frontend
->AddExpectedEvent(ids
, APPCACHE_PROGRESS_EVENT
); // final
1363 frontend
->AddExpectedEvent(ids
, APPCACHE_UPDATE_READY_EVENT
);
1365 // Seed storage with expected http response info for entry: a vary header.
1368 "Cache-Control: max-age=8675309\0"
1371 net::HttpResponseHeaders
* headers
=
1372 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
1373 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
1374 response_info
->request_time
= base::Time::Now();
1375 response_info
->response_time
= base::Time::Now();
1376 response_info
->headers
= headers
; // adds ref to headers
1377 scoped_refptr
<HttpResponseInfoIOBuffer
> io_buffer(
1378 new HttpResponseInfoIOBuffer(response_info
)); // adds ref to info
1379 response_writer_
->WriteInfo(
1381 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
1382 base::Unretained(this)));
1384 // Start update after data write completes asynchronously.
1387 void UpgradeSuccessMergedTypesTest() {
1388 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1391 group_
= new AppCacheGroup(service_
->storage(),
1392 MockHttpServer::GetMockUrl("files/manifest-merged-types"),
1393 service_
->storage()->NewGroupId());
1394 AppCacheUpdateJob
* update
=
1395 new AppCacheUpdateJob(service_
.get(), group_
.get());
1396 group_
->update_job_
= update
;
1398 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
1399 MockFrontend
* frontend1
= MakeMockFrontend();
1400 MockFrontend
* frontend2
= MakeMockFrontend();
1401 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1402 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1403 host1
->AssociateCompleteCache(cache
);
1404 host2
->AssociateCompleteCache(cache
);
1406 // Give the newest cache a master entry that is also one of the explicit
1407 // entries in the manifest.
1408 cache
->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"),
1409 AppCacheEntry(AppCacheEntry::MASTER
, 111));
1411 update
->StartUpdate(NULL
, GURL());
1413 // Set up checks for when update job finishes.
1414 do_checks_after_update_finished_
= true;
1415 expect_group_obsolete_
= false;
1416 expect_group_has_cache_
= true;
1417 expect_old_cache_
= cache
;
1418 tested_manifest_
= MANIFEST_MERGED_TYPES
;
1419 MockFrontend::HostIds
ids1(1, host1
->host_id());
1420 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1421 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1422 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // explicit1
1423 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // manifest
1424 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
1425 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
1426 MockFrontend::HostIds
ids2(1, host2
->host_id());
1427 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1428 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
1429 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
1430 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
1431 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // final
1432 frontend2
->AddExpectedEvent(ids2
, APPCACHE_UPDATE_READY_EVENT
);
1434 WaitForUpdateToFinish();
1437 void CacheAttemptFailUrlFetchTest() {
1438 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1441 group_
= new AppCacheGroup(service_
->storage(),
1442 MockHttpServer::GetMockUrl("files/manifest-with-404"),
1443 service_
->storage()->NewGroupId());
1444 AppCacheUpdateJob
* update
=
1445 new AppCacheUpdateJob(service_
.get(), group_
.get());
1446 group_
->update_job_
= update
;
1448 MockFrontend
* frontend
= MakeMockFrontend();
1449 AppCacheHost
* host
= MakeHost(1, frontend
);
1450 update
->StartUpdate(host
, GURL());
1452 // Set up checks for when update job finishes.
1453 do_checks_after_update_finished_
= true;
1454 expect_group_obsolete_
= false;
1455 expect_group_has_cache_
= false; // 404 explicit url is cache failure
1456 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1457 APPCACHE_CHECKING_EVENT
);
1459 WaitForUpdateToFinish();
1462 void UpgradeFailUrlFetchTest() {
1463 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1466 group_
= new AppCacheGroup(service_
->storage(),
1467 MockHttpServer::GetMockUrl("files/manifest-fb-404"),
1468 service_
->storage()->NewGroupId());
1469 AppCacheUpdateJob
* update
=
1470 new AppCacheUpdateJob(service_
.get(), group_
.get());
1471 group_
->update_job_
= update
;
1473 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 99);
1474 group_
->set_first_evictable_error_time(
1475 base::Time::Now() - kMaxEvictableErrorDuration
- kOneHour
);
1476 MockFrontend
* frontend1
= MakeMockFrontend();
1477 MockFrontend
* frontend2
= MakeMockFrontend();
1478 frontend1
->SetIgnoreProgressEvents(true);
1479 frontend2
->SetIgnoreProgressEvents(true);
1480 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1481 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1482 host1
->AssociateCompleteCache(cache
);
1483 host2
->AssociateCompleteCache(cache
);
1485 update
->StartUpdate(NULL
, GURL());
1487 // Set up checks for when update job finishes.
1488 do_checks_after_update_finished_
= true;
1489 expect_group_obsolete_
= false;
1490 expect_group_has_cache_
= true;
1491 expect_newest_cache_
= cache
; // newest cache unaffectd by failed update
1492 expect_eviction_
= true;
1493 MockFrontend::HostIds
ids1(1, host1
->host_id());
1494 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1495 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1496 frontend1
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
1497 MockFrontend::HostIds
ids2(1, host2
->host_id());
1498 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1499 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
1500 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
1502 WaitForUpdateToFinish();
1505 void UpgradeFailMasterUrlFetchTest() {
1506 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1508 tested_manifest_path_override_
= "files/manifest1-with-notmodified";
1511 const GURL kManifestUrl
=
1512 MockHttpServer::GetMockUrl(tested_manifest_path_override_
);
1513 group_
= new AppCacheGroup(
1514 service_
->storage(), kManifestUrl
,
1515 service_
->storage()->NewGroupId());
1516 AppCacheUpdateJob
* update
=
1517 new AppCacheUpdateJob(service_
.get(), group_
.get());
1518 group_
->update_job_
= update
;
1520 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 25);
1521 MockFrontend
* frontend1
= MakeMockFrontend();
1522 MockFrontend
* frontend2
= MakeMockFrontend();
1523 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1524 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1525 host1
->AssociateCompleteCache(cache
);
1526 host2
->AssociateCompleteCache(cache
);
1528 // Give the newest cache some existing entries; one will fail with a 404.
1530 MockHttpServer::GetMockUrl("files/notfound"),
1531 AppCacheEntry(AppCacheEntry::MASTER
, 222));
1533 MockHttpServer::GetMockUrl("files/explicit2"),
1534 AppCacheEntry(AppCacheEntry::MASTER
| AppCacheEntry::FOREIGN
, 333));
1536 MockHttpServer::GetMockUrl("files/servererror"),
1537 AppCacheEntry(AppCacheEntry::MASTER
, 444));
1539 MockHttpServer::GetMockUrl("files/notmodified"),
1540 AppCacheEntry(AppCacheEntry::EXPLICIT
, 555));
1542 // Seed the response_info working set with canned data for
1543 // files/servererror and for files/notmodified to test that the
1544 // existing entries for those resource are reused by the update job.
1545 const char kData
[] =
1547 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
1549 const std::string
kRawHeaders(kData
, arraysize(kData
));
1550 MakeAppCacheResponseInfo(kManifestUrl
, 444, kRawHeaders
);
1551 MakeAppCacheResponseInfo(kManifestUrl
, 555, kRawHeaders
);
1553 update
->StartUpdate(NULL
, GURL());
1555 // Set up checks for when update job finishes.
1556 do_checks_after_update_finished_
= true;
1557 expect_group_obsolete_
= false;
1558 expect_group_has_cache_
= true;
1559 expect_old_cache_
= cache
;
1560 tested_manifest_
= MANIFEST1
;
1561 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
1562 MockHttpServer::GetMockUrl("files/explicit2"),
1563 AppCacheEntry(AppCacheEntry::MASTER
))); // foreign flag is dropped
1564 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
1565 MockHttpServer::GetMockUrl("files/servererror"),
1566 AppCacheEntry(AppCacheEntry::MASTER
)));
1567 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
1568 MockHttpServer::GetMockUrl("files/notmodified"),
1569 AppCacheEntry(AppCacheEntry::EXPLICIT
)));
1570 expect_response_ids_
.insert(std::map
<GURL
, int64
>::value_type(
1571 MockHttpServer::GetMockUrl("files/servererror"), 444)); // copied
1572 expect_response_ids_
.insert(std::map
<GURL
, int64
>::value_type(
1573 MockHttpServer::GetMockUrl("files/notmodified"), 555)); // copied
1574 MockFrontend::HostIds
ids1(1, host1
->host_id());
1575 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1576 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1577 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // explicit1
1578 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // fallback1a
1579 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // notfound
1580 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // explicit2
1581 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // servererror
1582 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // notmodified
1583 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
1584 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
1585 MockFrontend::HostIds
ids2(1, host2
->host_id());
1586 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1587 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
1588 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // explicit1
1589 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // fallback1a
1590 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // notfound
1591 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // explicit2
1592 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // servererror
1593 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // notmodified
1594 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // final
1595 frontend2
->AddExpectedEvent(ids2
, APPCACHE_UPDATE_READY_EVENT
);
1597 WaitForUpdateToFinish();
1600 void EmptyManifestTest() {
1601 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1604 group_
= new AppCacheGroup(
1605 service_
->storage(), MockHttpServer::GetMockUrl("files/empty-manifest"),
1606 service_
->storage()->NewGroupId());
1607 AppCacheUpdateJob
* update
=
1608 new AppCacheUpdateJob(service_
.get(), group_
.get());
1609 group_
->update_job_
= update
;
1611 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 33);
1612 MockFrontend
* frontend1
= MakeMockFrontend();
1613 MockFrontend
* frontend2
= MakeMockFrontend();
1614 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1615 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1616 host1
->AssociateCompleteCache(cache
);
1617 host2
->AssociateCompleteCache(cache
);
1619 frontend1
->SetVerifyProgressEvents(true);
1621 update
->StartUpdate(NULL
, GURL());
1623 // Set up checks for when update job finishes.
1624 do_checks_after_update_finished_
= true;
1625 expect_group_obsolete_
= false;
1626 expect_group_has_cache_
= true;
1627 expect_old_cache_
= cache
;
1628 tested_manifest_
= EMPTY_MANIFEST
;
1629 MockFrontend::HostIds
ids1(1, host1
->host_id());
1630 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1631 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1632 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
1633 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
1634 MockFrontend::HostIds
ids2(1, host2
->host_id());
1635 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1636 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
1637 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // final
1638 frontend2
->AddExpectedEvent(ids2
, APPCACHE_UPDATE_READY_EVENT
);
1640 WaitForUpdateToFinish();
1643 void EmptyFileTest() {
1644 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1647 group_
= new AppCacheGroup(service_
->storage(),
1648 MockHttpServer::GetMockUrl("files/empty-file-manifest"),
1649 service_
->storage()->NewGroupId());
1650 AppCacheUpdateJob
* update
=
1651 new AppCacheUpdateJob(service_
.get(), group_
.get());
1652 group_
->update_job_
= update
;
1654 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 22);
1655 MockFrontend
* frontend
= MakeMockFrontend();
1656 AppCacheHost
* host
= MakeHost(1, frontend
);
1657 host
->AssociateCompleteCache(cache
);
1658 frontend
->SetVerifyProgressEvents(true);
1660 update
->StartUpdate(host
, GURL());
1662 // Set up checks for when update job finishes.
1663 do_checks_after_update_finished_
= true;
1664 expect_group_obsolete_
= false;
1665 expect_group_has_cache_
= true;
1666 tested_manifest_
= EMPTY_FILE_MANIFEST
;
1667 MockFrontend::HostIds
ids1(1, host
->host_id());
1668 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1669 frontend
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1670 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
1671 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
1672 frontend
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
1674 WaitForUpdateToFinish();
1677 void RetryRequestTest() {
1678 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1680 // Set some large number of times to return retry.
1681 // Expect 1 manifest fetch and 3 retries.
1682 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::RETRY_AFTER_0
, 4);
1683 net::URLRequestJobFactoryImpl
* new_factory(
1684 new net::URLRequestJobFactoryImpl
);
1685 new_factory
->SetProtocolHandler("http", new RetryRequestTestJobFactory
);
1686 io_thread_
->SetNewJobFactory(new_factory
);
1689 group_
= new AppCacheGroup(service_
->storage(),
1690 RetryRequestTestJob::kRetryUrl
,
1691 service_
->storage()->NewGroupId());
1692 AppCacheUpdateJob
* update
=
1693 new AppCacheUpdateJob(service_
.get(), group_
.get());
1694 group_
->update_job_
= update
;
1696 MockFrontend
* frontend
= MakeMockFrontend();
1697 AppCacheHost
* host
= MakeHost(1, frontend
);
1698 update
->StartUpdate(host
, GURL());
1700 // Set up checks for when update job finishes.
1701 do_checks_after_update_finished_
= true;
1702 expect_group_obsolete_
= false;
1703 expect_group_has_cache_
= false;
1704 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1705 APPCACHE_CHECKING_EVENT
);
1707 WaitForUpdateToFinish();
1710 void RetryNoRetryAfterTest() {
1711 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1713 // Set some large number of times to return retry.
1714 // Expect 1 manifest fetch and 0 retries.
1715 RetryRequestTestJob::Initialize(5, RetryRequestTestJob::NO_RETRY_AFTER
, 1);
1716 net::URLRequestJobFactoryImpl
* new_factory(
1717 new net::URLRequestJobFactoryImpl
);
1718 new_factory
->SetProtocolHandler("http", new RetryRequestTestJobFactory
);
1719 io_thread_
->SetNewJobFactory(new_factory
);
1722 group_
= new AppCacheGroup(service_
->storage(),
1723 RetryRequestTestJob::kRetryUrl
,
1724 service_
->storage()->NewGroupId());
1725 AppCacheUpdateJob
* update
=
1726 new AppCacheUpdateJob(service_
.get(), group_
.get());
1727 group_
->update_job_
= update
;
1729 MockFrontend
* frontend
= MakeMockFrontend();
1730 AppCacheHost
* host
= MakeHost(1, frontend
);
1731 update
->StartUpdate(host
, GURL());
1733 // Set up checks for when update job finishes.
1734 do_checks_after_update_finished_
= true;
1735 expect_group_obsolete_
= false;
1736 expect_group_has_cache_
= false;
1737 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1738 APPCACHE_CHECKING_EVENT
);
1740 WaitForUpdateToFinish();
1743 void RetryNonzeroRetryAfterTest() {
1744 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1746 // Set some large number of times to return retry.
1747 // Expect 1 request and 0 retry attempts.
1748 RetryRequestTestJob::Initialize(
1749 5, RetryRequestTestJob::NONZERO_RETRY_AFTER
, 1);
1750 net::URLRequestJobFactoryImpl
* new_factory(
1751 new net::URLRequestJobFactoryImpl
);
1752 new_factory
->SetProtocolHandler("http", new RetryRequestTestJobFactory
);
1753 io_thread_
->SetNewJobFactory(new_factory
);
1756 group_
= new AppCacheGroup(service_
->storage(),
1757 RetryRequestTestJob::kRetryUrl
,
1758 service_
->storage()->NewGroupId());
1759 AppCacheUpdateJob
* update
=
1760 new AppCacheUpdateJob(service_
.get(), group_
.get());
1761 group_
->update_job_
= update
;
1763 MockFrontend
* frontend
= MakeMockFrontend();
1764 AppCacheHost
* host
= MakeHost(1, frontend
);
1765 update
->StartUpdate(host
, GURL());
1767 // Set up checks for when update job finishes.
1768 do_checks_after_update_finished_
= true;
1769 expect_group_obsolete_
= false;
1770 expect_group_has_cache_
= false;
1771 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1772 APPCACHE_CHECKING_EVENT
);
1774 WaitForUpdateToFinish();
1777 void RetrySuccessTest() {
1778 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1780 // Set 2 as the retry limit (does not exceed the max).
1781 // Expect 1 manifest fetch, 2 retries, 1 url fetch, 1 manifest refetch.
1782 RetryRequestTestJob::Initialize(2, RetryRequestTestJob::RETRY_AFTER_0
, 5);
1783 net::URLRequestJobFactoryImpl
* new_factory(
1784 new net::URLRequestJobFactoryImpl
);
1785 new_factory
->SetProtocolHandler("http", new RetryRequestTestJobFactory
);
1786 io_thread_
->SetNewJobFactory(new_factory
);
1789 group_
= new AppCacheGroup(service_
->storage(),
1790 RetryRequestTestJob::kRetryUrl
,
1791 service_
->storage()->NewGroupId());
1792 AppCacheUpdateJob
* update
=
1793 new AppCacheUpdateJob(service_
.get(), group_
.get());
1794 group_
->update_job_
= update
;
1796 MockFrontend
* frontend
= MakeMockFrontend();
1797 AppCacheHost
* host
= MakeHost(1, frontend
);
1798 update
->StartUpdate(host
, GURL());
1800 // Set up checks for when update job finishes.
1801 do_checks_after_update_finished_
= true;
1802 expect_group_obsolete_
= false;
1803 expect_group_has_cache_
= true;
1804 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1805 APPCACHE_CHECKING_EVENT
);
1807 WaitForUpdateToFinish();
1810 void RetryUrlTest() {
1811 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1813 // Set 1 as the retry limit (does not exceed the max).
1814 // Expect 1 manifest fetch, 1 url fetch, 1 url retry, 1 manifest refetch.
1815 RetryRequestTestJob::Initialize(1, RetryRequestTestJob::RETRY_AFTER_0
, 4);
1816 net::URLRequestJobFactoryImpl
* new_factory(
1817 new net::URLRequestJobFactoryImpl
);
1818 new_factory
->SetProtocolHandler("http", new RetryRequestTestJobFactory
);
1819 io_thread_
->SetNewJobFactory(new_factory
);
1822 group_
= new AppCacheGroup(service_
->storage(), GURL("http://retryurl"),
1823 service_
->storage()->NewGroupId());
1824 AppCacheUpdateJob
* update
=
1825 new AppCacheUpdateJob(service_
.get(), group_
.get());
1826 group_
->update_job_
= update
;
1828 MockFrontend
* frontend
= MakeMockFrontend();
1829 AppCacheHost
* host
= MakeHost(1, frontend
);
1830 update
->StartUpdate(host
, GURL());
1832 // Set up checks for when update job finishes.
1833 do_checks_after_update_finished_
= true;
1834 expect_group_obsolete_
= false;
1835 expect_group_has_cache_
= true;
1836 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1837 APPCACHE_CHECKING_EVENT
);
1839 WaitForUpdateToFinish();
1842 void FailStoreNewestCacheTest() {
1843 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1846 MockAppCacheStorage
* storage
=
1847 reinterpret_cast<MockAppCacheStorage
*>(service_
->storage());
1848 storage
->SimulateStoreGroupAndNewestCacheFailure();
1850 group_
= new AppCacheGroup(
1851 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1852 service_
->storage()->NewGroupId());
1853 AppCacheUpdateJob
* update
=
1854 new AppCacheUpdateJob(service_
.get(), group_
.get());
1855 group_
->update_job_
= update
;
1857 MockFrontend
* frontend
= MakeMockFrontend();
1858 AppCacheHost
* host
= MakeHost(1, frontend
);
1859 update
->StartUpdate(host
, GURL());
1861 // Set up checks for when update job finishes.
1862 do_checks_after_update_finished_
= true;
1863 expect_group_obsolete_
= false;
1864 expect_group_has_cache_
= false; // storage failed
1865 frontend
->AddExpectedEvent(MockFrontend::HostIds(1, host
->host_id()),
1866 APPCACHE_CHECKING_EVENT
);
1868 WaitForUpdateToFinish();
1871 void UpgradeFailStoreNewestCacheTest() {
1872 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1875 MockAppCacheStorage
* storage
=
1876 reinterpret_cast<MockAppCacheStorage
*>(service_
->storage());
1877 storage
->SimulateStoreGroupAndNewestCacheFailure();
1879 group_
= new AppCacheGroup(
1880 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
1881 service_
->storage()->NewGroupId());
1882 AppCacheUpdateJob
* update
=
1883 new AppCacheUpdateJob(service_
.get(), group_
.get());
1884 group_
->update_job_
= update
;
1886 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 11);
1887 MockFrontend
* frontend1
= MakeMockFrontend();
1888 MockFrontend
* frontend2
= MakeMockFrontend();
1889 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1890 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1891 host1
->AssociateCompleteCache(cache
);
1892 host2
->AssociateCompleteCache(cache
);
1894 update
->StartUpdate(NULL
, GURL());
1896 // Set up checks for when update job finishes.
1897 do_checks_after_update_finished_
= true;
1898 expect_group_obsolete_
= false;
1899 expect_group_has_cache_
= true;
1900 expect_newest_cache_
= cache
; // unchanged
1901 MockFrontend::HostIds
ids1(1, host1
->host_id());
1902 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1903 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
1904 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
1905 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
1906 frontend1
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
1907 MockFrontend::HostIds
ids2(1, host2
->host_id());
1908 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
1909 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
1910 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
1911 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
1912 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
1914 WaitForUpdateToFinish();
1917 void MasterEntryFailStoreNewestCacheTest() {
1918 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1921 MockAppCacheStorage
* storage
=
1922 reinterpret_cast<MockAppCacheStorage
*>(service_
->storage());
1923 storage
->SimulateStoreGroupAndNewestCacheFailure();
1925 const GURL kManifestUrl
= MockHttpServer::GetMockUrl("files/notmodified");
1926 const int64 kManifestResponseId
= 11;
1928 // Seed the response_info working set with canned data for
1929 // files/servererror and for files/notmodified to test that the
1930 // existing entries for those resource are reused by the update job.
1931 const char kData
[] =
1933 "Content-type: text/cache-manifest\0"
1934 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
1936 const std::string
kRawHeaders(kData
, arraysize(kData
));
1937 MakeAppCacheResponseInfo(kManifestUrl
, kManifestResponseId
, kRawHeaders
);
1939 group_
= new AppCacheGroup(
1940 service_
->storage(), kManifestUrl
,
1941 service_
->storage()->NewGroupId());
1942 scoped_refptr
<AppCache
> cache(
1943 MakeCacheForGroup(service_
->storage()->NewCacheId(),
1944 kManifestResponseId
));
1946 MockFrontend
* frontend
= MakeMockFrontend();
1947 AppCacheHost
* host
= MakeHost(1, frontend
);
1948 host
->first_party_url_
= kManifestUrl
;
1949 host
->SelectCache(MockHttpServer::GetMockUrl("files/empty1"),
1950 kAppCacheNoCacheId
, kManifestUrl
);
1952 // Set up checks for when update job finishes.
1953 do_checks_after_update_finished_
= true;
1954 tested_manifest_
= EMPTY_MANIFEST
;
1955 tested_manifest_path_override_
= "files/notmodified";
1956 expect_group_obsolete_
= false;
1957 expect_group_has_cache_
= true;
1958 expect_newest_cache_
= cache
.get(); // unchanged
1959 MockFrontend::HostIds
ids1(1, host
->host_id());
1960 frontend
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
1961 frontend
->expected_error_message_
=
1962 "Failed to commit new cache to storage";
1964 WaitForUpdateToFinish();
1967 void UpgradeFailMakeGroupObsoleteTest() {
1968 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
1971 MockAppCacheStorage
* storage
=
1972 reinterpret_cast<MockAppCacheStorage
*>(service_
->storage());
1973 storage
->SimulateMakeGroupObsoleteFailure();
1975 group_
= new AppCacheGroup(
1976 service_
->storage(), MockHttpServer::GetMockUrl("files/nosuchfile"),
1977 service_
->storage()->NewGroupId());
1978 AppCacheUpdateJob
* update
=
1979 new AppCacheUpdateJob(service_
.get(), group_
.get());
1980 group_
->update_job_
= update
;
1982 AppCache
* cache
= MakeCacheForGroup(1, 111);
1983 MockFrontend
* frontend1
= MakeMockFrontend();
1984 MockFrontend
* frontend2
= MakeMockFrontend();
1985 AppCacheHost
* host1
= MakeHost(1, frontend1
);
1986 AppCacheHost
* host2
= MakeHost(2, frontend2
);
1987 host1
->AssociateCompleteCache(cache
);
1988 host2
->AssociateCompleteCache(cache
);
1990 update
->StartUpdate(NULL
, GURL());
1992 // Set up checks for when update job finishes.
1993 do_checks_after_update_finished_
= true;
1994 expect_group_obsolete_
= false;
1995 expect_group_has_cache_
= true;
1996 expect_newest_cache_
= cache
; // newest cache unaffected by update
1997 MockFrontend::HostIds
ids1(1, host1
->host_id());
1998 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
1999 frontend1
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2000 MockFrontend::HostIds
ids2(1, host2
->host_id());
2001 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
2002 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
2004 WaitForUpdateToFinish();
2007 void MasterEntryFetchManifestFailTest() {
2008 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2011 group_
= new AppCacheGroup(service_
->storage(), GURL("http://failme"), 111);
2012 AppCacheUpdateJob
* update
=
2013 new AppCacheUpdateJob(service_
.get(), group_
.get());
2014 group_
->update_job_
= update
;
2016 MockFrontend
* frontend
= MakeMockFrontend();
2017 AppCacheHost
* host
= MakeHost(1, frontend
);
2018 host
->new_master_entry_url_
= GURL("http://failme/blah");
2019 update
->StartUpdate(host
, host
->new_master_entry_url_
);
2021 // Set up checks for when update job finishes.
2022 do_checks_after_update_finished_
= true;
2023 expect_group_obsolete_
= false;
2024 expect_group_has_cache_
= false;
2025 MockFrontend::HostIds
ids1(1, host
->host_id());
2026 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2027 frontend
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2029 WaitForUpdateToFinish();
2032 void MasterEntryBadManifestTest() {
2033 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2036 group_
= new AppCacheGroup(service_
->storage(),
2037 MockHttpServer::GetMockUrl("files/bad-manifest"), 111);
2038 AppCacheUpdateJob
* update
=
2039 new AppCacheUpdateJob(service_
.get(), group_
.get());
2040 group_
->update_job_
= update
;
2042 MockFrontend
* frontend
= MakeMockFrontend();
2043 AppCacheHost
* host
= MakeHost(1, frontend
);
2044 host
->new_master_entry_url_
= MockHttpServer::GetMockUrl("files/blah");
2045 update
->StartUpdate(host
, host
->new_master_entry_url_
);
2047 // Set up checks for when update job finishes.
2048 do_checks_after_update_finished_
= true;
2049 expect_group_obsolete_
= false;
2050 expect_group_has_cache_
= false;
2051 MockFrontend::HostIds
ids1(1, host
->host_id());
2052 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2053 frontend
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2055 WaitForUpdateToFinish();
2058 void MasterEntryManifestNotFoundTest() {
2059 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2062 group_
= new AppCacheGroup(
2063 service_
->storage(),
2064 MockHttpServer::GetMockUrl("files/nosuchfile"),
2066 AppCacheUpdateJob
* update
=
2067 new AppCacheUpdateJob(service_
.get(), group_
.get());
2068 group_
->update_job_
= update
;
2070 MockFrontend
* frontend
= MakeMockFrontend();
2071 AppCacheHost
* host
= MakeHost(1, frontend
);
2072 host
->new_master_entry_url_
= MockHttpServer::GetMockUrl("files/blah");
2074 update
->StartUpdate(host
, host
->new_master_entry_url_
);
2076 // Set up checks for when update job finishes.
2077 do_checks_after_update_finished_
= true;
2078 expect_group_obsolete_
= false;
2079 expect_group_has_cache_
= false;
2080 MockFrontend::HostIds
ids1(1, host
->host_id());
2081 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2082 frontend
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2084 WaitForUpdateToFinish();
2087 void MasterEntryFailUrlFetchTest() {
2088 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2091 group_
= new AppCacheGroup(service_
->storage(),
2092 MockHttpServer::GetMockUrl("files/manifest-fb-404"), 111);
2093 AppCacheUpdateJob
* update
=
2094 new AppCacheUpdateJob(service_
.get(), group_
.get());
2095 group_
->update_job_
= update
;
2097 MockFrontend
* frontend
= MakeMockFrontend();
2098 frontend
->SetIgnoreProgressEvents(true);
2099 AppCacheHost
* host
= MakeHost(1, frontend
);
2100 host
->new_master_entry_url_
=
2101 MockHttpServer::GetMockUrl("files/explicit1");
2103 update
->StartUpdate(host
, host
->new_master_entry_url_
);
2105 // Set up checks for when update job finishes.
2106 do_checks_after_update_finished_
= true;
2107 expect_group_obsolete_
= false;
2108 expect_group_has_cache_
= false; // 404 fallback url is cache failure
2109 MockFrontend::HostIds
ids1(1, host
->host_id());
2110 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2111 frontend
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2112 frontend
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2114 WaitForUpdateToFinish();
2117 void MasterEntryAllFailTest() {
2118 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2121 group_
= new AppCacheGroup(
2122 service_
->storage(),
2123 MockHttpServer::GetMockUrl("files/manifest1"),
2125 AppCacheUpdateJob
* update
=
2126 new AppCacheUpdateJob(service_
.get(), group_
.get());
2127 group_
->update_job_
= update
;
2129 MockFrontend
* frontend1
= MakeMockFrontend();
2130 frontend1
->SetIgnoreProgressEvents(true);
2131 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2132 host1
->new_master_entry_url_
=
2133 MockHttpServer::GetMockUrl("files/nosuchfile");
2134 update
->StartUpdate(host1
, host1
->new_master_entry_url_
);
2136 MockFrontend
* frontend2
= MakeMockFrontend();
2137 frontend2
->SetIgnoreProgressEvents(true);
2138 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2139 host2
->new_master_entry_url_
=
2140 MockHttpServer::GetMockUrl("files/servererror");
2141 update
->StartUpdate(host2
, host2
->new_master_entry_url_
);
2143 // Set up checks for when update job finishes.
2144 do_checks_after_update_finished_
= true;
2145 expect_group_obsolete_
= false;
2146 expect_group_has_cache_
= false; // all pending masters failed
2147 MockFrontend::HostIds
ids1(1, host1
->host_id());
2148 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2149 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2150 frontend1
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2151 MockFrontend::HostIds
ids2(1, host2
->host_id());
2152 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
2153 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
2154 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
2156 WaitForUpdateToFinish();
2159 void UpgradeMasterEntryAllFailTest() {
2160 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2163 group_
= new AppCacheGroup(
2164 service_
->storage(),
2165 MockHttpServer::GetMockUrl("files/manifest1"),
2167 AppCacheUpdateJob
* update
=
2168 new AppCacheUpdateJob(service_
.get(), group_
.get());
2169 group_
->update_job_
= update
;
2171 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
2172 MockFrontend
* frontend1
= MakeMockFrontend();
2173 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2174 host1
->AssociateCompleteCache(cache
);
2176 MockFrontend
* frontend2
= MakeMockFrontend();
2177 frontend2
->SetIgnoreProgressEvents(true);
2178 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2179 host2
->new_master_entry_url_
=
2180 MockHttpServer::GetMockUrl("files/nosuchfile");
2181 update
->StartUpdate(host2
, host2
->new_master_entry_url_
);
2183 MockFrontend
* frontend3
= MakeMockFrontend();
2184 frontend3
->SetIgnoreProgressEvents(true);
2185 AppCacheHost
* host3
= MakeHost(3, frontend3
);
2186 host3
->new_master_entry_url_
=
2187 MockHttpServer::GetMockUrl("files/servererror");
2188 update
->StartUpdate(host3
, host3
->new_master_entry_url_
);
2190 // Set up checks for when update job finishes.
2191 do_checks_after_update_finished_
= true;
2192 expect_group_obsolete_
= false;
2193 expect_group_has_cache_
= true;
2194 expect_old_cache_
= cache
;
2195 tested_manifest_
= MANIFEST1
;
2196 MockFrontend::HostIds
ids1(1, host1
->host_id());
2197 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2198 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2199 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2200 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2201 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2202 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
2203 MockFrontend::HostIds
ids2(1, host2
->host_id());
2204 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
2205 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
2206 MockFrontend::HostIds
ids3(1, host3
->host_id());
2207 frontend3
->AddExpectedEvent(ids3
, APPCACHE_CHECKING_EVENT
);
2208 frontend3
->AddExpectedEvent(ids3
, APPCACHE_DOWNLOADING_EVENT
);
2209 frontend3
->AddExpectedEvent(ids3
, APPCACHE_ERROR_EVENT
);
2211 WaitForUpdateToFinish();
2214 void MasterEntrySomeFailTest() {
2215 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2218 group_
= new AppCacheGroup(
2219 service_
->storage(),
2220 MockHttpServer::GetMockUrl("files/manifest1"),
2222 AppCacheUpdateJob
* update
=
2223 new AppCacheUpdateJob(service_
.get(), group_
.get());
2224 group_
->update_job_
= update
;
2226 MockFrontend
* frontend1
= MakeMockFrontend();
2227 frontend1
->SetIgnoreProgressEvents(true);
2228 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2229 host1
->new_master_entry_url_
=
2230 MockHttpServer::GetMockUrl("files/nosuchfile");
2231 update
->StartUpdate(host1
, host1
->new_master_entry_url_
);
2233 MockFrontend
* frontend2
= MakeMockFrontend();
2234 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2235 host2
->new_master_entry_url_
=
2236 MockHttpServer::GetMockUrl("files/explicit2");
2237 update
->StartUpdate(host2
, host2
->new_master_entry_url_
);
2239 // Set up checks for when update job finishes.
2240 do_checks_after_update_finished_
= true;
2241 expect_group_obsolete_
= false;
2242 expect_group_has_cache_
= true; // as long as one pending master succeeds
2243 tested_manifest_
= MANIFEST1
;
2244 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
2245 MockHttpServer::GetMockUrl("files/explicit2"),
2246 AppCacheEntry(AppCacheEntry::MASTER
)));
2247 MockFrontend::HostIds
ids1(1, host1
->host_id());
2248 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2249 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2250 frontend1
->AddExpectedEvent(ids1
, APPCACHE_ERROR_EVENT
);
2251 MockFrontend::HostIds
ids2(1, host2
->host_id());
2252 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
2253 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
2254 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
2255 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
2256 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // final
2257 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CACHED_EVENT
);
2259 WaitForUpdateToFinish();
2262 void UpgradeMasterEntrySomeFailTest() {
2263 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2266 group_
= new AppCacheGroup(
2267 service_
->storage(),
2268 MockHttpServer::GetMockUrl("files/manifest1"),
2270 AppCacheUpdateJob
* update
=
2271 new AppCacheUpdateJob(service_
.get(), group_
.get());
2272 group_
->update_job_
= update
;
2274 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
2275 MockFrontend
* frontend1
= MakeMockFrontend();
2276 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2277 host1
->AssociateCompleteCache(cache
);
2279 MockFrontend
* frontend2
= MakeMockFrontend();
2280 frontend2
->SetIgnoreProgressEvents(true);
2281 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2282 host2
->new_master_entry_url_
=
2283 MockHttpServer::GetMockUrl("files/nosuchfile");
2284 update
->StartUpdate(host2
, host2
->new_master_entry_url_
);
2286 MockFrontend
* frontend3
= MakeMockFrontend();
2287 AppCacheHost
* host3
= MakeHost(3, frontend3
);
2288 host3
->new_master_entry_url_
=
2289 MockHttpServer::GetMockUrl("files/explicit2");
2290 update
->StartUpdate(host3
, host3
->new_master_entry_url_
);
2292 // Set up checks for when update job finishes.
2293 do_checks_after_update_finished_
= true;
2294 expect_group_obsolete_
= false;
2295 expect_group_has_cache_
= true;
2296 expect_old_cache_
= cache
;
2297 tested_manifest_
= MANIFEST1
;
2298 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
2299 MockHttpServer::GetMockUrl("files/explicit2"),
2300 AppCacheEntry(AppCacheEntry::MASTER
)));
2301 MockFrontend::HostIds
ids1(1, host1
->host_id());
2302 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2303 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2304 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2305 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2306 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2307 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
2308 MockFrontend::HostIds
ids2(1, host2
->host_id());
2309 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
2310 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
2311 MockFrontend::HostIds
ids3(1, host3
->host_id());
2312 frontend3
->AddExpectedEvent(ids3
, APPCACHE_CHECKING_EVENT
);
2313 frontend3
->AddExpectedEvent(ids3
, APPCACHE_DOWNLOADING_EVENT
);
2314 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
);
2315 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
);
2316 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
); // final
2317 frontend3
->AddExpectedEvent(ids3
, APPCACHE_UPDATE_READY_EVENT
);
2319 WaitForUpdateToFinish();
2322 void MasterEntryNoUpdateTest() {
2323 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2326 group_
= new AppCacheGroup(service_
->storage(),
2327 MockHttpServer::GetMockUrl("files/notmodified"), 111);
2328 AppCacheUpdateJob
* update
=
2329 new AppCacheUpdateJob(service_
.get(), group_
.get());
2330 group_
->update_job_
= update
;
2332 AppCache
* cache
= MakeCacheForGroup(1, 111);
2333 MockFrontend
* frontend1
= MakeMockFrontend();
2334 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2335 host1
->AssociateCompleteCache(cache
);
2337 // Give cache an existing entry that can also be fetched.
2338 cache
->AddEntry(MockHttpServer::GetMockUrl("files/explicit2"),
2339 AppCacheEntry(AppCacheEntry::EXPLICIT
, 222));
2341 // Reset the update time to null so we can verify it gets
2342 // modified in this test case by the UpdateJob.
2343 cache
->set_update_time(base::Time());
2345 MockFrontend
* frontend2
= MakeMockFrontend();
2346 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2347 host2
->new_master_entry_url_
=
2348 MockHttpServer::GetMockUrl("files/explicit1");
2349 update
->StartUpdate(host2
, host2
->new_master_entry_url_
);
2351 AppCacheHost
* host3
= MakeHost(3, frontend2
); // same frontend as host2
2352 host3
->new_master_entry_url_
=
2353 MockHttpServer::GetMockUrl("files/explicit2");
2354 update
->StartUpdate(host3
, host3
->new_master_entry_url_
);
2356 // Set up checks for when update job finishes.
2357 do_checks_after_update_finished_
= true;
2358 expect_group_obsolete_
= false;
2359 expect_group_has_cache_
= true;
2360 expect_newest_cache_
= cache
; // newest cache still the same cache
2361 expect_non_null_update_time_
= true;
2362 tested_manifest_
= PENDING_MASTER_NO_UPDATE
;
2363 MockFrontend::HostIds
ids1(1, host1
->host_id());
2364 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2365 frontend1
->AddExpectedEvent(ids1
, APPCACHE_NO_UPDATE_EVENT
);
2366 MockFrontend::HostIds
ids3(1, host3
->host_id());
2367 frontend2
->AddExpectedEvent(ids3
, APPCACHE_CHECKING_EVENT
);
2368 MockFrontend::HostIds ids2and3
;
2369 ids2and3
.push_back(host2
->host_id());
2370 ids2and3
.push_back(host3
->host_id());
2371 frontend2
->AddExpectedEvent(ids2and3
, APPCACHE_NO_UPDATE_EVENT
);
2373 WaitForUpdateToFinish();
2376 void StartUpdateMidCacheAttemptTest() {
2377 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2380 group_
= new AppCacheGroup(
2381 service_
->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
2382 service_
->storage()->NewGroupId());
2383 AppCacheUpdateJob
* update
=
2384 new AppCacheUpdateJob(service_
.get(), group_
.get());
2385 group_
->update_job_
= update
;
2387 MockFrontend
* frontend1
= MakeMockFrontend();
2388 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2389 host1
->new_master_entry_url_
=
2390 MockHttpServer::GetMockUrl("files/explicit2");
2391 update
->StartUpdate(host1
, host1
->new_master_entry_url_
);
2393 // Set up additional updates to be started while update is in progress.
2394 MockFrontend
* frontend2
= MakeMockFrontend();
2395 frontend2
->SetIgnoreProgressEvents(true);
2396 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2397 host2
->new_master_entry_url_
=
2398 MockHttpServer::GetMockUrl("files/nosuchfile");
2400 MockFrontend
* frontend3
= MakeMockFrontend();
2401 AppCacheHost
* host3
= MakeHost(3, frontend3
);
2402 host3
->new_master_entry_url_
=
2403 MockHttpServer::GetMockUrl("files/explicit1");
2405 MockFrontend
* frontend4
= MakeMockFrontend();
2406 AppCacheHost
* host4
= MakeHost(4, frontend4
);
2407 host4
->new_master_entry_url_
=
2408 MockHttpServer::GetMockUrl("files/explicit2");
2410 MockFrontend
* frontend5
= MakeMockFrontend();
2411 AppCacheHost
* host5
= MakeHost(5, frontend5
); // no master entry url
2413 frontend1
->TriggerAdditionalUpdates(APPCACHE_DOWNLOADING_EVENT
, update
);
2414 frontend1
->AdditionalUpdateHost(host2
); // fetch will fail
2415 frontend1
->AdditionalUpdateHost(host3
); // same as an explicit entry
2416 frontend1
->AdditionalUpdateHost(host4
); // same as another master entry
2417 frontend1
->AdditionalUpdateHost(NULL
); // no host
2418 frontend1
->AdditionalUpdateHost(host5
); // no master entry url
2420 // Set up checks for when update job finishes.
2421 do_checks_after_update_finished_
= true;
2422 expect_group_obsolete_
= false;
2423 expect_group_has_cache_
= true;
2424 tested_manifest_
= MANIFEST1
;
2425 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
2426 MockHttpServer::GetMockUrl("files/explicit2"),
2427 AppCacheEntry(AppCacheEntry::MASTER
)));
2428 MockFrontend::HostIds
ids1(1, host1
->host_id());
2429 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2430 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2431 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2432 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2433 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2434 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CACHED_EVENT
);
2435 MockFrontend::HostIds
ids2(1, host2
->host_id());
2436 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
2437 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
2438 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
2439 MockFrontend::HostIds
ids3(1, host3
->host_id());
2440 frontend3
->AddExpectedEvent(ids3
, APPCACHE_CHECKING_EVENT
);
2441 frontend3
->AddExpectedEvent(ids3
, APPCACHE_DOWNLOADING_EVENT
);
2442 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
);
2443 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
);
2444 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
); // final
2445 frontend3
->AddExpectedEvent(ids3
, APPCACHE_CACHED_EVENT
);
2446 MockFrontend::HostIds
ids4(1, host4
->host_id());
2447 frontend4
->AddExpectedEvent(ids4
, APPCACHE_CHECKING_EVENT
);
2448 frontend4
->AddExpectedEvent(ids4
, APPCACHE_DOWNLOADING_EVENT
);
2449 frontend4
->AddExpectedEvent(ids4
, APPCACHE_PROGRESS_EVENT
);
2450 frontend4
->AddExpectedEvent(ids4
, APPCACHE_PROGRESS_EVENT
);
2451 frontend4
->AddExpectedEvent(ids4
, APPCACHE_PROGRESS_EVENT
); // final
2452 frontend4
->AddExpectedEvent(ids4
, APPCACHE_CACHED_EVENT
);
2454 // Host 5 is not associated with cache so no progress/cached events.
2455 MockFrontend::HostIds
ids5(1, host5
->host_id());
2456 frontend5
->AddExpectedEvent(ids5
, APPCACHE_CHECKING_EVENT
);
2457 frontend5
->AddExpectedEvent(ids5
, APPCACHE_DOWNLOADING_EVENT
);
2459 WaitForUpdateToFinish();
2462 void StartUpdateMidNoUpdateTest() {
2463 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2466 group_
= new AppCacheGroup(
2467 service_
->storage(), MockHttpServer::GetMockUrl("files/notmodified"),
2468 service_
->storage()->NewGroupId());
2469 AppCacheUpdateJob
* update
=
2470 new AppCacheUpdateJob(service_
.get(), group_
.get());
2471 group_
->update_job_
= update
;
2473 AppCache
* cache
= MakeCacheForGroup(1, 111);
2474 MockFrontend
* frontend1
= MakeMockFrontend();
2475 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2476 host1
->AssociateCompleteCache(cache
);
2478 // Give cache an existing entry.
2479 cache
->AddEntry(MockHttpServer::GetMockUrl("files/explicit2"),
2480 AppCacheEntry(AppCacheEntry::EXPLICIT
, 222));
2482 // Start update with a pending master entry that will fail to give us an
2483 // event to trigger other updates.
2484 MockFrontend
* frontend2
= MakeMockFrontend();
2485 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2486 host2
->new_master_entry_url_
=
2487 MockHttpServer::GetMockUrl("files/nosuchfile");
2488 update
->StartUpdate(host2
, host2
->new_master_entry_url_
);
2490 // Set up additional updates to be started while update is in progress.
2491 MockFrontend
* frontend3
= MakeMockFrontend();
2492 AppCacheHost
* host3
= MakeHost(3, frontend3
);
2493 host3
->new_master_entry_url_
=
2494 MockHttpServer::GetMockUrl("files/explicit1");
2496 MockFrontend
* frontend4
= MakeMockFrontend();
2497 AppCacheHost
* host4
= MakeHost(4, frontend4
); // no master entry url
2499 MockFrontend
* frontend5
= MakeMockFrontend();
2500 AppCacheHost
* host5
= MakeHost(5, frontend5
);
2501 host5
->new_master_entry_url_
=
2502 MockHttpServer::GetMockUrl("files/explicit2"); // existing entry
2504 MockFrontend
* frontend6
= MakeMockFrontend();
2505 AppCacheHost
* host6
= MakeHost(6, frontend6
);
2506 host6
->new_master_entry_url_
=
2507 MockHttpServer::GetMockUrl("files/explicit1");
2509 frontend2
->TriggerAdditionalUpdates(APPCACHE_ERROR_EVENT
, update
);
2510 frontend2
->AdditionalUpdateHost(host3
);
2511 frontend2
->AdditionalUpdateHost(NULL
); // no host
2512 frontend2
->AdditionalUpdateHost(host4
); // no master entry url
2513 frontend2
->AdditionalUpdateHost(host5
); // same as existing cache entry
2514 frontend2
->AdditionalUpdateHost(host6
); // same as another master entry
2516 // Set up checks for when update job finishes.
2517 do_checks_after_update_finished_
= true;
2518 expect_group_obsolete_
= false;
2519 expect_group_has_cache_
= true;
2520 expect_newest_cache_
= cache
; // newest cache unaffected by update
2521 tested_manifest_
= PENDING_MASTER_NO_UPDATE
;
2522 MockFrontend::HostIds
ids1(1, host1
->host_id()); // prior associated host
2523 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2524 frontend1
->AddExpectedEvent(ids1
, APPCACHE_NO_UPDATE_EVENT
);
2525 MockFrontend::HostIds
ids2(1, host2
->host_id());
2526 frontend2
->AddExpectedEvent(ids2
, APPCACHE_ERROR_EVENT
);
2527 MockFrontend::HostIds
ids3(1, host3
->host_id());
2528 frontend3
->AddExpectedEvent(ids3
, APPCACHE_CHECKING_EVENT
);
2529 frontend3
->AddExpectedEvent(ids3
, APPCACHE_NO_UPDATE_EVENT
);
2530 MockFrontend::HostIds
ids4(1, host4
->host_id()); // unassociated w/cache
2531 frontend4
->AddExpectedEvent(ids4
, APPCACHE_CHECKING_EVENT
);
2532 MockFrontend::HostIds
ids5(1, host5
->host_id());
2533 frontend5
->AddExpectedEvent(ids5
, APPCACHE_CHECKING_EVENT
);
2534 frontend5
->AddExpectedEvent(ids5
, APPCACHE_NO_UPDATE_EVENT
);
2535 MockFrontend::HostIds
ids6(1, host6
->host_id());
2536 frontend6
->AddExpectedEvent(ids6
, APPCACHE_CHECKING_EVENT
);
2537 frontend6
->AddExpectedEvent(ids6
, APPCACHE_NO_UPDATE_EVENT
);
2539 WaitForUpdateToFinish();
2542 void StartUpdateMidDownloadTest() {
2543 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2546 group_
= new AppCacheGroup(
2547 service_
->storage(),
2548 MockHttpServer::GetMockUrl("files/manifest1"),
2550 AppCacheUpdateJob
* update
=
2551 new AppCacheUpdateJob(service_
.get(), group_
.get());
2552 group_
->update_job_
= update
;
2554 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(), 42);
2555 MockFrontend
* frontend1
= MakeMockFrontend();
2556 AppCacheHost
* host1
= MakeHost(1, frontend1
);
2557 host1
->AssociateCompleteCache(cache
);
2559 update
->StartUpdate(NULL
, GURL());
2561 // Set up additional updates to be started while update is in progress.
2562 MockFrontend
* frontend2
= MakeMockFrontend();
2563 AppCacheHost
* host2
= MakeHost(2, frontend2
);
2564 host2
->new_master_entry_url_
=
2565 MockHttpServer::GetMockUrl("files/explicit1");
2567 MockFrontend
* frontend3
= MakeMockFrontend();
2568 AppCacheHost
* host3
= MakeHost(3, frontend3
);
2569 host3
->new_master_entry_url_
=
2570 MockHttpServer::GetMockUrl("files/explicit2");
2572 MockFrontend
* frontend4
= MakeMockFrontend();
2573 AppCacheHost
* host4
= MakeHost(4, frontend4
); // no master entry url
2575 MockFrontend
* frontend5
= MakeMockFrontend();
2576 AppCacheHost
* host5
= MakeHost(5, frontend5
);
2577 host5
->new_master_entry_url_
=
2578 MockHttpServer::GetMockUrl("files/explicit2");
2580 frontend1
->TriggerAdditionalUpdates(APPCACHE_PROGRESS_EVENT
, update
);
2581 frontend1
->AdditionalUpdateHost(host2
); // same as entry in manifest
2582 frontend1
->AdditionalUpdateHost(NULL
); // no host
2583 frontend1
->AdditionalUpdateHost(host3
); // new master entry
2584 frontend1
->AdditionalUpdateHost(host4
); // no master entry url
2585 frontend1
->AdditionalUpdateHost(host5
); // same as another master entry
2587 // Set up checks for when update job finishes.
2588 do_checks_after_update_finished_
= true;
2589 expect_group_obsolete_
= false;
2590 expect_group_has_cache_
= true;
2591 tested_manifest_
= MANIFEST1
;
2592 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
2593 MockHttpServer::GetMockUrl("files/explicit2"),
2594 AppCacheEntry(AppCacheEntry::MASTER
)));
2595 MockFrontend::HostIds
ids1(1, host1
->host_id()); // prior associated host
2596 frontend1
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2597 frontend1
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2598 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2599 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2600 frontend1
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2601 frontend1
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
2602 MockFrontend::HostIds
ids2(1, host2
->host_id());
2603 frontend2
->AddExpectedEvent(ids2
, APPCACHE_CHECKING_EVENT
);
2604 frontend2
->AddExpectedEvent(ids2
, APPCACHE_DOWNLOADING_EVENT
);
2605 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
);
2606 frontend2
->AddExpectedEvent(ids2
, APPCACHE_PROGRESS_EVENT
); // final
2607 frontend2
->AddExpectedEvent(ids2
, APPCACHE_UPDATE_READY_EVENT
);
2608 MockFrontend::HostIds
ids3(1, host3
->host_id());
2609 frontend3
->AddExpectedEvent(ids3
, APPCACHE_CHECKING_EVENT
);
2610 frontend3
->AddExpectedEvent(ids3
, APPCACHE_DOWNLOADING_EVENT
);
2611 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
);
2612 frontend3
->AddExpectedEvent(ids3
, APPCACHE_PROGRESS_EVENT
); // final
2613 frontend3
->AddExpectedEvent(ids3
, APPCACHE_UPDATE_READY_EVENT
);
2614 MockFrontend::HostIds
ids4(1, host4
->host_id()); // unassociated w/cache
2615 frontend4
->AddExpectedEvent(ids4
, APPCACHE_CHECKING_EVENT
);
2616 frontend4
->AddExpectedEvent(ids4
, APPCACHE_DOWNLOADING_EVENT
);
2617 MockFrontend::HostIds
ids5(1, host5
->host_id());
2618 frontend5
->AddExpectedEvent(ids5
, APPCACHE_CHECKING_EVENT
);
2619 frontend5
->AddExpectedEvent(ids5
, APPCACHE_DOWNLOADING_EVENT
);
2620 frontend5
->AddExpectedEvent(ids5
, APPCACHE_PROGRESS_EVENT
);
2621 frontend5
->AddExpectedEvent(ids5
, APPCACHE_PROGRESS_EVENT
); // final
2622 frontend5
->AddExpectedEvent(ids5
, APPCACHE_UPDATE_READY_EVENT
);
2624 WaitForUpdateToFinish();
2627 void QueueMasterEntryTest() {
2628 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2631 group_
= new AppCacheGroup(
2632 service_
->storage(),
2633 MockHttpServer::GetMockUrl("files/manifest1"),
2635 AppCacheUpdateJob
* update
=
2636 new AppCacheUpdateJob(service_
.get(), group_
.get());
2637 group_
->update_job_
= update
;
2639 // Pretend update job has been running and is about to terminate.
2640 group_
->update_status_
= AppCacheGroup::DOWNLOADING
;
2641 update
->internal_state_
= AppCacheUpdateJob::REFETCH_MANIFEST
;
2642 EXPECT_TRUE(update
->IsTerminating());
2644 // Start an update. Should be queued.
2645 MockFrontend
* frontend
= MakeMockFrontend();
2646 AppCacheHost
* host
= MakeHost(1, frontend
);
2647 host
->new_master_entry_url_
=
2648 MockHttpServer::GetMockUrl("files/explicit2");
2649 update
->StartUpdate(host
, host
->new_master_entry_url_
);
2650 EXPECT_TRUE(update
->pending_master_entries_
.empty());
2651 EXPECT_FALSE(group_
->queued_updates_
.empty());
2653 // Delete update, causing it to finish, which should trigger a new update
2654 // for the queued host and master entry after a delay.
2656 EXPECT_FALSE(group_
->restart_update_task_
.IsCancelled());
2658 // Set up checks for when queued update job finishes.
2659 do_checks_after_update_finished_
= true;
2660 expect_group_obsolete_
= false;
2661 expect_group_has_cache_
= true;
2662 tested_manifest_
= MANIFEST1
;
2663 expect_extra_entries_
.insert(AppCache::EntryMap::value_type(
2664 host
->new_master_entry_url_
, AppCacheEntry(AppCacheEntry::MASTER
)));
2665 MockFrontend::HostIds
ids1(1, host
->host_id());
2666 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2667 frontend
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2668 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2669 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2670 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2671 frontend
->AddExpectedEvent(ids1
, APPCACHE_CACHED_EVENT
);
2673 // Group status will be APPCACHE_STATUS_IDLE so cannot call
2674 // WaitForUpdateToFinish.
2675 group_
->AddUpdateObserver(this);
2678 void IfModifiedSinceTest() {
2679 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2681 net::URLRequestJobFactoryImpl
* new_factory(
2682 new net::URLRequestJobFactoryImpl
);
2683 new_factory
->SetProtocolHandler("http", new IfModifiedSinceJobFactory
);
2684 io_thread_
->SetNewJobFactory(new_factory
);
2687 group_
= new AppCacheGroup(
2688 service_
->storage(), GURL("http://headertest"), 111);
2689 AppCacheUpdateJob
* update
=
2690 new AppCacheUpdateJob(service_
.get(), group_
.get());
2691 group_
->update_job_
= update
;
2693 // First test against a cache attempt. Will start manifest fetch
2695 HttpHeadersRequestTestJob::Initialize(std::string(), std::string());
2696 MockFrontend mock_frontend
;
2697 AppCacheHost
host(1, &mock_frontend
, service_
.get());
2698 update
->StartUpdate(&host
, GURL());
2699 HttpHeadersRequestTestJob::Verify();
2702 // Now simulate a refetch manifest request. Will start fetch request
2707 net::HttpResponseHeaders
* headers
=
2708 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
2709 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
2710 response_info
->headers
= headers
; // adds ref to headers
2712 HttpHeadersRequestTestJob::Initialize(std::string(), std::string());
2713 update
= new AppCacheUpdateJob(service_
.get(), group_
.get());
2714 group_
->update_job_
= update
;
2715 group_
->update_status_
= AppCacheGroup::DOWNLOADING
;
2716 update
->manifest_response_info_
.reset(response_info
);
2717 update
->internal_state_
= AppCacheUpdateJob::REFETCH_MANIFEST
;
2718 update
->FetchManifest(false); // not first request
2719 HttpHeadersRequestTestJob::Verify();
2722 // Change the headers to include a Last-Modified header. Manifest refetch
2723 // should include If-Modified-Since header.
2724 const char data2
[] =
2726 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2728 net::HttpResponseHeaders
* headers2
=
2729 new net::HttpResponseHeaders(std::string(data2
, arraysize(data2
)));
2730 response_info
= new net::HttpResponseInfo();
2731 response_info
->headers
= headers2
;
2733 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT",
2735 update
= new AppCacheUpdateJob(service_
.get(), group_
.get());
2736 group_
->update_job_
= update
;
2737 group_
->update_status_
= AppCacheGroup::DOWNLOADING
;
2738 update
->manifest_response_info_
.reset(response_info
);
2739 update
->internal_state_
= AppCacheUpdateJob::REFETCH_MANIFEST
;
2740 update
->FetchManifest(false); // not first request
2741 HttpHeadersRequestTestJob::Verify();
2747 void IfModifiedSinceUpgradeTest() {
2748 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2750 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT",
2752 net::URLRequestJobFactoryImpl
* new_factory(
2753 new net::URLRequestJobFactoryImpl
);
2754 new_factory
->SetProtocolHandler("http", new IfModifiedSinceJobFactory
);
2755 io_thread_
->SetNewJobFactory(new_factory
);
2758 group_
= new AppCacheGroup(
2759 service_
->storage(),
2760 MockHttpServer::GetMockUrl("files/manifest1"),
2762 AppCacheUpdateJob
* update
=
2763 new AppCacheUpdateJob(service_
.get(), group_
.get());
2764 group_
->update_job_
= update
;
2766 // Give the newest cache a manifest enry that is in storage.
2767 response_writer_
.reset(
2768 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
2769 group_
->group_id()));
2771 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(),
2772 response_writer_
->response_id());
2773 MockFrontend
* frontend
= MakeMockFrontend();
2774 AppCacheHost
* host
= MakeHost(1, frontend
);
2775 host
->AssociateCompleteCache(cache
);
2777 // Set up checks for when update job finishes.
2778 do_checks_after_update_finished_
= true;
2779 expect_group_obsolete_
= false;
2780 expect_group_has_cache_
= true;
2781 expect_old_cache_
= cache
;
2782 tested_manifest_
= MANIFEST1
;
2783 MockFrontend::HostIds
ids1(1, host
->host_id());
2784 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2785 frontend
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2786 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2787 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2788 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2789 frontend
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
2791 // Seed storage with expected manifest response info that will cause
2792 // an If-Modified-Since header to be put in the manifest fetch request.
2795 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2797 net::HttpResponseHeaders
* headers
=
2798 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
2799 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
2800 response_info
->headers
= headers
; // adds ref to headers
2801 scoped_refptr
<HttpResponseInfoIOBuffer
> io_buffer(
2802 new HttpResponseInfoIOBuffer(response_info
)); // adds ref to info
2803 response_writer_
->WriteInfo(
2805 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
2806 base::Unretained(this)));
2808 // Start update after data write completes asynchronously.
2811 void IfNoneMatchUpgradeTest() {
2812 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2814 HttpHeadersRequestTestJob::Initialize(std::string(), "\"LadeDade\"");
2815 net::URLRequestJobFactoryImpl
* new_factory(
2816 new net::URLRequestJobFactoryImpl
);
2817 new_factory
->SetProtocolHandler("http", new IfModifiedSinceJobFactory
);
2818 io_thread_
->SetNewJobFactory(new_factory
);
2821 group_
= new AppCacheGroup(
2822 service_
->storage(),
2823 MockHttpServer::GetMockUrl("files/manifest1"),
2825 AppCacheUpdateJob
* update
=
2826 new AppCacheUpdateJob(service_
.get(), group_
.get());
2827 group_
->update_job_
= update
;
2829 // Give the newest cache a manifest enry that is in storage.
2830 response_writer_
.reset(
2831 service_
->storage()->CreateResponseWriter(group_
->manifest_url(),
2832 group_
->group_id()));
2834 AppCache
* cache
= MakeCacheForGroup(service_
->storage()->NewCacheId(),
2835 response_writer_
->response_id());
2836 MockFrontend
* frontend
= MakeMockFrontend();
2837 AppCacheHost
* host
= MakeHost(1, frontend
);
2838 host
->AssociateCompleteCache(cache
);
2840 // Set up checks for when update job finishes.
2841 do_checks_after_update_finished_
= true;
2842 expect_group_obsolete_
= false;
2843 expect_group_has_cache_
= true;
2844 expect_old_cache_
= cache
;
2845 tested_manifest_
= MANIFEST1
;
2846 MockFrontend::HostIds
ids1(1, host
->host_id());
2847 frontend
->AddExpectedEvent(ids1
, APPCACHE_CHECKING_EVENT
);
2848 frontend
->AddExpectedEvent(ids1
, APPCACHE_DOWNLOADING_EVENT
);
2849 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2850 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
);
2851 frontend
->AddExpectedEvent(ids1
, APPCACHE_PROGRESS_EVENT
); // final
2852 frontend
->AddExpectedEvent(ids1
, APPCACHE_UPDATE_READY_EVENT
);
2854 // Seed storage with expected manifest response info that will cause
2855 // an If-None-Match header to be put in the manifest fetch request.
2858 "ETag: \"LadeDade\"\0"
2860 net::HttpResponseHeaders
* headers
=
2861 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
2862 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
2863 response_info
->headers
= headers
; // adds ref to headers
2864 scoped_refptr
<HttpResponseInfoIOBuffer
> io_buffer(
2865 new HttpResponseInfoIOBuffer(response_info
)); // adds ref to info
2866 response_writer_
->WriteInfo(
2868 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData
,
2869 base::Unretained(this)));
2871 // Start update after data write completes asynchronously.
2874 void IfNoneMatchRefetchTest() {
2875 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2877 HttpHeadersRequestTestJob::Initialize(std::string(), "\"LadeDade\"");
2878 net::URLRequestJobFactoryImpl
* new_factory(
2879 new net::URLRequestJobFactoryImpl
);
2880 new_factory
->SetProtocolHandler("http", new IfModifiedSinceJobFactory
);
2881 io_thread_
->SetNewJobFactory(new_factory
);
2884 group_
= new AppCacheGroup(
2885 service_
->storage(), GURL("http://headertest"), 111);
2886 AppCacheUpdateJob
* update
=
2887 new AppCacheUpdateJob(service_
.get(), group_
.get());
2888 group_
->update_job_
= update
;
2890 // Simulate a refetch manifest request that uses an ETag header.
2893 "ETag: \"LadeDade\"\0"
2895 net::HttpResponseHeaders
* headers
=
2896 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
2897 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
2898 response_info
->headers
= headers
; // adds ref to headers
2900 group_
->update_status_
= AppCacheGroup::DOWNLOADING
;
2901 update
->manifest_response_info_
.reset(response_info
);
2902 update
->internal_state_
= AppCacheUpdateJob::REFETCH_MANIFEST
;
2903 update
->FetchManifest(false); // not first request
2904 HttpHeadersRequestTestJob::Verify();
2910 void MultipleHeadersRefetchTest() {
2911 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2913 // Verify that code is correct when building multiple extra headers.
2914 HttpHeadersRequestTestJob::Initialize(
2915 "Sat, 29 Oct 1994 19:43:31 GMT", "\"LadeDade\"");
2916 net::URLRequestJobFactoryImpl
* new_factory(
2917 new net::URLRequestJobFactoryImpl
);
2918 new_factory
->SetProtocolHandler("http", new IfModifiedSinceJobFactory
);
2919 io_thread_
->SetNewJobFactory(new_factory
);
2922 group_
= new AppCacheGroup(
2923 service_
->storage(), GURL("http://headertest"), 111);
2924 AppCacheUpdateJob
* update
=
2925 new AppCacheUpdateJob(service_
.get(), group_
.get());
2926 group_
->update_job_
= update
;
2928 // Simulate a refetch manifest request that uses an ETag header.
2931 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2932 "ETag: \"LadeDade\"\0"
2934 net::HttpResponseHeaders
* headers
=
2935 new net::HttpResponseHeaders(std::string(data
, arraysize(data
)));
2936 net::HttpResponseInfo
* response_info
= new net::HttpResponseInfo();
2937 response_info
->headers
= headers
; // adds ref to headers
2939 group_
->update_status_
= AppCacheGroup::DOWNLOADING
;
2940 update
->manifest_response_info_
.reset(response_info
);
2941 update
->internal_state_
= AppCacheUpdateJob::REFETCH_MANIFEST
;
2942 update
->FetchManifest(false); // not first request
2943 HttpHeadersRequestTestJob::Verify();
2949 void CrossOriginHttpsSuccessTest() {
2950 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2952 GURL manifest_url
= MockHttpServer::GetMockHttpsUrl(
2953 "files/valid_cross_origin_https_manifest");
2956 group_
= new AppCacheGroup(
2957 service_
->storage(), manifest_url
, service_
->storage()->NewGroupId());
2958 AppCacheUpdateJob
* update
=
2959 new AppCacheUpdateJob(service_
.get(), group_
.get());
2960 group_
->update_job_
= update
;
2962 MockFrontend
* frontend
= MakeMockFrontend();
2963 AppCacheHost
* host
= MakeHost(1, frontend
);
2964 update
->StartUpdate(host
, GURL());
2966 // Set up checks for when update job finishes.
2967 do_checks_after_update_finished_
= true;
2968 expect_group_obsolete_
= false;
2969 expect_group_has_cache_
= true;
2970 tested_manifest_
= NONE
;
2971 MockFrontend::HostIds
host_ids(1, host
->host_id());
2972 frontend
->AddExpectedEvent(host_ids
, APPCACHE_CHECKING_EVENT
);
2974 WaitForUpdateToFinish();
2977 void CrossOriginHttpsDeniedTest() {
2978 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent());
2980 GURL manifest_url
= MockHttpServer::GetMockHttpsUrl(
2981 "files/invalid_cross_origin_https_manifest");
2984 group_
= new AppCacheGroup(
2985 service_
->storage(), manifest_url
, service_
->storage()->NewGroupId());
2986 AppCacheUpdateJob
* update
=
2987 new AppCacheUpdateJob(service_
.get(), group_
.get());
2988 group_
->update_job_
= update
;
2990 MockFrontend
* frontend
= MakeMockFrontend();
2991 AppCacheHost
* host
= MakeHost(1, frontend
);
2992 update
->StartUpdate(host
, GURL());
2994 // Set up checks for when update job finishes.
2995 do_checks_after_update_finished_
= true;
2996 expect_group_obsolete_
= false;
2997 expect_group_has_cache_
= false;
2998 tested_manifest_
= NONE
;
2999 MockFrontend::HostIds
host_ids(1, host
->host_id());
3000 frontend
->AddExpectedEvent(host_ids
, APPCACHE_CHECKING_EVENT
);
3002 WaitForUpdateToFinish();
3005 void WaitForUpdateToFinish() {
3006 if (group_
->update_status() == AppCacheGroup::IDLE
)
3009 group_
->AddUpdateObserver(this);
3012 void OnUpdateComplete(AppCacheGroup
* group
) override
{
3013 ASSERT_EQ(group_
.get(), group
);
3014 protect_newest_cache_
= group
->newest_complete_cache();
3018 void UpdateFinished() {
3019 // We unwind the stack prior to finishing up to let stack-based objects
3021 base::ThreadTaskRunnerHandle::Get()->PostTask(
3022 FROM_HERE
, base::Bind(&AppCacheUpdateJobTest::UpdateFinishedUnwound
,
3023 base::Unretained(this)));
3026 void UpdateFinishedUnwound() {
3027 EXPECT_EQ(AppCacheGroup::IDLE
, group_
->update_status());
3028 EXPECT_TRUE(group_
->update_job() == NULL
);
3029 if (do_checks_after_update_finished_
)
3030 VerifyExpectations();
3032 // Clean up everything that was created on the IO thread.
3033 protect_newest_cache_
= NULL
;
3035 STLDeleteContainerPointers(hosts_
.begin(), hosts_
.end());
3036 STLDeleteContainerPointers(frontends_
.begin(), frontends_
.end());
3037 response_infos_
.clear();
3038 service_
.reset(NULL
);
3043 void MakeService() {
3044 service_
.reset(new MockAppCacheService());
3045 service_
->set_request_context(io_thread_
->request_context());
3048 AppCache
* MakeCacheForGroup(int64 cache_id
, int64 manifest_response_id
) {
3049 return MakeCacheForGroup(cache_id
, group_
->manifest_url(),
3050 manifest_response_id
);
3053 AppCache
* MakeCacheForGroup(int64 cache_id
, const GURL
& manifest_entry_url
,
3054 int64 manifest_response_id
) {
3055 AppCache
* cache
= new AppCache(service_
->storage(), cache_id
);
3056 cache
->set_complete(true);
3057 cache
->set_update_time(base::Time::Now() - kOneHour
);
3058 group_
->AddCache(cache
);
3059 group_
->set_last_full_update_check_time(cache
->update_time());
3061 // Add manifest entry to cache.
3062 cache
->AddEntry(manifest_entry_url
,
3063 AppCacheEntry(AppCacheEntry::MANIFEST
, manifest_response_id
));
3065 // Specific tests that expect a newer time should set
3066 // expect_full_update_time_newer_than_ which causes this
3067 // equality expectation to be ignored.
3068 expect_full_update_time_equal_to_
= cache
->update_time();
3073 AppCacheHost
* MakeHost(int host_id
, AppCacheFrontend
* frontend
) {
3074 AppCacheHost
* host
= new AppCacheHost(host_id
, frontend
, service_
.get());
3075 hosts_
.push_back(host
);
3079 AppCacheResponseInfo
* MakeAppCacheResponseInfo(
3080 const GURL
& manifest_url
, int64 response_id
,
3081 const std::string
& raw_headers
) {
3082 net::HttpResponseInfo
* http_info
= new net::HttpResponseInfo();
3083 http_info
->headers
= new net::HttpResponseHeaders(raw_headers
);
3084 scoped_refptr
<AppCacheResponseInfo
> info(
3085 new AppCacheResponseInfo(service_
->storage(), manifest_url
,
3086 response_id
, http_info
, 0));
3087 response_infos_
.push_back(info
);
3091 MockFrontend
* MakeMockFrontend() {
3092 MockFrontend
* frontend
= new MockFrontend();
3093 frontends_
.push_back(frontend
);
3097 // Verifies conditions about the group and notifications after an update
3098 // has finished. Cannot verify update job internals as update is deleted.
3099 void VerifyExpectations() {
3100 RetryRequestTestJob::Verify();
3101 HttpHeadersRequestTestJob::Verify();
3103 EXPECT_EQ(expect_group_obsolete_
, group_
->is_obsolete());
3104 EXPECT_EQ(expect_group_is_being_deleted_
|| expect_eviction_
,
3105 group_
->is_being_deleted());
3107 if (!expect_eviction_
) {
3108 EXPECT_EQ(expect_evictable_error_
,
3109 !group_
->first_evictable_error_time().is_null());
3110 if (expect_evictable_error_
) {
3111 MockAppCacheStorage
* storage
=
3112 reinterpret_cast<MockAppCacheStorage
*>(service_
->storage());
3113 EXPECT_EQ(group_
->first_evictable_error_time(),
3114 storage
->stored_eviction_times_
[group_
->group_id()].second
);
3118 if (!expect_full_update_time_newer_than_
.is_null()) {
3119 EXPECT_LT(expect_full_update_time_newer_than_
,
3120 group_
->last_full_update_check_time());
3121 } else if (!expect_full_update_time_equal_to_
.is_null()) {
3122 EXPECT_EQ(expect_full_update_time_equal_to_
,
3123 group_
->last_full_update_check_time());
3126 if (expect_group_has_cache_
) {
3127 EXPECT_TRUE(group_
->newest_complete_cache() != NULL
);
3129 if (expect_non_null_update_time_
)
3130 EXPECT_TRUE(!group_
->newest_complete_cache()->update_time().is_null());
3132 if (expect_old_cache_
) {
3133 EXPECT_NE(expect_old_cache_
, group_
->newest_complete_cache());
3134 EXPECT_TRUE(group_
->old_caches().end() !=
3135 std::find(group_
->old_caches().begin(),
3136 group_
->old_caches().end(), expect_old_cache_
));
3138 if (expect_newest_cache_
) {
3139 EXPECT_EQ(expect_newest_cache_
, group_
->newest_complete_cache());
3140 EXPECT_TRUE(group_
->old_caches().end() ==
3141 std::find(group_
->old_caches().begin(),
3142 group_
->old_caches().end(), expect_newest_cache_
));
3144 // Tests that don't know which newest cache to expect contain updates
3145 // that succeed (because the update creates a new cache whose pointer
3146 // is unknown to the test). Check group and newest cache were stored
3147 // when update succeeds.
3148 MockAppCacheStorage
* storage
=
3149 reinterpret_cast<MockAppCacheStorage
*>(service_
->storage());
3150 EXPECT_TRUE(storage
->IsGroupStored(group_
.get()));
3151 EXPECT_TRUE(storage
->IsCacheStored(group_
->newest_complete_cache()));
3153 // Check that all entries in the newest cache were stored.
3154 const AppCache::EntryMap
& entries
=
3155 group_
->newest_complete_cache()->entries();
3156 for (AppCache::EntryMap::const_iterator it
= entries
.begin();
3157 it
!= entries
.end(); ++it
) {
3158 EXPECT_NE(kAppCacheNoResponseId
, it
->second
.response_id());
3160 // Check that any copied entries have the expected response id
3161 // and that entries that are not copied have a different response id.
3162 std::map
<GURL
, int64
>::iterator found
=
3163 expect_response_ids_
.find(it
->first
);
3164 if (found
!= expect_response_ids_
.end()) {
3165 EXPECT_EQ(found
->second
, it
->second
.response_id());
3166 } else if (expect_old_cache_
) {
3167 AppCacheEntry
* old_entry
= expect_old_cache_
->GetEntry(it
->first
);
3169 EXPECT_NE(old_entry
->response_id(), it
->second
.response_id());
3174 EXPECT_TRUE(group_
->newest_complete_cache() == NULL
);
3177 // Check expected events.
3178 for (size_t i
= 0; i
< frontends_
.size(); ++i
) {
3179 MockFrontend
* frontend
= frontends_
[i
];
3181 MockFrontend::RaisedEvents
& expected_events
= frontend
->expected_events_
;
3182 MockFrontend::RaisedEvents
& actual_events
= frontend
->raised_events_
;
3183 EXPECT_EQ(expected_events
.size(), actual_events
.size());
3185 // Check each expected event.
3187 j
< expected_events
.size() && j
< actual_events
.size(); ++j
) {
3188 EXPECT_EQ(expected_events
[j
].second
, actual_events
[j
].second
);
3190 MockFrontend::HostIds
& expected_ids
= expected_events
[j
].first
;
3191 MockFrontend::HostIds
& actual_ids
= actual_events
[j
].first
;
3192 EXPECT_EQ(expected_ids
.size(), actual_ids
.size());
3194 for (size_t k
= 0; k
< expected_ids
.size(); ++k
) {
3195 int id
= expected_ids
[k
];
3196 EXPECT_TRUE(std::find(actual_ids
.begin(), actual_ids
.end(), id
) !=
3201 if (!frontend
->expected_error_message_
.empty()) {
3202 EXPECT_EQ(frontend
->expected_error_message_
,
3203 frontend
->error_message_
);
3207 // Verify expected cache contents last as some checks are asserts
3208 // and will abort the test if they fail.
3209 if (tested_manifest_
) {
3210 AppCache
* cache
= group_
->newest_complete_cache();
3211 ASSERT_TRUE(cache
!= NULL
);
3212 EXPECT_EQ(group_
.get(), cache
->owning_group());
3213 EXPECT_TRUE(cache
->is_complete());
3215 switch (tested_manifest_
) {
3217 VerifyManifest1(cache
);
3219 case MANIFEST_MERGED_TYPES
:
3220 VerifyManifestMergedTypes(cache
);
3222 case EMPTY_MANIFEST
:
3223 VerifyEmptyManifest(cache
);
3225 case EMPTY_FILE_MANIFEST
:
3226 VerifyEmptyFileManifest(cache
);
3228 case PENDING_MASTER_NO_UPDATE
:
3229 VerifyMasterEntryNoUpdate(cache
);
3231 case MANIFEST_WITH_INTERCEPT
:
3232 VerifyManifestWithIntercept(cache
);
3241 void VerifyManifest1(AppCache
* cache
) {
3242 size_t expected
= 3 + expect_extra_entries_
.size();
3243 EXPECT_EQ(expected
, cache
->entries().size());
3244 const char* kManifestPath
= tested_manifest_path_override_
?
3245 tested_manifest_path_override_
:
3247 AppCacheEntry
* entry
=
3248 cache
->GetEntry(MockHttpServer::GetMockUrl(kManifestPath
));
3250 EXPECT_EQ(AppCacheEntry::MANIFEST
, entry
->types());
3251 entry
= cache
->GetEntry(MockHttpServer::GetMockUrl("files/explicit1"));
3253 EXPECT_TRUE(entry
->IsExplicit());
3254 entry
= cache
->GetEntry(
3255 MockHttpServer::GetMockUrl("files/fallback1a"));
3257 EXPECT_EQ(AppCacheEntry::FALLBACK
, entry
->types());
3259 for (AppCache::EntryMap::iterator i
= expect_extra_entries_
.begin();
3260 i
!= expect_extra_entries_
.end(); ++i
) {
3261 entry
= cache
->GetEntry(i
->first
);
3263 EXPECT_EQ(i
->second
.types(), entry
->types());
3267 ASSERT_EQ(expected
, cache
->fallback_namespaces_
.size());
3268 EXPECT_TRUE(cache
->fallback_namespaces_
[0] ==
3270 APPCACHE_FALLBACK_NAMESPACE
,
3271 MockHttpServer::GetMockUrl("files/fallback1"),
3272 MockHttpServer::GetMockUrl("files/fallback1a"),
3275 EXPECT_TRUE(cache
->online_whitelist_namespaces_
.empty());
3276 EXPECT_TRUE(cache
->online_whitelist_all_
);
3278 EXPECT_TRUE(cache
->update_time_
> base::Time());
3281 void VerifyManifestMergedTypes(AppCache
* cache
) {
3282 size_t expected
= 2;
3283 EXPECT_EQ(expected
, cache
->entries().size());
3284 AppCacheEntry
* entry
= cache
->GetEntry(
3285 MockHttpServer::GetMockUrl("files/manifest-merged-types"));
3287 EXPECT_EQ(AppCacheEntry::EXPLICIT
| AppCacheEntry::MANIFEST
,
3289 entry
= cache
->GetEntry(MockHttpServer::GetMockUrl("files/explicit1"));
3291 EXPECT_EQ(AppCacheEntry::EXPLICIT
| AppCacheEntry::FALLBACK
|
3292 AppCacheEntry::MASTER
, entry
->types());
3295 ASSERT_EQ(expected
, cache
->fallback_namespaces_
.size());
3296 EXPECT_TRUE(cache
->fallback_namespaces_
[0] ==
3298 APPCACHE_FALLBACK_NAMESPACE
,
3299 MockHttpServer::GetMockUrl("files/fallback1"),
3300 MockHttpServer::GetMockUrl("files/explicit1"),
3303 EXPECT_EQ(expected
, cache
->online_whitelist_namespaces_
.size());
3304 EXPECT_TRUE(cache
->online_whitelist_namespaces_
[0] ==
3306 APPCACHE_NETWORK_NAMESPACE
,
3307 MockHttpServer::GetMockUrl("files/online1"),
3309 EXPECT_FALSE(cache
->online_whitelist_all_
);
3311 EXPECT_TRUE(cache
->update_time_
> base::Time());
3314 void VerifyEmptyManifest(AppCache
* cache
) {
3315 const char* kManifestPath
= tested_manifest_path_override_
?
3316 tested_manifest_path_override_
:
3317 "files/empty-manifest";
3318 size_t expected
= 1;
3319 EXPECT_EQ(expected
, cache
->entries().size());
3320 AppCacheEntry
* entry
= cache
->GetEntry(
3321 MockHttpServer::GetMockUrl(kManifestPath
));
3323 EXPECT_EQ(AppCacheEntry::MANIFEST
, entry
->types());
3325 EXPECT_TRUE(cache
->fallback_namespaces_
.empty());
3326 EXPECT_TRUE(cache
->online_whitelist_namespaces_
.empty());
3327 EXPECT_FALSE(cache
->online_whitelist_all_
);
3329 EXPECT_TRUE(cache
->update_time_
> base::Time());
3332 void VerifyEmptyFileManifest(AppCache
* cache
) {
3333 EXPECT_EQ(size_t(2), cache
->entries().size());
3334 AppCacheEntry
* entry
= cache
->GetEntry(
3335 MockHttpServer::GetMockUrl("files/empty-file-manifest"));
3337 EXPECT_EQ(AppCacheEntry::MANIFEST
, entry
->types());
3339 entry
= cache
->GetEntry(
3340 MockHttpServer::GetMockUrl("files/empty1"));
3342 EXPECT_EQ(AppCacheEntry::EXPLICIT
, entry
->types());
3343 EXPECT_TRUE(entry
->has_response_id());
3345 EXPECT_TRUE(cache
->fallback_namespaces_
.empty());
3346 EXPECT_TRUE(cache
->online_whitelist_namespaces_
.empty());
3347 EXPECT_FALSE(cache
->online_whitelist_all_
);
3349 EXPECT_TRUE(cache
->update_time_
> base::Time());
3352 void VerifyMasterEntryNoUpdate(AppCache
* cache
) {
3353 EXPECT_EQ(size_t(3), cache
->entries().size());
3354 AppCacheEntry
* entry
= cache
->GetEntry(
3355 MockHttpServer::GetMockUrl("files/notmodified"));
3357 EXPECT_EQ(AppCacheEntry::MANIFEST
, entry
->types());
3359 entry
= cache
->GetEntry(
3360 MockHttpServer::GetMockUrl("files/explicit1"));
3362 EXPECT_EQ(AppCacheEntry::MASTER
, entry
->types());
3363 EXPECT_TRUE(entry
->has_response_id());
3365 entry
= cache
->GetEntry(
3366 MockHttpServer::GetMockUrl("files/explicit2"));
3368 EXPECT_EQ(AppCacheEntry::EXPLICIT
| AppCacheEntry::MASTER
, entry
->types());
3369 EXPECT_TRUE(entry
->has_response_id());
3371 EXPECT_TRUE(cache
->fallback_namespaces_
.empty());
3372 EXPECT_TRUE(cache
->online_whitelist_namespaces_
.empty());
3373 EXPECT_FALSE(cache
->online_whitelist_all_
);
3375 EXPECT_TRUE(cache
->update_time_
> base::Time());
3378 void VerifyManifestWithIntercept(AppCache
* cache
) {
3379 EXPECT_EQ(2u, cache
->entries().size());
3380 const char* kManifestPath
= "files/manifest-with-intercept";
3381 AppCacheEntry
* entry
=
3382 cache
->GetEntry(MockHttpServer::GetMockUrl(kManifestPath
));
3384 EXPECT_EQ(AppCacheEntry::MANIFEST
, entry
->types());
3385 entry
= cache
->GetEntry(MockHttpServer::GetMockUrl("files/intercept1a"));
3387 EXPECT_TRUE(entry
->IsIntercept());
3388 EXPECT_TRUE(cache
->online_whitelist_namespaces_
.empty());
3389 EXPECT_FALSE(cache
->online_whitelist_all_
);
3390 EXPECT_TRUE(cache
->update_time_
> base::Time());
3394 // Various manifest files used in this test.
3395 enum TestedManifest
{
3398 MANIFEST_MERGED_TYPES
,
3400 EMPTY_FILE_MANIFEST
,
3401 PENDING_MASTER_NO_UPDATE
,
3402 MANIFEST_WITH_INTERCEPT
3405 scoped_ptr
<IOThread
> io_thread_
;
3407 scoped_ptr
<MockAppCacheService
> service_
;
3408 scoped_refptr
<AppCacheGroup
> group_
;
3409 scoped_refptr
<AppCache
> protect_newest_cache_
;
3410 scoped_ptr
<base::WaitableEvent
> event_
;
3412 scoped_ptr
<AppCacheResponseWriter
> response_writer_
;
3414 // Hosts used by an async test that need to live until update job finishes.
3415 // Otherwise, test can put host on the stack instead of here.
3416 std::vector
<AppCacheHost
*> hosts_
;
3418 // Response infos used by an async test that need to live until update job
3420 std::vector
<scoped_refptr
<AppCacheResponseInfo
> > response_infos_
;
3422 // Flag indicating if test cares to verify the update after update finishes.
3423 bool do_checks_after_update_finished_
;
3424 bool expect_group_obsolete_
;
3425 bool expect_group_has_cache_
;
3426 bool expect_group_is_being_deleted_
;
3427 bool expect_evictable_error_
;
3428 bool expect_eviction_
;
3429 base::Time expect_full_update_time_newer_than_
;
3430 base::Time expect_full_update_time_equal_to_
;
3431 AppCache
* expect_old_cache_
;
3432 AppCache
* expect_newest_cache_
;
3433 bool expect_non_null_update_time_
;
3434 std::vector
<MockFrontend
*> frontends_
; // to check expected events
3435 TestedManifest tested_manifest_
;
3436 const char* tested_manifest_path_override_
;
3437 AppCache::EntryMap expect_extra_entries_
;
3438 std::map
<GURL
, int64
> expect_response_ids_
;
3441 TEST_F(AppCacheUpdateJobTest
, AlreadyChecking
) {
3442 MockAppCacheService service
;
3443 scoped_refptr
<AppCacheGroup
> group(
3444 new AppCacheGroup(service
.storage(), GURL("http://manifesturl.com"),
3445 service
.storage()->NewGroupId()));
3447 AppCacheUpdateJob
update(&service
, group
.get());
3449 // Pretend group is in checking state.
3450 group
->update_job_
= &update
;
3451 group
->update_status_
= AppCacheGroup::CHECKING
;
3453 update
.StartUpdate(NULL
, GURL());
3454 EXPECT_EQ(AppCacheGroup::CHECKING
, group
->update_status());
3456 MockFrontend mock_frontend
;
3457 AppCacheHost
host(1, &mock_frontend
, &service
);
3458 update
.StartUpdate(&host
, GURL());
3460 MockFrontend::RaisedEvents events
= mock_frontend
.raised_events_
;
3461 size_t expected
= 1;
3462 EXPECT_EQ(expected
, events
.size());
3463 EXPECT_EQ(expected
, events
[0].first
.size());
3464 EXPECT_EQ(host
.host_id(), events
[0].first
[0]);
3465 EXPECT_EQ(APPCACHE_CHECKING_EVENT
, events
[0].second
);
3466 EXPECT_EQ(AppCacheGroup::CHECKING
, group
->update_status());
3469 TEST_F(AppCacheUpdateJobTest
, AlreadyDownloading
) {
3470 MockAppCacheService service
;
3471 scoped_refptr
<AppCacheGroup
> group(
3472 new AppCacheGroup(service
.storage(), GURL("http://manifesturl.com"),
3473 service
.storage()->NewGroupId()));
3475 AppCacheUpdateJob
update(&service
, group
.get());
3477 // Pretend group is in downloading state.
3478 group
->update_job_
= &update
;
3479 group
->update_status_
= AppCacheGroup::DOWNLOADING
;
3481 update
.StartUpdate(NULL
, GURL());
3482 EXPECT_EQ(AppCacheGroup::DOWNLOADING
, group
->update_status());
3484 MockFrontend mock_frontend
;
3485 AppCacheHost
host(1, &mock_frontend
, &service
);
3486 update
.StartUpdate(&host
, GURL());
3488 MockFrontend::RaisedEvents events
= mock_frontend
.raised_events_
;
3489 size_t expected
= 2;
3490 EXPECT_EQ(expected
, events
.size());
3492 EXPECT_EQ(expected
, events
[0].first
.size());
3493 EXPECT_EQ(host
.host_id(), events
[0].first
[0]);
3494 EXPECT_EQ(APPCACHE_CHECKING_EVENT
, events
[0].second
);
3496 EXPECT_EQ(expected
, events
[1].first
.size());
3497 EXPECT_EQ(host
.host_id(), events
[1].first
[0]);
3498 EXPECT_EQ(APPCACHE_DOWNLOADING_EVENT
, events
[1].second
);
3500 EXPECT_EQ(AppCacheGroup::DOWNLOADING
, group
->update_status());
3503 TEST_F(AppCacheUpdateJobTest
, StartCacheAttempt
) {
3504 RunTestOnIOThread(&AppCacheUpdateJobTest::StartCacheAttemptTest
);
3507 TEST_F(AppCacheUpdateJobTest
, StartUpgradeAttempt
) {
3508 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpgradeAttemptTest
);
3511 TEST_F(AppCacheUpdateJobTest
, CacheAttemptFetchManifestFail
) {
3512 RunTestOnIOThread(&AppCacheUpdateJobTest::CacheAttemptFetchManifestFailTest
);
3515 TEST_F(AppCacheUpdateJobTest
, UpgradeFetchManifestFail
) {
3516 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFetchManifestFailTest
);
3519 TEST_F(AppCacheUpdateJobTest
, ManifestRedirect
) {
3520 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest
);
3523 TEST_F(AppCacheUpdateJobTest
, ManifestMissingMimeTypeTest
) {
3524 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestMissingMimeTypeTest
);
3527 TEST_F(AppCacheUpdateJobTest
, ManifestNotFound
) {
3528 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestNotFoundTest
);
3531 TEST_F(AppCacheUpdateJobTest
, ManifestGone
) {
3532 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestGoneTest
);
3535 TEST_F(AppCacheUpdateJobTest
, CacheAttemptNotModified
) {
3536 RunTestOnIOThread(&AppCacheUpdateJobTest::CacheAttemptNotModifiedTest
);
3539 TEST_F(AppCacheUpdateJobTest
, UpgradeNotModified
) {
3540 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNotModifiedTest
);
3543 TEST_F(AppCacheUpdateJobTest
, UpgradeManifestDataUnchanged
) {
3544 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeManifestDataUnchangedTest
);
3547 TEST_F(AppCacheUpdateJobTest
, Bug95101Test
) {
3548 RunTestOnIOThread(&AppCacheUpdateJobTest::Bug95101Test
);
3551 TEST_F(AppCacheUpdateJobTest
, BasicCacheAttemptSuccess
) {
3552 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicCacheAttemptSuccessTest
);
3555 TEST_F(AppCacheUpdateJobTest
, DownloadInterceptEntriesTest
) {
3556 RunTestOnIOThread(&AppCacheUpdateJobTest::DownloadInterceptEntriesTest
);
3559 TEST_F(AppCacheUpdateJobTest
, BasicUpgradeSuccess
) {
3560 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicUpgradeSuccessTest
);
3563 TEST_F(AppCacheUpdateJobTest
, UpgradeLoadFromNewestCache
) {
3564 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeLoadFromNewestCacheTest
);
3567 TEST_F(AppCacheUpdateJobTest
, UpgradeNoLoadFromNewestCache
) {
3568 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNoLoadFromNewestCacheTest
);
3571 TEST_F(AppCacheUpdateJobTest
, UpgradeLoadFromNewestCacheVaryHeader
) {
3573 &AppCacheUpdateJobTest::UpgradeLoadFromNewestCacheVaryHeaderTest
);
3576 TEST_F(AppCacheUpdateJobTest
, UpgradeSuccessMergedTypes
) {
3577 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeSuccessMergedTypesTest
);
3580 TEST_F(AppCacheUpdateJobTest
, CacheAttemptFailUrlFetch
) {
3581 RunTestOnIOThread(&AppCacheUpdateJobTest::CacheAttemptFailUrlFetchTest
);
3584 TEST_F(AppCacheUpdateJobTest
, UpgradeFailUrlFetch
) {
3585 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailUrlFetchTest
);
3588 TEST_F(AppCacheUpdateJobTest
, UpgradeFailMasterUrlFetch
) {
3589 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailMasterUrlFetchTest
);
3592 TEST_F(AppCacheUpdateJobTest
, EmptyManifest
) {
3593 RunTestOnIOThread(&AppCacheUpdateJobTest::EmptyManifestTest
);
3596 TEST_F(AppCacheUpdateJobTest
, EmptyFile
) {
3597 RunTestOnIOThread(&AppCacheUpdateJobTest::EmptyFileTest
);
3600 TEST_F(AppCacheUpdateJobTest
, RetryRequest
) {
3601 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryRequestTest
);
3604 TEST_F(AppCacheUpdateJobTest
, RetryNoRetryAfter
) {
3605 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryNoRetryAfterTest
);
3608 TEST_F(AppCacheUpdateJobTest
, RetryNonzeroRetryAfter
) {
3609 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryNonzeroRetryAfterTest
);
3612 TEST_F(AppCacheUpdateJobTest
, RetrySuccess
) {
3613 RunTestOnIOThread(&AppCacheUpdateJobTest::RetrySuccessTest
);
3616 TEST_F(AppCacheUpdateJobTest
, RetryUrl
) {
3617 RunTestOnIOThread(&AppCacheUpdateJobTest::RetryUrlTest
);
3620 TEST_F(AppCacheUpdateJobTest
, FailStoreNewestCache
) {
3621 RunTestOnIOThread(&AppCacheUpdateJobTest::FailStoreNewestCacheTest
);
3624 TEST_F(AppCacheUpdateJobTest
, MasterEntryFailStoreNewestCacheTest
) {
3626 &AppCacheUpdateJobTest::MasterEntryFailStoreNewestCacheTest
);
3629 TEST_F(AppCacheUpdateJobTest
, UpgradeFailStoreNewestCache
) {
3630 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailStoreNewestCacheTest
);
3633 TEST_F(AppCacheUpdateJobTest
, UpgradeFailMakeGroupObsolete
) {
3634 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFailMakeGroupObsoleteTest
);
3637 TEST_F(AppCacheUpdateJobTest
, MasterEntryFetchManifestFail
) {
3638 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryFetchManifestFailTest
);
3641 TEST_F(AppCacheUpdateJobTest
, MasterEntryBadManifest
) {
3642 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryBadManifestTest
);
3645 TEST_F(AppCacheUpdateJobTest
, MasterEntryManifestNotFound
) {
3646 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryManifestNotFoundTest
);
3649 TEST_F(AppCacheUpdateJobTest
, MasterEntryFailUrlFetch
) {
3650 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryFailUrlFetchTest
);
3653 TEST_F(AppCacheUpdateJobTest
, MasterEntryAllFail
) {
3654 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryAllFailTest
);
3657 TEST_F(AppCacheUpdateJobTest
, UpgradeMasterEntryAllFail
) {
3658 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeMasterEntryAllFailTest
);
3661 TEST_F(AppCacheUpdateJobTest
, MasterEntrySomeFail
) {
3662 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntrySomeFailTest
);
3665 TEST_F(AppCacheUpdateJobTest
, UpgradeMasterEntrySomeFail
) {
3666 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeMasterEntrySomeFailTest
);
3669 TEST_F(AppCacheUpdateJobTest
, MasterEntryNoUpdate
) {
3670 RunTestOnIOThread(&AppCacheUpdateJobTest::MasterEntryNoUpdateTest
);
3673 TEST_F(AppCacheUpdateJobTest
, StartUpdateMidCacheAttempt
) {
3674 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpdateMidCacheAttemptTest
);
3677 TEST_F(AppCacheUpdateJobTest
, StartUpdateMidNoUpdate
) {
3678 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpdateMidNoUpdateTest
);
3681 TEST_F(AppCacheUpdateJobTest
, StartUpdateMidDownload
) {
3682 RunTestOnIOThread(&AppCacheUpdateJobTest::StartUpdateMidDownloadTest
);
3685 TEST_F(AppCacheUpdateJobTest
, QueueMasterEntry
) {
3686 RunTestOnIOThread(&AppCacheUpdateJobTest::QueueMasterEntryTest
);
3689 TEST_F(AppCacheUpdateJobTest
, IfModifiedSince
) {
3690 RunTestOnIOThread(&AppCacheUpdateJobTest::IfModifiedSinceTest
);
3693 TEST_F(AppCacheUpdateJobTest
, IfModifiedSinceUpgrade
) {
3694 RunTestOnIOThread(&AppCacheUpdateJobTest::IfModifiedSinceUpgradeTest
);
3697 TEST_F(AppCacheUpdateJobTest
, IfNoneMatchUpgrade
) {
3698 RunTestOnIOThread(&AppCacheUpdateJobTest::IfNoneMatchUpgradeTest
);
3701 TEST_F(AppCacheUpdateJobTest
, IfNoneMatchRefetch
) {
3702 RunTestOnIOThread(&AppCacheUpdateJobTest::IfNoneMatchRefetchTest
);
3705 TEST_F(AppCacheUpdateJobTest
, MultipleHeadersRefetch
) {
3706 RunTestOnIOThread(&AppCacheUpdateJobTest::MultipleHeadersRefetchTest
);
3709 TEST_F(AppCacheUpdateJobTest
, CrossOriginHttpsSuccess
) {
3710 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest
);
3713 TEST_F(AppCacheUpdateJobTest
, CrossOriginHttpsDenied
) {
3714 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest
);
3717 } // namespace content