Commit 0c3dde98 authored by rbpotter's avatar rbpotter Committed by Commit Bot

PDF extension tests: Remove dependency on PDFScriptingAPI

In order to migrate pdf_scripting_api.js to be a module script for the
Print Preview Polymer 3 migration, we need to stop executing it as a
standard script in EnsurePDFHasLoaded and pdf_extension_test.cc. Since
the current usage of this script only relies on a few lines of logic
contained in the PDF scripting API rather than the entire class,
inline these lines in C++ rather than injecting pdf_scripting_api.js.

Bug: 1012574
Change-Id: Ib2b43b83819102c19be20a58e163f04b7c0d6e2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902257Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713916}
parent 892c6d40
......@@ -208,11 +208,11 @@ class PDFExtensionTest : public extensions::ExtensionApiTest {
FAIL() << catcher.message();
}
// Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has
// finished loading. Return true if it loads successfully or false if it
// fails. If it doesn't finish loading the test will hang. This is done from
// outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works
// correctly from there.
// Load the PDF at the given URL and ensure it has finished loading. Return
// true if it loads successfully or false if it fails. If it doesn't finish
// loading the test will hang. This is done from outside of the BrowserPlugin
// guest to ensure sending messages to/from the plugin works correctly from
// there, since the PDFScriptingAPI relies on doing this as well.
bool LoadPdf(const GURL& url) {
ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents = GetActiveWebContents();
......@@ -1110,10 +1110,10 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilitySelection) {
ASSERT_TRUE(guest_contents);
WebContents* web_contents = GetActiveWebContents();
CHECK(content::ExecuteScript(web_contents,
"var scriptingAPI = new PDFScriptingAPI(window, "
" document.getElementsByTagName('embed')[0]);"
"scriptingAPI.selectAll();"));
CHECK(content::ExecuteScript(
web_contents,
"document.getElementsByTagName('embed')[0].postMessage("
"{type: 'selectAll'});"));
EnableAccessibilityForWebContents(guest_contents);
WaitForAccessibilityTreeToContainNodeWithName(guest_contents,
......
......@@ -4,27 +4,25 @@
#include "chrome/browser/pdf/pdf_extension_test_util.h"
#include "chrome/grit/component_extension_resources.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/base/resource/resource_bundle.h"
namespace pdf_extension_test_util {
bool EnsurePDFHasLoaded(content::WebContents* web_contents) {
std::string scripting_api_js =
ui::ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_PDF_PDF_SCRIPTING_API_JS)
.as_string();
CHECK(content::ExecuteScript(web_contents, scripting_api_js));
bool load_success = false;
CHECK(content::ExecuteScriptAndExtractBool(
web_contents,
"var scriptingAPI = new PDFScriptingAPI(window, "
" document.getElementsByTagName('embed')[0]);"
"scriptingAPI.setLoadCallback(function(success) {"
" window.domAutomationController.send(success);"
"});",
"window.addEventListener('message', event => {"
" if (event.origin !="
" 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai' ||"
" event.data.type != 'documentLoaded') {"
" return;"
" }"
" window.domAutomationController.send("
" event.data.load_state == 'success');"
"});"
"document.getElementsByTagName('embed')[0].postMessage("
" {type: 'initialize'});",
&load_success));
return load_success;
}
......
......@@ -11,8 +11,7 @@ class WebContents;
namespace pdf_extension_test_util {
// Ensures through PDFScriptingAPI that a PDF has finished loading inside the
// given |web_contents|.
// Ensures that a PDF has finished loading inside the given |web_contents|.
// Returns true if it loads successfully or false if it fails. If it doesn't
// finish loading the test will hang.
bool EnsurePDFHasLoaded(content::WebContents* web_contents);
......
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