OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/fileapi/mock_url_request_delegate.h" | 9 #include "content/browser/fileapi/mock_url_request_delegate.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() OVERRIDE { |
38 helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); | 38 helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); |
39 | 39 |
40 // A new unstored registration/version. | 40 // A new unstored registration/version. |
41 scope_ = GURL("http://host/scope/"); | 41 scope_ = GURL("http://host/scope/"); |
42 script_url_ = GURL("http://host/script.js"); | 42 script_url_ = GURL("http://host/script.js"); |
43 registration_ = new ServiceWorkerRegistration( | 43 registration_ = new ServiceWorkerRegistration( |
44 scope_, script_url_, 1L, context()->AsWeakPtr()); | 44 scope_, script_url_, 1L, context()->AsWeakPtr()); |
45 version_ = new ServiceWorkerVersion( | 45 version_ = new ServiceWorkerVersion( |
46 registration_, | 46 registration_.get(), 1L, context()->AsWeakPtr()); |
47 1L, context()->AsWeakPtr()); | |
48 | 47 |
49 // An empty host. | 48 // An empty host. |
50 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 49 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
51 kMockRenderProcessId, 1 /* provider_id */, | 50 kMockRenderProcessId, 1 /* provider_id */, |
52 context()->AsWeakPtr(), NULL)); | 51 context()->AsWeakPtr(), NULL)); |
53 provider_host_ = host->AsWeakPtr(); | 52 provider_host_ = host->AsWeakPtr(); |
54 context()->AddProviderHost(host.Pass()); | 53 context()->AddProviderHost(host.Pass()); |
55 | 54 |
56 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 55 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
57 base::RunLoop().RunUntilIdle(); | 56 base::RunLoop().RunUntilIdle(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 &url_request_delegate_, | 91 &url_request_delegate_, |
93 NULL); | 92 NULL); |
94 scoped_ptr<ServiceWorkerContextRequestHandler> handler( | 93 scoped_ptr<ServiceWorkerContextRequestHandler> handler( |
95 new ServiceWorkerContextRequestHandler( | 94 new ServiceWorkerContextRequestHandler( |
96 context()->AsWeakPtr(), | 95 context()->AsWeakPtr(), |
97 provider_host_, | 96 provider_host_, |
98 base::WeakPtr<storage::BlobStorageContext>(), | 97 base::WeakPtr<storage::BlobStorageContext>(), |
99 RESOURCE_TYPE_SERVICE_WORKER)); | 98 RESOURCE_TYPE_SERVICE_WORKER)); |
100 scoped_refptr<net::URLRequestJob> job = | 99 scoped_refptr<net::URLRequestJob> job = |
101 handler->MaybeCreateJob(request.get(), NULL); | 100 handler->MaybeCreateJob(request.get(), NULL); |
102 ASSERT_TRUE(job); | 101 ASSERT_TRUE(job.get()); |
103 ServiceWorkerWriteToCacheJob* sw_job = | 102 ServiceWorkerWriteToCacheJob* sw_job = |
104 static_cast<ServiceWorkerWriteToCacheJob*>(job.get()); | 103 static_cast<ServiceWorkerWriteToCacheJob*>(job.get()); |
105 | 104 |
106 // Verify the net request is not initialized to bypass the browser cache. | 105 // Verify the net request is not initialized to bypass the browser cache. |
107 EXPECT_FALSE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE); | 106 EXPECT_FALSE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE); |
108 } | 107 } |
109 | 108 |
110 TEST_F(ServiceWorkerContextRequestHandlerTest, UpdateAfter24Hours) { | 109 TEST_F(ServiceWorkerContextRequestHandlerTest, UpdateAfter24Hours) { |
111 // Give the registration a old update time and pretend | 110 // Give the registration a old update time and pretend |
112 // we're installing a new version. | 111 // we're installing a new version. |
(...skipping 10 matching lines...) Expand all Loading... |
123 &url_request_delegate_, | 122 &url_request_delegate_, |
124 NULL); | 123 NULL); |
125 scoped_ptr<ServiceWorkerContextRequestHandler> handler( | 124 scoped_ptr<ServiceWorkerContextRequestHandler> handler( |
126 new ServiceWorkerContextRequestHandler( | 125 new ServiceWorkerContextRequestHandler( |
127 context()->AsWeakPtr(), | 126 context()->AsWeakPtr(), |
128 provider_host_, | 127 provider_host_, |
129 base::WeakPtr<storage::BlobStorageContext>(), | 128 base::WeakPtr<storage::BlobStorageContext>(), |
130 RESOURCE_TYPE_SERVICE_WORKER)); | 129 RESOURCE_TYPE_SERVICE_WORKER)); |
131 scoped_refptr<net::URLRequestJob> job = | 130 scoped_refptr<net::URLRequestJob> job = |
132 handler->MaybeCreateJob(request.get(), NULL); | 131 handler->MaybeCreateJob(request.get(), NULL); |
133 ASSERT_TRUE(job); | 132 ASSERT_TRUE(job.get()); |
134 ServiceWorkerWriteToCacheJob* sw_job = | 133 ServiceWorkerWriteToCacheJob* sw_job = |
135 static_cast<ServiceWorkerWriteToCacheJob*>(job.get()); | 134 static_cast<ServiceWorkerWriteToCacheJob*>(job.get()); |
136 | 135 |
137 // Verify the net request is initialized to bypass the browser cache. | 136 // Verify the net request is initialized to bypass the browser cache. |
138 EXPECT_TRUE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE); | 137 EXPECT_TRUE(sw_job->net_request_->load_flags() & net::LOAD_BYPASS_CACHE); |
139 } | 138 } |
140 | 139 |
141 } // namespace content | 140 } // namespace content |
OLD | NEW |