Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: content/renderer/previews_state_helper_unittest.cc

Issue 2910783002: Adds Lo-Fi fallback support for new Data Reduction Proxy protocol. (Closed)
Patch Set: Added integration test the excercises page-polices fallback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/previews_state_helper_unittest.cc
diff --git a/content/renderer/previews_state_helper_unittest.cc b/content/renderer/previews_state_helper_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f035ff743d40eaeb1bc3f1a2f7af69eed6e443e3
--- /dev/null
+++ b/content/renderer/previews_state_helper_unittest.cc
@@ -0,0 +1,130 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/previews_state_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+namespace {} // namespaces
megjablon 2017/06/05 23:47:59 Remove
dougarnett 2017/06/06 16:49:46 Done.
+
+TEST(PreviewsStateHelperTest, UpdatePreviewsStateNoServerTransformRequested) {
+ blink::WebURLResponse response_no_headers;
megjablon 2017/06/05 23:47:59 update your #includes
dougarnett 2017/06/06 16:49:46 Done.
+
+ // No transforms specified.
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(PREVIEWS_UNSPECIFIED,
+ response_no_headers));
+
+ // Client Lo-Fi preserved if no Server Lo-Fi nor Lite Page.
+ EXPECT_EQ(CLIENT_LOFI_ON, UpdatePreviewsStateFromMainFrameResponse(
+ CLIENT_LOFI_ON, response_no_headers));
+}
+
+TEST(PreviewsStateHelperTest, UpdatePreviewsStateNoTransformResponseHeaders) {
+ blink::WebURLResponse response_no_headers;
+ // Lite Page enabled but no CPCT nor page-polices => all cleared.
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ response_no_headers));
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(SERVER_LITE_PAGE_ON,
+ response_no_headers));
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | CLIENT_LOFI_ON, response_no_headers));
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON, response_no_headers));
+
+ // Legacy Lo-Fi path (Lite Pages not enabled but Server Lo-Fi is).
+ EXPECT_EQ(SERVER_LOFI_ON, UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LOFI_ON, response_no_headers));
+ EXPECT_EQ(SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LOFI_ON | CLIENT_LOFI_ON, response_no_headers));
+}
+
+TEST(PreviewsStateHelperTest, UpdatePreviewsStateLitePageTransform) {
+ blink::WebURLResponse response_with_lite_page;
+ response_with_lite_page.AddHTTPHeaderField("chrome-proxy-content-transform",
+ "lite-page");
+ EXPECT_EQ(SERVER_LITE_PAGE_ON,
+ UpdatePreviewsStateFromMainFrameResponse(SERVER_LITE_PAGE_ON,
+ response_with_lite_page));
+ EXPECT_EQ(SERVER_LITE_PAGE_ON,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ response_with_lite_page));
+ EXPECT_EQ(SERVER_LITE_PAGE_ON,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | CLIENT_LOFI_ON, response_with_lite_page));
+ EXPECT_EQ(SERVER_LITE_PAGE_ON,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON, response_with_lite_page));
+}
+
+TEST(PreviewsStateHelperTest, UpdatePreviewsStateLoFiFallbackPagePolicy) {
+ blink::WebURLResponse response_with_page_policy;
+ response_with_page_policy.AddHTTPHeaderField("Chrome-Proxy", "SomeNoise");
+ response_with_page_policy.AddHTTPHeaderField("Chrome-Proxy",
+ "Page-Policies=Empty-Image");
+
+ // No fallbacks if Server Lo-Fi not enabled.
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON, response_with_page_policy));
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED, UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | CLIENT_LOFI_ON,
+ response_with_page_policy));
+
+ // Lo-Fi fallbacks if Server Lo-Fi enabled and get empty-image directive.
+ EXPECT_EQ(SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ response_with_page_policy));
+ EXPECT_EQ(SERVER_LOFI_ON, UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON,
+ response_with_page_policy));
+}
+
+TEST(PreviewsStateHelperTest, UpdatePreviewsStateLoFiFallbackAndOtherPolicies) {
+ blink::WebURLResponse response_with_page_policy;
+ response_with_page_policy.AddHTTPHeaderField("chrome-proxy", "Prefix=Noise");
+ response_with_page_policy.AddHTTPHeaderField(
+ "chrome-proxy", "page-policies=new-hotness|empty-image|newer-hotness");
+ response_with_page_policy.AddHTTPHeaderField("chrome-proxy",
+ "Suffix=More|Noise");
+
+ // Lo-Fi fallbacks if Server Lo-Fi enabled and get empty-image directive.
+ EXPECT_EQ(SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ response_with_page_policy));
+ EXPECT_EQ(SERVER_LOFI_ON, UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON,
+ response_with_page_policy));
+}
+
+TEST(PreviewsStateHelperTest, UpdatePreviewsStateNoKnownPolicies) {
+ blink::WebURLResponse response_with_page_policy;
+ response_with_page_policy.AddHTTPHeaderField("chrome-proxy", "Prefix=Noise");
+ response_with_page_policy.AddHTTPHeaderField(
+ "chrome-proxy",
+ "page-policies=new-hotness|new-empty-image|newer-hotness");
+ response_with_page_policy.AddHTTPHeaderField("chrome-proxy",
+ "Suffix=More|Noise");
+
+ // Lo-Fi fallbacks if Server Lo-Fi enabled and get empty-image directive.
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED,
+ UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON | CLIENT_LOFI_ON,
+ response_with_page_policy));
+ EXPECT_EQ(PREVIEWS_UNSPECIFIED, UpdatePreviewsStateFromMainFrameResponse(
+ SERVER_LITE_PAGE_ON | SERVER_LOFI_ON,
+ response_with_page_policy));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698