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

Add a browser test for the PDF Viewer password dialog

Also check-in the requisite encrypted PDF.

Fixed: 1167036
Change-Id: I4234d3bfd3cb600907f3e9262e64aaf3cace9e8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638916
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846309}
parent 8c7b5e87
......@@ -994,6 +994,10 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionJSTest, Metrics) {
RunTestsInJsModule("metrics_test.js", "test.pdf");
}
IN_PROC_BROWSER_TEST_F(PDFExtensionJSTest, ViewerPasswordDialog) {
RunTestsInJsModule("viewer_password_dialog_test.js", "encrypted.pdf");
}
IN_PROC_BROWSER_TEST_F(PDFExtensionJSTest, ArrayBufferAllocator) {
// Run several times to see if there are issues with unloading.
RunTestsInJsModule("beep_test.js", "array_buffer.pdf");
......
......@@ -29,6 +29,8 @@ Polymer({
this.$.submit.disabled = false;
this.invalid = true;
password.select();
this.fire('password-denied-for-testing');
},
submit() {
......
......@@ -37,6 +37,7 @@ js_type_check("closure_compile") {
#":toolbar_manager_test",
#":touch_handling_test",
":viewer_password_dialog_test",
":viewer_pdf_sidenav_test",
":viewer_pdf_toolbar_new_test",
":viewer_properties_dialog_test",
......@@ -165,6 +166,16 @@ js_library("title_test") {
externs_list = [ "$externs_path/test.js" ]
}
js_library("viewer_password_dialog_test") {
deps = [
"../webui:test_util.m",
"//chrome/browser/resources/pdf:pdf_viewer_wrapper",
"//ui/webui/resources/cr_elements/cr_button:cr_button.m",
"//ui/webui/resources/cr_elements/cr_input:cr_input.m",
]
externs_list = [ "$externs_path/test.js" ]
}
js_library("viewer_pdf_sidenav_test") {
deps = [ "//chrome/browser/resources/pdf:pdf_viewer_wrapper" ]
externs_list = [ "$externs_path/test.js" ]
......
{{header}}
{{object 1 0}} <<
/Type /Catalog
/Pages 2 0 R
>>
endobj
{{object 2 0}} <<
/Type /Pages
/MediaBox [ 0 0 200 200 ]
/Count 1
/Kids [ 3 0 R ]
>>
endobj
{{object 3 0}} <<
/Type /Page
/Parent 2 0 R
>>
endobj
{{object 4 0}} <<
/Filter /Standard
/Length 40
/P -4
/R 2
/V 1
% Owner password: "ownerpass"
/O <f86213eb0ced81f097947f3b343e34cac8ca92ce8f6fee2556fa31ec1fe968af>
% User password: "userpass"
/U <42d5dec3556574de62408780cc4b137ad56ce9edcbe92cf2b5fc12322eb028e5>
>>
endobj
{{xref}}
trailer <<
/ID [<e4c50f3e9b4ba1da3c3b7ae7d381221b><e4c50f3e9b4ba1da3c3b7ae7d381221b>]
/Encrypt 4 0 R
/Root 1 0 R
{{trailersize}}
>>
{{startxref}}
%%EOF
This diff was suppressed by a .gitattributes entry.
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {eventToPromise} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/_test_resources/webui/test_util.m.js';
import {PDFViewerElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer_wrapper.js';
const viewer = /** @type {!PDFViewerElement} */ (
document.body.querySelector('pdf-viewer'));
/** @return {!ViewerPasswordDialogElement} */
function getPasswordDialog() {
return /** @type {!ViewerPasswordDialogElement} */ (
viewer.shadowRoot.querySelector('#password-dialog'));
}
/** @return {!CrInputElement} */
function getPasswordInput() {
return /** @type {!CrInputElement} */ (
getPasswordDialog().shadowRoot.querySelector('#password'));
}
/** @return {!CrButtonElement} */
function getSubmitButton() {
return /** @type {!CrButtonElement} */ (
getPasswordDialog().shadowRoot.querySelector('#submit'));
}
function submitPassword() {
const button = getSubmitButton();
button.click();
// The submit button and input field should both be disabled.
chrome.test.assertTrue(button.disabled);
chrome.test.assertTrue(getPasswordInput().disabled);
}
/** @param {string} password */
async function tryIncorrectPassword(password) {
const input = getPasswordInput();
input.value = password;
const whenPasswordDenied =
eventToPromise('password-denied-for-testing', getPasswordDialog());
submitPassword();
await whenPasswordDenied;
// The input field should be marked invalid and re-enabled.
chrome.test.assertTrue(input.invalid);
chrome.test.assertFalse(input.disabled);
// The submit button should be re-enabled.
chrome.test.assertFalse(getSubmitButton().disabled);
}
/** @param {string} password */
async function tryCorrectPassword(password) {
const input = getPasswordInput();
input.value = password;
// The dialog should close in response to a correct password.
const whenDialogClosed = eventToPromise('close', getPasswordDialog());
submitPassword();
await whenDialogClosed;
chrome.test.assertFalse(!!getPasswordDialog());
}
const tests = [
async function testPasswordDialog() {
const passwordDialog = getPasswordDialog();
chrome.test.assertTrue(!!passwordDialog);
// The input field should be marked valid and enabled.
const input = getPasswordInput();
chrome.test.assertTrue(!!input);
chrome.test.assertFalse(input.invalid);
chrome.test.assertFalse(input.disabled);
// The submit button should be enabled.
chrome.test.assertFalse(getSubmitButton().disabled);
await tryIncorrectPassword('incorrect');
await tryCorrectPassword('ownerpass');
chrome.test.succeed();
},
];
chrome.test.runTests(tests);
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