Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1679375 - Add tests for web ext storage impl #7

Merged
merged 7 commits into from
Dec 10, 2020

Conversation

brizental
Copy link
Contributor

@brizental brizental commented Dec 4, 2020

...and have the unit tests run directly on Firefox (or try)

[This is draft, full description will come later]

[UPDATE]

From the commit message:

In order to access the web extensions APIs directly on
the browser we need to play a bit of a telephone game.

We use selenium to instantiate and run code as if on the
browser console, but on the console we still don't have access
to the webextensions APIs neither can we send messages directly
the a web extensions background script.

It occured to me that I may be wrong about not being able to directly message the background script, but such a change, if confirmed, could be done in a follow up. It would remove a bit of the complexity, by making the content script unnecessary.

With this in mind, we send a custom event ("test") from the console,
which will contain information about the exact web extention API we
want to access and with what arguments we want to execute it.

Packed with this commit is a webextension that I created to help with
these tests. The content script of this web extension listens for the
"test" custom events. Whenever a new one is received, the content
script, which still doesn't have access to most web ext APIs, will pass
the message from the website to the background script.

The background script of this webextension, is listening for such
messages, and will process the message and execute the requested API.
When that is done, the background script will pass the response back to
the content script. The content script will send the response back in
another custom event ("testResponse").

The tests will listen for "testResponse" events, when this event is
received we step out of the executeAsyncScript block and return the
response received.

All of this will happen inside a proxy around the desired web ext APIs,
so that calling code doesn't even need to know all that is happening and
can hapilly call web ext APIs without worrying.

@brizental brizental requested a review from Dexterp37 December 4, 2020 16:22
@brizental
Copy link
Contributor Author

This is ready for review, but I'd recommend we wait for #8 to be merged since it depends on it and also commit history is crazy right now because this branch is based off of that one.

I'll also write a more detailed description for this PR once that is done.

@brizental brizental changed the title Bug 1679375 - Implement Store for web extensions storage API Bug 1679375 - Add tests for web ext storage impl Dec 9, 2020
@brizental brizental force-pushed the 1679375-storage-webext branch from 4bcfcb0 to 48f4e42 Compare December 9, 2020 13:12
brizental added 2 commits December 9, 2020 14:39
In order to access the web extensions APIs directly on
the browser we need to play a bit of a telephone game.

We use selenium to instantiate and run code as if on the
browser console, but on the console we still don't have access
to the webextensions APIs neither can we send messages directly
the a web extensions background script.

With this in mind, we send a custom event ("test") from the console,
which will contain information about the exact web extention API we
want to access and with what arguments we want to execute it.

Packed with this commit is a webextension that I created to help with
these tests. The content script of this web extension listens for the
"test" custom events. Whenever a new one is received, the content
script, which still doesn't have access to most web ext APIs, will pass
the message from the website to the background script.

The background script of this webextension, is listening for such
messages, and will process the message and execute the requested API.
When that is done, the background script will pass the response back to
the content script. The content script will send the response back in
another custom event ("testResponse").

The tests will listen for "testResponse" events, when this event is
received we step out of the executeAsyncScript block and return the
response received.

All of this will happen inside a proxy around the desired web ext APIs,
so that calling code doesn't even need to know all that is happening and
can hapilly call web ext APIs without worrying.
Specifically, this orb with install Firefox, Chrome, GeckoDiver and
ChromeDriver.
@brizental brizental force-pushed the 1679375-storage-webext branch from 48f4e42 to 04b7126 Compare December 9, 2020 13:55
@brizental
Copy link
Contributor Author

(Filed a bug about the clearly wrong size comment, https://bugzilla.mozilla.org/show_bug.cgi?id=1681516)

@brizental brizental marked this pull request as ready for review December 9, 2020 14:03
Copy link
Contributor

@Dexterp37 Dexterp37 left a comment

Choose a reason for hiding this comment

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

r+wc

.mocharc.json Show resolved Hide resolved
tests/utils/webext/index.ts Outdated Show resolved Hide resolved
tests/utils/webext/sample/background.js Show resolved Hide resolved
tests/utils/webext/sample/content.js Show resolved Hide resolved
tests/utils/webext/sample/manifest.json Show resolved Hide resolved
@moz-glean
Copy link
Collaborator

Build size report

Merging #7 into main will:

  • Decrease the size of the webext build (npm run build:webext) by -8700%.
  • Decrease the size of the Qt build (npm run build:qt) by -2100%.

Build Current size New size Size increase
webext 31.30K 31.22K 📉 -8700%
qt 15.64K 15.62K 📉 -2100%

@brizental brizental merged commit 7a1d79d into main Dec 10, 2020
@brizental brizental deleted the 1679375-storage-webext branch December 10, 2020 10:41
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.

3 participants