Commit 6f733b25 authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding pingback reporting for blacklisted navigations

This adds a previews type state to the pingback that represents that no
preview was served due to the blacklist acting on one of its rules. The
states are still mutually exclusive.

Bug: 849328
Change-Id: I40235d318b68e9674b67ae40df30153c30aba178
Reviewed-on: https://chromium-review.googlesource.com/1086242
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564744}
parent 9193ee21
......@@ -23,6 +23,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_page_load_timing.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/previews/core/previews_user_data.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_data.h"
#include "content/public/browser/navigation_handle.h"
......@@ -147,6 +148,13 @@ DataReductionProxyMetricsObserver::OnCommit(
if (!data || !data->used_data_reduction_proxy())
return STOP_OBSERVING;
data_ = data->DeepCopy();
previews::PreviewsUserData* previews_data =
chrome_navigation_data->previews_user_data();
if (previews_data) {
data_->set_black_listed(previews_data->black_listed_for_lite_page());
}
process_id_ = navigation_handle->GetWebContents()
->GetMainFrame()
->GetProcess()
......
......@@ -31,6 +31,7 @@
#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 "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/previews/core/previews_user_data.h"
#include "content/public/test/web_contents_tester.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
......@@ -45,17 +46,30 @@ const int kMemoryKb = 1024;
data_reduction_proxy::DataReductionProxyData* DataForNavigationHandle(
content::WebContents* web_contents,
content::NavigationHandle* navigation_handle) {
ChromeNavigationData* chrome_navigation_data = new ChromeNavigationData();
content::WebContentsTester::For(web_contents)
->SetNavigationData(navigation_handle,
base::WrapUnique(chrome_navigation_data));
data_reduction_proxy::DataReductionProxyData* data =
new data_reduction_proxy::DataReductionProxyData();
chrome_navigation_data->SetDataReductionProxyData(base::WrapUnique(data));
auto chrome_navigation_data = std::make_unique<ChromeNavigationData>();
auto drp_data =
std::make_unique<data_reduction_proxy::DataReductionProxyData>();
data_reduction_proxy::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) {
ChromeNavigationData* chrome_navigation_data =
static_cast<ChromeNavigationData*>(
navigation_handle->GetNavigationData());
auto data = std::make_unique<previews::PreviewsUserData>(1);
auto* data_ptr = data.get();
chrome_navigation_data->set_previews_user_data(std::move(data));
return data_ptr;
}
// Pingback client responsible for recording the timing information it receives
// from a SendPingback call.
class TestPingbackClient
......@@ -113,11 +127,13 @@ class TestDataReductionProxyMetricsObserver
TestDataReductionProxyMetricsObserver(content::WebContents* web_contents,
TestPingbackClient* pingback_client,
bool data_reduction_proxy_used,
bool lite_page_used)
bool lite_page_used,
bool black_listed)
: web_contents_(web_contents),
pingback_client_(pingback_client),
data_reduction_proxy_used_(data_reduction_proxy_used),
lite_page_used_(lite_page_used) {}
lite_page_used_(lite_page_used),
black_listed_(black_listed) {}
~TestDataReductionProxyMetricsObserver() override {}
......@@ -129,6 +145,10 @@ class TestDataReductionProxyMetricsObserver
data->set_used_data_reduction_proxy(data_reduction_proxy_used_);
data->set_request_url(GURL(kDefaultTestUrl));
data->set_lite_page_received(lite_page_used_);
auto* previews_data = PreviewsDataForNavigationHandle(navigation_handle);
previews_data->set_black_listed_for_lite_page(black_listed_);
return DataReductionProxyMetricsObserver::OnCommit(navigation_handle,
source_id);
}
......@@ -161,6 +181,7 @@ class TestDataReductionProxyMetricsObserver
TestPingbackClient* pingback_client_;
bool data_reduction_proxy_used_;
bool lite_page_used_;
bool black_listed_;
DISALLOW_COPY_AND_ASSIGN(TestDataReductionProxyMetricsObserver);
};
......@@ -172,7 +193,8 @@ class DataReductionProxyMetricsObserverTest
: pingback_client_(new TestPingbackClient()),
data_reduction_proxy_used_(false),
is_using_lite_page_(false),
opt_out_expected_(false) {}
opt_out_expected_(false),
black_listed_(false) {}
void ResetTest() {
page_load_metrics::InitPageLoadTimingForTest(&timing_);
......@@ -196,10 +218,12 @@ class DataReductionProxyMetricsObserverTest
void RunTest(bool data_reduction_proxy_used,
bool is_using_lite_page,
bool opt_out_expected) {
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();
......@@ -208,7 +232,8 @@ class DataReductionProxyMetricsObserverTest
void 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);
RunTest(data_reduction_proxy_used, is_using_lite_page, opt_out_expected,
false);
NavigateToUntrackedUrl();
}
......@@ -256,6 +281,11 @@ class DataReductionProxyMetricsObserverTest
EXPECT_EQ(lofi_expected, pingback_client_->data().lofi_received());
}
void ValidateBlackListInPingback(bool black_listed) {
EXPECT_TRUE(pingback_client_->send_pingback_called());
EXPECT_EQ(black_listed, pingback_client_->data().black_listed());
}
void ValidateRendererCrash(bool renderer_crashed) {
EXPECT_TRUE(pingback_client_->send_pingback_called());
EXPECT_EQ(renderer_crashed,
......@@ -397,7 +427,7 @@ class DataReductionProxyMetricsObserverTest
tracker->AddObserver(
std::make_unique<TestDataReductionProxyMetricsObserver>(
web_contents(), pingback_client_.get(), data_reduction_proxy_used_,
is_using_lite_page_));
is_using_lite_page_, black_listed_));
}
std::unique_ptr<TestPingbackClient> pingback_client_;
......@@ -407,6 +437,7 @@ class DataReductionProxyMetricsObserverTest
bool data_reduction_proxy_used_;
bool is_using_lite_page_;
bool opt_out_expected_;
bool black_listed_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMetricsObserverTest);
};
......@@ -414,7 +445,7 @@ class DataReductionProxyMetricsObserverTest
TEST_F(DataReductionProxyMetricsObserverTest, DataReductionProxyOff) {
ResetTest();
// Verify that when the data reduction proxy was not used, no UMA is reported.
RunTest(false, false, false);
RunTest(false, false, false, false);
ValidateHistograms();
}
......@@ -422,7 +453,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, DataReductionProxyOn) {
ResetTest();
// Verify that when the data reduction proxy was used, but lite page was not
// used, the correpsonding UMA is reported.
RunTest(true, false, false);
RunTest(true, false, false, false);
ValidateHistograms();
}
......@@ -430,7 +461,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, LitePageEnabled) {
ResetTest();
// Verify that when the data reduction proxy was used and lite page was used,
// both histograms are reported.
RunTest(true, true, false);
RunTest(true, true, false, false);
ValidateHistograms();
}
......@@ -473,7 +504,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) {
ResetTest();
// Verify that when an opt out occurs, that it is reported in the pingback.
timing_.document_timing->load_event_start = base::nullopt;
RunTest(true, true, true);
RunTest(true, true, true, false);
observer()->BroadcastEventToObservers(
PreviewsInfoBarDelegate::OptOutEventKey());
NavigateToUntrackedUrl();
......@@ -500,11 +531,17 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) {
0,
{} /* load_timing_info */};
RunTest(true, false, false);
RunTest(true, false, false, false);
SimulateLoadedResource(resource);
NavigateToUntrackedUrl();
ValidateTimes();
ValidateLoFiInPingback(true);
ValidateBlackListInPingback(false);
ResetTest();
RunTest(true, false, false, true);
NavigateToUntrackedUrl();
ValidateBlackListInPingback(true);
ResetTest();
// Verify that when data reduction proxy was not used, SendPingback is not
......@@ -524,7 +561,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) {
TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) {
ResetTest();
RunTest(true, false, false);
RunTest(true, false, false, false);
std::unique_ptr<DataReductionProxyData> data =
std::make_unique<DataReductionProxyData>();
......@@ -615,7 +652,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) {
TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) {
ResetTest();
RunTest(true, false, false);
RunTest(true, false, false, false);
std::unique_ptr<DataReductionProxyData> data =
std::make_unique<DataReductionProxyData>();
......@@ -711,7 +748,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) {
TEST_F(DataReductionProxyMetricsObserverTest, ProcessIdSentOnRendererCrash) {
ResetTest();
RunTest(true, false, false);
RunTest(true, false, false, false);
std::unique_ptr<DataReductionProxyData> data =
std::make_unique<DataReductionProxyData>();
data->set_used_data_reduction_proxy(true);
......@@ -722,7 +759,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, ProcessIdSentOnRendererCrash) {
ValidateRendererCrash(true);
ResetTest();
RunTest(true, false, false);
RunTest(true, false, false, false);
data = std::make_unique<DataReductionProxyData>();
data->set_used_data_reduction_proxy(true);
data->set_request_url(GURL(kDefaultTestUrl));
......
......@@ -149,6 +149,9 @@ void AddDataToPageloadMetrics(const DataReductionProxyData& request_data,
} else if (request_data.lite_page_received()) {
request->set_previews_type(PageloadMetrics_PreviewsType_LITE_PAGE);
was_preview_shown = true;
} else if (request_data.black_listed()) {
request->set_previews_type(
PageloadMetrics_PreviewsType_CLIENT_BLACKLIST_PREVENTED_PREVIEW);
} else {
request->set_previews_type(PageloadMetrics_PreviewsType_NONE);
}
......
......@@ -123,7 +123,8 @@ class DataReductionProxyPingbackClientImplTest : public testing::Test {
bool lite_page_received,
bool app_background_occurred,
bool opt_out_occurred,
bool crash) {
bool crash,
bool black_listed) {
timing_ = std::make_unique<DataReductionProxyPageLoadTiming>(
base::Time::FromJsTime(1500) /* navigation_start */,
base::Optional<base::TimeDelta>(
......@@ -156,6 +157,7 @@ class DataReductionProxyPingbackClientImplTest : public testing::Test {
request_data.set_connection_type(
net::NetworkChangeNotifier::CONNECTION_UNKNOWN);
request_data.set_lofi_received(lofi_received);
request_data.set_black_listed(black_listed);
request_data.set_client_lofi_requested(client_lofi_requested);
request_data.set_lite_page_received(lite_page_received);
request_data.set_page_id(page_id_);
......@@ -211,7 +213,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyPingbackContent) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -292,7 +295,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyHoldback) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -320,7 +324,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest,
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
// Two more pingbacks batched together.
......@@ -329,13 +334,15 @@ TEST_F(DataReductionProxyPingbackClientImplTest,
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 2);
page_ids.push_back(page_id());
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 3);
// Ignore the first pingback.
......@@ -416,12 +423,14 @@ TEST_F(DataReductionProxyPingbackClientImplTest, SendTwoPingbacks) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 2);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
......@@ -444,7 +453,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, NoPingbackSent) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, false, 1);
histogram_tester().ExpectTotalCount(kHistogramSucceeded, 0);
EXPECT_FALSE(factory()->GetFetcherByID(0));
......@@ -462,7 +472,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyReportingBehvaior) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -475,7 +486,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyReportingBehvaior) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectBucketCount(kHistogramAttempted, false, 1);
test_fetcher = factory()->GetFetcherByID(0);
EXPECT_FALSE(test_fetcher);
......@@ -489,7 +501,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyReportingBehvaior) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectBucketCount(kHistogramAttempted, false, 2);
test_fetcher = factory()->GetFetcherByID(0);
EXPECT_FALSE(test_fetcher);
......@@ -503,7 +516,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyReportingBehvaior) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectBucketCount(kHistogramAttempted, true, 2);
test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -520,7 +534,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, FailedPingback) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -542,7 +557,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyLoFiContentNoOptOut) {
CreateAndSendPingback(
true /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */);
false /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -571,7 +587,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyLoFiContentOptOut) {
CreateAndSendPingback(
true /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
true /* opt_out_occurred */, false /* renderer_crash */);
true /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -601,7 +618,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest,
CreateAndSendPingback(
false /* lofi_received */, true /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
true /* opt_out_occurred */, false /* renderer_crash */);
true /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -630,7 +648,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyLoFiContentBackground) {
CreateAndSendPingback(
true /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, true /* app_background_occurred */,
true /* opt_out_occurred */, false /* renderer_crash */);
true /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -648,6 +667,36 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyLoFiContentBackground) {
EXPECT_FALSE(factory()->GetFetcherByID(0));
}
TEST_F(DataReductionProxyPingbackClientImplTest, VerifyBlackListContent) {
Init();
EXPECT_FALSE(factory()->GetFetcherByID(0));
pingback_client()->OverrideRandom(true, 0.5f);
static_cast<DataReductionProxyPingbackClient*>(pingback_client())
->SetPingbackReportingFraction(1.0f);
base::Time current_time = base::Time::UnixEpoch();
pingback_client()->set_current_time(current_time);
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, false /* renderer_crash */,
true /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
EXPECT_EQ(test_fetcher->upload_content_type(), "application/x-protobuf");
RecordPageloadMetricsRequest batched_request;
batched_request.ParseFromString(test_fetcher->upload_data());
EXPECT_EQ(batched_request.pageloads_size(), 1);
PageloadMetrics pageload_metrics = batched_request.pageloads(0);
EXPECT_EQ(PageloadMetrics_PreviewsType_CLIENT_BLACKLIST_PREVENTED_PREVIEW,
pageload_metrics.previews_type());
EXPECT_EQ(PageloadMetrics_PreviewsOptOut_UNKNOWN,
pageload_metrics.previews_opt_out());
test_fetcher->delegate()->OnURLFetchComplete(test_fetcher);
EXPECT_FALSE(factory()->GetFetcherByID(0));
}
TEST_F(DataReductionProxyPingbackClientImplTest, VerifyLitePageContent) {
Init();
EXPECT_FALSE(factory()->GetFetcherByID(0));
......@@ -659,7 +708,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyLitePageContent) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
true /* lite_page_received */, false /* app_background_occurred */,
true /* opt_out_occurred */, false /* renderer_crash */);
true /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -688,11 +738,13 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyTwoLitePagePingbacks) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
true /* lite_page_received */, false /* app_background_occurred */,
true /* opt_out_occurred */, false /* renderer_crash */);
true /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
true /* lite_page_received */, false /* app_background_occurred */,
true /* opt_out_occurred */, false /* renderer_crash */);
true /* opt_out_occurred */, false /* renderer_crash */,
false /* black_listed */);
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 2);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_TRUE(test_fetcher);
......@@ -730,7 +782,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyCrashOomBehavior) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, true /* renderer_crash */);
false /* opt_out_occurred */, true /* renderer_crash */,
false /* black_listed */);
ReportCrash(true /* oom */);
......@@ -763,7 +816,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest, VerifyCrashNotOomBehavior) {
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, true /* renderer_crash */);
false /* opt_out_occurred */, true /* renderer_crash */,
false /* black_listed */);
ReportCrash(false /* oom */);
......@@ -797,7 +851,8 @@ TEST_F(DataReductionProxyPingbackClientImplTest,
CreateAndSendPingback(
false /* lofi_received */, false /* client_lofi_requested */,
false /* lite_page_received */, false /* app_background_occurred */,
false /* opt_out_occurred */, true /* renderer_crash */);
false /* opt_out_occurred */, true /* renderer_crash */,
false /* black_listed */);
// Don't report the crash dump details.
scoped_task_environment_.FastForwardBy(base::TimeDelta::FromSeconds(5));
......
......@@ -19,6 +19,7 @@ DataReductionProxyData::DataReductionProxyData()
lite_page_received_(false),
lofi_policy_received_(false),
lofi_received_(false),
black_listed_(false),
effective_connection_type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
connection_type_(net::NetworkChangeNotifier::CONNECTION_UNKNOWN) {}
......
......@@ -111,6 +111,10 @@ class DataReductionProxyData : public base::SupportsUserData::Data {
const base::Optional<uint64_t>& page_id() const { return page_id_; }
void set_page_id(uint64_t page_id) { page_id_ = page_id; }
// Whether the blacklist prevented a preview.
bool black_listed() const { return black_listed_; }
void set_black_listed(bool black_listed) { black_listed_ = black_listed; }
// Removes |this| from |request|.
static void ClearData(net::URLRequest* request);
......@@ -153,6 +157,9 @@ class DataReductionProxyData : public base::SupportsUserData::Data {
// Whether a lite page response was seen for the request or navigation.
bool lofi_received_;
// Whether the blacklist prevented a preview.
bool black_listed_;
// The session key used for this request or navigation.
std::string session_key_;
......
......@@ -56,6 +56,12 @@ TEST_F(DataReductionProxyDataTest, BasicSettersAndGetters) {
data->set_lofi_received(false);
EXPECT_FALSE(data->lofi_received());
EXPECT_FALSE(data->black_listed());
data->set_black_listed(true);
EXPECT_TRUE(data->black_listed());
data->set_black_listed(false);
EXPECT_FALSE(data->black_listed());
EXPECT_EQ(std::string(), data->session_key());
std::string session_key = "test-key";
data->set_session_key(session_key);
......@@ -122,6 +128,7 @@ TEST_F(DataReductionProxyDataTest, DeepCopy) {
data->set_lofi_requested(tests[i].lofi_test_value);
data->set_lite_page_received(tests[i].lofi_test_value);
data->set_lofi_received(tests[i].lofi_test_value);
data->set_black_listed(tests[i].lofi_test_value);
data->set_session_key(kSessionKey);
data->set_request_url(kTestURL);
data->set_effective_connection_type(net::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
......@@ -130,6 +137,7 @@ TEST_F(DataReductionProxyDataTest, DeepCopy) {
EXPECT_EQ(tests[i].lofi_test_value, copy->lofi_requested());
EXPECT_EQ(tests[i].lofi_test_value, copy->lite_page_received());
EXPECT_EQ(tests[i].lofi_test_value, copy->lofi_received());
EXPECT_EQ(tests[i].lofi_test_value, copy->black_listed());
EXPECT_EQ(tests[i].data_reduction_used, copy->used_data_reduction_proxy());
EXPECT_EQ(kSessionKey, copy->session_key());
EXPECT_EQ(kTestURL, copy->request_url());
......
......@@ -69,12 +69,17 @@ message PageloadMetrics {
// The various server previews that can be shown.
enum PreviewsType {
// No server preview was applied.
// No server preview was applied, but the URL/navigation was not
// blacklisted.
NONE = 0;
// Image placeholders were used on the page.
LOFI = 1;
// The main resource was a lite page.
LITE_PAGE = 2;
// Blacklisting rules caused no server preview to be requested. It's
// possible in the future that client previews might be shown when server
// previews are blacklisted, currently this is not possible.
CLIENT_BLACKLIST_PREVENTED_PREVIEW = 3;
}
// What type of crash occured on the page.
......
......@@ -245,6 +245,10 @@ bool PreviewsIOData::ShouldAllowPreviewAtECT(
PreviewsEligibilityReason status = previews_black_list_->IsLoadedAndAllowed(
request.url(), type, &passed_reasons);
if (status != PreviewsEligibilityReason::ALLOWED) {
if (type == PreviewsType::LITE_PAGE) {
PreviewsUserData::GetData(request)->set_black_listed_for_lite_page(
true);
}
LogPreviewDecisionMade(status, request.url(), base::Time::Now(), type,
std::move(passed_reasons), page_id);
return false;
......@@ -346,6 +350,10 @@ bool PreviewsIOData::IsURLAllowedForPreview(const net::URLRequest& request,
PreviewsEligibilityReason status = previews_black_list_->IsLoadedAndAllowed(
request.url(), type, &passed_reasons);
if (status != PreviewsEligibilityReason::ALLOWED) {
if (type == PreviewsType::LITE_PAGE) {
PreviewsUserData::GetData(request)->set_black_listed_for_lite_page(
true);
}
LogPreviewDecisionMade(status, request.url(), base::Time::Now(), type,
std::move(passed_reasons),
PreviewsUserData::GetData(request)->page_id());
......
......@@ -480,6 +480,25 @@ TEST_F(PreviewsIODataTest, TestDisallowPreviewBecauseOfBlackListState) {
variations::testing::ClearAllVariationParams();
}
TEST_F(PreviewsIODataTest, TestSetBlacklistBoolDueToBlackListState) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kPreviews);
std::unique_ptr<net::URLRequest> request = CreateRequest();
base::HistogramTester histogram_tester;
InitializeUIServiceWithoutWaitingForBlackList();
base::RunLoop().RunUntilIdle();
io_data()->AddPreviewNavigation(GURL(request->url()), true,
PreviewsType::LITE_PAGE, 1);
auto* data =
PreviewsUserData::Create(request.get(), 54321 /* page_id, not used */);
EXPECT_FALSE(data->black_listed_for_lite_page());
EXPECT_FALSE(io_data()->ShouldAllowPreviewAtECT(
*request, PreviewsType::LITE_PAGE, net::EFFECTIVE_CONNECTION_TYPE_2G,
{}));
EXPECT_TRUE(data->black_listed_for_lite_page());
}
TEST_F(PreviewsIODataTest, TestDisallowOfflineWhenNetworkQualityUnavailable) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kPreviews);
......
......@@ -50,6 +50,15 @@ class PreviewsUserData : public base::SupportsUserData::Data {
return data_savings_inflation_percent_;
}
// Whether a lite page preview was prevented from being shown due to the
// blacklist.
bool black_listed_for_lite_page() const {
return black_listed_for_lite_page_;
}
void set_black_listed_for_lite_page(bool black_listed_for_lite_page) {
black_listed_for_lite_page_ = black_listed_for_lite_page;
}
// Sets that the page load received the Cache-Control:no-transform
// directive. Expected to be set upon receiving a committed response.
void SetCacheControlNoTransformDirective() {
......@@ -84,6 +93,10 @@ class PreviewsUserData : public base::SupportsUserData::Data {
// Whether the origin provided a no-transform directive.
bool cache_control_no_transform_directive_ = false;
// Whether a lite page preview was prevented from being shown due to the
// blacklist.
bool black_listed_for_lite_page_ = false;
// The committed previews type, if any.
previews::PreviewsType committed_previews_type_ = PreviewsType::NONE;
......
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