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

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

Issue 1721813002: Adding DRP specfic UMA for FirstContentfulPaint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 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 73d5e14bfc40d6e55e71c16efbcef71c9472245d..1b1b3b771fbef6dc4a981aaa87762ae90a53b949 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
@@ -11,47 +11,51 @@
#include <utility>
#include "base/command_line.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "base/test/histogram_tester.h"
#include "base/test/mock_entropy_provider.h"
#include "base/time/time.h"
#include "base/values.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_metrics.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_headers.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/core/common/lofi_decider.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/proxy/proxy_config.h"
+#include "net/proxy/proxy_info.h"
#include "net/proxy/proxy_server.h"
#include "net/socket/socket_test_util.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
namespace data_reduction_proxy {
namespace {
using TestNetworkDelegate = net::NetworkDelegateImpl;
const char kOtherProxy[] = "testproxy:17";
#if defined(OS_ANDROID)
const Client kClient = Client::CHROME_ANDROID;
@@ -421,20 +425,74 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) {
lofi_decider()->SetIsUsingLoFiMode(
config()->ShouldEnableLoFiMode(*fake_request.get()));
network_delegate()->NotifyBeforeSendProxyHeaders(
fake_request.get(), data_reduction_proxy_info, &headers);
VerifyHeaders(tests[i].is_data_reduction_proxy, true, headers);
VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy);
}
}
}
+TEST_F(DataReductionProxyNetworkDelegateTest, RequestDataConfigurations) {
+ const struct {
+ bool lofi_on;
+ bool used_data_reduction_proxy;
+ } tests[] = {
+ {
+ // Lo-Fi off.
+ false, true,
+ },
+ {
+ // Data reduction proxy not used.
+ false, false,
+ },
+ {
+ // Data reduction proxy not used, Lo-Fi should not be used.
+ true, false,
+ },
+ {
+ // Lo-Fi on.
+ true, true,
+ },
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ net::ProxyInfo data_reduction_proxy_info;
+ std::string data_reduction_proxy;
+ base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy);
+ if (tests[i].used_data_reduction_proxy)
+ data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy);
+ else
+ data_reduction_proxy_info.UseNamedProxy("port.of.other.proxy");
+ {
+ // Main frame loaded. Lo-Fi should be used.
+ net::HttpRequestHeaders headers;
+
+ std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
+ GURL("http://www.google.com/"), nullptr, std::string(), 0));
+ fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME);
+ lofi_decider()->SetIsUsingLoFiMode(tests[i].lofi_on);
+ network_delegate()->NotifyBeforeSendProxyHeaders(
+ fake_request.get(), data_reduction_proxy_info, &headers);
+ DataReductionProxyData* data =
+ DataReductionProxyData::GetData(*fake_request.get());
+ if (!tests[i].used_data_reduction_proxy) {
+ EXPECT_FALSE(data);
+ } else {
+ EXPECT_TRUE(data);
+ EXPECT_TRUE(data->used_data_reduction_proxy());
+ EXPECT_EQ(tests[i].lofi_on, data->lofi_requested());
+ }
+ }
+ }
+}
+
TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
const std::string kReceivedValidOCLHistogramName =
"Net.HttpContentLengthWithValidOCL";
const std::string kOriginalValidOCLHistogramName =
"Net.HttpOriginalContentLengthWithValidOCL";
const std::string kDifferenceValidOCLHistogramName =
"Net.HttpContentLengthDifferenceWithValidOCL";
// Lo-Fi histograms.
const std::string kReceivedValidOCLLoFiOnHistogramName =

Powered by Google App Engine
This is Rietveld 408576698