GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 36cc780d authored by Alex Catarineu's avatar Alex Catarineu

Fix dom-objects-enumeration tests

- Use fixture server.
- Use same method for both worker and window tests.
- Require results to exactly match what we expect.
parent f4b6d697
......@@ -829,6 +829,7 @@ sub marionette_run {
system(xvfb_run($test), "$FindBin::Bin/virtualenv-marionette-5.0.0/$bin/tor-browser-tests",
'--log-unittest', winpath($result_file_txt),
'--log-html', winpath($result_file_html),
'--server-root', winpath("$FindBin::Bin/test-data"),
'--binary', ffbin_path($tbbinfos, $test),
'--profile', winpath($tbbinfos->{ffprofiledir}),
$OSNAME eq 'cygwin' ? () : ('--workspace', $test->{workspace}),
......
from marionette_driver import By
from marionette_driver.errors import MarionetteException
from marionette_harness import MarionetteTestCase
import testsuite
class Test(MarionetteTestCase):
def setUp(self):
MarionetteTestCase.setUp(self)
ts = testsuite.TestSuite()
self.ts = ts
self.marionette.set_pref("network.proxy.allow_hijacking_localhost", False)
self.test_page_file_url = self.marionette.absolute_url("dom-objects-enumeration.html?testType=worker")
self.expectedObjects = [
"AbortController",
......@@ -21,10 +15,15 @@ class Test(MarionetteTestCase):
"Array",
"ArrayBuffer",
"atob",
"Atomics",
"BigInt",
"BigInt64Array",
"BigUint64Array",
"Blob",
"Boolean",
"BroadcastChannel",
"btoa",
"ByteLengthQueuingStrategy",
"Cache",
"caches",
"CacheStorage",
......@@ -34,7 +33,9 @@ class Test(MarionetteTestCase):
"CloseEvent",
"console",
"constructor",
"CountQueuingStrategy",
"createImageBitmap",
"crossOriginIsolated",
"crypto",
"Crypto",
"CustomEvent",
......@@ -47,9 +48,14 @@ class Test(MarionetteTestCase):
"__defineSetter__",
"Directory",
"dispatchEvent",
"DOMCursor",
"DOMError",
"DOMException",
"DOMMatrix",
"DOMMatrixReadOnly",
"DOMPoint",
"DOMPointReadOnly",
"DOMQuad",
"DOMRect",
"DOMRectReadOnly",
"DOMRequest",
"DOMStringList",
"dump",
......@@ -72,7 +78,7 @@ class Test(MarionetteTestCase):
"Float64Array",
"FormData",
"Function",
"getAllPropertyNames",
"globalThis",
"hasOwnProperty",
"Headers",
"IDBCursor",
......@@ -101,13 +107,14 @@ class Test(MarionetteTestCase):
"isNaN",
"isPrototypeOf",
"isSecureContext",
"Iterator",
"JSON",
"location",
"__lookupGetter__",
"__lookupSetter__",
"Map",
"Math",
"MediaCapabilities",
"MediaCapabilitiesInfo",
"MessageChannel",
"MessageEvent",
"MessagePort",
......@@ -117,12 +124,14 @@ class Test(MarionetteTestCase):
"Notification",
"Number",
"Object",
"onclose",
"onerror",
"onlanguagechange",
"onmessage",
"onmessageerror",
"onoffline",
"ononline",
"onrejectionhandled",
"onunhandledrejection",
"origin",
"parseFloat",
"parseInt",
......@@ -134,13 +143,17 @@ class Test(MarionetteTestCase):
"PerformanceObserver",
"PerformanceObserverEntryList",
"PerformanceResourceTiming",
"PerformanceServerTiming",
"postMessage",
"ProgressEvent",
"Promise",
"PromiseRejectionEvent",
"propertyIsEnumerable",
"__proto__",
"Proxy",
"queueMicrotask",
"RangeError",
"ReadableStream",
"ReferenceError",
"Reflect",
"RegExp",
......@@ -151,7 +164,6 @@ class Test(MarionetteTestCase):
"Set",
"setInterval",
"setTimeout",
"StopIteration",
"StorageManager",
"String",
"SubtleCrypto",
......@@ -160,7 +172,6 @@ class Test(MarionetteTestCase):
"TextDecoder",
"TextEncoder",
"toLocaleString",
"toSource",
"toString",
"TypeError",
"Uint16Array",
......@@ -169,13 +180,10 @@ class Test(MarionetteTestCase):
"Uint8ClampedArray",
"undefined",
"unescape",
"uneval",
"unwatch",
"URIError",
"URL",
"URLSearchParams",
"valueOf",
"watch",
"WeakMap",
"WeakSet",
"WebAssembly",
......@@ -191,14 +199,13 @@ class Test(MarionetteTestCase):
def test_dom_objects_enumeration_workers(self):
with self.marionette.using_context('content'):
URL = "file://%s/workers/dom-objects-enumeration.html" % self.ts.t['options']['test_data_dir']
self.marionette.navigate(URL)
self.marionette.set_search_timeout(50000)
self.marionette.navigate(self.test_page_file_url)
self.marionette.timeout.implicit = 5
elt = self.marionette.find_element('id', 'enumeration')
r = elt.text.split("\n")
err = False
unknown_objects = ''
for l in elt.text.split("\n"):
for l in r:
if l in self.expectedObjects:
continue
err = True
......@@ -206,3 +213,12 @@ class Test(MarionetteTestCase):
err_msg = "Unknown objects:\n%s" % unknown_objects
self.assertFalse(err, msg=err_msg)
for l in self.expectedObjects:
if l in r:
continue
err = True
unknown_objects += l + "\n"
err_msg = "Expected objects not found:\n%s" % unknown_objects
self.assertFalse(err, msg=err_msg)
\ No newline at end of file
......@@ -3,13 +3,12 @@
<head>
<meta charset="utf-8">
<title>Web Workers dom objects enumeration</title>
<title>dom objects enumeration</title>
</head>
<body>
<h1>Web Workers dom objects enumeration</h1>
<h1>dom objects enumeration</h1>
<script src="dom-objects-enumeration.js"></script>
</body>
<script src="dom-objects-enumeration.js"></script>
</html>
(() => {
// getAllPropertyNames function taken from:
// https://stackoverflow.com/questions/8024149/is-it-possible-to-get-the-non-enumerable-inherited-property-names-of-an-object
function getAllPropertyNames(obj) {
const props = [];
do {
Object.getOwnPropertyNames(obj).forEach((prop) => {
if (props.indexOf(prop) === -1) {
props.push(prop);
}
});
} while (obj = Object.getPrototypeOf(obj));
return [...new Set(props)].sort();
}
function getGlobalNames() {
return getAllPropertyNames(globalThis);
}
if (!self.document) {
// This is a worker
self.postMessage(getGlobalNames());
} else {
// Not a worker, loaded via script.
const enumeration = document.createElement("div");
enumeration.setAttribute("id", "enumeration");
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
let onmessage = (allObjects) => {
for (const name of allObjects) {
enumeration.innerHTML += name + "<br/>";
}
document.getElementsByTagName("body")[0].appendChild(enumeration);
};
if (urlParams.get("testType") === "worker") {
// Must enumerate worker globals
const worker = new Worker("dom-objects-enumeration.js");
worker.onmessage = (e) => onmessage(e.data);
} else {
// Must enumerate window global
onmessage(getGlobalNames());
}
}
})();
\ No newline at end of file
// getAllPropertyNames function taken from:
// https://stackoverflow.com/questions/8024149/is-it-possible-to-get-the-non-enumerable-inherited-property-names-of-an-object
function getAllPropertyNames( obj ) {
var props = [];
do {
Object.getOwnPropertyNames( obj ).forEach(function ( prop ) {
if ( props.indexOf( prop ) === -1 ) {
props.push( prop );
}
});
} while ( obj = Object.getPrototypeOf( obj ) );
return props;
}
onmessage = function(e) {
var allObjects = getAllPropertyNames(self);
var res = Array();
for (var i in allObjects.sort()) {
res.push(allObjects[i]);
}
postMessage(res);
}
var enumeration = document.createElement('div');
enumeration.setAttribute("id", "enumeration");
if (window.Worker) {
var myWorker = new Worker("dom-objects-enumeration-worker.js");
myWorker.postMessage("Hello");
myWorker.onmessage = function(e) {
var allObjects = e.data;
for (var i in allObjects.sort()) {
var name = allObjects[i];
enumeration.innerHTML += name + "<br/>";
}
document.getElementsByTagName("body")[0].appendChild(enumeration);
}
}
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