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

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

Issue 435873002: ServiceWorker: Remove wildcard from scope matching (Chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/public/browser/service_worker_context.h" 5 #include "content/public/browser/service_worker_context.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 scoped_ptr<EmbeddedWorkerTestHelper> helper_; 135 scoped_ptr<EmbeddedWorkerTestHelper> helper_;
136 const int render_process_id_; 136 const int render_process_id_;
137 }; 137 };
138 138
139 // Make sure basic registration is working. 139 // Make sure basic registration is working.
140 TEST_F(ServiceWorkerContextTest, Register) { 140 TEST_F(ServiceWorkerContextTest, Register) {
141 int64 registration_id = kInvalidServiceWorkerRegistrationId; 141 int64 registration_id = kInvalidServiceWorkerRegistrationId;
142 int64 version_id = kInvalidServiceWorkerVersionId; 142 int64 version_id = kInvalidServiceWorkerVersionId;
143 bool called = false; 143 bool called = false;
144 context()->RegisterServiceWorker( 144 context()->RegisterServiceWorker(
145 GURL("http://www.example.com/*"), 145 GURL("http://www.example.com/"),
146 GURL("http://www.example.com/service_worker.js"), 146 GURL("http://www.example.com/service_worker.js"),
147 render_process_id_, 147 render_process_id_,
148 NULL, 148 NULL,
149 MakeRegisteredCallback(&called, &registration_id, &version_id)); 149 MakeRegisteredCallback(&called, &registration_id, &version_id));
150 150
151 ASSERT_FALSE(called); 151 ASSERT_FALSE(called);
152 base::RunLoop().RunUntilIdle(); 152 base::RunLoop().RunUntilIdle();
153 EXPECT_TRUE(called); 153 EXPECT_TRUE(called);
154 154
155 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); 155 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
(...skipping 22 matching lines...) Expand all
178 // Test registration when the service worker rejects the install event. The 178 // Test registration when the service worker rejects the install event. The
179 // registration callback should indicate success, but there should be no waiting 179 // registration callback should indicate success, but there should be no waiting
180 // or active worker in the registration. 180 // or active worker in the registration.
181 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { 181 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
182 helper_.reset(); // Make sure the process lookups stay overridden. 182 helper_.reset(); // Make sure the process lookups stay overridden.
183 helper_.reset(new RejectInstallTestHelper(render_process_id_)); 183 helper_.reset(new RejectInstallTestHelper(render_process_id_));
184 int64 registration_id = kInvalidServiceWorkerRegistrationId; 184 int64 registration_id = kInvalidServiceWorkerRegistrationId;
185 int64 version_id = kInvalidServiceWorkerVersionId; 185 int64 version_id = kInvalidServiceWorkerVersionId;
186 bool called = false; 186 bool called = false;
187 context()->RegisterServiceWorker( 187 context()->RegisterServiceWorker(
188 GURL("http://www.example.com/*"), 188 GURL("http://www.example.com/"),
189 GURL("http://www.example.com/service_worker.js"), 189 GURL("http://www.example.com/service_worker.js"),
190 render_process_id_, 190 render_process_id_,
191 NULL, 191 NULL,
192 MakeRegisteredCallback(&called, &registration_id, &version_id)); 192 MakeRegisteredCallback(&called, &registration_id, &version_id));
193 193
194 ASSERT_FALSE(called); 194 ASSERT_FALSE(called);
195 base::RunLoop().RunUntilIdle(); 195 base::RunLoop().RunUntilIdle();
196 EXPECT_TRUE(called); 196 EXPECT_TRUE(called);
197 197
198 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); 198 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count());
(...skipping 22 matching lines...) Expand all
221 // Test registration when the service worker rejects the activate event. The 221 // Test registration when the service worker rejects the activate event. The
222 // registration callback should indicate success, but there should be no waiting 222 // registration callback should indicate success, but there should be no waiting
223 // or active worker in the registration. 223 // or active worker in the registration.
224 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { 224 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
225 helper_.reset(); // Make sure the process lookups stay overridden. 225 helper_.reset(); // Make sure the process lookups stay overridden.
226 helper_.reset(new RejectActivateTestHelper(render_process_id_)); 226 helper_.reset(new RejectActivateTestHelper(render_process_id_));
227 int64 registration_id = kInvalidServiceWorkerRegistrationId; 227 int64 registration_id = kInvalidServiceWorkerRegistrationId;
228 int64 version_id = kInvalidServiceWorkerVersionId; 228 int64 version_id = kInvalidServiceWorkerVersionId;
229 bool called = false; 229 bool called = false;
230 context()->RegisterServiceWorker( 230 context()->RegisterServiceWorker(
231 GURL("http://www.example.com/*"), 231 GURL("http://www.example.com/"),
232 GURL("http://www.example.com/service_worker.js"), 232 GURL("http://www.example.com/service_worker.js"),
233 render_process_id_, 233 render_process_id_,
234 NULL, 234 NULL,
235 MakeRegisteredCallback(&called, &registration_id, &version_id)); 235 MakeRegisteredCallback(&called, &registration_id, &version_id));
236 236
237 ASSERT_FALSE(called); 237 ASSERT_FALSE(called);
238 base::RunLoop().RunUntilIdle(); 238 base::RunLoop().RunUntilIdle();
239 EXPECT_TRUE(called); 239 EXPECT_TRUE(called);
240 240
241 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); 241 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
(...skipping 14 matching lines...) Expand all
256 base::Bind(&ExpectRegisteredWorkers, 256 base::Bind(&ExpectRegisteredWorkers,
257 SERVICE_WORKER_ERROR_NOT_FOUND, 257 SERVICE_WORKER_ERROR_NOT_FOUND,
258 kInvalidServiceWorkerVersionId, 258 kInvalidServiceWorkerVersionId,
259 false /* expect_waiting */, 259 false /* expect_waiting */,
260 false /* expect_active */)); 260 false /* expect_active */));
261 base::RunLoop().RunUntilIdle(); 261 base::RunLoop().RunUntilIdle();
262 } 262 }
263 263
264 // Make sure registrations are cleaned up when they are unregistered. 264 // Make sure registrations are cleaned up when they are unregistered.
265 TEST_F(ServiceWorkerContextTest, Unregister) { 265 TEST_F(ServiceWorkerContextTest, Unregister) {
266 GURL pattern("http://www.example.com/*"); 266 GURL pattern("http://www.example.com/");
267 267
268 bool called = false; 268 bool called = false;
269 int64 registration_id = kInvalidServiceWorkerRegistrationId; 269 int64 registration_id = kInvalidServiceWorkerRegistrationId;
270 int64 version_id = kInvalidServiceWorkerVersionId; 270 int64 version_id = kInvalidServiceWorkerVersionId;
271 context()->RegisterServiceWorker( 271 context()->RegisterServiceWorker(
272 pattern, 272 pattern,
273 GURL("http://www.example.com/service_worker.js"), 273 GURL("http://www.example.com/service_worker.js"),
274 render_process_id_, 274 render_process_id_,
275 NULL, 275 NULL,
276 MakeRegisteredCallback(&called, &registration_id, &version_id)); 276 MakeRegisteredCallback(&called, &registration_id, &version_id));
(...skipping 19 matching lines...) Expand all
296 SERVICE_WORKER_ERROR_NOT_FOUND, 296 SERVICE_WORKER_ERROR_NOT_FOUND,
297 kInvalidServiceWorkerVersionId, 297 kInvalidServiceWorkerVersionId,
298 false /* expect_waiting */, 298 false /* expect_waiting */,
299 false /* expect_active */)); 299 false /* expect_active */));
300 base::RunLoop().RunUntilIdle(); 300 base::RunLoop().RunUntilIdle();
301 } 301 }
302 302
303 // Make sure that when a new registration replaces an existing 303 // Make sure that when a new registration replaces an existing
304 // registration, that the old one is cleaned up. 304 // registration, that the old one is cleaned up.
305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
306 GURL pattern("http://www.example.com/*"); 306 GURL pattern("http://www.example.com/");
307 307
308 bool called = false; 308 bool called = false;
309 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 309 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
310 int64 old_version_id = kInvalidServiceWorkerVersionId; 310 int64 old_version_id = kInvalidServiceWorkerVersionId;
311 context()->RegisterServiceWorker( 311 context()->RegisterServiceWorker(
312 pattern, 312 pattern,
313 GURL("http://www.example.com/service_worker.js"), 313 GURL("http://www.example.com/service_worker.js"),
314 render_process_id_, 314 render_process_id_,
315 NULL, 315 NULL,
316 MakeRegisteredCallback(&called, &old_registration_id, &old_version_id)); 316 MakeRegisteredCallback(&called, &old_registration_id, &old_version_id));
(...skipping 22 matching lines...) Expand all
339 // returned for the previous registration. 339 // returned for the previous registration.
340 EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id); 340 EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id);
341 EXPECT_NE(kInvalidServiceWorkerVersionId, new_version_id); 341 EXPECT_NE(kInvalidServiceWorkerVersionId, new_version_id);
342 EXPECT_NE(old_registration_id, new_registration_id); 342 EXPECT_NE(old_registration_id, new_registration_id);
343 EXPECT_NE(old_version_id, new_version_id); 343 EXPECT_NE(old_version_id, new_version_id);
344 } 344 }
345 345
346 // Make sure that when registering a duplicate pattern+script_url 346 // Make sure that when registering a duplicate pattern+script_url
347 // combination, that the same registration is used. 347 // combination, that the same registration is used.
348 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { 348 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
349 GURL pattern("http://www.example.com/*"); 349 GURL pattern("http://www.example.com/");
350 GURL script_url("http://www.example.com/service_worker.js"); 350 GURL script_url("http://www.example.com/service_worker.js");
351 351
352 bool called = false; 352 bool called = false;
353 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 353 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
354 int64 old_version_id = kInvalidServiceWorkerVersionId; 354 int64 old_version_id = kInvalidServiceWorkerVersionId;
355 context()->RegisterServiceWorker( 355 context()->RegisterServiceWorker(
356 pattern, 356 pattern,
357 script_url, 357 script_url,
358 render_process_id_, 358 render_process_id_,
359 NULL, 359 NULL,
(...skipping 21 matching lines...) Expand all
381 EXPECT_EQ(old_registration_id, new_registration_id); 381 EXPECT_EQ(old_registration_id, new_registration_id);
382 EXPECT_EQ(old_version_id, new_version_id); 382 EXPECT_EQ(old_version_id, new_version_id);
383 } 383 }
384 384
385 // TODO(nhiroki): Test this for on-disk storage. 385 // TODO(nhiroki): Test this for on-disk storage.
386 TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) { 386 TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) {
387 int64 registration_id = kInvalidServiceWorkerRegistrationId; 387 int64 registration_id = kInvalidServiceWorkerRegistrationId;
388 int64 version_id = kInvalidServiceWorkerVersionId; 388 int64 version_id = kInvalidServiceWorkerVersionId;
389 bool called = false; 389 bool called = false;
390 context()->RegisterServiceWorker( 390 context()->RegisterServiceWorker(
391 GURL("http://www.example.com/*"), 391 GURL("http://www.example.com/"),
392 GURL("http://www.example.com/service_worker.js"), 392 GURL("http://www.example.com/service_worker.js"),
393 render_process_id_, 393 render_process_id_,
394 NULL, 394 NULL,
395 MakeRegisteredCallback(&called, &registration_id, &version_id)); 395 MakeRegisteredCallback(&called, &registration_id, &version_id));
396 396
397 ASSERT_FALSE(called); 397 ASSERT_FALSE(called);
398 base::RunLoop().RunUntilIdle(); 398 base::RunLoop().RunUntilIdle();
399 EXPECT_TRUE(called); 399 EXPECT_TRUE(called);
400 400
401 context()->storage()->FindRegistrationForId( 401 context()->storage()->FindRegistrationForId(
(...skipping 27 matching lines...) Expand all
429 GURL("http://www.example.com"), 429 GURL("http://www.example.com"),
430 base::Bind(&ExpectRegisteredWorkers, 430 base::Bind(&ExpectRegisteredWorkers,
431 SERVICE_WORKER_ERROR_NOT_FOUND, 431 SERVICE_WORKER_ERROR_NOT_FOUND,
432 version_id, 432 version_id,
433 false /* expect_waiting */, 433 false /* expect_waiting */,
434 true /* expect_active */)); 434 true /* expect_active */));
435 base::RunLoop().RunUntilIdle(); 435 base::RunLoop().RunUntilIdle();
436 436
437 called = false; 437 called = false;
438 context()->RegisterServiceWorker( 438 context()->RegisterServiceWorker(
439 GURL("http://www.example.com/*"), 439 GURL("http://www.example.com/"),
440 GURL("http://www.example.com/service_worker.js"), 440 GURL("http://www.example.com/service_worker.js"),
441 render_process_id_, 441 render_process_id_,
442 NULL, 442 NULL,
443 MakeRegisteredCallback(&called, &registration_id, &version_id)); 443 MakeRegisteredCallback(&called, &registration_id, &version_id));
444 444
445 ASSERT_FALSE(called); 445 ASSERT_FALSE(called);
446 base::RunLoop().RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
447 EXPECT_TRUE(called); 447 EXPECT_TRUE(called);
448 448
449 context()->storage()->FindRegistrationForId( 449 context()->storage()->FindRegistrationForId(
450 registration_id, 450 registration_id,
451 GURL("http://www.example.com"), 451 GURL("http://www.example.com"),
452 base::Bind(&ExpectRegisteredWorkers, 452 base::Bind(&ExpectRegisteredWorkers,
453 SERVICE_WORKER_OK, 453 SERVICE_WORKER_OK,
454 version_id, 454 version_id,
455 false /* expect_waiting */, 455 false /* expect_waiting */,
456 true /* expect_active */)); 456 true /* expect_active */));
457 base::RunLoop().RunUntilIdle(); 457 base::RunLoop().RunUntilIdle();
458 } 458 }
459 459
460 } // namespace content 460 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698