Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ engine/

surfer.json

src/zen/tests/mochitests/*

src/browser/app/profile/*.js
pnpm-lock.yaml

Expand Down
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import js from '@eslint/js';
import globals from 'globals';
import { defineConfig } from 'eslint/config';
import { defineConfig, globalIgnores } from 'eslint/config';
import zenGlobals from './src/zen/zen.globals.js';

export default defineConfig([
Expand All @@ -23,4 +23,5 @@ export default defineConfig([
},
ignores: ['**/vendor/**', '**/tests/**'],
},
globalIgnores(['**/mochitests/**']),
]);
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ category-zen-CKS =
.tooltiptext = { pane-zen-CKS-title }
pane-settings-CKS-title = { -brand-short-name } Keyboard Shortcuts

category-zen-marketplace =
.tooltiptext = Zen Mods

zen-settings-CKS-header = Customize your keyboard shortcuts
zen-settings-CKS-description = Change the default keyboard shortcuts to your liking and improve your browsing experience

Expand Down
115 changes: 115 additions & 0 deletions scripts/import_external_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import tomllib
import shutil

BASE_PATH = os.path.join("src", "zen", "tests")
EXTERNAL_TESTS_MANIFEST = os.path.join(BASE_PATH, "manifest.toml")
EXTERNAL_TESTS_OUTPUT = os.path.join(BASE_PATH, "mochitests")

FILE_PREFIX = """
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This file is autogenerated by scripts/import_external_tests.py
# Do not edit manually.

BROWSER_CHROME_MANIFESTS += [
"""

FILE_SUFFIX = "]"

def get_tests_manifest():
with open(EXTERNAL_TESTS_MANIFEST, "rb") as f:
return tomllib.load(f)

def die_with_error(message):
print(f"ERROR: {message}")
exit(1)

def validate_tests_path(path, files, ignore_list):
for ignore in ignore_list:
if ignore not in files:
die_with_error(f"Ignore file '{ignore}' not found in tests folder '{path}'")
if "browser.toml" not in files or "browser.js" in ignore_list:
die_with_error(f"'browser.toml' not found in tests folder '{path}'")

def disable_and_replace_manifest(manifest, output_path):
toml_file = os.path.join(output_path, "browser.toml")
disabled_tests = manifest.get("disable", [])
with open(toml_file, "r") as f:
data = f.read()
for test in disabled_tests:
segment = f'["{test}"]'
if segment not in data:
die_with_error(f"Could not disable test '{test}' as it was not found in '{toml_file}'")
replace_with = f'["{test}"]\ndisabled="Disabled by import_external_tests.py"'
data = data.replace(segment, replace_with)
for replacement in manifest.get("replace-manifest", {}).keys():
if replacement not in data:
die_with_error(f"Could not replace manifest entry '{replacement}' as it was not found in '{toml_file}'")
data = data.replace(replacement, manifest["replace-manifest"][replacement])
with open(toml_file, "w") as f:
f.write(data)

def import_test_suite(test_suite, source_path, output_path, ignore_list, manifest, is_direct_path=False):
print(f"Importing test suite '{test_suite}' from '{source_path}'")
tests_folder = os.path.join("engine", source_path)
if not is_direct_path:
tests_folder = os.path.join(tests_folder, "tests")
if not os.path.exists(tests_folder):
die_with_error(f"Tests folder not found: {tests_folder}")
files = os.listdir(tests_folder)
validate_tests_path(tests_folder, files, ignore_list)
if os.path.exists(output_path):
shutil.rmtree(output_path)
os.makedirs(output_path, exist_ok=True)
for item in files:
if item in ignore_list:
continue
s = os.path.join(tests_folder, item)
d = os.path.join(output_path, item)
if os.path.isdir(s):
shutil.copytree(s, d)
else:
shutil.copy2(s, d)
disable_and_replace_manifest(manifest[test_suite], output_path)

def write_moz_build_file(manifest):
moz_build_path = os.path.join(EXTERNAL_TESTS_OUTPUT, "moz.build")
print(f"Writing moz.build file to '{moz_build_path}'")
with open(moz_build_path, "w") as f:
f.write(FILE_PREFIX)
for test_suite in manifest.keys():
f.write(f'\t"{test_suite}/browser.toml",\n')
f.write(FILE_SUFFIX)

def make_sure_ordered_tests(manifest):
ordered_tests = sorted(manifest.keys())
if list(manifest.keys()) != ordered_tests:
die_with_error("Test suites in manifest.toml are not in alphabetical order.")

def main():
manifest = get_tests_manifest()
if os.path.exists(EXTERNAL_TESTS_OUTPUT):
shutil.rmtree(EXTERNAL_TESTS_OUTPUT)
os.makedirs(EXTERNAL_TESTS_OUTPUT, exist_ok=True)

make_sure_ordered_tests(manifest)
for test_suite, config in manifest.items():
import_test_suite(
test_suite=test_suite,
source_path=config["source"],
output_path=os.path.join(EXTERNAL_TESTS_OUTPUT, test_suite),
ignore_list=config.get("ignore", []),
is_direct_path=config.get("is_direct_path", False),
manifest=manifest
)
write_moz_build_file(manifest)

if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'engine', 'testing', 'mochitest', 'ignorePrefs.json'
)

MOCHITEST_NAME = "mochitests"

class JSONWithCommentsDecoder(json.JSONDecoder):
def __init__(self, **kw):
Expand Down Expand Up @@ -68,7 +69,9 @@ def run_mach_with_paths(test_paths):
os.execvp(command[0], command)

if path in ("", "all"):
test_dirs = [p for p in Path("zen/tests").iterdir() if p.is_dir()]
test_dirs = [p for p in Path("zen/tests").iterdir() if p.is_dir() and p.name != MOCHITEST_NAME]
mochitest_dirs = [p for p in Path(f"zen/tests/{MOCHITEST_NAME}").iterdir() if p.is_dir()]
test_dirs.extend(mochitest_dirs)
test_paths = [str(p) for p in test_dirs]
run_mach_with_paths(test_paths)
else:
Expand Down
29 changes: 29 additions & 0 deletions src/zen/tests/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

[reportbrokensite]
source = "browser/components/reportbrokensite/test/browser"
is_direct_path = true
disable = [
"browser_addon_data_sent.js"
]

[reportbrokensite.replace-manifest]
"../../../../../" = "../../../../"

[safebrowsing]
source = "browser/components/safebrowsing/content/test"
is_direct_path = true

[shell]
source = "browser/components/shell/test"
is_direct_path = true

[tooltiptext]
source = "toolkit/components/tooltiptext"

[translations]
source = "browser/components/translations/tests/browser"
is_direct_path = true
15 changes: 15 additions & 0 deletions src/zen/tests/mochitests/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This file is autogenerated by scripts/import_external_tests.py
# Do not edit manually.

BROWSER_CHROME_MANIFESTS += [
"reportbrokensite/browser.toml",
"safebrowsing/browser.toml",
"shell/browser.toml",
"tooltiptext/browser.toml",
"translations/browser.toml",
]
50 changes: 50 additions & 0 deletions src/zen/tests/mochitests/reportbrokensite/browser.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[DEFAULT]
tags = "report-broken-site"
support-files = [
"example_report_page.html",
"head.js",
"sendMoreInfoTestEndpoint.html",
]

["browser_addon_data_sent.js"]
disabled="Disabled by import_external_tests.py"
support-files = [ "send_more_info.js" ]
skip-if = ["os == 'win' && os_version == '11.26100' && processor == 'x86_64' && opt"] # Bug 1955805

["browser_antitracking_data_sent.js"]
support-files = [ "send_more_info.js" ]

["browser_back_buttons.js"]

["browser_error_messages.js"]

["browser_experiment_data_sent.js"]
support-files = [ "send_more_info.js" ]

["browser_keyboard_navigation.js"]
skip-if = ["os == 'linux' && os_version == '24.04' && processor == 'x86_64' && tsan"] # Bug 1867132

["browser_parent_menuitems.js"]

["browser_prefers_contrast.js"]

["browser_reason_dropdown.js"]

["browser_report_send.js"]
support-files = [ "send.js" ]

["browser_send_more_info.js"]
support-files = [
"send_more_info.js",
"../../../../toolkit/components/gfx/content/videotest.mp4",
]

["browser_tab_key_order.js"]

["browser_tab_switch_handling.js"]

["browser_webcompat.com_fallback.js"]
support-files = [
"send_more_info.js",
"../../../../toolkit/components/gfx/content/videotest.mp4",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

/* Tests to ensure that the right data is sent for
* private windows and when ETP blocks content.
*/

