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

Side by Side Diff: content/browser/service_worker/embedded_worker_test_helper.cc

Issue 1135743002: Check the size of ResourceRecords in ServiceWorkerDatabase::ReadRegistration() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added check logic in ServiceWorkerStorage and updated tests. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/embedded_worker_test_helper.h" 5 #include "content/browser/service_worker/embedded_worker_test_helper.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 wrapper_->Shutdown(); 84 wrapper_->Shutdown();
85 wrapper_ = NULL; 85 wrapper_ = NULL;
86 } 86 }
87 87
88 void EmbeddedWorkerTestHelper::OnStartWorker( 88 void EmbeddedWorkerTestHelper::OnStartWorker(
89 int embedded_worker_id, 89 int embedded_worker_id,
90 int64 service_worker_version_id, 90 int64 service_worker_version_id,
91 const GURL& scope, 91 const GURL& scope,
92 const GURL& script_url, 92 const GURL& script_url,
93 bool pause_after_download) { 93 bool pause_after_download) {
94 embedded_worker_id_service_worker_version_id_map_[embedded_worker_id] =
95 service_worker_version_id;
94 if (pause_after_download) { 96 if (pause_after_download) {
95 SimulatePausedAfterDownload(embedded_worker_id); 97 SimulatePausedAfterDownload(embedded_worker_id);
96 return; 98 return;
97 } 99 }
98 SimulateWorkerReadyForInspection(embedded_worker_id); 100 SimulateWorkerReadyForInspection(embedded_worker_id);
101 SimulateLoadWorkerMainScript(embedded_worker_id);
99 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); 102 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id);
100 SimulateWorkerScriptEvaluated(embedded_worker_id); 103 SimulateWorkerScriptEvaluated(embedded_worker_id);
101 SimulateWorkerStarted(embedded_worker_id); 104 SimulateWorkerStarted(embedded_worker_id);
102 } 105 }
103 106
104 void EmbeddedWorkerTestHelper::OnResumeAfterDownload(int embedded_worker_id) { 107 void EmbeddedWorkerTestHelper::OnResumeAfterDownload(int embedded_worker_id) {
105 SimulateWorkerReadyForInspection(embedded_worker_id); 108 SimulateWorkerReadyForInspection(embedded_worker_id);
109 SimulateLoadWorkerMainScript(embedded_worker_id);
106 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); 110 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id);
107 SimulateWorkerScriptEvaluated(embedded_worker_id); 111 SimulateWorkerScriptEvaluated(embedded_worker_id);
108 SimulateWorkerStarted(embedded_worker_id); 112 SimulateWorkerStarted(embedded_worker_id);
109 } 113 }
110 114
111 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { 115 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) {
112 // By default just notify the sender that the worker is stopped. 116 // By default just notify the sender that the worker is stopped.
113 SimulateWorkerStopped(embedded_worker_id); 117 SimulateWorkerStopped(embedded_worker_id);
114 } 118 }
115 119
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 179 }
176 180
177 void EmbeddedWorkerTestHelper::SimulateWorkerReadyForInspection( 181 void EmbeddedWorkerTestHelper::SimulateWorkerReadyForInspection(
178 int embedded_worker_id) { 182 int embedded_worker_id) {
179 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 183 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
180 ASSERT_TRUE(worker != NULL); 184 ASSERT_TRUE(worker != NULL);
181 registry()->OnWorkerReadyForInspection(worker->process_id(), 185 registry()->OnWorkerReadyForInspection(worker->process_id(),
182 embedded_worker_id); 186 embedded_worker_id);
183 } 187 }
184 188
189 void EmbeddedWorkerTestHelper::SimulateLoadWorkerMainScript(
190 int embedded_worker_id) {
191 int64 version_id =
192 embedded_worker_id_service_worker_version_id_map_[embedded_worker_id];
193 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id);
194 if (!version || version->script_cache_map()->size())
195 return;
196 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
197 // Add a dymmy ResourceRecord for the main script to the script cache map of
198 // the ServiceWorkerVersion. We use embedded_worker_id for resource_id to
199 // avoid ID corraption.
nhiroki 2015/05/11 05:46:04 nit: dymmy -> dummy, corraption -> corruption (or
horo 2015/05/11 07:41:30 Done.
200 records.push_back(ServiceWorkerDatabase::ResourceRecord(
201 embedded_worker_id, version->script_url(), 100));
202 version->script_cache_map()->SetResources(records);
203 }
204
185 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( 205 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded(
186 int thread_id, int embedded_worker_id) { 206 int thread_id, int embedded_worker_id) {
187 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 207 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
188 ASSERT_TRUE(worker != NULL); 208 ASSERT_TRUE(worker != NULL);
189 registry()->OnWorkerScriptLoaded( 209 registry()->OnWorkerScriptLoaded(
190 worker->process_id(), thread_id, embedded_worker_id); 210 worker->process_id(), thread_id, embedded_worker_id);
191 } 211 }
192 212
193 void EmbeddedWorkerTestHelper::SimulateWorkerScriptEvaluated( 213 void EmbeddedWorkerTestHelper::SimulateWorkerScriptEvaluated(
194 int embedded_worker_id) { 214 int embedded_worker_id) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 request_id, 324 request_id,
305 request)); 325 request));
306 } 326 }
307 327
308 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { 328 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() {
309 DCHECK(context()); 329 DCHECK(context());
310 return context()->embedded_worker_registry(); 330 return context()->embedded_worker_registry();
311 } 331 }
312 332
313 } // namespace content 333 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698