Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 #include "core/html/HTMLIFrameElement.h" | 39 #include "core/html/HTMLIFrameElement.h" |
| 40 #include "core/loader/DocumentLoader.h" | 40 #include "core/loader/DocumentLoader.h" |
| 41 #include "core/loader/EmptyClients.h" | 41 #include "core/loader/EmptyClients.h" |
| 42 #include "core/loader/SubresourceFilter.h" | 42 #include "core/loader/SubresourceFilter.h" |
| 43 #include "core/page/Page.h" | 43 #include "core/page/Page.h" |
| 44 #include "core/testing/DummyPageHolder.h" | 44 #include "core/testing/DummyPageHolder.h" |
| 45 #include "platform/loader/fetch/FetchInitiatorInfo.h" | 45 #include "platform/loader/fetch/FetchInitiatorInfo.h" |
| 46 #include "platform/loader/fetch/ResourceRequest.h" | 46 #include "platform/loader/fetch/ResourceRequest.h" |
| 47 #include "platform/loader/fetch/UniqueIdentifier.h" | 47 #include "platform/loader/fetch/UniqueIdentifier.h" |
| 48 #include "platform/loader/testing/MockResource.h" | 48 #include "platform/loader/testing/MockResource.h" |
| 49 #include "platform/testing/TestingPlatformSupport.h" | |
|
kinuko
2017/05/29 05:50:02
No longer needed
fmeawad
2017/05/30 17:20:59
Done.
| |
| 49 #include "platform/weborigin/KURL.h" | 50 #include "platform/weborigin/KURL.h" |
| 50 #include "platform/weborigin/SecurityViolationReportingPolicy.h" | 51 #include "platform/weborigin/SecurityViolationReportingPolicy.h" |
| 51 #include "public/platform/WebAddressSpace.h" | 52 #include "public/platform/WebAddressSpace.h" |
| 52 #include "public/platform/WebCachePolicy.h" | 53 #include "public/platform/WebCachePolicy.h" |
| 53 #include "public/platform/WebDocumentSubresourceFilter.h" | 54 #include "public/platform/WebDocumentSubresourceFilter.h" |
| 54 #include "public/platform/WebInsecureRequestPolicy.h" | 55 #include "public/platform/WebInsecureRequestPolicy.h" |
| 55 #include "testing/gmock/include/gmock/gmock.h" | 56 #include "testing/gmock/include/gmock/gmock.h" |
| 56 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
| 57 | 58 |
| 58 namespace blink { | 59 namespace blink { |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 ResourceRequest resource_request(input_url); | 518 ResourceRequest resource_request(input_url); |
| 518 | 519 |
| 519 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, | 520 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, |
| 520 resource_request); | 521 resource_request); |
| 521 | 522 |
| 522 EXPECT_EQ(is_present ? String(header_value) : String(), | 523 EXPECT_EQ(is_present ? String(header_value) : String(), |
| 523 resource_request.HttpHeaderField(header_name)); | 524 resource_request.HttpHeaderField(header_name)); |
| 524 } | 525 } |
| 525 }; | 526 }; |
| 526 | 527 |
| 528 TEST_F(FrameFetchContextHintsTest, MonitorDeviceRAMHints) { | |
| 529 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); | |
| 530 ClientHintsPreferences preferences; | |
| 531 preferences.SetShouldSendDeviceRAM(true); | |
| 532 document->GetClientHintsPreferences().UpdateFrom(preferences); | |
| 533 MemoryCoordinator::SetPhysicalMemoryMBForTesting(4096); | |
| 534 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); | |
| 535 MemoryCoordinator::SetPhysicalMemoryMBForTesting(2048); | |
| 536 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2"); | |
| 537 MemoryCoordinator::SetPhysicalMemoryMBForTesting(64385); | |
| 538 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32"); | |
| 539 MemoryCoordinator::SetPhysicalMemoryMBForTesting(768); | |
| 540 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "0.5"); | |
| 541 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | |
| 542 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | |
| 543 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | |
| 544 } | |
| 545 | |
| 527 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { | 546 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { |
| 528 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 547 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 529 ClientHintsPreferences preferences; | 548 ClientHintsPreferences preferences; |
| 530 preferences.SetShouldSendDPR(true); | 549 preferences.SetShouldSendDPR(true); |
| 531 document->GetClientHintsPreferences().UpdateFrom(preferences); | 550 document->GetClientHintsPreferences().UpdateFrom(preferences); |
| 532 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 551 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 533 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); | 552 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); |
| 534 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); | 553 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); |
| 535 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 554 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
| 536 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 555 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 557 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 576 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
| 558 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); | 577 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); |
| 559 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); | 578 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); |
| 560 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); | 579 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); |
| 561 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", | 580 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", |
| 562 666.6666); | 581 666.6666); |
| 563 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 582 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 564 } | 583 } |
| 565 | 584 |
| 566 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { | 585 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { |
| 586 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); | |
| 567 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 587 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 568 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 588 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
| 569 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 589 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
| 570 | 590 |
| 571 ClientHintsPreferences preferences; | 591 ClientHintsPreferences preferences; |
| 592 preferences.SetShouldSendDeviceRAM(true); | |
| 572 preferences.SetShouldSendDPR(true); | 593 preferences.SetShouldSendDPR(true); |
| 573 preferences.SetShouldSendResourceWidth(true); | 594 preferences.SetShouldSendResourceWidth(true); |
| 574 preferences.SetShouldSendViewportWidth(true); | 595 preferences.SetShouldSendViewportWidth(true); |
| 596 MemoryCoordinator::SetPhysicalMemoryMBForTesting(4096); | |
| 575 document->GetClientHintsPreferences().UpdateFrom(preferences); | 597 document->GetClientHintsPreferences().UpdateFrom(preferences); |
| 598 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); | |
| 576 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 599 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 577 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 600 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
| 578 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 601 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
| 579 } | 602 } |
| 580 | 603 |
| 604 TEST_F(FrameFetchContextHintsTest, ClientHintsDeviceRAM) { | |
| 605 EXPECT_EQ(0.125, FrameFetchContext::ClientHintsDeviceRAM(128)); // 128MB | |
| 606 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRAM(256)); // 256MB | |
| 607 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRAM(510)); // <512MB | |
| 608 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(512)); // 512MB | |
| 609 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(640)); // 512+128MB | |
| 610 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(768)); // 512+256MB | |
| 611 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(1000)); // <1GB | |
| 612 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(1024)); // 1GB | |
| 613 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(1536)); // 1.5GB | |
| 614 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(2000)); // <2GB | |
| 615 EXPECT_EQ(2, FrameFetchContext::ClientHintsDeviceRAM(2048)); // 2GB | |
| 616 EXPECT_EQ(4, FrameFetchContext::ClientHintsDeviceRAM(5120)); // 5GB | |
| 617 EXPECT_EQ(8, FrameFetchContext::ClientHintsDeviceRAM(8192)); // 8GB | |
| 618 EXPECT_EQ(16, FrameFetchContext::ClientHintsDeviceRAM(16384)); // 16GB | |
| 619 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRAM(32768)); // 32GB | |
| 620 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRAM(64385)); // <64GB | |
| 621 } | |
| 622 | |
| 581 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { | 623 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { |
| 582 // Default case | 624 // Default case |
| 583 ResourceRequest request("http://www.example.com"); | 625 ResourceRequest request("http://www.example.com"); |
| 584 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, | 626 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, |
| 585 fetch_context->ResourceRequestCachePolicy( | 627 fetch_context->ResourceRequestCachePolicy( |
| 586 request, Resource::kMainResource, FetchParameters::kNoDefer)); | 628 request, Resource::kMainResource, FetchParameters::kNoDefer)); |
| 587 | 629 |
| 588 // Post | 630 // Post |
| 589 ResourceRequest post_request("http://www.example.com"); | 631 ResourceRequest post_request("http://www.example.com"); |
| 590 post_request.SetHTTPMethod(HTTPNames::POST); | 632 post_request.SetHTTPMethod(HTTPNames::POST); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); | 948 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); |
| 907 | 949 |
| 908 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); | 950 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); |
| 909 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 951 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
| 910 | 952 |
| 911 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); | 953 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); |
| 912 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 954 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
| 913 } | 955 } |
| 914 | 956 |
| 915 } // namespace blink | 957 } // namespace blink |
| OLD | NEW |