summaryrefslogtreecommitdiff
path: root/test/unit/test_repo_query_cacher.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/test_repo_query_cacher.py')
-rw-r--r--test/unit/test_repo_query_cacher.py33
1 files changed, 4 insertions, 29 deletions
diff --git a/test/unit/test_repo_query_cacher.py b/test/unit/test_repo_query_cacher.py
index d5c7396..ee9f0fd 100644
--- a/test/unit/test_repo_query_cacher.py
+++ b/test/unit/test_repo_query_cacher.py
@@ -22,40 +22,15 @@ import json
from selenium.webdriver.support.ui import WebDriverWait
from ..script_loader import load_script
-
-tab_id_responder = '''
-function tell_tab_id(msg, sender, respond_cb) {
- if (msg[0] === "learn_tab_id")
- respond_cb(sender.tab.id);
-}
-browser.runtime.onMessage.addListener(tell_tab_id);
-'''
+from .utils import *
def content_script():
- return load_script('content/repo_query_cacher.js') + ''';
- start();
- browser.runtime.sendMessage(["learn_tab_id"])
- .then(tid => window.wrappedJSObject.haketilo_tab = tid);
- '''
+ script = load_script('content/repo_query_cacher.js')
+ return f'{script}; {tab_id_asker}; start();'
def bypass_js():
return load_script('background/CORS_bypass_server.js') + '; start();'
-def run_content_script_in_new_window(driver, url):
- initial_handle = driver.current_window_handle
- handles = driver.window_handles
- driver.execute_script('window.open(arguments[0], "_blank");', url)
- WebDriverWait(driver, 10).until(lambda d: d.window_handles is not handles)
- new_handle = [h for h in driver.window_handles if h not in handles][0]
-
- driver.switch_to.window(new_handle)
-
- get_tab_id = lambda d: d.execute_script('return window.haketilo_tab;')
- tab_id = WebDriverWait(driver, 10).until(get_tab_id)
-
- driver.switch_to.window(initial_handle)
- return tab_id
-
def fetch_through_cache(driver, tab_id, url):
return driver.execute_script(
'''
@@ -90,7 +65,7 @@ def test_repo_query_cacher_normal_use(driver, execute_in_page):
for i in range(2):
result = fetch_through_cache(driver, tab_id, 'https://nxdoma.in/')
- assert set(result.keys()) == {'ok', 'status', 'error-json'}
+ assert set(result.keys()) == {'ok', 'status', 'error_json'}
assert result['ok'] == False
assert result['status'] == 404