Skip to content

Conversation

elijahsawyers
Copy link

@elijahsawyers elijahsawyers commented Feb 12, 2025

Validate this change by writing a few simple tests that verify that some APIs on browser.runtime behave as expected.

The RFC document can be viewed here.

@@ -0,0 +1,64 @@
async function testGetURLErrorCases() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think usually the actual WPT tests are added separately from the infrastructure changes and tests for the infrastructure should be added to https://github.com/web-platform-tests/wpt/tree/master/infrastructure

@kiaraarose kiaraarose force-pushed the web_extension_tests branch 3 times, most recently from 5640ee5 to d1f118f Compare February 17, 2025 08:06
@@ -975,6 +1009,7 @@ def on_environment_change(self, new_environment):

def do_test(self, test):
url = self.test_url(test)
self.protocol.test_path = test.path

Choose a reason for hiding this comment

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

i think there is a better way to get that path than the way i'm doing it here. open to suggestions

@elijahsawyers elijahsawyers force-pushed the web_extension_tests branch 2 times, most recently from c04b7f2 to be054c4 Compare February 19, 2025 20:12
@elijahsawyers elijahsawyers marked this pull request as ready for review February 19, 2025 20:15
@elijahsawyers elijahsawyers requested a review from a team as a code owner February 19, 2025 20:15
@OrKoN
Copy link
Contributor

OrKoN commented Apr 2, 2025

Would it be possible to rebase the PR?

@kiaraarose kiaraarose force-pushed the web_extension_tests branch from bec3e11 to 724f3a7 Compare April 3, 2025 20:29
@kiaraarose
Copy link

Would it be possible to rebase the PR?

Updated the branch.

@OrKoN
Copy link
Contributor

OrKoN commented Apr 4, 2025

Thanks! locally I get the same error that shows on the bots now:

self._require_webdriver_bidi = test.testdriver_features is not None and 'bidi' in test.testdriver_features or 'extensions' in test.testdriver_features
TypeError: argument of type 'NoneType' is not iterable

@kiaraarose kiaraarose force-pushed the web_extension_tests branch from 724f3a7 to 83e7425 Compare April 15, 2025 23:15
@kiaraarose
Copy link

Thanks! locally I get the same error that shows on the bots now:

self._require_webdriver_bidi = test.testdriver_features is not None and 'bidi' in test.testdriver_features or 'extensions' in test.testdriver_features
TypeError: argument of type 'NoneType' is not iterable

thanks! not sure why i wasn't seeing that locally. pushed a fix

@kiaraarose kiaraarose force-pushed the web_extension_tests branch from 83e7425 to 8f96b02 Compare June 12, 2025 18:18
@kiaraarose kiaraarose force-pushed the web_extension_tests branch 3 times, most recently from 7d5ff6c to 7bb2dcd Compare June 16, 2025 21:16
@kiaraarose kiaraarose force-pushed the web_extension_tests branch 3 times, most recently from 679357f to 8000041 Compare July 3, 2025 15:49
@kiaraarose kiaraarose force-pushed the web_extension_tests branch from 8000041 to 7c36afe Compare August 7, 2025 15:17

setup({ explicit_done: true })

globalThis.runTestsWithWebExtension = function(extensionPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is off here

Comment on lines 16 to 19
path: extensionPath
})
.then((result) => {
let test;
Copy link
Contributor

Choose a reason for hiding this comment

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

Also inconsistent 2/4 spaces

Comment on lines 32 to 36
if (!data.result)
test.set_status(test.FAIL)

if (!data.remainingTests)
test_driver.uninstall_web_extension(result.extension).then(() => { done() })
Copy link
Contributor

Choose a reason for hiding this comment

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

Please brace single-line ifs

let test;

browser.test.onTestStarted.addListener((data) => {
test = async_test(data.testName)
Copy link
Contributor

Choose a reason for hiding this comment

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

This depends on tests always running in serial. Is that absolutely guaranteed by the web extensions API? Would we be bteer having a map from testName to test and in onTestFinished getting the relevant test out of the map? We could at least try to assert that the name is what we expect.

Choose a reason for hiding this comment

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

the tests run serially. another test will only start once the previous one finished

* @returns {Promise} Returns the extension identifier as defined in the spec.
* Rejected if the extension fails to load.
*/
install_web_extension: function(path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring doesn't seem to match the actual implementation.

@@ -701,6 +701,12 @@ def print(self,
body[prop] = value
return self.send_session_command("POST", "print", body)

def install_web_extension(self, extension):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a more idiomatic API in this client would be to have an Extensions object with install and uninstall methods so the API would look like client.extensions.install(path=<path>). Also it's unclear what extension is; I think it's a dict, but we should have named parameters instead and assemble the dict inside the method.

def setup(self):
self.webdriver = self.parent.webdriver

def install_web_extension(self, extension):
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here, break apart the extension argument into named parameters as much as possible.

Validate this change by writing a few simple tests that verify that
some APIs on browser.runtime behave as expected.
@kiaraarose
Copy link

@jgraham I applied your suggested changes. can you take another look?

@zombie
Copy link
Contributor

zombie commented Sep 4, 2025

I've just confirmed this still runs and passes the sample tests with a Firefox build from latest checkout, and also with

python wpt run --channel=nightly --install-browser firefox web-extensions --no-headless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.