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..9c066f397eed1dbda564f6ace084daa23c9c4f81 100644 |
--- a/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp |
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp |
@@ -523,6 +523,24 @@ 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", "DPR", false, ""); |
+ ExpectHeader("http://www.example.com/1.gif", "Width", false, ""); |
+ ExpectHeader("http://www.example.com/1.gif", "Viewport-Width", false, ""); |
+} |
+ |
TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { |
ExpectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
ClientHintsPreferences preferences; |
@@ -563,20 +581,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"); |