Skip to content

Commit 0ae7c19

Browse files
authored
test: Import some mochitests from firefox, p=#10897
* test: Import some mochitests from firefox, b=no-bug, c=tests, scripts, tabs * feat: Added lint rules to ignore mochi tests, b=no-bug, c=tests * chore: Finish importing tests, b=no-bug, c=workflows, tests, scripts, tabs
1 parent e525b32 commit 0ae7c19

File tree

76 files changed

+6225
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+6225
-3
lines changed

.github/workflows/sync-upstream.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ jobs:
9595
echo "Checking if patches apply cleanly..."
9696
npm run import
9797
98+
- name: Import external tests
99+
if: steps.git-check.outputs.files_changed == 'true'
100+
run: python3 scripts/import_external_tests.py
101+
98102
- name: Create pull request
99103
uses: peter-evans/create-pull-request@v7
100104
if: steps.git-check.outputs.files_changed == 'true'

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ engine/
1717

1818
surfer.json
1919

20+
src/zen/tests/mochitests/*
21+
2022
src/browser/app/profile/*.js
2123
pnpm-lock.yaml
2224

eslint.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import js from '@eslint/js';
66
import globals from 'globals';
7-
import { defineConfig } from 'eslint/config';
7+
import { defineConfig, globalIgnores } from 'eslint/config';
88
import zenGlobals from './src/zen/zen.globals.js';
99

1010
export default defineConfig([
@@ -23,4 +23,5 @@ export default defineConfig([
2323
},
2424
ignores: ['**/vendor/**', '**/tests/**'],
2525
},
26+
globalIgnores(['**/mochitests/**']),
2627
]);

locales/en-US/browser/browser/preferences/zen-preferences.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ category-zen-CKS =
191191
.tooltiptext = { pane-zen-CKS-title }
192192
pane-settings-CKS-title = { -brand-short-name } Keyboard Shortcuts
193193
194+
category-zen-marketplace =
195+
.tooltiptext = Zen Mods
196+
194197
zen-settings-CKS-header = Customize your keyboard shortcuts
195198
zen-settings-CKS-description = Change the default keyboard shortcuts to your liking and improve your browsing experience
196199

scripts/import_external_tests.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
import os
6+
import tomllib
7+
import shutil
8+
9+
BASE_PATH = os.path.join("src", "zen", "tests")
10+
EXTERNAL_TESTS_MANIFEST = os.path.join(BASE_PATH, "manifest.toml")
11+
EXTERNAL_TESTS_OUTPUT = os.path.join(BASE_PATH, "mochitests")
12+
13+
FILE_PREFIX = """
14+
# This Source Code Form is subject to the terms of the Mozilla Public
15+
# License, v. 2.0. If a copy of the MPL was not distributed with this
16+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
17+
18+
# This file is autogenerated by scripts/import_external_tests.py
19+
# Do not edit manually.
20+
21+
BROWSER_CHROME_MANIFESTS += [
22+
"""
23+
24+
FILE_SUFFIX = "]"
25+
26+
27+
def get_tests_manifest():
28+
with open(EXTERNAL_TESTS_MANIFEST, "rb") as f:
29+
return tomllib.load(f)
30+
31+
32+
def die_with_error(message):
33+
print(f"ERROR: {message}")
34+
exit(1)
35+
36+
37+
def validate_tests_path(path, files, ignore_list):
38+
for ignore in ignore_list:
39+
if ignore not in files:
40+
die_with_error(f"Ignore file '{ignore}' not found in tests folder '{path}'")
41+
if "browser.toml" not in files or "browser.js" in ignore_list:
42+
die_with_error(f"'browser.toml' not found in tests folder '{path}'")
43+
44+
45+
def disable_and_replace_manifest(manifest, output_path):
46+
toml_file = os.path.join(output_path, "browser.toml")
47+
disabled_tests = manifest.get("disable", [])
48+
with open(toml_file, "r") as f:
49+
data = f.read()
50+
for test in disabled_tests:
51+
segment = f'["{test}"]'
52+
if segment not in data:
53+
die_with_error(f"Could not disable test '{test}' as it was not found in '{toml_file}'")
54+
replace_with = f'["{test}"]\ndisabled="Disabled by import_external_tests.py"'
55+
data = data.replace(segment, replace_with)
56+
for replacement in manifest.get("replace-manifest", {}).keys():
57+
if replacement not in data:
58+
die_with_error(f"Could not replace manifest entry '{replacement}' as it was not found in '{toml_file}'")
59+
data = data.replace(replacement, manifest["replace-manifest"][replacement])
60+
with open(toml_file, "w") as f:
61+
f.write(data)
62+
63+
64+
def import_test_suite(test_suite, source_path, output_path, ignore_list, manifest, is_direct_path=False):
65+
print(f"Importing test suite '{test_suite}' from '{source_path}'")
66+
tests_folder = os.path.join("engine", source_path)
67+
if not is_direct_path:
68+
tests_folder = os.path.join(tests_folder, "tests")
69+
if not os.path.exists(tests_folder):
70+
die_with_error(f"Tests folder not found: {tests_folder}")
71+
files = os.listdir(tests_folder)
72+
validate_tests_path(tests_folder, files, ignore_list)
73+
if os.path.exists(output_path):
74+
shutil.rmtree(output_path)
75+
os.makedirs(output_path, exist_ok=True)
76+
for item in files:
77+
if item in ignore_list:
78+
continue
79+
s = os.path.join(tests_folder, item)
80+
d = os.path.join(output_path, item)
81+
if os.path.isdir(s):
82+
shutil.copytree(s, d)
83+
else:
84+
shutil.copy2(s, d)
85+
disable_and_replace_manifest(manifest[test_suite], output_path)
86+
87+
88+
def write_moz_build_file(manifest):
89+
moz_build_path = os.path.join(EXTERNAL_TESTS_OUTPUT, "moz.build")
90+
print(f"Writing moz.build file to '{moz_build_path}'")
91+
with open(moz_build_path, "w") as f:
92+
f.write(FILE_PREFIX)
93+
for test_suite in manifest.keys():
94+
f.write(f'\t"{test_suite}/browser.toml",\n')
95+
f.write(FILE_SUFFIX)
96+
97+
98+
def make_sure_ordered_tests(manifest):
99+
ordered_tests = sorted(manifest.keys())
100+
if list(manifest.keys()) != ordered_tests:
101+
die_with_error("Test suites in manifest.toml are not in alphabetical order.")
102+
103+
104+
def main():
105+
manifest = get_tests_manifest()
106+
if os.path.exists(EXTERNAL_TESTS_OUTPUT):
107+
shutil.rmtree(EXTERNAL_TESTS_OUTPUT)
108+
os.makedirs(EXTERNAL_TESTS_OUTPUT, exist_ok=True)
109+
110+
make_sure_ordered_tests(manifest)
111+
for test_suite, config in manifest.items():
112+
import_test_suite(
113+
test_suite=test_suite,
114+
source_path=config["source"],
115+
output_path=os.path.join(EXTERNAL_TESTS_OUTPUT, test_suite),
116+
ignore_list=config.get("ignore", []),
117+
is_direct_path=config.get("is_direct_path", False),
118+
manifest=manifest
119+
)
120+
write_moz_build_file(manifest)
121+
122+
123+
if __name__ == "__main__":
124+
main()

scripts/run_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
'engine', 'testing', 'mochitest', 'ignorePrefs.json'
1616
)
1717

18+
MOCHITEST_NAME = "mochitests"
19+
1820

1921
def copy_ignore_prefs():
2022
print("Copying ignorePrefs.json from src/zen/tests to engine/testing/mochitest...")
@@ -59,7 +61,9 @@ def run_mach_with_paths(test_paths):
5961
os.execvp(command[0], command)
6062

6163
if path in ("", "all"):
62-
test_dirs = [p for p in Path("zen/tests").iterdir() if p.is_dir()]
64+
test_dirs = [p for p in Path("zen/tests").iterdir() if p.is_dir() and p.name != MOCHITEST_NAME]
65+
mochitest_dirs = [p for p in Path(f"zen/tests/{MOCHITEST_NAME}").iterdir() if p.is_dir()]
66+
test_dirs.extend(mochitest_dirs)
6367
test_paths = [str(p) for p in test_dirs]
6468
run_mach_with_paths(test_paths)
6569
else:

src/zen/tests/ignorePrefs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
"zen.mods.last-update",
1111
"zen.view.compact.enable-at-startup",
1212
"zen.urlbar.suggestions-learner",
13-
"browser.newtabpage.activity-stream.trendingSearch.defaultSearchEngine"
13+
"browser.newtabpage.activity-stream.trendingSearch.defaultSearchEngine",
14+
15+
// From the imported safebrowsing tests
16+
"urlclassifier.phishTable",
17+
"urlclassifier.malwareTable"
1418
]

src/zen/tests/manifest.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
[reportbrokensite]
7+
source = "browser/components/reportbrokensite/test/browser"
8+
is_direct_path = true
9+
disable = [
10+
"browser_addon_data_sent.js"
11+
]
12+
13+
[reportbrokensite.replace-manifest]
14+
"../../../../../" = "../../../../"
15+
16+
[safebrowsing]
17+
source = "browser/components/safebrowsing/content/test"
18+
is_direct_path = true
19+
20+
[shell]
21+
source = "browser/components/shell/test"
22+
is_direct_path = true
23+
disable = [
24+
"browser_1119088.js",
25+
"browser_setDesktopBackgroundPreview.js",
26+
]
27+
28+
[tooltiptext]
29+
source = "toolkit/components/tooltiptext"
30+

src/zen/tests/mochitests/moz.build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
# This file is autogenerated by scripts/import_external_tests.py
7+
# Do not edit manually.
8+
9+
BROWSER_CHROME_MANIFESTS += [
10+
"reportbrokensite/browser.toml",
11+
"safebrowsing/browser.toml",
12+
"shell/browser.toml",
13+
"tooltiptext/browser.toml",
14+
]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[DEFAULT]
2+
tags = "report-broken-site"
3+
support-files = [
4+
"example_report_page.html",
5+
"head.js",
6+
"sendMoreInfoTestEndpoint.html",
7+
]
8+
9+
["browser_addon_data_sent.js"]
10+
disabled="Disabled by import_external_tests.py"
11+
support-files = [ "send_more_info.js" ]
12+
skip-if = ["os == 'win' && os_version == '11.26100' && processor == 'x86_64' && opt"] # Bug 1955805
13+
14+
["browser_antitracking_data_sent.js"]
15+
support-files = [ "send_more_info.js" ]
16+
17+
["browser_back_buttons.js"]
18+
19+
["browser_error_messages.js"]
20+
21+
["browser_experiment_data_sent.js"]
22+
support-files = [ "send_more_info.js" ]
23+
24+
["browser_keyboard_navigation.js"]
25+
skip-if = [
26+
"os == 'linux' && os_version == '24.04' && processor == 'x86_64' && tsan", # Bug 1867132
27+
"os == 'linux' && os_version == '24.04' && processor == 'x86_64' && asan", # Bug 1867132
28+
"os == 'linux' && os_version == '24.04' && processor == 'x86_64' && debug", # Bug 1867132
29+
"os == 'win' && os_version == '11.26100' && processor == 'x86_64' && asan", # Bug 1867132
30+
]
31+
32+
["browser_learn_more_link.js"]
33+
34+
["browser_parent_menuitems.js"]
35+
36+
["browser_prefers_contrast.js"]
37+
38+
["browser_reason_dropdown.js"]
39+
40+
["browser_report_send.js"]
41+
support-files = [ "send.js" ]
42+
43+
["browser_send_more_info.js"]
44+
support-files = [
45+
"send_more_info.js",
46+
"../../../../toolkit/components/gfx/content/videotest.mp4",
47+
]
48+
49+
["browser_tab_key_order.js"]
50+
51+
["browser_tab_switch_handling.js"]
52+
53+
["browser_webcompat.com_fallback.js"]
54+
support-files = [
55+
"send_more_info.js",
56+
"../../../../toolkit/components/gfx/content/videotest.mp4",
57+
]

0 commit comments

Comments
 (0)