Skip to content

Commit

Permalink
Bug 1793227, part 9 - Automated fixes for js/xpconnect/tests/browser/…
Browse files Browse the repository at this point in the history
…. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D158508
  • Loading branch information
amccreight committed Oct 10, 2022
1 parent 1e9cfa4 commit cbfad78
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ js/src/tests/
js/src/Y.js

# Changes to XPConnect tests must be carefully audited.
js/xpconnect/tests/browser/
js/xpconnect/tests/mochitest/
js/xpconnect/tests/unit/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// number corresponding to code in XPCJSContext.cpp
await SpecialPowers.pushPrefEnv({
set: [["dom.max_chrome_script_run_time", 2]]
set: [["dom.max_chrome_script_run_time", 2]],
});
await SpecialPowers.promiseTimeout(0);

Expand All @@ -39,14 +39,22 @@ add_task(async function test_browser_hang() {
);
return events.parent?.some(e => e[1] == "slow_script_warning");
}, "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");
ok(event, "Should have registered an event.");
if (event) {
is(event[3], "browser", "Should register as browser hang.");
let args = event[5];
is(args.uri_type, "browser", "Should register browser uri type.");
Assert.greater(duration + 1, parseFloat(args.hang_duration), "hang duration should not exaggerate.");
Assert.less(duration - 1, parseFloat(args.hang_duration), "hang duration should not undersell.");
Assert.greater(
duration + 1,
parseFloat(args.hang_duration),
"hang duration should not exaggerate."
);
Assert.less(
duration - 1,
parseFloat(args.hang_duration),
"hang duration should not undersell."
);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@
"use strict";

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 ContentTask.spawn(browser, {}, async () => {
const { EventUtils } = ChromeUtils.import(
"resource://specialpowers/SpecialPowersEventUtils.jsm"
);
const DOMWindowUtils = EventUtils._getDOMWindowUtils(content.window);
is(DOMWindowUtils.isHandlingUserInput, false,
"not yet handling user input");
is(
DOMWindowUtils.isHandlingUserInput,
false,
"not yet handling user input"
);
const button = content.document.getElementById("button");

let resolve;
const p = new Promise(r => { resolve = r; });
const p = new Promise(r => {
resolve = r;
});

button.addEventListener("click", () => {
is(DOMWindowUtils.isHandlingUserInput, true, "handling user input");
content.document.hasStorageAccess().then(() => {
is(DOMWindowUtils.isHandlingUserInput, true,
"still handling user input");
is(
DOMWindowUtils.isHandlingUserInput,
true,
"still handling user input"
);
Promise.resolve().then(() => {
is(DOMWindowUtils.isHandlingUserInput, false,
"no more handling user input");
is(
DOMWindowUtils.isHandlingUserInput,
false,
"no more handling user input"
);
resolve();
});
});
Expand Down
21 changes: 11 additions & 10 deletions js/xpconnect/tests/browser/browser_realm_key_and_document_domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
"use strict";

async function test_document(url) {
await BrowserTestUtils.withNewTab(url, async function (browser) {
let result = await ContentTask.spawn(
browser, {},
async function() {
let result = content.document.getElementById("result");
return result.innerText;
}
);
await BrowserTestUtils.withNewTab(url, async function(browser) {
let result = await ContentTask.spawn(browser, {}, async function() {
let result = content.document.getElementById("result");
return result.innerText;
});
is(result, "OK", "test succeeds");
});
}

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() {
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"
);
});

0 comments on commit cbfad78

Please sign in to comment.