| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/fetch/ClientHintsPreferences.h" | 6 #include "core/fetch/ClientHintsPreferences.h" |
| 7 | 7 |
| 8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 class ClientHintsPreferencesTest : public ::testing::Test { | 12 class ClientHintsPreferencesTest : public ::testing::Test { |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 TEST_F(ClientHintsPreferencesTest, Basic) | 15 TEST_F(ClientHintsPreferencesTest, Basic) |
| 16 { | 16 { |
| 17 struct TestCase { | 17 struct TestCase { |
| 18 const char* headerValue; | 18 const char* headerValue; |
| 19 bool expectationRW; | 19 bool expectationResourceWidth; |
| 20 bool expectationDPR; | 20 bool expectationDPR; |
| 21 bool expectationViewportWidth; |
| 21 } cases[] = { | 22 } cases[] = { |
| 22 {"rw, dpr", true, true}, | 23 {"width, dpr, viewportWidth", true, true, false}, |
| 23 {"Rw, dPr", true, true}, | 24 {"WiDtH, dPr, viewport-width", true, true, true}, |
| 24 {"RW, DPR", true, true}, | 25 {"WIDTH, DPR, VIWEPROT-Width", true, true, false}, |
| 25 {"dprw", false, false}, | 26 {"VIewporT-Width, wutwut, width", true, false, true}, |
| 26 {"DPRW", false, false}, | 27 {"dprw", false, false, false}, |
| 28 {"DPRW", false, false, false}, |
| 27 }; | 29 }; |
| 28 | 30 |
| 29 for (auto testCase : cases) { | 31 for (const auto& testCase : cases) { |
| 30 ClientHintsPreferences preferences; | 32 ClientHintsPreferences preferences; |
| 31 const char* value = testCase.headerValue; | 33 const char* value = testCase.headerValue; |
| 32 bool expectationRW = testCase.expectationRW; | |
| 33 bool expectationDPR = testCase.expectationDPR; | |
| 34 | 34 |
| 35 handleAcceptClientHintsHeader(value, preferences); | 35 handleAcceptClientHintsHeader(value, preferences); |
| 36 EXPECT_EQ(expectationRW, preferences.shouldSendRW()); | 36 EXPECT_EQ(testCase.expectationResourceWidth, preferences.shouldSendResou
rceWidth()); |
| 37 EXPECT_EQ(expectationDPR, preferences.shouldSendDPR()); | 37 EXPECT_EQ(testCase.expectationDPR, preferences.shouldSendDPR()); |
| 38 EXPECT_EQ(testCase.expectationViewportWidth, preferences.shouldSendViewp
ortWidth()); |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 } // namespace blink | 42 } // namespace blink |
| OLD | NEW |