aboutsummaryrefslogtreecommitdiff
path: root/test/extension_crafting.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/extension_crafting.py')
-rw-r--r--test/extension_crafting.py49
1 files changed, 46 insertions, 3 deletions
diff --git a/test/extension_crafting.py b/test/extension_crafting.py
index bf54691..680c45e 100644
--- a/test/extension_crafting.py
+++ b/test/extension_crafting.py
@@ -6,7 +6,7 @@ Making temporary WebExtensions for use in the test suite
# This file is part of Haketilo.
#
-# Copyright (C) 2021 Wojtek Kosior <koszko@koszko.org>
+# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,11 +27,16 @@ Making temporary WebExtensions for use in the test suite
import json
import zipfile
+import re
+import shutil
+import subprocess
+
from pathlib import Path
from uuid import uuid4
from tempfile import TemporaryDirectory
-import shutil
-import subprocess
+
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.common.exceptions import NoSuchElementException
from .misc_constants import *
@@ -170,3 +175,41 @@ def make_extension(destination_dir,
html.add_to_xpi(xpi)
return destination_path
+
+extract_base_url_re = re.compile(r'^(.*)manifest.json$')
+
+def get_extension_base_url(driver):
+ """
+ Extension's internall UUID is not directly exposed in Selenium. Instead, we
+ can navigate to about:debugging and inspect the manifest URL present there
+ to get the base url like:
+ moz-extension://b225c78f-d108-4caa-8406-f38b37d8dee5/
+ which can then be used to navigate to extension-bundled pages.
+ """
+ # For newer Firefoxes
+ driver.get('about:debugging#/runtime/this-firefox')
+
+ def get_manifest_link_newer_ff(driver):
+ try:
+ return driver.find_element_by_class_name('qa-manifest-url')
+ except NoSuchElementException:
+ pass
+
+ try:
+ details = driver.find_element_by_class_name('error-page-details')
+ except NoSuchElementException:
+ return False
+
+ if '#/runtime/this-firefox' in details.text:
+ return "not_newer_ff"
+
+ manifest_link = WebDriverWait(driver, 10).until(get_manifest_link_newer_ff)
+
+ if manifest_link == "not_newer_ff":
+ driver.get("about:debugging#addons")
+ driver.implicitly_wait(10)
+ manifest_link = driver.find_element_by_class_name('manifest-url')
+ driver.implicitly_wait(0)
+
+ manifest_url = manifest_link.get_attribute('href')
+ return extract_base_url_re.match(manifest_url).group(1)