Closed Bug 1641735 Opened 4 years ago Closed 3 years ago

Improve extension testing framework for GeckoView to not require useAddonManager in ExtensionTestUtils.loadExtension

Categories

(WebExtensions :: Android, enhancement, P2)

Unspecified
All
enhancement

Tracking

(firefox94 fixed)

RESOLVED FIXED
94 Branch
Tracking Status
firefox94 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 2 open bugs)

Details

Attachments

(4 files)

ExtensionTestUtils.loadExtension is used to load extensions in tests. Many extension tests on desktop (and Fennec) did not depend on the addon manager, so to reduce the overhead in tests, the utility generates an add-on without addon manager by default. useAddonManager is only used in tests where the addon manager is significant.

In GeckoView, various UI-related APIs (tabs, browserAction, pageAction) only work when the extension has been registered via the Addon Manager. Unfortunately, this results in lots of boilerplate in extension tests, where every test that uses UI on Android includes useAddonManager: "permanent" plus an extension ID, see e.g. bug 1615329 and bug 1599580.

We should improve ExtensionTestUtils.loadExtension (the mochitest one, not the one for xpcshell tests) to not require useAddonManager for it to work.
There are several ways to do that. It could be done by adding useAddonManager to every loadExtension call on Android/GeckoView, by providing a minimal mock of the AddonWrapper from the addon manager internals, or maybe even modifying GeckoView internals to account for this.

I don't think there's much we can do on the GV side to circumvent that, I don't think a mock AddonManager is worth either, unless we have a very compelling reason to do that.

Component: Extensions → General
Product: GeckoView → WebExtensions
Component: General → Android
Assignee: nobody → rob
Priority: -- → P2
Severity: -- → N/A
Blocks: 1381237

This patch introduces the androidBrowserTest option to offer an
alternative to adding a boilerplate useAddonManager + extension ID in
mochitests that use certain extension APIs.

The androidBrowserTest option of ExtensionTestUtils.loadExtension exists
to allow Android tests to correctly register with the AddonManager
without unnecessarily forcing this registration on desktop.

This patch replaces all unnecessary uses of useAddonManager with the
androidBrowserTest option, which is essentially the same but only
enables the "useAddonManager" option on Android. This is to make it more
obvious when a test really depends on the AddonManager (on desktop),
opposed to only depending on it indirectly as part of the GeckoView
implementation.

In some tests, useAddonManager was not used before because the test is
marked as skipped, but I've added the option regardless for the future.

In the past, add_task was generator-based, and tests were automatically
rewritten to use Promises. Some tests have weird constructs such as the
use of Promise.all+await or still using generators. These have been
fixed.

Some tests request the tabs permission without actually needing it.

This patch does not affect the behavior of the tests.

test_ext_tab_runtimeConnect.html can be re-enabled since bug 1534640 got fixed.
test_ext_tabs_reload.html had a race condition.
test_ext_tabs_reload_bypass_cache.html fix similar to bug 1335180.

Attachment #9238730 - Attachment description: Bug 1641735 - Add androidBrowserTest option in ExtensionTestUtils.loadExtension → Bug 1641735 - Set useAddonManager by default on Android in mochitests
Pushed by rob@robwu.nl:
https://hg.mozilla.org/integration/autoland/rev/90d683f96928
Set useAddonManager by default on Android in mochitests r=zombie
https://hg.mozilla.org/integration/autoland/rev/ba58b88f06ff
Replace unnecessary uses of useAddonManager of ExtensionTestUtils.loadExtension r=zombie,agi,extension-reviewers
https://hg.mozilla.org/integration/autoland/rev/2dc275e3cc0f
Code cleanup of some extension tests r=geckoview-reviewers,agi,mixedpuppy
https://hg.mozilla.org/integration/autoland/rev/f5d6ae6aea44
Re-enable some tabs tests on Android r=agi,extension-reviewers,zombie
See Also: → 1802571
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: