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..d8e114013c016554b82b46fd89a6e62087ec9bb3 100644 |
--- a/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp |
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp |
@@ -46,6 +46,7 @@ |
#include "platform/loader/fetch/ResourceRequest.h" |
#include "platform/loader/fetch/UniqueIdentifier.h" |
#include "platform/loader/testing/MockResource.h" |
+#include "platform/testing/TestingPlatformSupport.h" |
#include "platform/weborigin/KURL.h" |
#include "platform/weborigin/SecurityViolationReportingPolicy.h" |
#include "public/platform/WebAddressSpace.h" |
@@ -523,6 +524,36 @@ class FrameFetchContextHintsTest : public FrameFetchContextTest { |
} |
}; |
+class ClientHintsTestPlatform : public TestingPlatformSupport { |
+ public: |
+ void SetDevicePhysicalMemoryMB(int64_t physical_memory_mb) { |
+ physical_memory_mb_ = static_cast<size_t>(physical_memory_mb); |
+ } |
+ size_t AmountOfPhysicalMemoryMB() override { return physical_memory_mb_; } |
+ |
+ private: |
+ size_t physical_memory_mb_; |
+}; |
+ |
+TEST_F(FrameFetchContextHintsTest, MonitorDeviceRAMHints) { |
+ ScopedTestingPlatformSupport<ClientHintsTestPlatform> platform; |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", false, ""); |
+ ClientHintsPreferences preferences; |
+ preferences.SetShouldSendDeviceRAM(true); |
+ document->GetClientHintsPreferences().UpdateFrom(preferences); |
+ platform->SetDevicePhysicalMemoryMB(4096); |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "4"); |
+ platform->SetDevicePhysicalMemoryMB(2048); |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "2"); |
+ platform->SetDevicePhysicalMemoryMB(64385); |
+ ExpectHeader("http://www.example.com/1.gif", "device-ram", true, "32"); |
+ platform->SetDevicePhysicalMemoryMB(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 +594,44 @@ TEST_F(FrameFetchContextHintsTest, MonitorViewportWidthHints) { |
} |
TEST_F(FrameFetchContextHintsTest, MonitorAllHints) { |
+ ScopedTestingPlatformSupport<ClientHintsTestPlatform> platform; |
+ 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->SetDevicePhysicalMemoryMB(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"); |