Skip to content

proposal: Add amendments to browser.test API (#1051) - #1057

Open
justinlulejian wants to merge 4 commits into
w3c:mainfrom
justinlulejian:browser-test-amend
Open

proposal: Add amendments to browser.test API (#1051)#1057
justinlulejian wants to merge 4 commits into
w3c:mainfrom
justinlulejian:browser-test-amend

Conversation

@justinlulejian

Copy link
Copy Markdown

No description provided.

- `message` (string, optional)

**`browser.test.succeed(message)`**
Immediately marks the current test as passed, optionally with a custom message. This is helpful in cases where returning a Promise or `undefined` is less obvious than explicitly indicating success.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This differs from what we do in Safari/WebKit. browser.test.succeed(message) is just an alias for assertTrue(true, message). We have browser.test.notifyPass(message) as the "marks the current test as passed" method. IIRC, this is what Chrome and Firefox did too last I checked when we added these.

Should WebKit have succeed alias to notifyPass instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Chrome browser.test.notifyPass/browser.test.notifyFail are for the whole suite of browser.test.runTests, whereas browser.test.succeed in for the specific test case it's run in. For Safari, is browser.test.notifyPass/browser.test.notifyFail for the whole suite of tests or each individual test case? If the latter, then yes you could have browser.test.succeed/browser.test.fail just alias to browser.test.notifyPass/browser.test.notifyFail.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Chrome browser.test.notifyPass/browser.test.notifyFail are for the whole suite of browser.test.runTests

what about outside the context of runTests? how does notifyPass/notifyFail behave?

@kiaraarose kiaraarose Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this is what Chrome and Firefox did too last I checked when we added these.

Firefox also does an alias: https://searchfox.org/firefox-main/source/toolkit/components/extensions/child/ext-test.js#299-305

- `message` (string, optional)

**`browser.test.fail(message)`**
Immediately marks the current test as failed, optionally with a custom message. This is helpful in cases where returning a Promise or `undefined` is less obvious than explicitly indicating failure.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to https://github.com/w3c/webextensions/pull/1057/changes#r3724127353. We have browser.test.fail(message) as an alias for assertTrue(false, message). browser.test.notifyFail(message) is "marks the current test as failed" method.

Should WebKit have fail alias to notifyFail instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@xeenon
xeenon requested a review from kiaraarose August 5, 2026 21:26

### Properties

**`browser.test.isUserGestureActive`** (boolean)

@xeenon xeenon Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebKit currently has isProcessingUserGesture. We will need to add support for the new name before we can adopt this in WPT.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had switched this since it was suggested as a good alternative. Chrome also implements it as isProcessingUserGesture. Do other browser have a strong position on this? Otherwise I'm happy saving the effort and keeping it as isProcessingUserGesture.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm fine with isUserGestureActive. but as Tim said, we would need to adopt in WebKit and wait for that change to be picked up in Safari Tech Preview before using it in the wpt test

Comment thread proposals/browser_test_api.md Outdated
Runs the provided function in the context of a user gesture.

**Parameters**
- `fn` (function)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we document a return value (whatever the function returns?). I mentioned that at the last meeting and #1051 (comment)

I don't mind not returning anything, but then someone always needs to do something like:

await new Promise(resolve => {
  browser.test.runWithUserGesture(
    () => resolve(browser.permissions.request(perms))
  );
});

Opposed to:

await browser.test.runWithUserGesture(
  () => browser.permissions.request(perms)
);

FWIW, our (differently named) test helper in Firefox does currently NOT return the value, to discourage the reader from thinking (incorrectly) that returning a promise would extend the user gesture beyond the current run of the event loop.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a returns section to this method. Chrome usually combines it internally with chrome.test.succeed internally so that's why I omitted it, but I agree it's more ergonomic to the function's result to not have to wrap it in a promise each time. The refactor and impl would be pretty simple to implement in Chrome.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return the result in WebKit

Comment thread proposals/browser_test_api.md
@justinlulejian
justinlulejian requested review from Rob--W and xeenon August 7, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants