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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 ResourceRequest resource_request(input_url); | 516 ResourceRequest resource_request(input_url); |
517 | 517 |
518 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, | 518 fetch_context->AddClientHintsIfNecessary(hints_preferences, resource_width, |
519 resource_request); | 519 resource_request); |
520 | 520 |
521 EXPECT_EQ(is_present ? String(header_value) : String(), | 521 EXPECT_EQ(is_present ? String(header_value) : String(), |
522 resource_request.HttpHeaderField(header_name)); | 522 resource_request.HttpHeaderField(header_name)); |
523 } | 523 } |
524 }; | 524 }; |
525 | 525 |
526 TEST_F(FrameFetchContextHintsTest, MonitorDeviceRamHints) { | |
527 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); | |
528 ClientHintsPreferences preferences; | |
529 preferences.SetShouldSendDeviceRam(true); | |
530 document->GetClientHintsPreferences().UpdateFrom(preferences); | |
531 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(4096); | |
532 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); | |
533 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(2048); | |
534 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2"); | |
535 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(64385); | |
536 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32"); | |
537 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(768); | |
538 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "0.5"); | |
539 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | |
540 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | |
panicker
2017/05/24 17:27:20
Maybe drop Viewport-Width, Width?
fmeawad
2017/05/24 18:24:57
Actually we need to make sure we are not setting a
| |
541 } | |
542 | |
526 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { | 543 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { |
527 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 544 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
528 ClientHintsPreferences preferences; | 545 ClientHintsPreferences preferences; |
529 preferences.SetShouldSendDPR(true); | 546 preferences.SetShouldSendDPR(true); |
530 document->GetClientHintsPreferences().UpdateFrom(preferences); | 547 document->GetClientHintsPreferences().UpdateFrom(preferences); |
531 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 548 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
532 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); | 549 dummy_page_holder->GetPage().SetDeviceScaleFactorDeprecated(2.5); |
533 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); | 550 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); |
534 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 551 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
535 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 552 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"); | 573 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
557 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); | 574 dummy_page_holder->GetFrameView().SetLayoutSizeFixedToFrameSize(false); |
558 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); | 575 dummy_page_holder->GetFrameView().SetLayoutSize(IntSize(800, 800)); |
559 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); | 576 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800"); |
560 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", | 577 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", |
561 666.6666); | 578 666.6666); |
562 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 579 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
563 } | 580 } |
564 | 581 |
565 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { | 582 TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { |
583 ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); | |
566 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 584 ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
567 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); | 585 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
568 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); | 586 ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
569 | 587 |
570 ClientHintsPreferences preferences; | 588 ClientHintsPreferences preferences; |
589 preferences.SetShouldSendDeviceRam(true); | |
571 preferences.SetShouldSendDPR(true); | 590 preferences.SetShouldSendDPR(true); |
572 preferences.SetShouldSendResourceWidth(true); | 591 preferences.SetShouldSendResourceWidth(true); |
573 preferences.SetShouldSendViewportWidth(true); | 592 preferences.SetShouldSendViewportWidth(true); |
593 Platform::Current()->SetDevicePhysicalMemoryMBForTesting(4096); | |
574 document->GetClientHintsPreferences().UpdateFrom(preferences); | 594 document->GetClientHintsPreferences().UpdateFrom(preferences); |
595 ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); | |
575 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 596 ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
576 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 597 ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
577 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 598 ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
578 } | 599 } |
579 | 600 |
601 TEST_F(FrameFetchContextHintsTest, ClientHintsDeviceRam) { | |
602 EXPECT_EQ(0.125, FrameFetchContext::ClientHintsDeviceRam(128)); // 128MB | |
603 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRam(256)); // 256MB | |
604 EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRam(510)); // <512MB | |
605 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(512)); // 512MB | |
606 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(640)); // 512+128MB | |
607 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(768)); // 512+256MB | |
608 EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(1000)); // <1GB | |
609 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRam(1024)); // 1GB | |
610 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRam(1536)); // 1.5GB | |
611 EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRam(2000)); // <2GB | |
612 EXPECT_EQ(2, FrameFetchContext::ClientHintsDeviceRam(2048)); // 2GB | |
613 EXPECT_EQ(4, FrameFetchContext::ClientHintsDeviceRam(5120)); // 5GB | |
614 EXPECT_EQ(8, FrameFetchContext::ClientHintsDeviceRam(8192)); // 8GB | |
615 EXPECT_EQ(16, FrameFetchContext::ClientHintsDeviceRam(16384)); // 16GB | |
616 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRam(32768)); // 32GB | |
617 EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRam(64385)); // <64GB | |
618 } | |
619 | |
580 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { | 620 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { |
581 // Default case | 621 // Default case |
582 ResourceRequest request("http://www.example.com"); | 622 ResourceRequest request("http://www.example.com"); |
583 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, | 623 EXPECT_EQ(WebCachePolicy::kUseProtocolCachePolicy, |
584 fetch_context->ResourceRequestCachePolicy( | 624 fetch_context->ResourceRequestCachePolicy( |
585 request, Resource::kMainResource, FetchParameters::kNoDefer)); | 625 request, Resource::kMainResource, FetchParameters::kNoDefer)); |
586 | 626 |
587 // Post | 627 // Post |
588 ResourceRequest post_request("http://www.example.com"); | 628 ResourceRequest post_request("http://www.example.com"); |
589 post_request.SetHTTPMethod(HTTPNames::POST); | 629 post_request.SetHTTPMethod(HTTPNames::POST); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); | 945 SetFilterPolicy(WebDocumentSubresourceFilter::kWouldDisallow); |
906 | 946 |
907 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); | 947 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequest()); |
908 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 948 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
909 | 949 |
910 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); | 950 EXPECT_EQ(ResourceRequestBlockedReason::kNone, CanRequestPreload()); |
911 EXPECT_EQ(0, GetFilteredLoadCallCount()); | 951 EXPECT_EQ(0, GetFilteredLoadCallCount()); |
912 } | 952 } |
913 | 953 |
914 } // namespace blink | 954 } // namespace blink |
OLD | NEW |