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

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 comments Created 3 years, 8 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..ad88bdf4967ae706a5b997afcb120e56a422fb47 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,28 +194,38 @@ 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_;
};
class TestLoFiUIService : public LoFiUIService {
public:
- TestLoFiUIService() : on_lofi_response_(false) {}
+ TestLoFiUIService() {}
~TestLoFiUIService() override {}
- bool DidNotifyLoFiResponse() const { return on_lofi_response_; }
+ const base::Optional<bool>& LoFiResponseWasServer() const {
+ return on_lofi_response_;
+ }
- void OnLoFiReponseReceived(const net::URLRequest& request) override {
- on_lofi_response_ = true;
+ void OnLoFiReponseReceived(const net::URLRequest& request,
+ bool is_server_lofi) override {
+ on_lofi_response_ = is_server_lofi;
}
+ void ClearResponse() { on_lofi_response_.reset(); }
+
private:
- bool on_lofi_response_;
+ base::Optional<bool> on_lofi_response_;
};
enum ProxyTestConfig { USE_SECURE_PROXY, USE_INSECURE_PROXY, BYPASS_PROXY };
@@ -358,10 +373,18 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test {
header_value.find("empty-image") != std::string::npos);
}
- void VerifyDidNotifyLoFiResponse(bool lofi_response) const {
- EXPECT_EQ(lofi_response, lofi_ui_service_->DidNotifyLoFiResponse());
+ void VerifyDidNotifyLoFiResponse(bool lofi_response,
+ bool was_server_lofi) const {
+ base::Optional<bool> lofi_response_was_server =
+ lofi_ui_service_->LoFiResponseWasServer();
+ EXPECT_EQ(lofi_response, lofi_response_was_server.has_value());
+ if (lofi_response_was_server) {
+ EXPECT_EQ(was_server_lofi, lofi_response_was_server.value());
+ }
}
+ void ClearLoFiUIService() { lofi_ui_service_->ClearResponse(); }
+
void VerifyDataReductionProxyData(const net::URLRequest& request,
bool data_reduction_proxy_used,
bool lofi_used) {
@@ -1301,11 +1324,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 +1337,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, test.was_server);
}
}

Powered by Google App Engine
This is Rietveld 408576698