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

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

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/link_header_support.h" 5 #include "content/browser/service_worker/link_header_support.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/browser/loader/resource_request_info_impl.h" 10 #include "content/browser/loader/resource_request_info_impl.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 provider_host()->provider_id()) 185 provider_host()->provider_id())
186 .get(), 186 .get(),
187 "<../foo.js>; rel=serviceworker", context_wrapper()); 187 "<../foo.js>; rel=serviceworker", context_wrapper());
188 base::RunLoop().RunUntilIdle(); 188 base::RunLoop().RunUntilIdle();
189 189
190 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 190 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
191 ASSERT_EQ(1u, registrations.size()); 191 ASSERT_EQ(1u, registrations.size());
192 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); 192 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern);
193 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), 193 EXPECT_EQ(GURL("https://example.com/foo/foo.js"),
194 registrations[0].active_version.script_url); 194 registrations[0].active_version.script_url);
195 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
196 registrations[0].update_via_cache);
195 } 197 }
196 198
197 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) { 199 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeWithFragment) {
198 CreateDocumentProviderHost(); 200 CreateDocumentProviderHost();
199 ProcessLinkHeaderForRequest( 201 ProcessLinkHeaderForRequest(
200 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"), 202 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"),
201 provider_host()->provider_id()) 203 provider_host()->provider_id())
202 .get(), 204 .get(),
203 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper()); 205 "<../bar.js>; rel=serviceworker; scope=\"scope#ref\"", context_wrapper());
204 base::RunLoop().RunUntilIdle(); 206 base::RunLoop().RunUntilIdle();
205 207
206 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 208 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
207 ASSERT_EQ(1u, registrations.size()); 209 ASSERT_EQ(1u, registrations.size());
208 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), 210 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"),
209 registrations[0].pattern); 211 registrations[0].pattern);
210 EXPECT_EQ(GURL("https://example.com/foo/bar.js"), 212 EXPECT_EQ(GURL("https://example.com/foo/bar.js"),
211 registrations[0].active_version.script_url); 213 registrations[0].active_version.script_url);
214 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
215 registrations[0].update_via_cache);
212 } 216 }
213 217
214 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) { 218 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeAbsoluteUrl) {
215 CreateDocumentProviderHost(); 219 CreateDocumentProviderHost();
216 ProcessLinkHeaderForRequest( 220 ProcessLinkHeaderForRequest(
217 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"), 221 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"),
218 provider_host()->provider_id()) 222 provider_host()->provider_id())
219 .get(), 223 .get(),
220 "<bar.js>; rel=serviceworker; " 224 "<bar.js>; rel=serviceworker; "
221 "scope=\"https://example.com:443/foo/bar/scope\"", 225 "scope=\"https://example.com:443/foo/bar/scope\"",
222 context_wrapper()); 226 context_wrapper());
223 base::RunLoop().RunUntilIdle(); 227 base::RunLoop().RunUntilIdle();
224 228
225 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 229 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
226 ASSERT_EQ(1u, registrations.size()); 230 ASSERT_EQ(1u, registrations.size());
227 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"), 231 EXPECT_EQ(GURL("https://example.com/foo/bar/scope"),
228 registrations[0].pattern); 232 registrations[0].pattern);
229 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"), 233 EXPECT_EQ(GURL("https://example.com/foo/bar/bar.js"),
230 registrations[0].active_version.script_url); 234 registrations[0].active_version.script_url);
235 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
236 registrations[0].update_via_cache);
231 } 237 }
232 238
233 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) { 239 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_ScopeDifferentOrigin) {
234 CreateDocumentProviderHost(); 240 CreateDocumentProviderHost();
235 ProcessLinkHeaderForRequest( 241 ProcessLinkHeaderForRequest(
236 CreateSubresourceRequest(GURL("https://example.com/foobar/"), 242 CreateSubresourceRequest(GURL("https://example.com/foobar/"),
237 provider_host()->provider_id()) 243 provider_host()->provider_id())
238 .get(), 244 .get(),
239 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"", 245 "<bar.js>; rel=serviceworker; scope=\"https://google.com/scope\"",
240 context_wrapper()); 246 context_wrapper());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 .get(), 285 .get(),
280 "<https://example.com/bar.js>; rel=serviceworker; scope=foo", 286 "<https://example.com/bar.js>; rel=serviceworker; scope=foo",
281 context_wrapper()); 287 context_wrapper());
282 base::RunLoop().RunUntilIdle(); 288 base::RunLoop().RunUntilIdle();
283 289
284 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 290 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
285 ASSERT_EQ(1u, registrations.size()); 291 ASSERT_EQ(1u, registrations.size());
286 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); 292 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern);
287 EXPECT_EQ(GURL("https://example.com/bar.js"), 293 EXPECT_EQ(GURL("https://example.com/bar.js"),
288 registrations[0].active_version.script_url); 294 registrations[0].active_version.script_url);
295 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
296 registrations[0].update_via_cache);
289 } 297 }
290 298
291 TEST_F(LinkHeaderServiceWorkerTest, 299 TEST_F(LinkHeaderServiceWorkerTest,
292 InstallServiceWorker_ScriptDifferentOrigin) { 300 InstallServiceWorker_ScriptDifferentOrigin) {
293 CreateDocumentProviderHost(); 301 CreateDocumentProviderHost();
294 ProcessLinkHeaderForRequest( 302 ProcessLinkHeaderForRequest(
295 CreateSubresourceRequest(GURL("https://example.com/foobar/"), 303 CreateSubresourceRequest(GURL("https://example.com/foobar/"),
296 provider_host()->provider_id()) 304 provider_host()->provider_id())
297 .get(), 305 .get(),
298 "<https://google.com/bar.js>; rel=serviceworker; scope=foo", 306 "<https://google.com/bar.js>; rel=serviceworker; scope=foo",
299 context_wrapper()); 307 context_wrapper());
300 base::RunLoop().RunUntilIdle(); 308 base::RunLoop().RunUntilIdle();
301 309
302 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 310 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
303 ASSERT_EQ(0u, registrations.size()); 311 ASSERT_EQ(0u, registrations.size());
304 } 312 }
305 313
314 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheNone) {
315 CreateDocumentProviderHost();
316 ProcessLinkHeaderForRequest(
317 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"),
318 provider_host()->provider_id())
319 .get(),
320 "<../foo.js>; rel=serviceworker; updateviacache=none", context_wrapper());
321 base::RunLoop().RunUntilIdle();
322
323 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
324 ASSERT_EQ(1u, registrations.size());
325 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern);
326 EXPECT_EQ(GURL("https://example.com/foo/foo.js"),
327 registrations[0].active_version.script_url);
328 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kNone,
329 registrations[0].update_via_cache);
330 }
331
332 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheImports) {
333 CreateDocumentProviderHost();
334 ProcessLinkHeaderForRequest(
335 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"),
336 provider_host()->provider_id())
337 .get(),
338 "<../foo.js>; rel=serviceworker; updateviacache=imports",
339 context_wrapper());
340 base::RunLoop().RunUntilIdle();
341
342 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
343 ASSERT_EQ(1u, registrations.size());
344 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern);
345 EXPECT_EQ(GURL("https://example.com/foo/foo.js"),
346 registrations[0].active_version.script_url);
347 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
348 registrations[0].update_via_cache);
349 }
350
351 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheAll) {
352 CreateDocumentProviderHost();
353 ProcessLinkHeaderForRequest(
354 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"),
355 provider_host()->provider_id())
356 .get(),
357 "<../foo.js>; rel=serviceworker; updateviacache=all", context_wrapper());
358 base::RunLoop().RunUntilIdle();
359
360 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
361 ASSERT_EQ(1u, registrations.size());
362 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern);
363 EXPECT_EQ(GURL("https://example.com/foo/foo.js"),
364 registrations[0].active_version.script_url);
365 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kAll,
366 registrations[0].update_via_cache);
367 }
368
369 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_CacheInvalidValue) {
370 CreateDocumentProviderHost();
371 ProcessLinkHeaderForRequest(
372 CreateSubresourceRequest(GURL("https://example.com/foo/bar/"),
373 provider_host()->provider_id())
374 .get(),
375 "<../foo.js>; rel=serviceworker; updateviacache=invalidvalue",
376 context_wrapper());
377 base::RunLoop().RunUntilIdle();
378
379 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
380 ASSERT_EQ(1u, registrations.size());
381 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern);
382 EXPECT_EQ(GURL("https://example.com/foo/foo.js"),
383 registrations[0].active_version.script_url);
384 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
385 registrations[0].update_via_cache);
386 }
387
306 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) { 388 TEST_F(LinkHeaderServiceWorkerTest, InstallServiceWorker_MultipleWorkers) {
307 CreateDocumentProviderHost(); 389 CreateDocumentProviderHost();
308 ProcessLinkHeaderForRequest( 390 ProcessLinkHeaderForRequest(
309 CreateSubresourceRequest(GURL("https://example.com/foobar/"), 391 CreateSubresourceRequest(GURL("https://example.com/foobar/"),
310 provider_host()->provider_id()) 392 provider_host()->provider_id())
311 .get(), 393 .get(),
312 "<bar.js>; rel=serviceworker; scope=foo, <baz.js>; " 394 "<bar.js>; rel=serviceworker; updateviacache=none; scope=foo, <baz.js>; "
313 "rel=serviceworker; scope=scope", 395 "rel=serviceworker; scope=scope; updateviacache=all",
314 context_wrapper()); 396 context_wrapper());
315 base::RunLoop().RunUntilIdle(); 397 base::RunLoop().RunUntilIdle();
316 398
317 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 399 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
318 ASSERT_EQ(2u, registrations.size()); 400 ASSERT_EQ(2u, registrations.size());
319 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern); 401 EXPECT_EQ(GURL("https://example.com/foobar/foo"), registrations[0].pattern);
320 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"), 402 EXPECT_EQ(GURL("https://example.com/foobar/bar.js"),
321 registrations[0].active_version.script_url); 403 registrations[0].active_version.script_url);
404 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kNone,
405 registrations[0].update_via_cache);
322 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern); 406 EXPECT_EQ(GURL("https://example.com/foobar/scope"), registrations[1].pattern);
323 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"), 407 EXPECT_EQ(GURL("https://example.com/foobar/baz.js"),
324 registrations[1].active_version.script_url); 408 registrations[1].active_version.script_url);
409 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kAll,
410 registrations[1].update_via_cache);
325 } 411 }
326 412
327 TEST_F(LinkHeaderServiceWorkerTest, 413 TEST_F(LinkHeaderServiceWorkerTest,
328 InstallServiceWorker_ValidAndInvalidValues) { 414 InstallServiceWorker_ValidAndInvalidValues) {
329 CreateDocumentProviderHost(); 415 CreateDocumentProviderHost();
330 ProcessLinkHeaderForRequest( 416 ProcessLinkHeaderForRequest(
331 CreateSubresourceRequest(GURL("https://example.com/foobar/"), 417 CreateSubresourceRequest(GURL("https://example.com/foobar/"),
332 provider_host()->provider_id()) 418 provider_host()->provider_id())
333 .get(), 419 .get(),
334 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; " 420 "<https://google.com/bar.js>; rel=serviceworker; scope=foo, <baz.js>; "
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 456
371 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker", 457 ProcessLinkHeaderForRequest(request.get(), "<../foo.js>; rel=serviceworker",
372 context_wrapper()); 458 context_wrapper());
373 base::RunLoop().RunUntilIdle(); 459 base::RunLoop().RunUntilIdle();
374 460
375 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 461 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
376 ASSERT_EQ(1u, registrations.size()); 462 ASSERT_EQ(1u, registrations.size());
377 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern); 463 EXPECT_EQ(GURL("https://example.com/foo/"), registrations[0].pattern);
378 EXPECT_EQ(GURL("https://example.com/foo/foo.js"), 464 EXPECT_EQ(GURL("https://example.com/foo/foo.js"),
379 registrations[0].active_version.script_url); 465 registrations[0].active_version.script_url);
466 EXPECT_EQ(blink::WebServiceWorkerUpdateViaCache::kImports,
467 registrations[0].update_via_cache);
380 } 468 }
381 469
382 TEST_F(LinkHeaderServiceWorkerTest, 470 TEST_F(LinkHeaderServiceWorkerTest,
383 InstallServiceWorker_NavigationToInsecureContext) { 471 InstallServiceWorker_NavigationToInsecureContext) {
384 CreateDocumentProviderHost(); 472 CreateDocumentProviderHost();
385 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/")); 473 provider_host()->SetDocumentUrl(GURL("http://example.com/foo/bar/"));
386 ProcessLinkHeaderForRequest( 474 ProcessLinkHeaderForRequest(
387 CreateRequest(GURL("http://example.com/foo/bar/"), 475 CreateRequest(GURL("http://example.com/foo/bar/"),
388 RESOURCE_TYPE_MAIN_FRAME, provider_host()->provider_id()) 476 RESOURCE_TYPE_MAIN_FRAME, provider_host()->provider_id())
389 .get(), 477 .get(),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 provider_host()->provider_id()) 528 provider_host()->provider_id())
441 .get(), 529 .get(),
442 "<../foo.js>; rel=serviceworker", context_wrapper()); 530 "<../foo.js>; rel=serviceworker", context_wrapper());
443 base::RunLoop().RunUntilIdle(); 531 base::RunLoop().RunUntilIdle();
444 532
445 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations(); 533 std::vector<ServiceWorkerRegistrationInfo> registrations = GetRegistrations();
446 ASSERT_EQ(1u, registrations.size()); 534 ASSERT_EQ(1u, registrations.size());
447 } 535 }
448 536
449 } // namespace content 537 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/link_header_support.cc ('k') | content/browser/service_worker/service_worker_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698