Bug 1793227, part 9 - Automated fixes for js/xpconnect/tests/browser/. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D158508
This commit is contained in:
Andrew McCreight 2022-10-10 22:22:02 +00:00
parent 1e9cfa44fc
commit cbfad78f92
4 changed files with 43 additions and 23 deletions

View file

@ -144,7 +144,6 @@ js/src/tests/
js/src/Y.js js/src/Y.js
# Changes to XPConnect tests must be carefully audited. # Changes to XPConnect tests must be carefully audited.
js/xpconnect/tests/browser/
js/xpconnect/tests/mochitest/ js/xpconnect/tests/mochitest/
js/xpconnect/tests/unit/ js/xpconnect/tests/unit/

View file

@ -12,7 +12,7 @@ add_task(async function test_browser_hang() {
// Trip some testing code to ensure we can test this. Sadly, this is a magic // Trip some testing code to ensure we can test this. Sadly, this is a magic
// number corresponding to code in XPCJSContext.cpp // number corresponding to code in XPCJSContext.cpp
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["dom.max_chrome_script_run_time", 2]] set: [["dom.max_chrome_script_run_time", 2]],
}); });
await SpecialPowers.promiseTimeout(0); await SpecialPowers.promiseTimeout(0);
@ -39,14 +39,22 @@ add_task(async function test_browser_hang() {
); );
return events.parent?.some(e => e[1] == "slow_script_warning"); return events.parent?.some(e => e[1] == "slow_script_warning");
}, "Should find an event after doing this.").catch(e => ok(false, e)); }, "Should find an event after doing this.").catch(e => ok(false, e));
events = (events.parent || []); events = events.parent || [];
let event = events.find(e => e[1] == "slow_script_warning"); let event = events.find(e => e[1] == "slow_script_warning");
ok(event, "Should have registered an event."); ok(event, "Should have registered an event.");
if (event) { if (event) {
is(event[3], "browser", "Should register as browser hang."); is(event[3], "browser", "Should register as browser hang.");
let args = event[5]; let args = event[5];
is(args.uri_type, "browser", "Should register browser uri type."); is(args.uri_type, "browser", "Should register browser uri type.");
Assert.greater(duration + 1, parseFloat(args.hang_duration), "hang duration should not exaggerate."); Assert.greater(
Assert.less(duration - 1, parseFloat(args.hang_duration), "hang duration should not undersell."); duration + 1,
parseFloat(args.hang_duration),
"hang duration should not exaggerate."
);
Assert.less(
duration - 1,
parseFloat(args.hang_duration),
"hang duration should not undersell."
);
} }
}); });

View file

@ -6,28 +6,40 @@
"use strict"; "use strict";
add_task(async function test_explicit_object_prototype() { add_task(async function test_explicit_object_prototype() {
const url = "http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_promise_userInteractionHandling.html"; const url =
"http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_promise_userInteractionHandling.html";
await BrowserTestUtils.withNewTab(url, async browser => { await BrowserTestUtils.withNewTab(url, async browser => {
await ContentTask.spawn(browser, {}, async () => { await ContentTask.spawn(browser, {}, async () => {
const { EventUtils } = ChromeUtils.import( const { EventUtils } = ChromeUtils.import(
"resource://specialpowers/SpecialPowersEventUtils.jsm" "resource://specialpowers/SpecialPowersEventUtils.jsm"
); );
const DOMWindowUtils = EventUtils._getDOMWindowUtils(content.window); const DOMWindowUtils = EventUtils._getDOMWindowUtils(content.window);
is(DOMWindowUtils.isHandlingUserInput, false, is(
"not yet handling user input"); DOMWindowUtils.isHandlingUserInput,
false,
"not yet handling user input"
);
const button = content.document.getElementById("button"); const button = content.document.getElementById("button");
let resolve; let resolve;
const p = new Promise(r => { resolve = r; }); const p = new Promise(r => {
resolve = r;
});
button.addEventListener("click", () => { button.addEventListener("click", () => {
is(DOMWindowUtils.isHandlingUserInput, true, "handling user input"); is(DOMWindowUtils.isHandlingUserInput, true, "handling user input");
content.document.hasStorageAccess().then(() => { content.document.hasStorageAccess().then(() => {
is(DOMWindowUtils.isHandlingUserInput, true, is(
"still handling user input"); DOMWindowUtils.isHandlingUserInput,
true,
"still handling user input"
);
Promise.resolve().then(() => { Promise.resolve().then(() => {
is(DOMWindowUtils.isHandlingUserInput, false, is(
"no more handling user input"); DOMWindowUtils.isHandlingUserInput,
false,
"no more handling user input"
);
resolve(); resolve();
}); });
}); });

View file

@ -6,22 +6,23 @@
"use strict"; "use strict";
async function test_document(url) { async function test_document(url) {
await BrowserTestUtils.withNewTab(url, async function (browser) { await BrowserTestUtils.withNewTab(url, async function(browser) {
let result = await ContentTask.spawn( let result = await ContentTask.spawn(browser, {}, async function() {
browser, {},
async function() {
let result = content.document.getElementById("result"); let result = content.document.getElementById("result");
return result.innerText; return result.innerText;
} });
);
is(result, "OK", "test succeeds"); is(result, "OK", "test succeeds");
}); });
} }
add_task(async function test_explicit_object_prototype() { add_task(async function test_explicit_object_prototype() {
await test_document("http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_realm_key_object_prototype_top.html"); await test_document(
"http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_realm_key_object_prototype_top.html"
);
}); });
add_task(async function test_implicit_object_prototype() { add_task(async function test_implicit_object_prototype() {
await test_document("http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_realm_key_promise_top.html"); await test_document(
"http://mochi.test:8888/browser/js/xpconnect/tests/browser/browser_realm_key_promise_top.html"
);
}); });