Commit e8ab8653 authored by Yuzu Saijo's avatar Yuzu Saijo Committed by Commit Bot

[bfcache] Add browsertest for printing and bfcache integration

This CL adds a browsertest to make sure that when printing feature is
used on a page, the page is not cached in BackForwardCache.

This is because we currently do not close the popup caused by printing
properly for bfcache. Blocklisting the feature is the first step, and
supporting it is the next step.

Bug: 106849
Change-Id: Ie8195ae88f94d967aed915422099c6e208b67c16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148706
Commit-Queue: Yuzu Saijo <yuzus@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760362}
parent c3ddb228
......@@ -33,6 +33,7 @@
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
......@@ -40,7 +41,9 @@
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h"
namespace printing {
......@@ -312,6 +315,74 @@ class IsolateOriginsPrintBrowserTest : public PrintBrowserTest {
}
};
class BackForwardCachePrintBrowserTest : public PrintBrowserTest {
public:
BackForwardCachePrintBrowserTest() = default;
~BackForwardCachePrintBrowserTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
::features::kBackForwardCache,
{
// Set a very long TTL before expiration (longer than the test
// timeout) so tests that are expecting deletion don't pass when
// they shouldn't.
{"TimeToLiveInBackForwardCacheInSeconds", "3600"},
});
InProcessBrowserTest::SetUpCommandLine(command_line);
}
content::WebContents* web_contents() const {
return browser()->tab_strip_model()->GetActiveWebContents();
}
content::RenderFrameHost* current_frame_host() {
return web_contents()->GetMainFrame();
}
void ExpectBlocklistedFeature(
blink::scheduler::WebSchedulerTrackedFeature feature,
base::Location location) {
base::HistogramBase::Sample sample = base::HistogramBase::Sample(feature);
AddSampleToBuckets(&expected_blocklisted_features_, sample);
EXPECT_THAT(
histogram_tester_.GetAllSamples(
"BackForwardCache.HistoryNavigationOutcome."
"BlocklistedFeature"),
testing::UnorderedElementsAreArray(expected_blocklisted_features_))
<< location.ToString();
EXPECT_THAT(
histogram_tester_.GetAllSamples(
"BackForwardCache.AllSites.HistoryNavigationOutcome."
"BlocklistedFeature"),
testing::UnorderedElementsAreArray(expected_blocklisted_features_))
<< location.ToString();
}
base::HistogramTester histogram_tester_;
private:
void AddSampleToBuckets(std::vector<base::Bucket>* buckets,
base::HistogramBase::Sample sample) {
auto it = std::find_if(
buckets->begin(), buckets->end(),
[sample](const base::Bucket& bucket) { return bucket.min == sample; });
if (it == buckets->end()) {
buckets->push_back(base::Bucket(sample, 1));
} else {
it->count++;
}
}
std::vector<base::Bucket> expected_blocklisted_features_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(BackForwardCachePrintBrowserTest);
};
constexpr char IsolateOriginsPrintBrowserTest::kIsolatedSite[];
class PrintExtensionBrowserTest : public extensions::ExtensionBrowserTest {
......@@ -616,6 +687,29 @@ IN_PROC_BROWSER_TEST_F(IsolateOriginsPrintBrowserTest, OopifPrinting) {
EXPECT_TRUE(IsOopifEnabled());
}
IN_PROC_BROWSER_TEST_F(BackForwardCachePrintBrowserTest, DisableCaching) {
ASSERT_TRUE(embedded_test_server()->Started());
// 1) Navigate to A and trigger printing.
GURL url(embedded_test_server()->GetURL("a.com", "/printing/test1.html"));
ui_test_utils::NavigateToURL(browser(), url);
content::RenderFrameHost* rfh_a = current_frame_host();
content::RenderFrameDeletedObserver delete_observer_rfh_a(rfh_a);
PrintAndWaitUntilPreviewIsReady(/*print_only_selection=*/false);
// 2) Navigate to B.
// The first page is not cached because printing preview was open.
GURL url_2(embedded_test_server()->GetURL("b.com", "/printing/test2.html"));
ui_test_utils::NavigateToURL(browser(), url_2);
delete_observer_rfh_a.WaitUntilDeleted();
// 3) Navigate back and checks the blocklisted feature is recorded in UMA.
web_contents()->GetController().GoBack();
EXPECT_TRUE(content::WaitForLoadStop(web_contents()));
ExpectBlocklistedFeature(
blink::scheduler::WebSchedulerTrackedFeature::kPrinting, FROM_HERE);
}
// Printing an extension option page.
// The test should not crash or timeout.
IN_PROC_BROWSER_TEST_F(PrintExtensionBrowserTest, PrintOptionPage) {
......
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