OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/data_reduction_proxy/content/renderer/content_previews_rend
er_frame_observer.h" |
| 6 |
| 7 #include "content/public/common/previews_state.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 10 |
| 11 namespace data_reduction_proxy { |
| 12 |
| 13 TEST(ContentPreviewsRenderFrameObserverTest, |
| 14 GetPreviewsStateNoServerTransformRequested) { |
| 15 blink::WebURLResponse response_no_headers; |
| 16 |
| 17 // No transforms specified. |
| 18 EXPECT_EQ(content::PREVIEWS_OFF, |
| 19 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 20 content::PREVIEWS_UNSPECIFIED, response_no_headers)); |
| 21 |
| 22 // Client Lo-Fi preserved if no Server Lo-Fi nor Lite Page. |
| 23 EXPECT_EQ(content::CLIENT_LOFI_ON, |
| 24 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 25 content::CLIENT_LOFI_ON, response_no_headers)); |
| 26 } |
| 27 |
| 28 TEST(ContentPreviewsRenderFrameObserverTest, |
| 29 GetPreviewsStateNoTransformResponseHeaders) { |
| 30 blink::WebURLResponse response_no_headers; |
| 31 // Lite Page enabled but no CPCT nor page-polices => all cleared. |
| 32 EXPECT_EQ(content::PREVIEWS_OFF, |
| 33 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 34 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 35 content::CLIENT_LOFI_ON, |
| 36 response_no_headers)); |
| 37 EXPECT_EQ(content::PREVIEWS_OFF, |
| 38 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 39 content::SERVER_LITE_PAGE_ON, response_no_headers)); |
| 40 EXPECT_EQ(content::PREVIEWS_OFF, |
| 41 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 42 content::SERVER_LITE_PAGE_ON | content::CLIENT_LOFI_ON, |
| 43 response_no_headers)); |
| 44 EXPECT_EQ(content::PREVIEWS_OFF, |
| 45 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 46 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 47 response_no_headers)); |
| 48 |
| 49 // Legacy Lo-Fi path (Lite Pages not enabled but Server Lo-Fi is). |
| 50 EXPECT_EQ(content::SERVER_LOFI_ON, |
| 51 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 52 content::SERVER_LOFI_ON, response_no_headers)); |
| 53 EXPECT_EQ(content::SERVER_LOFI_ON | content::CLIENT_LOFI_ON, |
| 54 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 55 content::SERVER_LOFI_ON | content::CLIENT_LOFI_ON, |
| 56 response_no_headers)); |
| 57 } |
| 58 |
| 59 TEST(ContentPreviewsRenderFrameObserverTest, |
| 60 GetPreviewsStateLitePageTransform) { |
| 61 blink::WebURLResponse response_with_lite_page; |
| 62 response_with_lite_page.AddHTTPHeaderField("chrome-proxy-content-transform", |
| 63 "lite-page"); |
| 64 EXPECT_EQ(content::SERVER_LITE_PAGE_ON, |
| 65 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 66 content::SERVER_LITE_PAGE_ON, response_with_lite_page)); |
| 67 EXPECT_EQ(content::SERVER_LITE_PAGE_ON, |
| 68 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 69 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 70 content::CLIENT_LOFI_ON, |
| 71 response_with_lite_page)); |
| 72 EXPECT_EQ(content::SERVER_LITE_PAGE_ON, |
| 73 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 74 content::SERVER_LITE_PAGE_ON | content::CLIENT_LOFI_ON, |
| 75 response_with_lite_page)); |
| 76 EXPECT_EQ(content::SERVER_LITE_PAGE_ON, |
| 77 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 78 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 79 response_with_lite_page)); |
| 80 } |
| 81 |
| 82 TEST(ContentPreviewsRenderFrameObserverTest, |
| 83 GetPreviewsStateLitePageAndLoFiTransforms) { |
| 84 blink::WebURLResponse response_with_lite_page_and_page_policy; |
| 85 response_with_lite_page_and_page_policy.AddHTTPHeaderField( |
| 86 "chrome-proxy-content-transform", "lite-page"); |
| 87 response_with_lite_page_and_page_policy.AddHTTPHeaderField( |
| 88 "Chrome-Proxy", "Page-Policies=Empty-Image"); |
| 89 |
| 90 EXPECT_EQ(content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 91 content::CLIENT_LOFI_ON, |
| 92 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 93 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 94 content::CLIENT_LOFI_ON, |
| 95 response_with_lite_page_and_page_policy)); |
| 96 EXPECT_EQ(content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 97 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 98 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 99 response_with_lite_page_and_page_policy)); |
| 100 } |
| 101 |
| 102 TEST(ContentPreviewsRenderFrameObserverTest, |
| 103 GetPreviewsStateLoFiFallbackPagePolicy) { |
| 104 blink::WebURLResponse response_with_page_policy; |
| 105 response_with_page_policy.AddHTTPHeaderField("Chrome-Proxy", "SomeNoise"); |
| 106 response_with_page_policy.AddHTTPHeaderField("Chrome-Proxy", |
| 107 "Page-Policies=Empty-Image"); |
| 108 |
| 109 // No fallbacks if Server Lo-Fi not enabled. |
| 110 EXPECT_EQ(content::PREVIEWS_OFF, |
| 111 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 112 content::SERVER_LITE_PAGE_ON, response_with_page_policy)); |
| 113 EXPECT_EQ(content::PREVIEWS_OFF, |
| 114 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 115 content::SERVER_LITE_PAGE_ON | content::CLIENT_LOFI_ON, |
| 116 response_with_page_policy)); |
| 117 |
| 118 // Lo-Fi fallbacks if Server Lo-Fi enabled and get empty-image directive. |
| 119 EXPECT_EQ(content::SERVER_LOFI_ON | content::CLIENT_LOFI_ON, |
| 120 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 121 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 122 content::CLIENT_LOFI_ON, |
| 123 response_with_page_policy)); |
| 124 EXPECT_EQ(content::SERVER_LOFI_ON, |
| 125 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 126 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 127 response_with_page_policy)); |
| 128 } |
| 129 |
| 130 TEST(ContentPreviewsRenderFrameObserverTest, |
| 131 GetPreviewsStateLoFiFallbackAndOtherPolicies) { |
| 132 blink::WebURLResponse response_with_page_policy; |
| 133 response_with_page_policy.AddHTTPHeaderField("chrome-proxy", "Prefix=Noise"); |
| 134 response_with_page_policy.AddHTTPHeaderField( |
| 135 "chrome-proxy", "page-policies=new-hotness|empty-image|newer-hotness"); |
| 136 response_with_page_policy.AddHTTPHeaderField("chrome-proxy", |
| 137 "Suffix=More|Noise"); |
| 138 |
| 139 // Lo-Fi fallbacks if Server Lo-Fi enabled and get empty-image directive. |
| 140 EXPECT_EQ(content::SERVER_LOFI_ON | content::CLIENT_LOFI_ON, |
| 141 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 142 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 143 content::CLIENT_LOFI_ON, |
| 144 response_with_page_policy)); |
| 145 EXPECT_EQ(content::SERVER_LOFI_ON, |
| 146 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 147 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 148 response_with_page_policy)); |
| 149 } |
| 150 |
| 151 TEST(ContentPreviewsRenderFrameObserverTest, GetPreviewsStateNoKnownPolicies) { |
| 152 blink::WebURLResponse response_with_page_policy; |
| 153 response_with_page_policy.AddHTTPHeaderField("chrome-proxy", "Prefix=Noise"); |
| 154 response_with_page_policy.AddHTTPHeaderField( |
| 155 "chrome-proxy", |
| 156 "page-policies=new-hotness|new-empty-image|newer-hotness"); |
| 157 response_with_page_policy.AddHTTPHeaderField("chrome-proxy", |
| 158 "Suffix=More|Noise"); |
| 159 |
| 160 // Lo-Fi fallbacks if Server Lo-Fi enabled and get empty-image directive. |
| 161 EXPECT_EQ(content::PREVIEWS_OFF, |
| 162 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 163 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON | |
| 164 content::CLIENT_LOFI_ON, |
| 165 response_with_page_policy)); |
| 166 EXPECT_EQ(content::PREVIEWS_OFF, |
| 167 ContentPreviewsRenderFrameObserver::GetPreviewsStateFromResponse( |
| 168 content::SERVER_LITE_PAGE_ON | content::SERVER_LOFI_ON, |
| 169 response_with_page_policy)); |
| 170 } |
| 171 |
| 172 } // namespace data_reduction_proxy |
OLD | NEW |