| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015, Google Inc. All rights reserved. | 2 * Copyright (c) 2015, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 preferences.setShouldSendDPR(true); | 428 preferences.setShouldSendDPR(true); |
| 429 preferences.setShouldSendResourceWidth(true); | 429 preferences.setShouldSendResourceWidth(true); |
| 430 preferences.setShouldSendViewportWidth(true); | 430 preferences.setShouldSendViewportWidth(true); |
| 431 document->clientHintsPreferences().updateFrom(preferences); | 431 document->clientHintsPreferences().updateFrom(preferences); |
| 432 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 432 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 433 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 433 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
| 434 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 434 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
| 435 } | 435 } |
| 436 | 436 |
| 437 TEST_F(FrameFetchContextTest, MainResource) { | 437 TEST_F(FrameFetchContextTest, MainResource) { |
| 438 std::pair<AtomicString, AtomicString> header; |
| 439 |
| 438 // Default case | 440 // Default case |
| 439 ResourceRequest request("http://www.example.com"); | 441 ResourceRequest request("http://www.example.com"); |
| 440 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, | 442 EXPECT_EQ( |
| 441 fetchContext->resourceRequestCachePolicy( | 443 WebCachePolicy::UseProtocolCachePolicy, |
| 442 request, Resource::MainResource, FetchRequest::NoDefer)); | 444 fetchContext->resourceRequestCachePolicy(request, Resource::MainResource, |
| 445 FetchRequest::NoDefer, header)); |
| 443 | 446 |
| 444 // Post | 447 // Post |
| 445 ResourceRequest postRequest("http://www.example.com"); | 448 ResourceRequest postRequest("http://www.example.com"); |
| 446 postRequest.setHTTPMethod("POST"); | 449 postRequest.setHTTPMethod("POST"); |
| 447 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, | 450 EXPECT_EQ( |
| 448 fetchContext->resourceRequestCachePolicy( | 451 WebCachePolicy::ValidatingCacheData, |
| 449 postRequest, Resource::MainResource, FetchRequest::NoDefer)); | 452 fetchContext->resourceRequestCachePolicy( |
| 453 postRequest, Resource::MainResource, FetchRequest::NoDefer, header)); |
| 450 | 454 |
| 451 // Re-post | 455 // Re-post |
| 452 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); | 456 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); |
| 453 EXPECT_EQ(WebCachePolicy::ReturnCacheDataDontLoad, | 457 EXPECT_EQ( |
| 454 fetchContext->resourceRequestCachePolicy( | 458 WebCachePolicy::ReturnCacheDataDontLoad, |
| 455 postRequest, Resource::MainResource, FetchRequest::NoDefer)); | 459 fetchContext->resourceRequestCachePolicy( |
| 460 postRequest, Resource::MainResource, FetchRequest::NoDefer, header)); |
| 456 | 461 |
| 457 // FrameLoadTypeReloadMainResource | 462 // FrameLoadTypeReloadMainResource |
| 458 document->frame()->loader().setLoadType(FrameLoadTypeReloadMainResource); | 463 document->frame()->loader().setLoadType(FrameLoadTypeReloadMainResource); |
| 459 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, | 464 EXPECT_EQ( |
| 460 fetchContext->resourceRequestCachePolicy( | 465 WebCachePolicy::ValidatingCacheData, |
| 461 request, Resource::MainResource, FetchRequest::NoDefer)); | 466 fetchContext->resourceRequestCachePolicy(request, Resource::MainResource, |
| 467 FetchRequest::NoDefer, header)); |
| 462 | 468 |
| 463 // Conditional request | 469 // Conditional request |
| 464 document->frame()->loader().setLoadType(FrameLoadTypeStandard); | 470 document->frame()->loader().setLoadType(FrameLoadTypeStandard); |
| 465 ResourceRequest conditional("http://www.example.com"); | 471 ResourceRequest conditional("http://www.example.com"); |
| 466 conditional.setHTTPHeaderField(HTTPNames::If_Modified_Since, "foo"); | 472 conditional.setHTTPHeaderField(HTTPNames::If_Modified_Since, "foo"); |
| 467 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, | 473 EXPECT_EQ( |
| 468 fetchContext->resourceRequestCachePolicy( | 474 WebCachePolicy::ValidatingCacheData, |
| 469 conditional, Resource::MainResource, FetchRequest::NoDefer)); | 475 fetchContext->resourceRequestCachePolicy( |
| 476 conditional, Resource::MainResource, FetchRequest::NoDefer, header)); |
| 470 | 477 |
| 471 // Set up a child frame | 478 // Set up a child frame |
| 472 FrameFetchContext* childFetchContext = createChildFrame(); | 479 FrameFetchContext* childFetchContext = createChildFrame(); |
| 473 | 480 |
| 474 // Child frame as part of back/forward | 481 // Child frame as part of back/forward |
| 475 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); | 482 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); |
| 476 EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, | 483 EXPECT_EQ( |
| 477 childFetchContext->resourceRequestCachePolicy( | 484 WebCachePolicy::ReturnCacheDataElseLoad, |
| 478 request, Resource::MainResource, FetchRequest::NoDefer)); | 485 childFetchContext->resourceRequestCachePolicy( |
| 486 request, Resource::MainResource, FetchRequest::NoDefer, header)); |
| 479 | 487 |
| 480 // Child frame as part of reload | 488 // Child frame as part of reload |
| 481 document->frame()->loader().setLoadType(FrameLoadTypeReload); | 489 document->frame()->loader().setLoadType(FrameLoadTypeReload); |
| 482 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, | 490 EXPECT_EQ( |
| 483 childFetchContext->resourceRequestCachePolicy( | 491 WebCachePolicy::ValidatingCacheData, |
| 484 request, Resource::MainResource, FetchRequest::NoDefer)); | 492 childFetchContext->resourceRequestCachePolicy( |
| 493 request, Resource::MainResource, FetchRequest::NoDefer, header)); |
| 485 | 494 |
| 486 // Child frame as part of reload bypassing cache | 495 // Child frame as part of reload bypassing cache |
| 487 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); | 496 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); |
| 488 EXPECT_EQ(WebCachePolicy::BypassingCache, | 497 EXPECT_EQ( |
| 489 childFetchContext->resourceRequestCachePolicy( | 498 WebCachePolicy::BypassingCache, |
| 490 request, Resource::MainResource, FetchRequest::NoDefer)); | 499 childFetchContext->resourceRequestCachePolicy( |
| 500 request, Resource::MainResource, FetchRequest::NoDefer, header)); |
| 491 } | 501 } |
| 492 | 502 |
| 493 TEST_F(FrameFetchContextTest, PopulateRequestData) { | 503 TEST_F(FrameFetchContextTest, PopulateRequestData) { |
| 494 struct TestCase { | 504 struct TestCase { |
| 495 const char* documentURL; | 505 const char* documentURL; |
| 496 bool documentSandboxed; | 506 bool documentSandboxed; |
| 497 const char* requestorOrigin; // "" => unique origin | 507 const char* requestorOrigin; // "" => unique origin |
| 498 WebURLRequest::FrameType frameType; | 508 WebURLRequest::FrameType frameType; |
| 499 const char* serializedOrigin; // "" => unique origin | 509 const char* serializedOrigin; // "" => unique origin |
| 500 } cases[] = { | 510 } cases[] = { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); | 743 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); |
| 734 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); | 744 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); |
| 735 | 745 |
| 736 ResourceRequest subRequest(test.url); | 746 ResourceRequest subRequest(test.url); |
| 737 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); | 747 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); |
| 738 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); | 748 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); |
| 739 } | 749 } |
| 740 } | 750 } |
| 741 | 751 |
| 742 } // namespace blink | 752 } // namespace blink |
| OLD | NEW |