Commit 4ecda944 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Chromium LUCI CQ

Enable browser tests for encrypted PDFs

The PDF Viewer has a password dialog that is prompted to the user before
the document loads. However, PDF browser tests run only after the
document loads.

Alter the EnsurePDFHasLoaded() helper method to also return when the PDF
prompts the password dialog.

To do so, a 'passwordPrompted' message is sent to the PDF Viewer
embedder.

Bug: 1167036
Change-Id: I17ae5daa4e6ce51ad1bc402c7d352beadae43256
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2639293
Auto-Submit: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846244}
parent c5e54900
......@@ -15,13 +15,16 @@ testing::AssertionResult EnsurePDFHasLoaded(
if (!content::ExecuteScriptAndExtractBool(
web_contents,
"window.addEventListener('message', event => {"
" if (event.origin !="
" 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai' ||"
" event.data.type != 'documentLoaded') {"
" if (event.origin !=="
" 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai') {"
" return;"
" }"
" window.domAutomationController.send("
" event.data.load_state == 'success');"
" if (event.data.type === 'documentLoaded') {"
" window.domAutomationController.send("
" event.data.load_state === 'success');"
" } else if (event.data.type === 'passwordPrompted') {"
" window.domAutomationController.send(true);"
" }"
"});"
"document.getElementsByTagName('embed')[0].postMessage("
" {type: 'initialize'});",
......
......@@ -14,9 +14,10 @@ class WebContents;
namespace pdf_extension_test_util {
// Ensures that a PDF has finished loading inside the given |web_contents|.
// The result indicates success if the PDF loads successfully, otherwise it
// indicates failure. If it doesn't finish loading the test will hang.
// Ensures, inside the given `web_contents`, that a PDF has either finished
// loading or prompted a password. The result indicates success if the PDF loads
// successfully, otherwise it indicates failure. If it doesn't finish loading,
// the test will hang.
testing::AssertionResult EnsurePDFHasLoaded(content::WebContents* web_contents)
WARN_UNUSED_RESULT;
......
......@@ -969,6 +969,7 @@ export class PDFViewerElement extends PDFViewerBaseElement {
// to an incorrect password.
if (!this.showPasswordDialog_) {
this.showPasswordDialog_ = true;
this.sendScriptingMessage({type: 'passwordPrompted'});
} else {
const passwordDialog = this.shadowRoot.querySelector('#password-dialog');
assert(passwordDialog);
......
......@@ -556,11 +556,13 @@ export class PDFViewerBaseElement extends PolymerElement {
let targetOrigin;
// Only send data back to the embedder if it is from the same origin,
// unless we're sending it to ourselves (which could happen in the case
// of tests). We also allow documentLoaded messages through as this won't
// leak important information.
// of tests). We also allow 'documentLoaded' and 'passwordPrompted'
// messages through as they do not leak sensitive information.
if (this.parentOrigin_ === window.location.origin) {
targetOrigin = this.parentOrigin_;
} else if (message.type === 'documentLoaded') {
} else if (
message.type === 'documentLoaded' ||
message.type === 'passwordPrompted') {
targetOrigin = '*';
} else {
targetOrigin = this.originalUrl;
......
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