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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 public: | 153 public: |
154 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) | 154 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) |
155 : context_(context) {} | 155 : context_(context) {} |
156 void Init() { | 156 void Init() { |
157 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); | 157 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); |
158 } | 158 } |
159 // ServiceWorkerContextObserver overrides. | 159 // ServiceWorkerContextObserver overrides. |
160 void OnVersionStateChanged(int64 version_id, | 160 void OnVersionStateChanged(int64 version_id, |
161 ServiceWorkerVersion::Status) override { | 161 ServiceWorkerVersion::Status) override { |
162 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
163 const ServiceWorkerVersion* version = | 163 const ServiceWorkerVersion* version = context_->GetLiveVersion(version_id); |
164 context_->context()->GetLiveVersion(version_id); | |
165 if (version->status() == ServiceWorkerVersion::ACTIVATED) { | 164 if (version->status() == ServiceWorkerVersion::ACTIVATED) { |
166 context_->RemoveObserver(this); | 165 context_->RemoveObserver(this); |
167 BrowserThread::PostTask(BrowserThread::UI, | 166 BrowserThread::PostTask(BrowserThread::UI, |
168 FROM_HERE, | 167 FROM_HERE, |
169 base::Bind(&WorkerActivatedObserver::Quit, this)); | 168 base::Bind(&WorkerActivatedObserver::Quit, this)); |
170 } | 169 } |
171 } | 170 } |
172 void Wait() { run_loop_.Run(); } | 171 void Wait() { run_loop_.Run(); } |
173 | 172 |
174 private: | 173 private: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 import_url, interceptor.Pass()); | 241 import_url, interceptor.Pass()); |
243 } | 242 } |
244 | 243 |
245 void CountScriptResources( | 244 void CountScriptResources( |
246 ServiceWorkerContextWrapper* wrapper, | 245 ServiceWorkerContextWrapper* wrapper, |
247 const GURL& scope, | 246 const GURL& scope, |
248 int* num_resources) { | 247 int* num_resources) { |
249 *num_resources = -1; | 248 *num_resources = -1; |
250 | 249 |
251 std::vector<ServiceWorkerRegistrationInfo> infos = | 250 std::vector<ServiceWorkerRegistrationInfo> infos = |
252 wrapper->context()->GetAllLiveRegistrationInfo(); | 251 wrapper->GetAllLiveRegistrationInfo(); |
253 if (infos.empty()) | 252 if (infos.empty()) |
254 return; | 253 return; |
255 | 254 |
256 int version_id; | 255 int version_id; |
257 size_t index = infos.size() - 1; | 256 size_t index = infos.size() - 1; |
258 if (infos[index].installing_version.version_id != | 257 if (infos[index].installing_version.version_id != |
259 kInvalidServiceWorkerVersionId) | 258 kInvalidServiceWorkerVersionId) |
260 version_id = infos[index].installing_version.version_id; | 259 version_id = infos[index].installing_version.version_id; |
261 else if (infos[index].waiting_version.version_id != | 260 else if (infos[index].waiting_version.version_id != |
262 kInvalidServiceWorkerVersionId) | 261 kInvalidServiceWorkerVersionId) |
263 version_id = infos[1].waiting_version.version_id; | 262 version_id = infos[1].waiting_version.version_id; |
264 else if (infos[index].active_version.version_id != | 263 else if (infos[index].active_version.version_id != |
265 kInvalidServiceWorkerVersionId) | 264 kInvalidServiceWorkerVersionId) |
266 version_id = infos[index].active_version.version_id; | 265 version_id = infos[index].active_version.version_id; |
267 else | 266 else |
268 return; | 267 return; |
269 | 268 |
270 ServiceWorkerVersion* version = | 269 ServiceWorkerVersion* version = wrapper->GetLiveVersion(version_id); |
271 wrapper->context()->GetLiveVersion(version_id); | |
272 *num_resources = static_cast<int>(version->script_cache_map()->size()); | 270 *num_resources = static_cast<int>(version->script_cache_map()->size()); |
273 } | 271 } |
274 | 272 |
275 } // namespace | 273 } // namespace |
276 | 274 |
277 class ServiceWorkerBrowserTest : public ContentBrowserTest { | 275 class ServiceWorkerBrowserTest : public ContentBrowserTest { |
278 protected: | 276 protected: |
279 using self = ServiceWorkerBrowserTest; | 277 using self = ServiceWorkerBrowserTest; |
280 | 278 |
281 void SetUpCommandLine(base::CommandLine* command_line) override { | 279 void SetUpCommandLine(base::CommandLine* command_line) override { |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 EXPECT_EQ(kExpectedNumResources, num_resources); | 1088 EXPECT_EQ(kExpectedNumResources, num_resources); |
1091 } | 1089 } |
1092 | 1090 |
1093 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { | 1091 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { |
1094 public: | 1092 public: |
1095 using self = ServiceWorkerBlackBoxBrowserTest; | 1093 using self = ServiceWorkerBlackBoxBrowserTest; |
1096 | 1094 |
1097 void FindRegistrationOnIO(const GURL& document_url, | 1095 void FindRegistrationOnIO(const GURL& document_url, |
1098 ServiceWorkerStatusCode* status, | 1096 ServiceWorkerStatusCode* status, |
1099 const base::Closure& continuation) { | 1097 const base::Closure& continuation) { |
1100 wrapper()->context()->storage()->FindRegistrationForDocument( | 1098 wrapper()->FindRegistrationForDocument( |
1101 document_url, | 1099 document_url, |
1102 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, | 1100 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, |
1103 this, | 1101 this, status, continuation)); |
1104 status, | |
1105 continuation)); | |
1106 } | 1102 } |
1107 | 1103 |
1108 void FindRegistrationOnIO2( | 1104 void FindRegistrationOnIO2( |
1109 ServiceWorkerStatusCode* out_status, | 1105 ServiceWorkerStatusCode* out_status, |
1110 const base::Closure& continuation, | 1106 const base::Closure& continuation, |
1111 ServiceWorkerStatusCode status, | 1107 ServiceWorkerStatusCode status, |
1112 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 1108 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
1113 *out_status = status; | 1109 *out_status = status; |
1114 if (!registration.get()) | 1110 if (!registration.get()) |
1115 EXPECT_NE(SERVICE_WORKER_OK, status); | 1111 EXPECT_NE(SERVICE_WORKER_OK, status); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1286 ASSERT_EQ(SERVICE_WORKER_OK, status); |
1291 // Stop the worker. | 1287 // Stop the worker. |
1292 StopWorker(SERVICE_WORKER_OK); | 1288 StopWorker(SERVICE_WORKER_OK); |
1293 // Restart the worker. | 1289 // Restart the worker. |
1294 StartWorker(SERVICE_WORKER_OK); | 1290 StartWorker(SERVICE_WORKER_OK); |
1295 // Stop the worker. | 1291 // Stop the worker. |
1296 StopWorker(SERVICE_WORKER_OK); | 1292 StopWorker(SERVICE_WORKER_OK); |
1297 } | 1293 } |
1298 | 1294 |
1299 } // namespace content | 1295 } // namespace content |
OLD | NEW |