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 192a2a4ba538991306dcec22d3c39c16836fc561..1b4fc8e4e620c9e3c8ccd6222041dd417a5cb258 100644 |
--- a/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp |
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp |
@@ -524,6 +524,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); |
+ MemoryCoordinator::SetPhysicalMemoryMBForTesting(4096); |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); |
+ MemoryCoordinator::SetPhysicalMemoryMBForTesting(2048); |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2"); |
+ MemoryCoordinator::SetPhysicalMemoryMBForTesting(64385); |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32"); |
+ MemoryCoordinator::SetPhysicalMemoryMBForTesting(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; |
@@ -564,20 +582,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); |
+ MemoryCoordinator::SetPhysicalMemoryMBForTesting(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"); |