From 0a0994ca64fceafde05997d93e5ca7d6e5baa7b2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 20 Dec 2023 00:31:45 -0500 Subject: HTML test updates (#398) * Rename y-test to test-case * Rename y-description to test-description * Remove extension name * Update placeholder favicon * Refactor scripts * Make element types more consistent * More updates * Rename * Simplify file URLs * Rename file * Add descriptions * Rename * Rename * Rename --- .eslintrc.json | 16 +- test/data/html/document-util.html | 372 ++++++++++++++++++++++++++++ test/data/html/dom-text-scanner.html | 395 ++++++++++++++++++++++++++++++ test/data/html/js/html-test-utilities.js | 184 ++++++++++++++ test/data/html/js/performance-frames.js | 63 +++++ test/data/html/js/popup-tests-frame1.js | 21 ++ test/data/html/js/popup-tests.js | 33 +++ test/data/html/performance-frame1.html | 26 ++ test/data/html/performance-frame2.html | 33 +++ test/data/html/performance.html | 27 ++ test/data/html/popup-tests-frame1.html | 40 +++ test/data/html/popup-tests-frame2.svg | 15 ++ test/data/html/popup-tests.html | 180 ++++++++++++++ test/data/html/test-document1.html | 387 ----------------------------- test/data/html/test-document2-frame1.html | 40 --- test/data/html/test-document2-frame2.svg | 15 -- test/data/html/test-document2-script.js | 121 --------- test/data/html/test-document2.html | 222 ----------------- test/data/html/test-document3-frame1.html | 44 ---- test/data/html/test-document3-frame2.html | 62 ----- test/data/html/test-document3.html | 26 -- test/data/html/test-dom-text-scanner.html | 393 ----------------------------- test/data/html/test-stylesheet.css | 12 +- test/document-util.test.js | 2 +- test/dom-text-scanner.test.js | 4 +- test/playwright/visual.spec.js | 16 +- 26 files changed, 1414 insertions(+), 1335 deletions(-) create mode 100644 test/data/html/document-util.html create mode 100644 test/data/html/dom-text-scanner.html create mode 100644 test/data/html/js/html-test-utilities.js create mode 100644 test/data/html/js/performance-frames.js create mode 100644 test/data/html/js/popup-tests-frame1.js create mode 100644 test/data/html/js/popup-tests.js create mode 100644 test/data/html/performance-frame1.html create mode 100644 test/data/html/performance-frame2.html create mode 100644 test/data/html/performance.html create mode 100644 test/data/html/popup-tests-frame1.html create mode 100644 test/data/html/popup-tests-frame2.svg create mode 100644 test/data/html/popup-tests.html delete mode 100644 test/data/html/test-document1.html delete mode 100644 test/data/html/test-document2-frame1.html delete mode 100644 test/data/html/test-document2-frame2.svg delete mode 100644 test/data/html/test-document2-script.js delete mode 100644 test/data/html/test-document2.html delete mode 100644 test/data/html/test-document3-frame1.html delete mode 100644 test/data/html/test-document3-frame2.html delete mode 100644 test/data/html/test-document3.html delete mode 100644 test/data/html/test-dom-text-scanner.html diff --git a/.eslintrc.json b/.eslintrc.json index a93888bb..1a427686 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -661,7 +661,7 @@ }, { "files": [ - "test/data/html/*.js" + "test/data/html/**/*.js" ], "parserOptions": { "sourceType": "script" @@ -670,9 +670,17 @@ "browser": true, "node": false, "webextensions": false - }, - "rules": { - "no-implicit-globals": "off" + } + }, + { + "files": [ + "test/data/html/**/*.js" + ], + "excludedFiles": [ + "test/data/html/js/html-test-utilities.js" + ], + "globals": { + "HtmlTestUtilities": "readonly" } }, { diff --git a/test/data/html/document-util.html b/test/data/html/document-util.html new file mode 100644 index 00000000..d8ac012e --- /dev/null +++ b/test/data/html/document-util.html @@ -0,0 +1,372 @@ + + + + + + DocumentUtil Tests + + + + + +

DocumentUtil Tests

+ + Automated test cases for DocumentUtil. + + + 真白「心配してくださって、ありがとございます」 + + + + 真白「心配してくださって、ありがとございます」 + + + + 真白「心配して「くださって」、ありがと「ございます」」 + + + + ありがとございます。ありがとございます。 + + + + ありがとございます。ありがとございます。 + + + + ありがとございます。!?ありがとございます。!? + + + + ありがとございます!!!ありがとございます!!! + + + + + + + + + + + + + + + + よみたん + + + +ありがとございます1 +ありがとございます2 +ありがとございます3 +ありがとございます4 +ありがとございます5 + + + +ありがとございます1 +ありがとございます2 +ありがとございます3 +ありがとございます4 +ありがとございます5 + + + + + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + trailing content + + + + + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + trailing content + + + + + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + trailing content + + + + + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + trailing content + + + + diff --git a/test/data/html/dom-text-scanner.html b/test/data/html/dom-text-scanner.html new file mode 100644 index 00000000..ff4d0493 --- /dev/null +++ b/test/data/html/dom-text-scanner.html @@ -0,0 +1,395 @@ + + + + + + DOMTextScanner Tests + + + + + +

DOMTextScanner Tests

+ + Automated test cases for DOMTextScanner. + + + Layout newlines expected due to entering and exiting display:block nodes. +
小ぢん
まり1
+
小ぢん
まり2
+
+ + + Layout newline expected due to sequential display:block elements. +
小ぢんまり1
小ぢんまり2
+
+ + + Layout newline expected due to sequential display:block elements separated by a newline. +
小ぢんまり1
+
小ぢんまり2
+
+ + + No newlines expected due to display:inline. +小ぢんまり1小ぢんまり2 + + + + No newlines expected due to white-space:normal. +小ぢんまり1 +小ぢんまり2 + + + + Newline expected due to white-space:pre. +
+小ぢんまり1
+小ぢんまり2
+
+
+ + + No newlines expected due to display:inline-block. Actual layout flow cannot be determined by DOM/CSS alone. +小ぢんまり1小ぢんまり2 + + + + Single newline expected due to display:block layout. +
小ぢんまり1
小ぢんまり2
+
+ + + Two newlines expected due to position:absolute causing a significant layout change. +
小ぢんまり1
小ぢんまり2
+
+ + + Two newlines expected due to position:fixed causing a significant layout change. +
小ぢんまり1
小ぢんまり2
+
+ + + Two newlines expected due to position:sticky being able to cause a significant layout change. +
小ぢんまり1
小ぢんまり2
+
+ + + Scanning text starting in an <rt> element. Should start scanning at the start of the <ruby> tag instead. +
()ぢんまり1
+
+ + + Skip <script> content. +
小ぢんまり1
+
+ + + Skip <style> content. +
小ぢんまり1
+
+ + + Skip <textarea> content. +
小ぢんまり1
+
+ + + Skip <input> content. +
小ぢんまり1
+
+ + + Skip <button> content. +
小ぢんまり1
+
+ + + Skip content with font-size:0. +
小ぢんcontentまり1
+
+ + + Skip content with opacity:0. +
小ぢんcontentまり1
+
+ + + Skip content with visibility:hidden. +
小ぢんcontentまり1
+
+ + + Skip content with display:none. +
小ぢんcontentまり1
+
+ + + Don't skip content with user-select:none. +
小ぢまり1
+
+ + + Skip content with user-select:none and a transparent color. +
小ぢんcontentまり1
+
+ + + \ No newline at end of file diff --git a/test/data/html/js/html-test-utilities.js b/test/data/html/js/html-test-utilities.js new file mode 100644 index 00000000..da3e753a --- /dev/null +++ b/test/data/html/js/html-test-utilities.js @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * Copyright (C) 2021-2022 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +class HtmlTestUtilities { + /** + * @param {Element} element + */ + static requestFullscreen(element) { + if (element.requestFullscreen) { + element.requestFullscreen(); + // @ts-expect-error - Browser compatibility + } else if (element.mozRequestFullScreen) { + // @ts-expect-error - Browser compatibility + element.mozRequestFullScreen(); + // @ts-expect-error - Browser compatibility + } else if (element.webkitRequestFullscreen) { + // @ts-expect-error - Browser compatibility + element.webkitRequestFullscreen(); + // @ts-expect-error - Browser compatibility + } else if (element.msRequestFullscreen) { + // @ts-expect-error - Browser compatibility + element.msRequestFullscreen(); + } + } + + /** */ + static exitFullscreen() { + if (document.exitFullscreen) { + document.exitFullscreen(); + // @ts-expect-error - Browser compatibility + } else if (document.mozCancelFullScreen) { + // @ts-expect-error - Browser compatibility + document.mozCancelFullScreen(); + // @ts-expect-error - Browser compatibility + } else if (document.webkitExitFullscreen) { + // @ts-expect-error - Browser compatibility + document.webkitExitFullscreen(); + // @ts-expect-error - Browser compatibility + } else if (document.msExitFullscreen) { + // @ts-expect-error - Browser compatibility + document.msExitFullscreen(); + } + } + + /** + * @returns {?Element} + */ + static getFullscreenElement() { + return ( + document.fullscreenElement || + // @ts-expect-error - Browser compatibility + document.msFullscreenElement || + // @ts-expect-error - Browser compatibility + document.mozFullScreenElement || + // @ts-expect-error - Browser compatibility + document.webkitFullscreenElement || + null + ); + } + + /** + * @param {Element} element + */ + static toggleFullscreen(element) { + if (this.getFullscreenElement()) { + this.exitFullscreen(); + } else { + this.requestFullscreen(element); + } + } + + /** + * @param {string} string + * @returns {Uint8Array} + */ + static stringToTypedArray(string) { + const array = new Uint8Array(string.length); + for (let i = 0; i < string.length; ++i) { + array[i] = string.charCodeAt(i); + } + return array; + } + + /** + * @param {string} dataUrl + * @returns {{content: string, type: string}} + * @throws {Error} + */ + static dataUrlToContent(dataUrl) { + const match = /^data:([^;]*);(base64,)?([\w\W]*)$/.exec(dataUrl); + if (match === null) { throw new Error('Invalid input'); } + const [, type, isBase64, data] = match; + const content = ( + isBase64 ? + new TextDecoder().decode(this.stringToTypedArray(atob(data))) : + data + ); + return {content, type}; + } + + /** + * @param {string} dataUrl + * @returns {Blob} + */ + static dataUrlToBlob(dataUrl) { + const {content, type} = this.dataUrlToContent(dataUrl); + return new Blob([content], {type}); + } + + /** + * @param {?Element} element + * @returns {string} + * @throws {Error} + */ + static getIframeSrc(element) { + if (!(element instanceof HTMLIFrameElement)) { + throw new Error('Element is not an iframe'); + } + return element.src; + } + + /** + * @param {Element|DocumentFragment} container + * @param {?Element} [fullscreenElement] + */ + static setupTest(container, fullscreenElement = null) { + const fullscreenLink = container.querySelector('.fullscreen-link'); + if (fullscreenLink !== null) { + if (fullscreenElement === null) { + fullscreenElement = container.querySelector('.fullscreen-element'); + } + fullscreenLink.addEventListener('click', (e) => { + if (fullscreenElement === null) { return; } + this.toggleFullscreen(fullscreenElement); + e.preventDefault(); + return false; + }, false); + } + + const template = container.querySelector('template'); + const templateContentContainer = container.querySelector('.template-content-container'); + if (template !== null && templateContentContainer !== null) { + const mode = (container instanceof HTMLElement ? container.dataset.shadowMode : void 0); + const shadow = templateContentContainer.attachShadow({ + mode: (mode === 'open' || mode === 'closed' ? mode : 'open') + }); + + const containerStyles = document.querySelector('#container-styles'); + if (containerStyles !== null) { + shadow.appendChild(containerStyles.cloneNode(true)); + } + + const content = document.importNode(template.content, true); + this.setupTest(content); + shadow.appendChild(content); + } + } + + /** + * @param {() => void} main + */ + static runMain(main) { + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', () => { main(); }); + } else { + main(); + } + } +} diff --git a/test/data/html/js/performance-frames.js b/test/data/html/js/performance-frames.js new file mode 100644 index 00000000..7484f971 --- /dev/null +++ b/test/data/html/js/performance-frames.js @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +HtmlTestUtilities.runMain(() => { + let totalCount = 0; + const container = document.querySelector('#container'); + const counter = document.querySelector('#counter'); + + /** + * @param {number} count + * @param {Event} event + */ + function addElements(count, event) { + event.preventDefault(); + + if (container !== null) { + for (let i = 0; i < count; ++i) { + const element = document.createElement('div'); + element.textContent = 'ありがとう'; + container.appendChild(element); + } + } + + totalCount += count; + if (counter !== null) { + counter.textContent = `${totalCount}`; + } + } + + for (const element of document.querySelectorAll('.add-elements')) { + if (!(element instanceof HTMLElement)) { continue; } + const {count} = element.dataset; + if (typeof count !== 'string') { continue; } + const countValue = Number.parseInt(count, 10); + if (!Number.isFinite(countValue)) { continue; } + element.addEventListener('click', addElements.bind(null, countValue)); + } + + const shadowIframeContainer = document.querySelector('#shadow-iframe-container-open'); + if (shadowIframeContainer !== null) { + const shadow = shadowIframeContainer.attachShadow({mode: 'open'}); + const templateElement = document.querySelector('#shadow-iframe-container-open-content-template'); + if (templateElement instanceof HTMLTemplateElement) { + const template = templateElement.content; + const content = document.importNode(template, true); + shadow.appendChild(content); + } + } +}); diff --git a/test/data/html/js/popup-tests-frame1.js b/test/data/html/js/popup-tests-frame1.js new file mode 100644 index 00000000..b1dc2756 --- /dev/null +++ b/test/data/html/js/popup-tests-frame1.js @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +HtmlTestUtilities.runMain(() => { + const {body} = document; + HtmlTestUtilities.setupTest(body, body); +}); diff --git a/test/data/html/js/popup-tests.js b/test/data/html/js/popup-tests.js new file mode 100644 index 00000000..3a46a045 --- /dev/null +++ b/test/data/html/js/popup-tests.js @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +HtmlTestUtilities.runMain(() => { + for (const element of document.querySelectorAll('test-case')) { + HtmlTestUtilities.setupTest(element); + } + + const iframeWithDataUrl = document.querySelector('#iframe-with-data-url'); + const src = HtmlTestUtilities.getIframeSrc(iframeWithDataUrl); + const iframeWithBlobUrl = document.querySelector('#iframe-with-blob-url'); + if (iframeWithBlobUrl instanceof HTMLIFrameElement) { + iframeWithBlobUrl.src = URL.createObjectURL(HtmlTestUtilities.dataUrlToBlob(src)); + } + for (const iframeWithSrcdoc of document.querySelectorAll('.iframe-with-srcdoc')) { + if (!(iframeWithSrcdoc instanceof HTMLIFrameElement)) { continue; } + iframeWithSrcdoc.srcdoc = HtmlTestUtilities.dataUrlToContent(src).content; + } +}); diff --git a/test/data/html/performance-frame1.html b/test/data/html/performance-frame1.html new file mode 100644 index 00000000..a60ba241 --- /dev/null +++ b/test/data/html/performance-frame1.html @@ -0,0 +1,26 @@ + + + + + + Performance Tests + + + + +
+ + Add elements + +
+ 1000 + 10000 + 100000 + 1000000 +
+ +
+
+ +
+ diff --git a/test/data/html/performance-frame2.html b/test/data/html/performance-frame2.html new file mode 100644 index 00000000..eb7d758b --- /dev/null +++ b/test/data/html/performance-frame2.html @@ -0,0 +1,33 @@ + + + + + + Performance Tests + + + + +
+ + <iframe> element inside of an open shadow DOM. + +
+ + + Add elements + +
+ 1000 + 10000 + 100000 + 1000000 +
+ +
+
+ +
+ diff --git a/test/data/html/performance.html b/test/data/html/performance.html new file mode 100644 index 00000000..16a160e7 --- /dev/null +++ b/test/data/html/performance.html @@ -0,0 +1,27 @@ + + + + + + Performance Tests + + + + + +

Performance Tests

+ + Testing performance with artificially demanding cases in a real browser + + + <iframe> element. + + + + + <iframe> element containing an <iframe> element inside of an open shadow DOM. + + + + + diff --git a/test/data/html/popup-tests-frame1.html b/test/data/html/popup-tests-frame1.html new file mode 100644 index 00000000..5074aac9 --- /dev/null +++ b/test/data/html/popup-tests-frame1.html @@ -0,0 +1,40 @@ + + + + + + Frame 1 + + + + +
+
+ ありがとう +
+ +
+ \ No newline at end of file diff --git a/test/data/html/popup-tests-frame2.svg b/test/data/html/popup-tests-frame2.svg new file mode 100644 index 00000000..380eab97 --- /dev/null +++ b/test/data/html/popup-tests-frame2.svg @@ -0,0 +1,15 @@ + + + +ありがとう + \ No newline at end of file diff --git a/test/data/html/popup-tests.html b/test/data/html/popup-tests.html new file mode 100644 index 00000000..ef2d36e6 --- /dev/null +++ b/test/data/html/popup-tests.html @@ -0,0 +1,180 @@ + + + + + + Popup Tests + + + + + + + +

Popup Tests

+ + + Tests involving popup functionality in different contextsts, such as fullscreen elements, <iframe> elements, and shadow DOMs. + + + + Standard content. +
+
+
+ ありがとう +
+ +
+
+
+ + + Content inside of an open shadow DOM. +
+ +
+ + + Content inside of a closed shadow DOM. +
+ +
+ + + <iframe> element. + + + + + <iframe> element inside of an open shadow DOM. +
+ +
+ + + <iframe> element inside of a closed shadow DOM. +
+ +
+ + + <iframe> element with data URL. + + + + + <iframe> element with blob URL. + + + + + <iframe> element with srcdoc. + + + + + <iframe> element with srcdoc and + sandbox="allow-same-origin allow-scripts". + + + + + + <iframe> element with srcdoc and sandbox="allow-scripts".
+ This element is expected to not work. +
+ +
+ + + SVG <img>. + + + + + SVG <object>. + + + + + SVG <embed>. + + + + + SVG <iframe>. + + + + + SVG <svg>. + + + ありがとう + + + + + diff --git a/test/data/html/test-document1.html b/test/data/html/test-document1.html deleted file mode 100644 index d66e459d..00000000 --- a/test/data/html/test-document1.html +++ /dev/null @@ -1,387 +0,0 @@ - - - - - - Yomitan Tests - - - - - -

Yomitan Tests

- -
- 真白「心配してくださって、ありがとございます」 -
- -
- 真白「心配してくださって、ありがとございます」 -
- -
- 真白「心配して「くださって」、ありがと「ございます」」 -
- -
- ありがとございます。ありがとございます。 -
- -
- ありがとございます。ありがとございます。 -
- -
- ありがとございます。!?ありがとございます。!? -
- -
- ありがとございます!!!ありがとございます!!! -
- -
- -
- -
- -
- -
- -
- -
- よみたん -
- -
-ありがとございます1 -ありがとございます2 -ありがとございます3 -ありがとございます4 -ありがとございます5 -
- -
-ありがとございます1 -ありがとございます2 -ありがとございます3 -ありがとございます4 -ありがとございます5 -
- -
- - あいうえお - かきくけこ - さしすせそ - たちつてと - なにぬねの - はひふへほ - まみむめも - や ゆ よ - らりるれろ - わゐ ゑを - trailing content -
- -
- - あいうえお - かきくけこ - さしすせそ - たちつてと - なにぬねの - はひふへほ - まみむめも - や ゆ よ - らりるれろ - わゐ ゑを - trailing content -
- -
- - あいうえお - かきくけこ - さしすせそ - たちつてと - なにぬねの - はひふへほ - まみむめも - や ゆ よ - らりるれろ - わゐ ゑを - trailing content -
- -
- - あいうえお - かきくけこ - さしすせそ - たちつてと - なにぬねの - はひふへほ - まみむめも - や ゆ よ - らりるれろ - わゐ ゑを - trailing content -
- - - diff --git a/test/data/html/test-document2-frame1.html b/test/data/html/test-document2-frame1.html deleted file mode 100644 index 52243e1e..00000000 --- a/test/data/html/test-document2-frame1.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - Yomitan Tests - - - -
-
- ありがとう -
-
- Toggle fullscreen - -
-
- \ No newline at end of file diff --git a/test/data/html/test-document2-frame2.svg b/test/data/html/test-document2-frame2.svg deleted file mode 100644 index 380eab97..00000000 --- a/test/data/html/test-document2-frame2.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - -ありがとう - \ No newline at end of file diff --git a/test/data/html/test-document2-script.js b/test/data/html/test-document2-script.js deleted file mode 100644 index d8e1278d..00000000 --- a/test/data/html/test-document2-script.js +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2023 Yomitan Authors - * Copyright (C) 2021-2022 Yomichan Authors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @param {Element} element - */ -function requestFullscreen(element) { - if (element.requestFullscreen) { - element.requestFullscreen(); - // @ts-expect-error - Browser compatibility - } else if (element.mozRequestFullScreen) { - // @ts-expect-error - Browser compatibility - element.mozRequestFullScreen(); - // @ts-expect-error - Browser compatibility - } else if (element.webkitRequestFullscreen) { - // @ts-expect-error - Browser compatibility - element.webkitRequestFullscreen(); - // @ts-expect-error - Browser compatibility - } else if (element.msRequestFullscreen) { - // @ts-expect-error - Browser compatibility - element.msRequestFullscreen(); - } -} - -/** */ -function exitFullscreen() { - if (document.exitFullscreen) { - document.exitFullscreen(); - // @ts-expect-error - Browser compatibility - } else if (document.mozCancelFullScreen) { - // @ts-expect-error - Browser compatibility - document.mozCancelFullScreen(); - // @ts-expect-error - Browser compatibility - } else if (document.webkitExitFullscreen) { - // @ts-expect-error - Browser compatibility - document.webkitExitFullscreen(); - // @ts-expect-error - Browser compatibility - } else if (document.msExitFullscreen) { - // @ts-expect-error - Browser compatibility - document.msExitFullscreen(); - } -} - -/** - * @returns {?Element} - */ -function getFullscreenElement() { - return ( - document.fullscreenElement || - // @ts-expect-error - Browser compatibility - document.msFullscreenElement || - // @ts-expect-error - Browser compatibility - document.mozFullScreenElement || - // @ts-expect-error - Browser compatibility - document.webkitFullscreenElement || - null - ); -} - -/** - * @param {Element} element - */ -function toggleFullscreen(element) { - if (getFullscreenElement()) { - exitFullscreen(); - } else { - requestFullscreen(element); - } -} - -/** - * @param {HTMLElement|DocumentFragment} container - * @param {?Element} [fullscreenElement] - */ -function setup(container, fullscreenElement = null) { - const fullscreenLink = container.querySelector('.fullscreen-link'); - if (fullscreenLink !== null) { - if (fullscreenElement === null) { - fullscreenElement = container.querySelector('.fullscreen-element'); - } - fullscreenLink.addEventListener('click', (e) => { - if (fullscreenElement === null) { return; } - toggleFullscreen(fullscreenElement); - e.preventDefault(); - return false; - }, false); - } - - const template = container.querySelector('template'); - const templateContentContainer = container.querySelector('.template-content-container'); - if (template !== null && templateContentContainer !== null) { - const mode = (container instanceof HTMLElement ? container.dataset.shadowMode : void 0); - const shadow = templateContentContainer.attachShadow({ - mode: (mode === 'open' || mode === 'closed' ? mode : 'open') - }); - - const containerStyles = document.querySelector('#container-styles'); - if (containerStyles !== null) { - shadow.appendChild(containerStyles.cloneNode(true)); - } - - const content = document.importNode(template.content, true); - setup(content); - shadow.appendChild(content); - } -} diff --git a/test/data/html/test-document2.html b/test/data/html/test-document2.html deleted file mode 100644 index c822c1d0..00000000 --- a/test/data/html/test-document2.html +++ /dev/null @@ -1,222 +0,0 @@ - - - - - - - Yomitan Manual Tests - - - - - - - - -

Yomitan Manual Tests

- Manual tests involving fullscreen elements, <iframe>s, and shadow DOMs. - - - Standard content. -
-
-
- ありがとう -
- -
-
-
- - - Content inside of an open shadow DOM. -
- -
- - - Content inside of a closed shadow DOM. -
- -
- - - <iframe> element. - - - - - <iframe> element inside of an open shadow DOM. -
- -
- - - <iframe> element inside of a closed shadow DOM. -
- -
- - - <iframe> element with data URL. - - - - - <iframe> element with blob URL. - - - - - <iframe> element with srcdoc. - - - - - <iframe> element with srcdoc and - sandbox="allow-same-origin allow-scripts". - - - - - - <iframe> element with srcdoc and sandbox="allow-scripts".
- This element is expected to not work. -
- -
- - - SVG <img>. - - - - - SVG <object>. - - - - - SVG <embed>. - - - - - SVG <iframe>. - - - - - SVG <svg>. - - - ありがとう - - - - - - - - - - diff --git a/test/data/html/test-document3-frame1.html b/test/data/html/test-document3-frame1.html deleted file mode 100644 index 83f82c6e..00000000 --- a/test/data/html/test-document3-frame1.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - Yomitan Manual Performance Tests - - -
- -
Add elements
- -
- 1000 - 10000 - 100000 - 1000000 - -
- -
-
- -
- diff --git a/test/data/html/test-document3-frame2.html b/test/data/html/test-document3-frame2.html deleted file mode 100644 index d947715d..00000000 --- a/test/data/html/test-document3-frame2.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - Yomitan Manual Performance Tests - - -
- -
<iframe> element inside of an open shadow DOM.
- -
- - - -
Add elements
- -
- 1000 - 10000 - 100000 - 1000000 -
- -
-
- - -
- diff --git a/test/data/html/test-document3.html b/test/data/html/test-document3.html deleted file mode 100644 index 218e211a..00000000 --- a/test/data/html/test-document3.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - Yomitan Manual Performance Tests - - - - - -

Yomitan Manual Performance Tests

-

Testing Yomitan performance with artificially demanding cases in a real browser

- -
-
<iframe> element.
- -
- -
-
<iframe> element containing an <iframe> element inside of an open shadow DOM.
- -
- - - diff --git a/test/data/html/test-dom-text-scanner.html b/test/data/html/test-dom-text-scanner.html deleted file mode 100644 index f22e0895..00000000 --- a/test/data/html/test-dom-text-scanner.html +++ /dev/null @@ -1,393 +0,0 @@ - - - - - - Yomitan DOMTextScanner Tests - - - - - -

Yomitan DOMTextScanner Tests

- - - Layout newlines expected due to entering and exiting display:block nodes. -
小ぢん
まり1
-
小ぢん
まり2
-
- - - Layout newline expected due to sequential display:block elements. -
小ぢんまり1
小ぢんまり2
-
- - - Layout newline expected due to sequential display:block elements separated by a newline. -
小ぢんまり1
-
小ぢんまり2
-
- - - No newlines expected due to display:inline. -小ぢんまり1小ぢんまり2 - - - - No newlines expected due to white-space:normal. -小ぢんまり1 -小ぢんまり2 - - - - Newline expected due to white-space:pre. -
-小ぢんまり1
-小ぢんまり2
-
-
- - - No newlines expected due to display:inline-block. Actual layout flow cannot be determined by DOM/CSS alone. -小ぢんまり1小ぢんまり2 - - - - Single newline expected due to display:block layout. -
小ぢんまり1
小ぢんまり2
-
- - - Two newlines expected due to position:absolute causing a significant layout change. -
小ぢんまり1
小ぢんまり2
-
- - - Two newlines expected due to position:fixed causing a significant layout change. -
小ぢんまり1
小ぢんまり2
-
- - - Two newlines expected due to position:sticky being able to cause a significant layout change. -
小ぢんまり1
小ぢんまり2
-
- - - Scanning text starting in an <rt> element. Should start scanning at the start of the <ruby> tag instead. -
()ぢんまり1
-
- - - Skip <script> content. -
小ぢんまり1
-
- - - Skip <style> content. -
小ぢんまり1
-
- - - Skip <textarea> content. -
小ぢんまり1
-
- - - Skip <input> content. -
小ぢんまり1
-
- - - Skip <button> content. -
小ぢんまり1
-
- - - Skip content with font-size:0. -
小ぢんcontentまり1
-
- - - Skip content with opacity:0. -
小ぢんcontentまり1
-
- - - Skip content with visibility:hidden. -
小ぢんcontentまり1
-
- - - Skip content with display:none. -
小ぢんcontentまり1
-
- - - Don't skip content with user-select:none. -
小ぢまり1
-
- - - Skip content with user-select:none and a transparent color. -
小ぢんcontentまり1
-
- - - \ No newline at end of file diff --git a/test/data/html/test-stylesheet.css b/test/data/html/test-stylesheet.css index 0d7a0f2e..7a97b523 100644 --- a/test/data/html/test-stylesheet.css +++ b/test/data/html/test-stylesheet.css @@ -19,8 +19,7 @@ p { margin: 0.33em 0; } -h1+p, -h1+y-description { +h1+test-description { margin-top: -0.67em; } @@ -29,8 +28,7 @@ a, a:visited { text-decoration: underline; } -.test, -y-test { +test-case { display: block; background-color: #ffffff; margin: 1em 0; @@ -39,8 +37,7 @@ y-test { border-radius: 4px; } -.test::before, -y-test::before { +test-case::before { content: 'Test ' counter(test-id); display: block; counter-increment: test-id; @@ -49,8 +46,7 @@ y-test::before { font-weight: bold; } -.description, -y-description { +test-description { color: #444444; font-style: italic; display: block; diff --git a/test/document-util.test.js b/test/document-util.test.js index 51872422..5f2e49ea 100644 --- a/test/document-util.test.js +++ b/test/document-util.test.js @@ -109,7 +109,7 @@ function findImposterElement(document) { return document.querySelector('div[style*="2147483646"]>*'); } -const test = createDomTest(path.join(dirname, 'data/html/test-document1.html')); +const test = createDomTest(path.join(dirname, 'data/html/document-util.html')); describe('DocumentUtil', () => { test('Text scanning functions', ({window}) => { diff --git a/test/dom-text-scanner.test.js b/test/dom-text-scanner.test.js index f53e326d..da38d24c 100644 --- a/test/dom-text-scanner.test.js +++ b/test/dom-text-scanner.test.js @@ -102,14 +102,14 @@ function createAbsoluteGetComputedStyle(window) { } -const test = createDomTest(path.join(dirname, 'data/html/test-dom-text-scanner.html')); +const test = createDomTest(path.join(dirname, 'data/html/dom-text-scanner.html')); describe('DOMTextScanner', () => { test('Seek tests', ({window}) => { const {document} = window; window.getComputedStyle = createAbsoluteGetComputedStyle(window); - for (const testElement of /** @type {NodeListOf} */ (document.querySelectorAll('y-test'))) { + for (const testElement of /** @type {NodeListOf} */ (document.querySelectorAll('test-case'))) { /** @type {import('test/dom-text-scanner').TestData|import('test/dom-text-scanner').TestData[]} */ let testData = parseJson(/** @type {string} */ (testElement.dataset.testData)); if (!Array.isArray(testData)) { diff --git a/test/playwright/visual.spec.js b/test/playwright/visual.spec.js index b912f8b4..02efc985 100644 --- a/test/playwright/visual.spec.js +++ b/test/playwright/visual.spec.js @@ -16,12 +16,8 @@ */ import path from 'path'; - -import { - expect, - root, - test -} from './playwright-util'; +import {pathToFileURL} from 'url'; +import {expect, root, test} from './playwright-util'; test.beforeEach(async ({context}) => { // wait for the on-install welcome.html tab to load, which becomes the foreground tab @@ -86,8 +82,8 @@ test('visual', async ({page, extensionId}) => { await (await /** @type {import('@playwright/test').Frame} */ (popup_frame).frameElement()).waitForElementState('hidden'); // wait for popup to disappear }; - // Load test-document1.html - await page.goto('file://' + path.join(root, 'test/data/html/test-document1.html')); + // Test document 1 + await page.goto(pathToFileURL(path.join(root, 'test/data/html/document-util.html')).toString()); await page.setViewportSize({width: 1000, height: 1800}); await page.keyboard.down('Shift'); let i = 1; @@ -96,8 +92,8 @@ test('visual', async ({page, extensionId}) => { i++; } - // Load test-document2.html - await page.goto('file://' + path.join(root, 'test/data/html/test-document2.html')); + // Test document 2 + await page.goto(pathToFileURL(path.join(root, 'test/data/html/popup-tests.html')).toString()); await page.setViewportSize({width: 1000, height: 4500}); await page.keyboard.down('Shift'); i = 1; -- cgit v1.2.3