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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc

Issue 2848293002: Adding the Previews infobar to pages that show a client LoFi image (Closed)
Patch Set: sclittle nit 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/core/browser/data_reduction_proxy_network_delegate_unittest.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
index 8f277a960a60490e1dcbc309e1e0c25c43653103..3672297f81bc418bd5551a09a0be9737827fc2dc 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
@@ -133,7 +133,8 @@ const Client kClient = Client::UNKNOWN;
class TestLoFiDecider : public LoFiDecider {
public:
TestLoFiDecider()
- : should_request_lofi_resource_(false),
+ : should_be_client_lofi_(false),
+ should_request_lofi_resource_(false),
ignore_is_using_data_reduction_proxy_check_(false) {}
~TestLoFiDecider() override {}
@@ -145,6 +146,10 @@ class TestLoFiDecider : public LoFiDecider {
should_request_lofi_resource_ = should_request_lofi_resource;
}
+ void SetIsUsingClientLoFi(bool should_be_client_lofi) {
+ should_be_client_lofi_ = should_be_client_lofi;
+ }
+
void MaybeSetAcceptTransformHeader(
const net::URLRequest& request,
bool is_previews_disabled,
@@ -189,11 +194,16 @@ class TestLoFiDecider : public LoFiDecider {
return should_request_lofi_resource_;
}
+ bool IsClientLoFiImageRequest(const net::URLRequest& request) const override {
+ return should_be_client_lofi_;
+ }
+
void ignore_is_using_data_reduction_proxy_check() {
ignore_is_using_data_reduction_proxy_check_ = true;
}
private:
+ bool should_be_client_lofi_;
bool should_request_lofi_resource_;
bool ignore_is_using_data_reduction_proxy_check_;
};
@@ -209,6 +219,8 @@ class TestLoFiUIService : public LoFiUIService {
on_lofi_response_ = true;
}
+ void ClearResponse() { on_lofi_response_ = false; }
+
private:
bool on_lofi_response_;
};
@@ -362,6 +374,8 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test {
EXPECT_EQ(lofi_response, lofi_ui_service_->DidNotifyLoFiResponse());
}
+ void ClearLoFiUIService() { lofi_ui_service_->ClearResponse(); }
+
void VerifyDataReductionProxyData(const net::URLRequest& request,
bool data_reduction_proxy_used,
bool lofi_used) {
@@ -1301,11 +1315,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) {
// Enable Lo-Fi.
const struct {
bool lofi_response;
- } tests[] = {
- {false}, {true},
- };
+ bool was_server;
+ } tests[] = {{false, false}, {true, true}, {true, false}};
- for (size_t i = 0; i < arraysize(tests); ++i) {
+ for (const auto& test : tests) {
+ lofi_decider()->SetIsUsingClientLoFi(false);
+ ClearLoFiUIService();
std::string response_headers =
"HTTP/1.1 200 OK\r\n"
"Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n"
@@ -1313,15 +1328,19 @@ TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) {
"Via: 1.1 Chrome-Compression-Proxy\r\n"
"x-original-content-length: 200\r\n";
- if (tests[i].lofi_response)
- response_headers += "Chrome-Proxy-Content-Transform: empty-image\r\n";
+ if (test.lofi_response) {
+ if (test.was_server)
+ response_headers += "Chrome-Proxy-Content-Transform: empty-image\r\n";
+ else
+ lofi_decider()->SetIsUsingClientLoFi(true);
+ }
response_headers += "\r\n";
auto request =
FetchURLRequest(GURL(kTestURL), nullptr, response_headers, 140, 0);
- EXPECT_EQ(tests[i].lofi_response,
+ EXPECT_EQ(test.was_server,
DataReductionProxyData::GetData(*request)->lofi_received());
- VerifyDidNotifyLoFiResponse(tests[i].lofi_response);
+ VerifyDidNotifyLoFiResponse(test.lofi_response);
}
}

Powered by Google App Engine
This is Rietveld 408576698