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

Unified Diff: third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp

Issue 2860093003: Implement device-ram client hints header (Closed)
Patch Set: Fix FrameFetchContextTest Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp b/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp
index e89e4d1a72ecbde388a176f5bc0a73fdea12f441..6fd385a4aabd318457cba21534a11c5cbfeb13d4 100644
--- a/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp
@@ -523,6 +523,23 @@ class FrameFetchContextHintsTest : public FrameFetchContextTest {
}
};
+TEST_F(FrameFetchContextHintsTest, MonitorDeviceRamHints) {
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", false, "");
+ ClientHintsPreferences preferences;
+ preferences.SetShouldSendDeviceRam(true);
+ document->GetClientHintsPreferences().UpdateFrom(preferences);
+ Platform::Current()->SetDevicePhysicalMemoryMBForTesting(4096);
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4");
+ Platform::Current()->SetDevicePhysicalMemoryMBForTesting(2048);
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2");
+ Platform::Current()->SetDevicePhysicalMemoryMBForTesting(64385);
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32");
+ Platform::Current()->SetDevicePhysicalMemoryMBForTesting(768);
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "0.5");
+ ExpectHeader("http://www.example.com/1.gif", "Width", false, "");
+ 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
+}
+
TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) {
ExpectHeader("http://www.example.com/1.gif", "DPR", false, "");
ClientHintsPreferences preferences;
@@ -563,20 +580,43 @@ TEST_F(FrameFetchContextHintsTest, MonitorViewportWidthHints) {
}
TEST_F(FrameFetchContextHintsTest, MonitorAllHints) {
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", false, "");
ExpectHeader("http://www.example.com/1.gif", "DPR", false, "");
ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, "");
ExpectHeader("http://www.example.com/1.gif", "Width", false, "");
ClientHintsPreferences preferences;
+ preferences.SetShouldSendDeviceRam(true);
preferences.SetShouldSendDPR(true);
preferences.SetShouldSendResourceWidth(true);
preferences.SetShouldSendViewportWidth(true);
+ Platform::Current()->SetDevicePhysicalMemoryMBForTesting(4096);
document->GetClientHintsPreferences().UpdateFrom(preferences);
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4");
ExpectHeader("http://www.example.com/1.gif", "DPR", true, "1");
ExpectHeader("http://www.example.com/1.gif", "Width", true, "400", 400);
ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500");
}
+TEST_F(FrameFetchContextHintsTest, ClientHintsDeviceRam) {
+ EXPECT_EQ(0.125, FrameFetchContext::ClientHintsDeviceRam(128)); // 128MB
+ EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRam(256)); // 256MB
+ EXPECT_EQ(0.25, FrameFetchContext::ClientHintsDeviceRam(510)); // <512MB
+ EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(512)); // 512MB
+ EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(640)); // 512+128MB
+ EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(768)); // 512+256MB
+ EXPECT_EQ(0.5, FrameFetchContext::ClientHintsDeviceRam(1000)); // <1GB
+ EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRam(1024)); // 1GB
+ EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRam(1536)); // 1.5GB
+ EXPECT_EQ(1, FrameFetchContext::ClientHintsDeviceRam(2000)); // <2GB
+ EXPECT_EQ(2, FrameFetchContext::ClientHintsDeviceRam(2048)); // 2GB
+ EXPECT_EQ(4, FrameFetchContext::ClientHintsDeviceRam(5120)); // 5GB
+ EXPECT_EQ(8, FrameFetchContext::ClientHintsDeviceRam(8192)); // 8GB
+ EXPECT_EQ(16, FrameFetchContext::ClientHintsDeviceRam(16384)); // 16GB
+ EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRam(32768)); // 32GB
+ EXPECT_EQ(32, FrameFetchContext::ClientHintsDeviceRam(64385)); // <64GB
+}
+
TEST_F(FrameFetchContextTest, MainResourceCachePolicy) {
// Default case
ResourceRequest request("http://www.example.com");

Powered by Google App Engine
This is Rietveld 408576698