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

Unified Diff: components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc

Issue 2911673002: New CPAT support in ContentLoFiDecider guarded by feature flag. (Closed)
Patch Set: FIxed a comment 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: components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
diff --git a/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc b/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
index d033a521d8fb8354a89497cbd43b0dbbe0e3cb0c..9e97e3a7a90481c5cc4974229a49a1e6d3c72140 100644
--- a/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
+++ b/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
@@ -15,12 +15,14 @@
#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
@@ -306,6 +308,119 @@ TEST_F(ContentLoFiDeciderTest, LoFiFlags) {
}
}
+TEST_F(ContentLoFiDeciderTest, MaybeSetAcceptTransformHeaderProxyDecides) {
megjablon 2017/05/30 18:38:53 It looks like there's a lot of repeated code in th
dougarnett 2017/05/30 22:15:48 In my previous mondo CL, I had used the struct app
bengr 2017/05/31 18:48:28 I don't like the pattern of using an array of stru
dougarnett 2017/05/31 23:05:21 Ok, broke up into 4 difference tests with simplifi
+ // Turn on proxy-decides-transform feature for these unit tests.
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndEnableFeature(
+ features::kDataReductionProxyDecidesTransform);
+
+ std::unique_ptr<data_reduction_proxy::ContentLoFiDecider> lofi_decider(
+ new data_reduction_proxy::ContentLoFiDecider());
+
+ content::PreviewsState lite_page_enabled = content::SERVER_LITE_PAGE_ON;
+ content::PreviewsState lofi_enabled = content::SERVER_LOFI_ON;
+ content::PreviewsState both_previews_enabled =
+ lite_page_enabled | lofi_enabled;
+
+ // Verify no accept header for HTTPS.
+ {
+ std::unique_ptr<net::URLRequest> request =
+ CreateRequestByType(content::RESOURCE_TYPE_MAIN_FRAME, true /* https */,
+ both_previews_enabled);
+ net::HttpRequestHeaders headers;
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers);
+
+ request = CreateRequestByType(content::RESOURCE_TYPE_IMAGE,
+ true /* https */, both_previews_enabled);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers);
+ }
+
+ // Verify no accept header if previews state indicates to not accept.
+ {
+ content::PreviewsState previews_off =
+ content::PREVIEWS_OFF & both_previews_enabled;
+ std::unique_ptr<net::URLRequest> request =
+ CreateRequest(true /* is main */, previews_off);
+ net::HttpRequestHeaders headers;
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers);
+
+ content::PreviewsState previews_no_transform =
+ content::PREVIEWS_NO_TRANSFORM & both_previews_enabled;
+ request = CreateRequest(true /* is main */, previews_no_transform);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers);
+ }
+
+ // Verify accepting lite-page per resource type.
+ {
+ std::unique_ptr<net::URLRequest> request =
+ CreateRequest(true /* is main */, lite_page_enabled);
+ net::HttpRequestHeaders headers1;
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers1);
+ VerifyLitePageHeader(true /* lite-page */, false /*if-heavy */, headers1);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers1);
+
+ net::HttpRequestHeaders headers2;
+ request = CreateRequest(false /* is main */, lite_page_enabled);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers2);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers2);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers2);
+ }
+
+ // Verify accepting empty-image per resource type.
+ {
+ std::unique_ptr<net::URLRequest> request = CreateRequestByType(
+ content::RESOURCE_TYPE_MAIN_FRAME, false /* https */, lofi_enabled);
+ net::HttpRequestHeaders headers1;
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers1);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers1);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers1);
+
+ net::HttpRequestHeaders headers2;
+ request = CreateRequestByType(content::RESOURCE_TYPE_IMAGE,
+ false /* https */, lofi_enabled);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers2);
+ VerifyLitePageHeader(false /* lite-page */, false /*if-heavy */, headers2);
+ VerifyLoFiHeader(true /* empty-image */, false /*if-heavy */, headers2);
+
+ net::HttpRequestHeaders headers3;
+ request = CreateRequestByType(content::RESOURCE_TYPE_FAVICON,
+ false /* https */, lofi_enabled);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers3);
+ VerifyLoFiHeader(true /* empty-image */, false /*if-heavy */, headers3);
+
+ net::HttpRequestHeaders headers4;
+ request = CreateRequestByType(content::RESOURCE_TYPE_SCRIPT,
+ false /* https */, lofi_enabled);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers4);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers4);
+
+ net::HttpRequestHeaders headers5;
+ request = CreateRequestByType(content::RESOURCE_TYPE_STYLESHEET,
+ false /* https */, lofi_enabled);
+ lofi_decider->MaybeSetAcceptTransformHeader(*request.get(), false,
+ &headers5);
+ VerifyLoFiHeader(false /* empty-image */, false /*if-heavy */, headers5);
+ }
+}
+
TEST_F(ContentLoFiDeciderTest, LoFiEnabledFieldTrial) {
base::FieldTrialList field_trial_list(nullptr);
base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
@@ -403,6 +518,11 @@ TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) {
}
TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) {
+ // Turn off proxy-decides-transform feature for these unit tests.
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndDisableFeature(
+ features::kDataReductionProxyDecidesTransform);
+
base::FieldTrialList field_trial_list(nullptr);
base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
"Enabled_Preview");
@@ -430,6 +550,11 @@ TEST_F(ContentLoFiDeciderTest, LitePageFieldTrial) {
}
TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackEnabled) {
+ // Turn off proxy-decides-transform feature for these unit tests.
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndDisableFeature(
+ features::kDataReductionProxyDecidesTransform);
+
base::FieldTrialList field_trial_list(nullptr);
base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
"Enabled_Preview");
@@ -475,6 +600,11 @@ TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackEnabled) {
}
TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackDisabled) {
+ // Turn off proxy-decides-transform feature for these unit tests.
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndDisableFeature(
+ features::kDataReductionProxyDecidesTransform);
+
base::FieldTrialList field_trial_list(nullptr);
base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
"Enabled_Preview");
@@ -514,6 +644,11 @@ TEST_F(ContentLoFiDeciderTest, LitePageFieldTrialFallbackDisabled) {
}
TEST_F(ContentLoFiDeciderTest, AutoLoFi) {
+ // Turn off proxy-decides-transform feature for these unit tests.
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndDisableFeature(
+ features::kDataReductionProxyDecidesTransform);
+
const struct {
bool auto_lofi_enabled_group;
bool auto_lofi_control_group;
@@ -562,6 +697,11 @@ TEST_F(ContentLoFiDeciderTest, AutoLoFi) {
}
TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) {
+ // Turn off proxy-decides-transform feature for these unit tests.
+ base::test::ScopedFeatureList scoped_feature_list;
+ scoped_feature_list.InitAndDisableFeature(
+ features::kDataReductionProxyDecidesTransform);
+
const struct {
bool slow_connections_flag_enabled;
bool network_prohibitively_slow;

Powered by Google App Engine
This is Rietveld 408576698