Commit 228d4e62 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Expose BarcodeDetector only on supported platforms

This change simplifies feature detection for developers by only exposing
the BarcodeDetector interface on platforms where it is possible for
BarcodeDetector.getSupportedFormats() to return a non-empty list.

Bug: 1137825
Change-Id: Ib52b6aef476decec48b1696509d44135f2b92caf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508448
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825061}
parent b14cbf9d
......@@ -246,7 +246,14 @@
},
{
name: "BarcodeDetector",
status: "stable",
status: {
// Built-in barcode detection APIs are only available from some
// platforms. See //services/shape_detection.
"Android": "stable",
"ChromeOS": "stable",
"Mac": "stable",
"default": "test",
},
},
{
// https://github.com/chrishtr/battery-savings/blob/master/explainer.md
......
[INTERFACES]
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface Notification : EventTarget
getter image
[NAMESPACES]
[GLOBAL OBJECT]
PASS Verify the interface of ServiceWorkerGlobalScope
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<title>ServiceWorkerGlobalScope platform-specific expose test.</title>
<script src="../../js-test-resources/js-test.js"></script>
<script src="resources/global-interface-listing-service-worker.js"></script>
</head>
<body>
<div id="console"></div>
<script>
// We can't use testharness.js in this test because this needs to dump text
// other than PASS/FAIL.
jsTestIsAsync = true;
register_service_worker(/*platform_specific=*/true);
</script>
</body>
</html>
......@@ -65,11 +65,6 @@ interface BackgroundFetchUpdateUIEvent : BackgroundFetchEvent
attribute @@toStringTag
method constructor
method updateUI
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface BidirectionalStream
attribute @@toStringTag
getter readable
......
......@@ -3,6 +3,7 @@
<head>
<title>ServiceWorkerGlobalScope expose test.</title>
<script src="../../js-test-resources/js-test.js"></script>
<script src="resources/global-interface-listing-service-worker.js"></script>
</head>
<body>
<div id="console"></div>
......@@ -12,44 +13,7 @@
jsTestIsAsync = true;
function unregister_service_worker(document_url) {
return navigator.serviceWorker.getRegistration(document_url)
.then(registration => {
if (registration)
return registration.unregister();
});
}
var scope = 'resources/global-interface-listing-worker';
var options = { scope: scope };
unregister_service_worker(scope)
.then(() => {
return navigator.serviceWorker.register(
'resources/global-interface-listing-worker.js',
options);
})
.then(registration => {
var sw = registration.installing;
return new Promise(resolve => {
var message_channel = new MessageChannel;
message_channel.port1.onmessage = (evt => resolve(evt));
sw.postMessage(null, [message_channel.port2]);
});
})
.then(evt => {
var pre = document.createElement('pre');
pre.appendChild(document.createTextNode(evt.data.result.join('\n')));
document.body.insertBefore(pre, document.body.firstChild);
return unregister_service_worker(scope);
})
.then(() => {
testPassed('Verify the interface of ServiceWorkerGlobalScope');
finishJSTest();
})
.catch(error => {
testFailed('error: ' + (error.message || error.name || error));
finishJSTest();
});
register_service_worker(/*platform_specific=*/false);
</script>
</body>
</html>
function unregister_service_worker(document_url) {
return navigator.serviceWorker.getRegistration(document_url)
.then(registration => {
if (registration)
return registration.unregister();
});
}
function register_service_worker(platformSpecific) {
var scope = 'resources/global-interface-listing-worker';
var options = { scope: scope };
unregister_service_worker(scope)
.then(() => {
return navigator.serviceWorker.register(
'resources/global-interface-listing-worker.js',
options);
})
.then(registration => {
var sw = registration.installing;
return new Promise(resolve => {
var message_channel = new MessageChannel;
message_channel.port1.onmessage = (evt => resolve(evt));
sw.postMessage({ platformSpecific }, [message_channel.port2]);
});
})
.then(evt => {
var pre = document.createElement('pre');
pre.appendChild(document.createTextNode(evt.data.result.join('\n')));
document.body.insertBefore(pre, document.body.firstChild);
return unregister_service_worker(scope);
})
.then(() => {
testPassed('Verify the interface of ServiceWorkerGlobalScope');
finishJSTest();
})
.catch(error => {
testFailed('error: ' + (error.message || error.name || error));
finishJSTest();
});
}
\ No newline at end of file
......@@ -6,15 +6,14 @@
importScripts('/js-test-resources/global-interface-listing.js');
self.addEventListener('message', function(event) {
var globals = [];
globalInterfaceListing(global_object,
global_property_names,
false,
globalInterfaceListing(
global_object, global_property_names, event.data.platformSpecific,
string => globals.push(string));
self.addEventListener('message', function(event) {
event.ports[0].postMessage({ result: globals });
event.ports[0].postMessage({result: globals});
});
})(this);
[INTERFACES]
interface Notification : EventTarget
getter image
[NAMESPACES]
[GLOBAL OBJECT]
PASS Verify the interface of ServiceWorkerGlobalScope
PASS successfullyParsed is true
TEST COMPLETE
This test documents all interface attributes and methods on DedicatedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
This test documents all interface attributes and methods on SharedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
[INTERFACES]
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface Notification : EventTarget
[NAMESPACES]
[GLOBAL OBJECT]
PASS Verify the interface of ServiceWorkerGlobalScope
PASS successfullyParsed is true
TEST COMPLETE
This test documents all interface attributes and methods on DedicatedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface Notification : EventTarget
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
......@@ -3,6 +3,11 @@ This test documents all interface attributes and methods on the global window ob
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
[INTERFACES]
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface Bluetooth : EventTarget
attribute @@toStringTag
method constructor
......
This test documents all interface attributes and methods on SharedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface Notification : EventTarget
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
......@@ -118,6 +118,7 @@ var wellKnownSymbols = new Map([
// platform-specific expectations files to a bare minimum to make updates in the
// common (platform-neutral) case as simple as possible.
var platformSpecificInterfaces = new Set([
'BarcodeDetector',
'Bluetooth',
'BluetoothCharacteristicProperties',
'BluetoothDevice',
......
[INTERFACES]
interface Notification : EventTarget
getter image
[NAMESPACES]
[GLOBAL OBJECT]
PASS Verify the interface of ServiceWorkerGlobalScope
PASS successfullyParsed is true
TEST COMPLETE
......@@ -49,11 +49,6 @@ interface BackgroundFetchUpdateUIEvent : BackgroundFetchEvent
attribute @@toStringTag
method constructor
method updateUI
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface Blob
attribute @@toStringTag
getter size
......
......@@ -42,11 +42,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method match
[Worker] method matchAll
[Worker] setter onprogress
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface Blob
[Worker] attribute @@toStringTag
[Worker] getter size
......
......@@ -275,11 +275,6 @@ interface BarProp
attribute @@toStringTag
getter visible
method constructor
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface BaseAudioContext : EventTarget
attribute @@toStringTag
getter audioWorklet
......
This test documents all interface attributes and methods on DedicatedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface Notification : EventTarget
[Worker] getter image
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
This test documents all interface attributes and methods on SharedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface Notification : EventTarget
[Worker] getter image
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
......@@ -42,11 +42,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method match
[Worker] method matchAll
[Worker] setter onprogress
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface Blob
[Worker] attribute @@toStringTag
[Worker] getter size
......
......@@ -58,11 +58,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method match
[Worker] method matchAll
[Worker] setter onprogress
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface BidirectionalStream
[Worker] attribute @@toStringTag
[Worker] getter readable
......
......@@ -3,4 +3,5 @@
<script>
description("This test documents all interface attributes and methods on DedicatedWorkerGlobalScope.");
worker = startWorker("resources/global-interface-listing-worker.js");
worker.postMessage({ platformSpecific: false });
</script>
......@@ -439,11 +439,6 @@ interface BarProp
attribute @@toStringTag
getter visible
method constructor
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface BaseAudioContext : EventTarget
attribute @@toStringTag
getter audioWorklet
......
This test documents all interface attributes and methods on DedicatedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface Notification : EventTarget
[Worker] getter image
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../resources/js-test.js"></script>
<script>
description("This test documents all interface attributes and methods on DedicatedWorkerGlobalScope.");
worker = startWorker("resources/global-interface-listing-worker.js");
worker.postMessage({ platformSpecific: true });
</script>
......@@ -3,6 +3,11 @@ This test documents all interface attributes and methods on the global window ob
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
[INTERFACES]
interface BarcodeDetector
static method getSupportedFormats
attribute @@toStringTag
method constructor
method detect
interface Bluetooth : EventTarget
attribute @@toStringTag
getter onadvertisementreceived
......
This test documents all interface attributes and methods on SharedWorkerGlobalScope.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Starting worker: resources/global-interface-listing-worker.js
[Worker] [INTERFACES]
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface Notification : EventTarget
[Worker] getter image
[Worker] [NAMESPACES]
[Worker] [GLOBAL OBJECT]
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../resources/js-test.js"></script>
<script>
description("This test documents all interface attributes and methods on SharedWorkerGlobalScope.");
worker = startWorker("resources/global-interface-listing-worker.js", "shared");
worker.port.postMessage({ platformSpecific: true });
</script>
......@@ -58,11 +58,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method match
[Worker] method matchAll
[Worker] setter onprogress
[Worker] interface BarcodeDetector
[Worker] static method getSupportedFormats
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method detect
[Worker] interface BidirectionalStream
[Worker] attribute @@toStringTag
[Worker] getter readable
......
......@@ -3,4 +3,5 @@
<script>
description("This test documents all interface attributes and methods on SharedWorkerGlobalScope.");
worker = startWorker("resources/global-interface-listing-worker.js", "shared");
worker.port.postMessage({ platformSpecific: false });
</script>
......@@ -7,36 +7,29 @@
importScripts('../../resources/js-test.js');
importScripts('../../resources/global-interface-listing.js');
if (!self.postMessage) {
function runTest(platformSpecific) {
globalInterfaceListing(
globalObject, propertyNamesInGlobal, platformSpecific, debug);
finishJSTest();
}
if (self.postMessage) {
self.onmessage = (e) => {
runTest(e.data.platformSpecific);
}
} else {
// Shared worker. Make postMessage send to the newest client, which in
// our tests is the only client.
// Store messages for sending until we have somewhere to send them.
self.postMessage = function(message) {
if (typeof self.pendingMessages === "undefined")
self.pendingMessages = [];
self.pendingMessages.push(message);
};
self.onconnect = function(event) {
self.postMessage = function(message) {
event.ports[0].postMessage(message);
};
// Offload any stored messages now that someone has connected to us.
if (typeof self.pendingMessages === "undefined")
return;
while (self.pendingMessages.length)
event.ports[0].postMessage(self.pendingMessages.shift());
event.ports[0].onmessage = (e) => {
runTest(e.data.platformSpecific);
};
};
}
// Note that this test is not split into platform-specific
// vs. platform-neutral versions like the non-worker global-interface-listing
// tests are. This is because it should be unlikely that there would be an
// interface that is both worker-specific and platform-specific. This can be
// reconsidered in the future if that does become the case however.
globalInterfaceListing(globalObject, propertyNamesInGlobal, false /* platformSpecific */, debug);
finishJSTest();
})(this);
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