Makes notificationBox compatible with Fx versions earlier than 93 (#398)
* Makes notificationBox compatible with Fx versions earlier than 93 * Adding tests for esr91 * Run mach bootstrap * run mach bootstrap right after cloning * Run both tests on same action * Set MACH_USE_SYSTEM_PYTHON
This commit is contained in:
Родитель
1d57d21bc7
Коммит
081c09c225
|
@ -0,0 +1,22 @@
|
|||
name: End-to-End Tests on esr91
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '30 1 * * *'
|
||||
pull_request:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '17.x'
|
||||
- run: npm install
|
||||
- run: brew install git-cinnabar
|
||||
- name: Run e2e test on esr91
|
||||
env:
|
||||
MACH_USE_SYSTEM_PYTHON: 1
|
||||
run: python3 scripts/tests/e2e-tests-esr91.py
|
|
@ -1,10 +1,10 @@
|
|||
name: End-to-End Tests
|
||||
name: End-to-End Tests on master
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '30 1 * * *'
|
||||
pull_request:
|
||||
pull_request:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
|
@ -16,5 +16,5 @@ jobs:
|
|||
node-version: '17.x'
|
||||
- run: npm install
|
||||
- run: brew install git-cinnabar
|
||||
- name: Run test
|
||||
run: python3 scripts/tests/e2e-tests.py
|
||||
- name: Run e2e test on master
|
||||
run: python3 scripts/tests/e2e-tests.py
|
|
@ -122,15 +122,43 @@ const translationNotificationManagers = new Map();
|
|||
}
|
||||
|
||||
const notificationBox = tab.browser.ownerGlobal.gBrowser.getNotificationBox(tab.browser);
|
||||
let notif = notificationBox.appendNotification("fxtranslation-notification", {
|
||||
priority: notificationBox.PRIORITY_INFO_HIGH,
|
||||
eventCallback() {
|
||||
// removed / dismissed / disconnected in any way.
|
||||
translationNotificationManagers.delete(tabId);
|
||||
// ^ may also happen when the tab is navigated.
|
||||
},
|
||||
notificationIs: TRANSLATION_NOTIFICATION_ELEMENT_ID,
|
||||
});
|
||||
let notif = null;
|
||||
|
||||
/*
|
||||
* we need to check if the notificationBox.appendNotification
|
||||
* requires 7 positional arguments and instantiate it differently
|
||||
* in order to keep it compatible with older Fx versions
|
||||
* see: https://github.com/mozilla/firefox-translations/issues/363#issuecomment-1151022189
|
||||
*/
|
||||
const notificationId = "fxtranslation-notification";
|
||||
const priority = notificationBox.PRIORITY_INFO_HIGH;
|
||||
const eventCallback = () => {
|
||||
// removed / dismissed / disconnected in any way.
|
||||
translationNotificationManagers.delete(tabId);
|
||||
// ^ may also happen when the tab is navigated.
|
||||
};
|
||||
const notificationIs = TRANSLATION_NOTIFICATION_ELEMENT_ID;
|
||||
|
||||
if (notificationBox.appendNotification.length === 7) {
|
||||
// firefox 93 and earlier
|
||||
notif = notificationBox.appendNotification(
|
||||
null,
|
||||
notificationId,
|
||||
null,
|
||||
priority,
|
||||
null,
|
||||
eventCallback,
|
||||
notificationIs
|
||||
);
|
||||
} else {
|
||||
// firefox 94 and later
|
||||
notif = notificationBox.appendNotification(notificationId, {
|
||||
priority,
|
||||
eventCallback,
|
||||
notificationIs,
|
||||
});
|
||||
}
|
||||
|
||||
let translationNotificationManager = new TranslationNotificationManager(
|
||||
this,
|
||||
modelRegistry,
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
{
|
||||
"name": "firefox_translations",
|
||||
"scripts": {
|
||||
"test": "if [[ -z \"${MOZ_AUTOMATION}\" ]]; then python scripts/tests/e2e-tests.py; fi",
|
||||
"test": "if [[ -z \"${MOZ_AUTOMATION}\" ]]; then npm run test-esr; npm run test-master; fi",
|
||||
"test-esr": "python scripts/tests/e2e-tests-esr91.py",
|
||||
"test-master": "python scripts/tests/e2e-tests.py",
|
||||
"lint:js": "eslint -c .eslintrc.js extension",
|
||||
"build": "cp extension/settings/prod.js extension/settings.js; npm run update-localization; web-ext build -s extension --overwrite-dest --no-config-discovery -n firefox_translations.xpi",
|
||||
"build-test": "cp extension/settings/test.js extension/settings.js; npm run update-localization; web-ext build -s extension --overwrite-dest --no-config-discovery -n firefox_translations.xpi",
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
import os.path
|
||||
from zipfile import ZipFile
|
||||
import subprocess
|
||||
from subprocess import PIPE, CalledProcessError
|
||||
import shutil
|
||||
import sys
|
||||
import json
|
||||
import glob
|
||||
|
||||
if not os.path.exists("scripts/tests/e2e-tests-esr91.py"):
|
||||
sys.exit("This script is intended to be executed from the root folder.")
|
||||
root = os.getcwd()
|
||||
|
||||
# Remove old gecko
|
||||
subprocess.call("rm -rf mozilla-esr91".split(), cwd=root)
|
||||
# First we build the extension
|
||||
subprocess.call("npm run build-test".split(), cwd=root)
|
||||
# then we clone gecko
|
||||
subprocess.call("git clone hg::https://hg.mozilla.org/mozilla-unified mozilla-esr91".split(), cwd=root)
|
||||
subprocess.call("git checkout bookmarks/esr91".split(), cwd="mozilla-esr91")
|
||||
# create the folder for the extension
|
||||
subprocess.call("rm -rf mozilla-esr91/browser/extensions/translations/extension".split(), cwd=root)
|
||||
# and extract the newly one built there
|
||||
subprocess.call("unzip web-ext-artifacts/firefox_translations.xpi -d mozilla-esr91/browser/extensions/translations/extension/".split(), cwd=root)
|
||||
# copy the tests
|
||||
subprocess.call("mkdir -p mozilla-esr91/browser/extensions/translations/test/browser/".split(), cwd=root)
|
||||
subprocess.call("cp scripts/tests/browser.ini mozilla-esr91/browser/extensions/translations/test/browser/".split(), cwd=root)
|
||||
subprocess.call("cp scripts/tests/browser_translation_test.html mozilla-esr91/browser/extensions/translations/test/browser/".split(), cwd=root)
|
||||
subprocess.call("cp scripts/tests/frame.html mozilla-esr91/browser/extensions/translations/test/browser/".split(), cwd=root)
|
||||
subprocess.call("cp scripts/tests/browser_translation_test.js mozilla-esr91/browser/extensions/translations/test/browser/".split(), cwd=root)
|
||||
subprocess.call("cp -r scripts/tests/esen/ mozilla-esr91/browser/extensions/translations/test/browser/esen/".split(), cwd=root)
|
||||
subprocess.call("cp -r scripts/tests/enes/ mozilla-esr91/browser/extensions/translations/test/browser/enes/".split(), cwd=root)
|
||||
with open('mozilla-esr91/browser/extensions/moz.build', 'a') as fp:
|
||||
fp.write('DIRS += [ \n')
|
||||
fp.write(' "translations", \n')
|
||||
fp.write('] \n')
|
||||
|
||||
# let's copy bergamot-translator's wasm artifacts at right place for tests
|
||||
subprocess.call("cp -r mozilla-esr91/browser/extensions/translations/extension/model/static/translation/ mozilla-esr91/browser/extensions/translations/test/browser/".split(), cwd=root)
|
||||
|
||||
# patching BrowserGlue.jsm to add the extension's version so it could be loaded
|
||||
f = open("extension/manifest.json")
|
||||
data = json.load(f)
|
||||
extension_version = data["version"]
|
||||
f.close()
|
||||
|
||||
f = open("scripts/tests/BrowserGlue.jsm")
|
||||
dataBrowserGlue = f.read()
|
||||
dataBrowserGlue = dataBrowserGlue.replace("{version}", '"{version}"'.format(version=extension_version))
|
||||
dataBrowserGlue = dataBrowserGlue.replace("_monitorTranslationsPref", "_monitorTranslationsPrefAddon")
|
||||
dataBrowserGlue = dataBrowserGlue.replace("lazy.AddonManager", "AddonManager")
|
||||
f.close()
|
||||
|
||||
fp = open("mozilla-esr91/browser/components/BrowserGlue.jsm")
|
||||
Lines = fp.readlines()
|
||||
fp.close()
|
||||
count = 0
|
||||
with open('mozilla-esr91/browser/components/BrowserGlue.jsm', 'w') as fp:
|
||||
for line in Lines:
|
||||
if len(Lines) > count + 1 and "_monitorWebcompatReporterPref() {" in Lines[count + 1]:
|
||||
fp.write(dataBrowserGlue + "\n")
|
||||
elif "this._monitorWebcompatReporterPref();" in line:
|
||||
fp.write(line)
|
||||
fp.write(" this._monitorTranslationsPrefAddon(); \n")
|
||||
else:
|
||||
fp.write(line)
|
||||
count += 1
|
||||
|
||||
# enable our test
|
||||
with open('mozilla-esr91/mozconfig', 'w') as f:
|
||||
print('ac_add_options --enable-artifact-builds', file=f)
|
||||
|
||||
with open('mozilla-esr91/browser/extensions/translations/moz.build', 'a') as f:
|
||||
print('BROWSER_CHROME_MANIFESTS += [\"test/browser/browser.ini\"]', file=f)
|
||||
|
||||
|
||||
print("****** Test with fallback gemm ******")
|
||||
|
||||
try:
|
||||
print("Building mozilla-esr91")
|
||||
subprocess.check_output("./mach build", stderr=subprocess.STDOUT, shell=True, universal_newlines=True, cwd="mozilla-esr91")
|
||||
print("Running test with fallback gemm")
|
||||
subprocess.check_output("./mach test --setpref=fxtranslations.running.mochitest=true browser/extensions/translations/test/browser/browser_translation_test.js", stderr=subprocess.STDOUT, shell=True, universal_newlines=True, cwd="mozilla-esr91")
|
||||
print("Test with fallback gemm Succeeded")
|
||||
except CalledProcessError as cpe:
|
||||
print(cpe.output)
|
||||
sys.exit("Tests with fallback gemm failed")
|
|
@ -16,7 +16,7 @@ subprocess.call("rm -rf gecko".split(), cwd=root)
|
|||
subprocess.call("npm run build-test".split(), cwd=root)
|
||||
# then we clone gecko
|
||||
subprocess.call("git clone hg::https://hg.mozilla.org/mozilla-central gecko".split(), cwd=root)
|
||||
# We then remove the old extension
|
||||
# create the folder for the extension
|
||||
subprocess.call("mkdir -p gecko/browser/extensions/translations/extension".split(), cwd=root)
|
||||
# and extract the newly one built there
|
||||
subprocess.call("unzip web-ext-artifacts/firefox_translations.xpi -d gecko/browser/extensions/translations/extension/".split(), cwd=root)
|
||||
|
|
Загрузка…
Ссылка в новой задаче