/* import-globals-from send.js */
/* import-globals-from send_more_info.js */

"use strict";

const { AddonTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/AddonTestUtils.sys.mjs"
);
AddonTestUtils.initMochitest(this);

Services.scriptloader.loadSubScript(
getRootDirectory(gTestPath) + "send_more_info.js",
this
);

add_common_setup();

const TEMP_ID = "[email protected]";
const TEMP_NAME = "Temporary Addon";
const TEMP_VERSION = "0.1.0";

const PERM_ID = "[email protected]";
const PERM_NAME = "Permanent Addon";
const PERM_VERSION = "0.2.0";

const DISABLED_ID = "[email protected]";
const DISABLED_NAME = "Disabled Addon";
const DISABLED_VERSION = "0.3.0";

const EXPECTED_ADDONS = [
{ id: PERM_ID, name: PERM_NAME, temporary: false, version: PERM_VERSION },
{ id: TEMP_ID, name: TEMP_NAME, temporary: true, version: TEMP_VERSION },
];

function loadAddon(id, name, version, isTemp = false) {
return ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: { gecko: { id } },
name,
version,
},
useAddonManager: isTemp ? "temporary" : "permanent",
});
}

async function installAddons() {
const temp = await loadAddon(TEMP_ID, TEMP_NAME, TEMP_VERSION, true);
await temp.startup();

const perm = await loadAddon(PERM_ID, PERM_NAME, PERM_VERSION);
await perm.startup();

const dis = await loadAddon(DISABLED_ID, DISABLED_NAME, DISABLED_VERSION);
await dis.startup();
await (await AddonManager.getAddonByID(DISABLED_ID)).disable();

return async () => {
await temp.unload();
await perm.unload();
await dis.unload();
};
}

add_task(async function testSendButton() {
ensureReportBrokenSitePreffedOn();
ensureReasonOptional();
const addonCleanup = await installAddons();

const tab = await openTab(REPORTABLE_PAGE_URL);

await testSend(tab, AppMenu(), {
addons: EXPECTED_ADDONS,
});

closeTab(tab);
await addonCleanup();
});

add_task(async function testSendingMoreInfo() {
ensureReportBrokenSitePreffedOn();
ensureSendMoreInfoEnabled();
const addonCleanup = await installAddons();

const tab = await openTab(REPORTABLE_PAGE_URL);

await testSendMoreInfo(tab, HelpMenu(), {
addons: EXPECTED_ADDONS,
});

closeTab(tab);
await addonCleanup();
});
Loading