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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698