Commit 1c886c53 authored by Tommy C. Li's avatar Tommy C. Li Committed by Commit Bot

Click to Open PDF: Add EMBED browsertest

This re-adds the previously approved and committed browsertest, but this
time with a fix for the flakiness.

The body of the test remains the same, but with an extra call to:
PluginTestUtils::WaitForPlaceholderReady(GetActiveWebContents(),
                                         "pdf_embed");

There is also an update the command line flags and an extra include.

This is patch 3/3 for this objective.

Bug: 887752, 879149, 878871
Change-Id: Ie8c70d68fb3e3ebf9e70e5d9f2f1aa2f37b190f4
Reviewed-on: https://chromium-review.googlesource.com/c/1336086Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608411}
parent 960996fe
......@@ -30,6 +30,7 @@
#include "chrome/browser/pdf/pdf_extension_test_util.h"
#include "chrome/browser/pdf/pdf_extension_util.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/plugins/plugin_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
......@@ -61,6 +62,7 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
......@@ -430,6 +432,12 @@ class PDFPluginDisabledTest : public PDFExtensionTest {
PDFPluginDisabledTest() {}
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
PDFExtensionTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting);
}
void SetUpOnMainThread() override {
PDFExtensionTest::SetUpOnMainThread();
......@@ -492,6 +500,29 @@ IN_PROC_BROWSER_TEST_F(PDFPluginDisabledTest, DirectNavigationToPDF) {
EXPECT_EQ(0, CountPDFProcesses());
}
IN_PROC_BROWSER_TEST_F(PDFPluginDisabledTest, EmbedPdfPlaceholderWithCSP) {
// Navigate to a page with CSP that uses <embed> to embed a PDF as a plugin.
GURL embed_page_url =
embedded_test_server()->GetURL("/pdf/pdf_embed_csp.html");
ui_test_utils::NavigateToURL(browser(), embed_page_url);
PluginTestUtils::WaitForPlaceholderReady(GetActiveWebContents(), "pdf_embed");
// Fake a click on the <embed>, then press Enter to trigger the download.
gfx::Point point_in_pdf(100, 100);
content::SimulateRoutedMouseClickAt(
GetActiveWebContents(), kDefaultKeyModifier,
blink::WebMouseEvent::Button::kLeft, point_in_pdf);
content::SimulateKeyPress(GetActiveWebContents(), ui::DomKey::ENTER,
ui::DomCode::ENTER, ui::VKEY_RETURN, false, false,
false, false);
// Validate that we downloaded a single PDF and didn't launch the PDF plugin.
GURL pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf"));
EXPECT_EQ(pdf_url, AwaitAndGetLastDownloadedUrl());
EXPECT_EQ(1u, GetNumberOfDownloads());
EXPECT_EQ(0, CountPDFProcesses());
}
IN_PROC_BROWSER_TEST_F(PDFPluginDisabledTest, IframePdfPlaceholderWithCSP) {
// Navigate to a page that uses <iframe> to embed a PDF as a plugin.
GURL iframe_page_url =
......
......@@ -6,7 +6,7 @@
style-src 'unsafe-inline'">
</head>
<body>
<embed type="application/pdf" src="test.pdf"
<embed id="pdf_embed" type="application/pdf" src="test.pdf"
style="position: fixed; top: 50; left: 50; width: 500; height: 600">
</body>
</html>
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