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 { ...@@ -208,11 +208,11 @@ class PDFExtensionTest : public extensions::ExtensionApiTest {
FAIL() << catcher.message(); FAIL() << catcher.message();
} }
// Load the PDF at the given URL and use the PDFScriptingAPI to ensure it has // Load the PDF at the given URL and ensure it has finished loading. Return
// finished loading. Return true if it loads successfully or false if it // true if it loads successfully or false if it fails. If it doesn't finish
// fails. If it doesn't finish loading the test will hang. This is done from // loading the test will hang. This is done from outside of the BrowserPlugin
// outside of the BrowserPlugin guest to ensure the PDFScriptingAPI works // guest to ensure sending messages to/from the plugin works correctly from
// correctly from there. // there, since the PDFScriptingAPI relies on doing this as well.
bool LoadPdf(const GURL& url) { bool LoadPdf(const GURL& url) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
WebContents* web_contents = GetActiveWebContents(); WebContents* web_contents = GetActiveWebContents();
...@@ -1110,10 +1110,10 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilitySelection) { ...@@ -1110,10 +1110,10 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibilitySelection) {
ASSERT_TRUE(guest_contents); ASSERT_TRUE(guest_contents);
WebContents* web_contents = GetActiveWebContents(); WebContents* web_contents = GetActiveWebContents();
CHECK(content::ExecuteScript(web_contents, CHECK(content::ExecuteScript(
"var scriptingAPI = new PDFScriptingAPI(window, " web_contents,
" document.getElementsByTagName('embed')[0]);" "document.getElementsByTagName('embed')[0].postMessage("
"scriptingAPI.selectAll();")); "{type: 'selectAll'});"));
EnableAccessibilityForWebContents(guest_contents); EnableAccessibilityForWebContents(guest_contents);
WaitForAccessibilityTreeToContainNodeWithName(guest_contents, WaitForAccessibilityTreeToContainNodeWithName(guest_contents,
......
...@@ -4,27 +4,25 @@ ...@@ -4,27 +4,25 @@
#include "chrome/browser/pdf/pdf_extension_test_util.h" #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 "content/public/test/browser_test_utils.h"
#include "ui/base/resource/resource_bundle.h"
namespace pdf_extension_test_util { namespace pdf_extension_test_util {
bool EnsurePDFHasLoaded(content::WebContents* web_contents) { 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; bool load_success = false;
CHECK(content::ExecuteScriptAndExtractBool( CHECK(content::ExecuteScriptAndExtractBool(
web_contents, web_contents,
"var scriptingAPI = new PDFScriptingAPI(window, " "window.addEventListener('message', event => {"
" document.getElementsByTagName('embed')[0]);" " if (event.origin !="
"scriptingAPI.setLoadCallback(function(success) {" " 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai' ||"
" window.domAutomationController.send(success);" " event.data.type != 'documentLoaded') {"
"});", " return;"
" }"
" window.domAutomationController.send("
" event.data.load_state == 'success');"
"});"
"document.getElementsByTagName('embed')[0].postMessage("
" {type: 'initialize'});",
&load_success)); &load_success));
return load_success; return load_success;
} }
......
...@@ -11,8 +11,7 @@ class WebContents; ...@@ -11,8 +11,7 @@ class WebContents;
namespace pdf_extension_test_util { namespace pdf_extension_test_util {
// Ensures through PDFScriptingAPI that a PDF has finished loading inside the // Ensures that a PDF has finished loading inside the given |web_contents|.
// given |web_contents|.
// Returns true if it loads successfully or false if it fails. If it doesn't // Returns true if it loads successfully or false if it fails. If it doesn't
// finish loading the test will hang. // finish loading the test will hang.
bool EnsurePDFHasLoaded(content::WebContents* web_contents); 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