Commit 3ea2fb1f authored by dpapad's avatar dpapad Committed by Commit Bot

PDF Viewer: Add type-checking for more tests.

Specifically:
 - basic_plugin_test
 - beep_test, nobeep_test
 - title_test, whitespace_title_test

Bug: 1000989
Change-Id: I43baab0c538bc106ac68e6ec88908053ed290f0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303430
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790049}
parent 9f743b7e
...@@ -203,8 +203,8 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -203,8 +203,8 @@ export class PDFViewerElement extends PDFViewerBaseElement {
// Non-Polymer properties // Non-Polymer properties
/** @private {number} */ /** @type {number} */
this.beepCount_ = 0; this.beepCount = 0;
/** @private {boolean} */ /** @private {boolean} */
this.hadPassword_ = false; this.hadPassword_ = false;
...@@ -732,7 +732,7 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -732,7 +732,7 @@ export class PDFViewerElement extends PDFViewerBaseElement {
*/ */
handleBeep_() { handleBeep_() {
// Beeps are annoying, so just track count for now. // Beeps are annoying, so just track count for now.
this.beepCount_ += 1; this.beepCount += 1;
} }
/** /**
......
...@@ -13,10 +13,10 @@ js_type_check("closure_compile") { ...@@ -13,10 +13,10 @@ js_type_check("closure_compile") {
] ]
deps = [ deps = [
#":annotations_feature_enabled_test", #":annotations_feature_enabled_test",
#":basic_plugin_test", ":basic_plugin_test",
":basic_test", ":basic_test",
":beep_test",
#":beep_test",
#":bookmarks_test", #":bookmarks_test",
":download_controls_test", ":download_controls_test",
":gesture_detector_test", ":gesture_detector_test",
...@@ -25,22 +25,32 @@ js_type_check("closure_compile") { ...@@ -25,22 +25,32 @@ js_type_check("closure_compile") {
#":material_elements_test", #":material_elements_test",
#":metrics_test", #":metrics_test",
#":navigator_test", #":navigator_test",
#":nobeep_test", ":nobeep_test",
#":page_change_test", #":page_change_test",
#":params_parser_test", #":params_parser_test",
#":printing_icon_test", #":printing_icon_test",
#":redirects_fail_test", #":redirects_fail_test",
":test_util", ":test_util",
":title_test",
#":title_test",
#":toolbar_manager_test", #":toolbar_manager_test",
#":touch_handling_test", #":touch_handling_test",
#":viewport_test", #":viewport_test",
#":whitespace_title_test", ":whitespace_title_test",
#":zoom_manager_test", #":zoom_manager_test",
] ]
} }
js_library("basic_plugin_test") {
deps = [
"//chrome/browser/resources/pdf:pdf_scripting_api",
"//chrome/browser/resources/pdf:pdf_viewer",
]
externs_list = [ "$externs_path/test.js" ]
}
js_library("basic_test") { js_library("basic_test") {
deps = [ deps = [
"//chrome/browser/resources/pdf:pdf_viewer", "//chrome/browser/resources/pdf:pdf_viewer",
...@@ -50,6 +60,14 @@ js_library("basic_test") { ...@@ -50,6 +60,14 @@ js_library("basic_test") {
externs_list = [ "$externs_path/test.js" ] externs_list = [ "$externs_path/test.js" ]
} }
js_library("beep_test") {
deps = [
"//chrome/browser/resources/pdf:pdf_scripting_api",
"//chrome/browser/resources/pdf:pdf_viewer",
]
externs_list = [ "$externs_path/test.js" ]
}
js_library("gesture_detector_test") { js_library("gesture_detector_test") {
deps = [ deps = [
"//chrome/browser/resources/pdf:gesture_detector", "//chrome/browser/resources/pdf:gesture_detector",
...@@ -71,9 +89,25 @@ js_library("download_controls_test") { ...@@ -71,9 +89,25 @@ js_library("download_controls_test") {
externs_list = [ "$externs_path/test.js" ] externs_list = [ "$externs_path/test.js" ]
} }
js_library("nobeep_test") {
deps = [
"//chrome/browser/resources/pdf:pdf_scripting_api",
"//chrome/browser/resources/pdf:pdf_viewer",
]
externs_list = [ "$externs_path/test.js" ]
}
js_library("test_util") { js_library("test_util") {
deps = [ deps = [
"//chrome/browser/resources/pdf:viewport", "//chrome/browser/resources/pdf:viewport",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
] ]
} }
js_library("title_test") {
externs_list = [ "$externs_path/test.js" ]
}
js_library("whitespace_title_test") {
externs_list = [ "$externs_path/test.js" ]
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import {PDFScriptingAPI} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_scripting_api.js'; import {PDFScriptingAPI} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_scripting_api.js';
import {PDFViewerElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer.js';
/** /**
* These tests require that the PDF plugin be available to run correctly. * These tests require that the PDF plugin be available to run correctly.
...@@ -12,25 +13,25 @@ const tests = [ ...@@ -12,25 +13,25 @@ const tests = [
* Test that the page is sized to the size of the document. * Test that the page is sized to the size of the document.
*/ */
function testPageSize() { function testPageSize() {
const viewer = /** @type {!PDFViewerElement} */ (
document.body.querySelector('#viewer'));
// Verify that the initial zoom is less than or equal to 100%. // Verify that the initial zoom is less than or equal to 100%.
chrome.test.assertTrue(viewer.viewport.getZoom() <= 1); chrome.test.assertTrue(viewer.viewport.getZoom() <= 1);
viewer.viewport.setZoom(1); viewer.viewport.setZoom(1);
const sizer = viewer.shadowRoot.querySelector('#sizer'); const sizer = viewer.shadowRoot.querySelector('#sizer');
chrome.test.assertEq(826, sizer.offsetWidth); chrome.test.assertEq(826, sizer.offsetWidth);
chrome.test.assertEq( chrome.test.assertEq(1066 + viewer.getToolbarHeight(), sizer.offsetHeight);
1066 + viewer.viewport.topToolbarHeight_, sizer.offsetHeight);
chrome.test.succeed(); chrome.test.succeed();
console.log('done page size');
}, },
function testGetSelectedText() { function testGetSelectedText() {
const client = new PDFScriptingAPI(window, window); const client = new PDFScriptingAPI(window, window);
client.selectAll(); client.selectAll();
client.getSelectedText(chrome.test.callbackPass(function(selectedText) { client.getSelectedText(function(selectedText) {
chrome.test.assertEq('this is some text\nsome more text', selectedText); chrome.test.assertEq('this is some text\nsome more text', selectedText);
})); chrome.test.succeed();
console.log('done select'); });
}, },
/** /**
...@@ -38,8 +39,6 @@ const tests = [ ...@@ -38,8 +39,6 @@ const tests = [
*/ */
function testHasCorrectTitle() { function testHasCorrectTitle() {
chrome.test.assertEq('test.pdf', document.title); chrome.test.assertEq('test.pdf', document.title);
console.log('done title');
chrome.test.succeed(); chrome.test.succeed();
}, },
]; ];
......
...@@ -3,13 +3,16 @@ ...@@ -3,13 +3,16 @@
// found in the LICENSE file. // found in the LICENSE file.
import {PDFScriptingAPI} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_scripting_api.js'; import {PDFScriptingAPI} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_scripting_api.js';
import {PDFViewerElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer.js';
const tests = [ const tests = [
/** /**
* Test that the JS was able to call back via "app.beep()" * Test that the JS was able to call back via "app.beep()"
*/ */
function testHasCorrectBeepCount() { function testHasCorrectBeepCount() {
chrome.test.assertEq(1, viewer.beepCount_); const viewer = /** @type {!PDFViewerElement} */ (
document.body.querySelector('#viewer'));
chrome.test.assertEq(1, viewer.beepCount);
chrome.test.succeed(); chrome.test.succeed();
} }
]; ];
......
...@@ -3,13 +3,16 @@ ...@@ -3,13 +3,16 @@
// found in the LICENSE file. // found in the LICENSE file.
import {PDFScriptingAPI} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_scripting_api.js'; import {PDFScriptingAPI} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_scripting_api.js';
import {PDFViewerElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer.js';
const tests = [ const tests = [
/** /**
* Test that blocked JS was not able to call back via "app.beep()" * Test that blocked JS was not able to call back via "app.beep()"
*/ */
function testHasCorrectBeepCount() { function testHasCorrectBeepCount() {
chrome.test.assertEq(0, viewer.beepCount_); const viewer = /** @type {!PDFViewerElement} */ (
document.body.querySelector('#viewer'));
chrome.test.assertEq(0, viewer.beepCount);
chrome.test.succeed(); chrome.test.succeed();
} }
]; ];
......
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