Commit e21cc524 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

DRP Pingbacks: Factor out the pingback logic to a base class

Since HTTPS Server Previews will also send pingbacks, and we don't want
a lot of copied code, this factors all DRP pingback logic out into a
shareable base class. The histogram recording stays in the DRP Observer.

Also factors out a test_utils class for testing pingbacks.

This CL has no behavorial changes to pingbacks themselves. However, in
the next CL, the OnCommit logic will move from the base class to the
derived classes.

Bug: 864665
Change-Id: I569bc58331b45b71ae702149e43a2630d523e6dc
Reviewed-on: https://chromium-review.googlesource.com/c/1351497
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611364}
parent 98f045a4
......@@ -939,6 +939,8 @@ jumbo_split_static_library("browser") {
"page_load_metrics/observers/core_page_load_metrics_observer.h",
"page_load_metrics/observers/data_reduction_proxy_metrics_observer.cc",
"page_load_metrics/observers/data_reduction_proxy_metrics_observer.h",
"page_load_metrics/observers/data_reduction_proxy_metrics_observer_base.cc",
"page_load_metrics/observers/data_reduction_proxy_metrics_observer_base.h",
"page_load_metrics/observers/data_saver_site_breakdown_metrics_observer.cc",
"page_load_metrics/observers/data_saver_site_breakdown_metrics_observer.h",
"page_load_metrics/observers/document_write_page_load_metrics_observer.cc",
......
......@@ -5,27 +5,11 @@
#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_H_
#define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_H_
#include <stdint.h>
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process_handle.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
namespace content {
class BrowserContext;
class NavigationHandle;
}
#include "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_base.h"
namespace data_reduction_proxy {
class DataReductionProxyData;
class DataReductionProxyPingbackClient;
namespace internal {
......@@ -50,22 +34,15 @@ extern const char kBytesInflation[];
} // namespace internal
// Observer responsible for recording core page load metrics releveant to
// DataReductionProxy.
// Observer responsible for recording core page load metrics histograms relevant
// to DataReductionProxy.
class DataReductionProxyMetricsObserver
: public page_load_metrics::PageLoadMetricsObserver {
: public DataReductionProxyMetricsObserverBase {
public:
DataReductionProxyMetricsObserver();
~DataReductionProxyMetricsObserver() override;
// page_load_metrics::PageLoadMetricsObserver:
ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) override;
ObservePolicy OnRedirect(
content::NavigationHandle* navigation_handle) override;
ObservePolicy OnCommit(content::NavigationHandle* navigation_handle,
ukm::SourceId source_id) override;
ObservePolicy FlushMetricsOnAppEnterBackground(
const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) override;
......@@ -98,114 +75,11 @@ class DataReductionProxyMetricsObserver
const page_load_metrics::PageLoadExtraInfo& info) override;
void OnParseStop(const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) override;
void OnLoadedResource(const page_load_metrics::ExtraRequestCompleteInfo&
extra_request_compelte_info) override;
void OnResourceDataUseObserved(
const std::vector<page_load_metrics::mojom::ResourceDataUpdatePtr>&
resources) override;
void OnEventOccurred(const void* const event_key) override;
void OnUserInput(const blink::WebInputEvent& event) override;
// Exponentially bucket the number of bytes for privacy-implicated resources.
// Input below 10KB returns 0.
static int64_t ExponentiallyBucketBytes(int64_t bytes);
private:
// Sends the page load information to the pingback client.
void SendPingback(const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info,
bool app_background_occurred);
// Records UMA of page size when the observer is about to be deleted.
void RecordPageSizeUMA() const;
// Gets the default DataReductionProxyPingbackClient. Overridden in testing.
virtual DataReductionProxyPingbackClient* GetPingbackClient() const;
// Used as a callback to getting a memory dump of the related renderer
// process.
void ProcessMemoryDump(
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> memory_dump);
// Gets the memory coordinator for Chrome. Virtual for testing.
virtual void RequestProcessDump(
base::ProcessId pid,
memory_instrumentation::MemoryInstrumentation::RequestGlobalDumpCallback
callback);
// Data related to this navigation.
std::unique_ptr<DataReductionProxyData> data_;
// The browser context this navigation is operating in.
content::BrowserContext* browser_context_;
// True if a Preview opt out occurred during this page load.
bool opted_out_;
// The number of resources that used data reduction proxy.
int num_data_reduction_proxy_resources_;
// The number of resources that did not come from cache.
int num_network_resources_;
// The total content network bytes that the user would have downloaded if they
// were not using data reduction proxy for HTTP resources.
int64_t insecure_original_network_bytes_;
// The total content network bytes that the user would have downloaded if they
// were not using data reduction proxy for HTTPS resources.
int64_t secure_original_network_bytes_;
// The total network bytes loaded through data reduction proxy. This value
// only concerns HTTP traffic.
int64_t network_bytes_proxied_;
// The total network bytes used for HTTP resources.
int64_t insecure_network_bytes_;
// The total network bytes used for HTTPS resources.
int64_t secure_network_bytes_;
// The total cached bytes used for HTTP resources.
int64_t insecure_cached_bytes_;
// The total cached bytes used for HTTPS resources.
int64_t secure_cached_bytes_;
// The process ID of the main frame renderer during OnCommit.
base::ProcessId process_id_;
// The memory usage of the main frame renderer shortly after OnLoadEventStart.
// Available after ProcessMemoryDump is called. 0 before that point.
int64_t renderer_memory_usage_kb_;
// A unique identifier to the child process of the render frame, stored in
// case of a renderer crash.
// Set at navigation commit time.
int render_process_host_id_;
// The number of touch events on the page.
uint32_t touch_count_;
// The number of scroll events on the page.
uint32_t scroll_count_;
// The number of main frame redirects that occurred before commit.
uint32_t redirect_count_;
// The time when the navigation started. Used to estimate
// |navigation_start_to_main_frame_fetch_start_|.
base::TimeTicks navigation_start_;
// The duration between the navigation start as reported by the navigation
// handle, and when the fetchStart of the main page HTML.
base::TimeDelta navigation_start_to_main_frame_fetch_start_;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<DataReductionProxyMetricsObserver> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMetricsObserver);
};
......
// Copyright 2018 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.
#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_BASE_H_
#define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_BASE_H_
#include <stdint.h>
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process_handle.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
namespace content {
class BrowserContext;
class NavigationHandle;
} // namespace content
namespace data_reduction_proxy {
class DataReductionProxyData;
class DataReductionProxyPingbackClient;
// Observer responsible for recording core page load metrics relevant to
// DataReductionProxy's pingback.
class DataReductionProxyMetricsObserverBase
: public page_load_metrics::PageLoadMetricsObserver {
public:
DataReductionProxyMetricsObserverBase();
~DataReductionProxyMetricsObserverBase() override;
// page_load_metrics::PageLoadMetricsObserver:
ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) override;
ObservePolicy OnRedirect(
content::NavigationHandle* navigation_handle) override;
ObservePolicy OnCommit(content::NavigationHandle* navigation_handle,
ukm::SourceId source_id) override;
ObservePolicy FlushMetricsOnAppEnterBackground(
const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) override;
void OnComplete(const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) override;
void OnLoadEventStart(
const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info) override;
void OnLoadedResource(const page_load_metrics::ExtraRequestCompleteInfo&
extra_request_compelte_info) override;
void OnResourceDataUseObserved(
const std::vector<page_load_metrics::mojom::ResourceDataUpdatePtr>&
resources) override;
void OnEventOccurred(const void* const event_key) override;
void OnUserInput(const blink::WebInputEvent& event) override;
// Exponentially bucket the number of bytes for privacy-implicated resources.
// Input below 10KB returns 0.
static int64_t ExponentiallyBucketBytes(int64_t bytes);
protected:
DataReductionProxyData* data() const { return data_.get(); }
int num_network_resources() const { return num_network_resources_; }
int num_data_reduction_proxy_resources() const {
return num_data_reduction_proxy_resources_;
}
int64_t network_bytes_proxied() const { return network_bytes_proxied_; }
int64_t insecure_network_bytes() const { return insecure_network_bytes_; }
int64_t secure_network_bytes() const { return secure_network_bytes_; }
int64_t insecure_original_network_bytes() const {
return insecure_original_network_bytes_;
}
int64_t secure_original_network_bytes() const {
return secure_original_network_bytes_;
}
SEQUENCE_CHECKER(sequence_checker_);
private:
// Sends the page load information to the pingback client.
void SendPingback(const page_load_metrics::mojom::PageLoadTiming& timing,
const page_load_metrics::PageLoadExtraInfo& info,
bool app_background_occurred);
// Gets the default DataReductionProxyPingbackClient. Overridden in testing.
virtual DataReductionProxyPingbackClient* GetPingbackClient() const;
// Used as a callback to getting a memory dump of the related renderer
// process.
void ProcessMemoryDump(
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> memory_dump);
// Gets the memory coordinator for Chrome. Virtual for testing.
virtual void RequestProcessDump(
base::ProcessId pid,
memory_instrumentation::MemoryInstrumentation::RequestGlobalDumpCallback
callback);
// Data related to this navigation.
std::unique_ptr<DataReductionProxyData> data_;
// The browser context this navigation is operating in.
content::BrowserContext* browser_context_;
// True if a Preview opt out occurred during this page load.
bool opted_out_;
// The number of resources that used data reduction proxy.
int num_data_reduction_proxy_resources_;
// The number of resources that did not come from cache.
int num_network_resources_;
// The total content network bytes that the user would have downloaded if they
// were not using data reduction proxy for HTTP resources.
int64_t insecure_original_network_bytes_;
// The total content network bytes that the user would have downloaded if they
// were not using data reduction proxy for HTTPS resources.
int64_t secure_original_network_bytes_;
// The total network bytes loaded through data reduction proxy. This value
// only concerns HTTP traffic.
int64_t network_bytes_proxied_;
// The total network bytes used for HTTP resources.
int64_t insecure_network_bytes_;
// The total network bytes used for HTTPS resources.
int64_t secure_network_bytes_;
// The total cached bytes used for HTTP resources.
int64_t insecure_cached_bytes_;
// The total cached bytes used for HTTPS resources.
int64_t secure_cached_bytes_;
// The process ID of the main frame renderer during OnCommit.
base::ProcessId process_id_;
// The memory usage of the main frame renderer shortly after OnLoadEventStart.
// Available after ProcessMemoryDump is called. 0 before that point.
int64_t renderer_memory_usage_kb_;
// A unique identifier to the child process of the render frame, stored in
// case of a renderer crash.
// Set at navigation commit time.
int render_process_host_id_;
// The number of touch events on the page.
uint32_t touch_count_;
// The number of scroll events on the page.
uint32_t scroll_count_;
// The number of main frame redirects that occurred before commit.
uint32_t redirect_count_;
// The time when the navigation started. Used to estimate
// |navigation_start_to_main_frame_fetch_start_|.
base::TimeTicks navigation_start_;
// The duration between the navigation start as reported by the navigation
// handle, and when the fetchStart of the main page HTML.
base::TimeDelta navigation_start_to_main_frame_fetch_start_;
base::WeakPtrFactory<DataReductionProxyMetricsObserverBase> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMetricsObserverBase);
};
} // namespace data_reduction_proxy
#endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_BASE_H_
// Copyright 2018 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 "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_test_utils.h"
#include "chrome/browser/loader/chrome_navigation_data.h"
#include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
#include "chrome/browser/page_load_metrics/page_load_tracker.h"
#include "chrome/browser/previews/previews_ui_tab_helper.h"
#include "components/previews/content/previews_user_data.h"
#include "content/public/test/web_contents_tester.h"
namespace data_reduction_proxy {
DataReductionProxyData* DataForNavigationHandle(
content::WebContents* web_contents,
content::NavigationHandle* navigation_handle) {
auto chrome_navigation_data = std::make_unique<ChromeNavigationData>();
auto drp_data = std::make_unique<DataReductionProxyData>();
DataReductionProxyData* data = drp_data.get();
chrome_navigation_data->SetDataReductionProxyData(std::move(drp_data));
content::WebContentsTester::For(web_contents)
->SetNavigationData(navigation_handle, std::move(chrome_navigation_data));
return data;
}
previews::PreviewsUserData* PreviewsDataForNavigationHandle(
content::NavigationHandle* navigation_handle) {
PreviewsUITabHelper* ui_tab_helper =
PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents());
previews::PreviewsUserData* previews_user_data =
ui_tab_helper->GetPreviewsUserData(navigation_handle);
if (previews_user_data)
return previews_user_data;
return ui_tab_helper->CreatePreviewsUserDataForNavigationHandle(
navigation_handle, 1u);
}
page_load_metrics::mojom::ResourceDataUpdatePtr
CreateDataReductionProxyResource(bool was_cached,
int64_t delta_bytes,
bool is_complete,
bool proxy_used,
double compression_ratio) {
auto resource_data_update =
page_load_metrics::mojom::ResourceDataUpdate::New();
resource_data_update->was_fetched_via_cache = was_cached;
resource_data_update->delta_bytes = was_cached ? 0 : delta_bytes;
resource_data_update->encoded_body_length = delta_bytes;
resource_data_update->is_complete = is_complete;
resource_data_update->proxy_used = true;
resource_data_update->data_reduction_proxy_compression_ratio_estimate =
compression_ratio;
return resource_data_update;
}
TestPingbackClient::TestPingbackClient()
: DataReductionProxyPingbackClientImpl(nullptr,
base::ThreadTaskRunnerHandle::Get(),
"unknown"),
send_pingback_called_(false) {}
TestPingbackClient::~TestPingbackClient() {}
void TestPingbackClient::SendPingback(
const DataReductionProxyData& data,
const DataReductionProxyPageLoadTiming& timing) {
timing_.reset(new DataReductionProxyPageLoadTiming(timing));
send_pingback_called_ = true;
data_ = data.DeepCopy();
}
void TestPingbackClient::Reset() {
send_pingback_called_ = false;
timing_.reset();
}
FakeInputEvent::FakeInputEvent(blink::WebInputEvent::Type type)
: WebInputEvent(sizeof(FakeInputEvent),
type,
blink::WebInputEvent::kNoModifiers,
base::TimeTicks::Now()) {}
DataReductionProxyMetricsObserverTestBase::
DataReductionProxyMetricsObserverTestBase()
: pingback_client_(new TestPingbackClient()),
data_reduction_proxy_used_(false),
is_using_lite_page_(false),
opt_out_expected_(false),
black_listed_(false) {}
DataReductionProxyMetricsObserverTestBase::
~DataReductionProxyMetricsObserverTestBase() {}
void DataReductionProxyMetricsObserverTestBase::ResetTest() {
page_load_metrics::InitPageLoadTimingForTest(&timing_);
// Reset to the default testing state. Does not reset histogram state.
timing_.navigation_start = base::Time::FromDoubleT(1);
timing_.response_start = base::TimeDelta::FromSeconds(2);
timing_.parse_timing->parse_start = base::TimeDelta::FromSeconds(3);
timing_.paint_timing->first_contentful_paint =
base::TimeDelta::FromSeconds(4);
timing_.paint_timing->first_paint = base::TimeDelta::FromSeconds(4);
timing_.paint_timing->first_meaningful_paint =
base::TimeDelta::FromSeconds(8);
timing_.paint_timing->first_image_paint = base::TimeDelta::FromSeconds(5);
timing_.paint_timing->first_text_paint = base::TimeDelta::FromSeconds(6);
timing_.document_timing->load_event_start = base::TimeDelta::FromSeconds(7);
timing_.parse_timing->parse_stop = base::TimeDelta::FromSeconds(4);
timing_.parse_timing->parse_blocked_on_script_load_duration =
base::TimeDelta::FromSeconds(1);
PopulateRequiredTimingFields(&timing_);
}
void DataReductionProxyMetricsObserverTestBase::RunTest(
bool data_reduction_proxy_used,
bool is_using_lite_page,
bool opt_out_expected,
bool black_listed) {
data_reduction_proxy_used_ = data_reduction_proxy_used;
is_using_lite_page_ = is_using_lite_page;
opt_out_expected_ = opt_out_expected;
black_listed_ = black_listed;
NavigateAndCommit(GURL(kDefaultTestUrl));
SimulateTimingUpdate(timing_);
pingback_client_->Reset();
}
void DataReductionProxyMetricsObserverTestBase::
RunTestAndNavigateToUntrackedUrl(bool data_reduction_proxy_used,
bool is_using_lite_page,
bool opt_out_expected) {
RunTest(data_reduction_proxy_used, is_using_lite_page, opt_out_expected,
false);
NavigateToUntrackedUrl();
}
void DataReductionProxyMetricsObserverTestBase::SimulateRendererCrash() {
observer()->RenderProcessGone(
base::TerminationStatus::TERMINATION_STATUS_ABNORMAL_TERMINATION);
}
// Verify that, if expected and actual are set, their values are equal.
// Otherwise, verify that both are unset.
void DataReductionProxyMetricsObserverTestBase::ExpectEqualOrUnset(
const base::Optional<base::TimeDelta>& expected,
const base::Optional<base::TimeDelta>& actual) {
if (expected && actual) {
EXPECT_EQ(expected.value(), actual.value());
} else {
EXPECT_TRUE(!expected);
EXPECT_TRUE(!actual);
}
}
void DataReductionProxyMetricsObserverTestBase::ValidateTimes() {
EXPECT_TRUE(pingback_client_->send_pingback_called());
EXPECT_EQ(timing_.navigation_start,
pingback_client_->timing()->navigation_start);
EXPECT_GT(pingback_client_->timing()->page_end_time, base::TimeDelta());
ExpectEqualOrUnset(timing_.paint_timing->first_contentful_paint,
pingback_client_->timing()->first_contentful_paint);
ExpectEqualOrUnset(
timing_.paint_timing->first_meaningful_paint,
pingback_client_->timing()->experimental_first_meaningful_paint);
ExpectEqualOrUnset(timing_.response_start,
pingback_client_->timing()->response_start);
ExpectEqualOrUnset(timing_.document_timing->load_event_start,
pingback_client_->timing()->load_event_start);
ExpectEqualOrUnset(timing_.paint_timing->first_image_paint,
pingback_client_->timing()->first_image_paint);
EXPECT_EQ(opt_out_expected_, pingback_client_->timing()->opt_out_occurred);
EXPECT_EQ(timing_.document_timing->load_event_start
? static_cast<int64_t>(kMemoryKb)
: 0,
pingback_client_->timing()->renderer_memory_usage_kb);
}
void DataReductionProxyMetricsObserverTestBase::ValidateLoFiInPingback(
bool lofi_expected) {
EXPECT_TRUE(pingback_client_->send_pingback_called());
EXPECT_EQ(lofi_expected, pingback_client_->data().lofi_received());
}
void DataReductionProxyMetricsObserverTestBase::ValidateBlackListInPingback(
bool black_listed) {
EXPECT_TRUE(pingback_client_->send_pingback_called());
EXPECT_EQ(black_listed, pingback_client_->data().black_listed());
}
void DataReductionProxyMetricsObserverTestBase::ValidateRendererCrash(
bool renderer_crashed) {
EXPECT_TRUE(pingback_client_->send_pingback_called());
EXPECT_EQ(renderer_crashed, pingback_client_->timing()->host_id !=
content::ChildProcessHost::kInvalidUniqueID);
}
void DataReductionProxyMetricsObserverTestBase::SetUp() {
page_load_metrics::PageLoadMetricsObserverTestHarness ::SetUp();
PreviewsUITabHelper::CreateForWebContents(web_contents());
}
} // namespace data_reduction_proxy
// Copyright 2018 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.
#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_TEST_UTILS_H_
#define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_TEST_UTILS_H_
#include <stdint.h>
#include <functional>
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_test_harness.h"
#include "chrome/common/page_load_metrics/page_load_timing.h"
#include "chrome/common/page_load_metrics/test/page_load_metrics_test_util.h"
#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_pingback_client_impl.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_page_load_timing.h"
#include "third_party/blink/public/platform/web_input_event.h"
namespace previews {
class PreviewsUserData;
}
namespace data_reduction_proxy {
const char kDefaultTestUrl[] = "http://google.com";
const int kMemoryKb = 1024;
// Attaches a new |DataReductionProxyData| to |navigation_handle|'s navigation
// data.
DataReductionProxyData* DataForNavigationHandle(
content::WebContents* web_contents,
content::NavigationHandle* navigation_handle);
// Attaches a new |PreviewsUserData| to the given |navigation_handle|.
previews::PreviewsUserData* PreviewsDataForNavigationHandle(
content::NavigationHandle* navigation_handle);
page_load_metrics::mojom::ResourceDataUpdatePtr
CreateDataReductionProxyResource(bool was_cached,
int64_t delta_bytes,
bool is_complete,
bool proxy_used,
double compression_ratio = 1.0);
// Pingback client responsible for recording the timing information it receives
// from a SendPingback call.
class TestPingbackClient : public DataReductionProxyPingbackClientImpl {
public:
TestPingbackClient();
~TestPingbackClient() override;
// Mocks sending a pingback. |data_| and |timing_| are set to |data| and
// |timing|.
void SendPingback(const DataReductionProxyData& data,
const DataReductionProxyPageLoadTiming& timing) override;
// Resets the internal state of |this|.
void Reset();
DataReductionProxyPageLoadTiming* timing() const { return timing_.get(); }
const DataReductionProxyData& data() const { return *data_; }
bool send_pingback_called() const { return send_pingback_called_; }
private:
std::unique_ptr<DataReductionProxyPageLoadTiming> timing_;
std::unique_ptr<DataReductionProxyData> data_;
bool send_pingback_called_;
DISALLOW_COPY_AND_ASSIGN(TestPingbackClient);
};
class FakeInputEvent : public blink::WebInputEvent {
public:
explicit FakeInputEvent(blink::WebInputEvent::Type type);
};
// This base test class does all the test support and validation associated with
// the DRP pingbacks.
class DataReductionProxyMetricsObserverTestBase
: public page_load_metrics::PageLoadMetricsObserverTestHarness {
public:
DataReductionProxyMetricsObserverTestBase();
~DataReductionProxyMetricsObserverTestBase() override;
// Resets all testing state. Should be called before every test case.
void ResetTest();
// Navigates and commits to |kDefaultTestUrl| and mocks a single timing
// update.
void RunTest(bool data_reduction_proxy_used,
bool is_using_lite_page,
bool opt_out_expected,
bool black_listed);
// The same as |RunTest| but also navigates to an untracked URL afterwards.
void RunTestAndNavigateToUntrackedUrl(bool data_reduction_proxy_used,
bool is_using_lite_page,
bool opt_out_expected);
// Mocks a renderer crash.
void SimulateRendererCrash();
// Verify that, if expected and actual are set, their values are equal.
// Otherwise, verify that both are unset.
void ExpectEqualOrUnset(const base::Optional<base::TimeDelta>& expected,
const base::Optional<base::TimeDelta>& actual);
// Validates the times in the pingback.
void ValidateTimes();
// Validates the LoFi state in the pingback.
void ValidateLoFiInPingback(bool lofi_expected);
// Validates the blacklist state in the pingback.
void ValidateBlackListInPingback(bool black_listed);
// Validates the renderer crash state in the pingback.
void ValidateRendererCrash(bool renderer_crashed);
// Set ups test state.
void SetUp() override;
TestPingbackClient* pingback_client() const { return pingback_client_.get(); }
page_load_metrics::mojom::PageLoadTimingPtr timing() {
return timing_.Clone();
}
bool cached_data_reduction_proxy_used() const {
return cached_data_reduction_proxy_used_;
}
bool data_reduction_proxy_used() const { return data_reduction_proxy_used_; }
bool is_using_lite_page() const { return is_using_lite_page_; }
bool opt_out_expected() const { return opt_out_expected_; }
bool black_listed() const { return black_listed_; }
protected:
std::unique_ptr<TestPingbackClient> pingback_client_;
page_load_metrics::mojom::PageLoadTiming timing_;
bool cached_data_reduction_proxy_used_ = false;
private:
bool data_reduction_proxy_used_;
bool is_using_lite_page_;
bool opt_out_expected_;
bool black_listed_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMetricsObserverTestBase);
};
} // namespace data_reduction_proxy
#endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_DATA_REDUCTION_PROXY_METRICS_OBSERVER_TEST_UTILS_H_
......@@ -2555,6 +2555,9 @@ test("unit_tests") {
"../browser/page_load_metrics/observers/ads_page_load_metrics_observer_unittest.cc",
"../browser/page_load_metrics/observers/amp_page_load_metrics_observer_unittest.cc",
"../browser/page_load_metrics/observers/core_page_load_metrics_observer_unittest.cc",
"../browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_base_unittest.cc",
"../browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_test_utils.cc",
"../browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_test_utils.h",
"../browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_unittest.cc",
"../browser/page_load_metrics/observers/document_write_page_load_metrics_observer_unittest.cc",
"../browser/page_load_metrics/observers/from_gws_page_load_metrics_observer_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment