Chromium Code Reviews| 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..401c2375be0d348673c56b1f573300e4386940f0 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" |
|
kinuko
2017/05/29 05:50:02
No longer needed
fmeawad
2017/05/30 17:20:59
Done.
|
| #include "platform/weborigin/KURL.h" |
| #include "platform/weborigin/SecurityViolationReportingPolicy.h" |
| #include "public/platform/WebAddressSpace.h" |
| @@ -524,6 +525,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 +583,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"); |