Commit 010cb689 authored by Arnaud Mandy's avatar Arnaud Mandy Committed by Commit Bot

WPT: Refactor shape-detection tests to use test-only-api.js

use of test-only-api.js in preparation for launching official MojoJS support
in WPT. This would not change the test results on Chromium waterfall
(everything should continue to pass) or upstream WPT (tests currently
fail because MojoJS isn't enabled).

Bug: 1123993
Change-Id: I38a1ad092a6eb9229d5c6be27bc670c89f6ef6cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391230Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Commit-Queue: Arnaud Mandy <arnaud.mandy@intel.com>
Cr-Commit-Position: refs/heads/master@{#805641}
parent 286e1ab7
importScripts("/resources/testharness.js");
importScripts("/resources/test-only-api.js");
importScripts("resources/shapedetection-helpers.js");
'use strict';
......
......@@ -9,17 +9,9 @@
//
// --enable-blink-features=MojoJS,MojoJSTest
let loadChromiumResources = Promise.resolve().then(() => {
if (!('MojoInterfaceInterceptor' in self)) {
// Do nothing on non-Chromium-based browsers or when the Mojo bindings are
// not present in the global namespace.
return;
}
async function loadChromiumResources() {
const prefix = '/gen/services/shape_detection/public/mojom';
let chain = Promise.resolve();
[
'/gen/layout_test_data/mojo/public/js/mojo_bindings.js',
const chromiumResources = [
'/gen/mojo/public/mojom/base/big_buffer.mojom.js',
'/gen/skia/public/mojom/image_info.mojom.js',
'/gen/skia/public/mojom/bitmap.mojom.js',
......@@ -29,26 +21,13 @@ let loadChromiumResources = Promise.resolve().then(() => {
`${prefix}/facedetection.mojom.js`,
`${prefix}/facedetection_provider.mojom.js`,
`${prefix}/textdetection.mojom.js`,
'/resources/chromium/mock-barcodedetection.js',
'/resources/chromium/mock-facedetection.js',
'/resources/chromium/mock-textdetection.js',
].forEach(path => {
// Use importScripts for workers.
if (typeof document === 'undefined') {
chain = chain.then(() => importScripts(path));
return;
}
let script = document.createElement('script');
script.src = path;
script.async = false;
chain = chain.then(() => new Promise(resolve => {
script.onload = () => resolve();
}));
document.head.appendChild(script);
});
];
return chain;
});
await loadMojoResources(chromiumResources);
await loadScript('/resources/chromium/mock-barcodedetection.js');
await loadScript('/resources/chromium/mock-facedetection.js');
await loadScript('/resources/chromium/mock-textdetection.js');
}
/**
* @param {String} detectionTestName
......@@ -58,15 +37,31 @@ let loadChromiumResources = Promise.resolve().then(() => {
*/
async function initialize_detection_tests(detectionTestName) {
let detectionTest;
// Use 'self' for workers.
if (typeof document === 'undefined') {
// Use 'self' for workers.
if (typeof self[detectionTestName] === 'undefined') {
await loadChromiumResources;
// test-only-api.js is already loaded in worker.js
if (isChromiumBased) {
await loadChromiumResources();
}
}
detectionTest = new self[detectionTestName]();
} else {
if (typeof window[detectionTestName] === 'undefined') {
await loadChromiumResources;
const script = document.createElement('script');
script.src = '/resources/test-only-api.js';
script.async = false;
const p = new Promise((resolve, reject) => {
script.onload = () => { resolve(); };
script.onerror = e => { reject(e); };
})
document.head.appendChild(script);
await p;
if (isChromiumBased) {
await loadChromiumResources();
}
}
detectionTest = new window[detectionTestName]();
}
......
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