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" |
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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 ResourceRequest resource_request(input_url); | 517 ResourceRequest resource_request(input_url); |
517 | 518 |
518 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, | 519 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, |
519 resource_request); | 520 resource_request); |
520 | 521 |
521 EXPECT_EQ(is_present ? String(header_value) : String(), | 522 EXPECT_EQ(is_present ? String(header_value) : String(), |
522 resource_request.HttpHeaderField(header_name)); | 523 resource_request.HttpHeaderField(header_name)); |
523 } | 524 } |
524 }; | 525 }; |
525 | 526 |
| 527 class ClientHintsTestPlatform : public TestingPlatformSupport { |
| 528 public: |
| 529 void SetDevicePhysicalMemoryMB(int64_t physical_memory_mb) { |
| 530 physical_memory_mb_ = static_cast<size_t>(physical_memory_mb); |
| 531 } |
| 532 size_t AmountOfPhysicalMemoryMB() override { return physical_memory_mb_; } |
| 533 |
| 534 private: |
| 535 size_t physical_memory_mb_; |
| 536 }; |
| 537 |
| 538 TEST_F(FrameFetchContextHintsTest, MonitorDeviceRAMHints) { |
| 539 ScopedTestingPlatformSupport<ClientHintsTestPlatform> platform; |
| 540 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); |
| 541 ClientHintsPreferences preferences; |
| 542 preferences.SetShouldSendDeviceRAM(true); |
| 543 document->GetClientHintsPreferences().UpdateFrom(preferences); |
| 544 platform->SetDevicePhysicalMemoryMB(4096); |
| 545 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); |
| 546 platform->SetDevicePhysicalMemoryMB(2048); |
| 547 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2"); |
| 548 platform->SetDevicePhysicalMemoryMB(64385); |
| 549 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32"); |
| 550 platform->SetDevicePhysicalMemoryMB(768); |
| 551 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "0.5"); |
| 552 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 553 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
| 554 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
| 555 } |
| 556 |
526 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { | 557 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { |
527 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 558 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
528 ClientHintsPreferences preferences; | 559 ClientHintsPreferences preferences; |
529 preferences.SetShouldSendDPR(true); | 560 preferences.SetShouldSendDPR(true); |
530 document->GetClientHintsPreferences().UpdateFrom(preferences); | 561 document->GetClientHintsPreferences().UpdateFrom(preferences); |
531 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 562 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
532 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); | 563 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); |
533 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); | 564 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); |
534 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 565 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
535 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 566 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
(...skipping 20 matching lines...) Expand all Loading... |
556 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 587 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
557 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); | 588 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); |
558 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); | 589 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); |
559 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); | 590 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); |
560 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", | 591 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", |
561 666.6666); | 592 666.6666); |
562 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 593 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
563 } | 594 } |
564 | 595 |
565 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { | 596 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { |
| 597 ScopedTestingPlatformSupport<ClientHintsTestPlatform> platform; |
| 598 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); |
566 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 599 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
567 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 600 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
568 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 601 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
569 | 602 |
570 ClientHintsPreferences preferences; | 603 ClientHintsPreferences preferences; |
| 604 preferences.SetShouldSendDeviceRAM(true); |
571 preferences.SetShouldSendDPR(true); | 605 preferences.SetShouldSendDPR(true); |
572 preferences.SetShouldSendResourceWidth(true); | 606 preferences.SetShouldSendResourceWidth(true); |
573 preferences.SetShouldSendViewportWidth(true); | 607 preferences.SetShouldSendViewportWidth(true); |
| 608 platform->SetDevicePhysicalMemoryMB(4096); |
574 document->GetClientHintsPreferences().UpdateFrom(preferences); | 609 document->GetClientHintsPreferences().UpdateFrom(preferences); |
| 610 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); |
575 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 611 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
576 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 612 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
577 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 613 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
578 } | 614 } |
579 | 615 |
| 616 TEST_F(FrameFetchContextHintsTest, ClientHintsDeviceRAM) { |
| 617 EXPECT_EQ(0.125, FrameFetchContext::ClientHintsDeviceRAM(128)); // 128MB |
| 618 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRAM(256)); // 256MB |
| 619 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRAM(510)); // <512MB |
| 620 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(512)); // 512MB |
| 621 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(640)); // 512+128MB |
| 622 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(768)); // 512+256MB |
| 623 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRAM(1000)); // <1GB |
| 624 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(1024)); // 1GB |
| 625 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(1536)); // 1.5GB |
| 626 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRAM(2000)); // <2GB |
| 627 EXPECT_EQ(2, FrameFetchContext::ClientHintsDeviceRAM(2048)); // 2GB |
| 628 EXPECT_EQ(4, FrameFetchContext::ClientHintsDeviceRAM(5120)); // 5GB |
| 629 EXPECT_EQ(8, FrameFetchContext::ClientHintsDeviceRAM(8192)); // 8GB |
| 630 EXPECT_EQ(16, FrameFetchContext::ClientHintsDeviceRAM(16384)); // 16GB |
| 631 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRAM(32768)); // 32GB |
| 632 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRAM(64385)); // <64GB |
| 633 } |
| 634 |
580 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { | 635 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { |
581 // Default case | 636 // Default case |
582 ResourceRequest request("http://www.example.com"); | 637 ResourceRequest request("http://www.example.com"); |
583 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, | 638 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, |
584 fetch_context->ResourceRequestCachePolicy( | 639 fetch_context->ResourceRequestCachePolicy( |
585 request, Resource::kMainResource, FetchParameters::kNoDefer)); | 640 request, Resource::kMainResource, FetchParameters::kNoDefer)); |
586 | 641 |
587 // Post | 642 // Post |
588 ResourceRequest post_request("http://www.example.com"); | 643 ResourceRequest post_request("http://www.example.com"); |
589 post_request.SetHTTPMethod(HTTPNames::POST); | 644 post_request.SetHTTPMethod(HTTPNames::POST); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); | 960 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); |
906 | 961 |
907 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); | 962 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); |
908 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 963 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
909 | 964 |
910 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); | 965 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); |
911 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 966 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
912 } | 967 } |
913 | 968 |
914 } // namespace blink | 969 } // namespace blink |
OLD | NEW |