Revision b75a5717
Added by koszko over 1 year ago
test/unit/test_repo_query_cacher.py | ||
---|---|---|
22 | 22 |
from selenium.webdriver.support.ui import WebDriverWait |
23 | 23 |
|
24 | 24 |
from ..script_loader import load_script |
25 |
from .utils import * |
|
26 | 25 |
|
27 | 26 |
def content_script(): |
28 | 27 |
script = load_script('content/repo_query_cacher.js') |
... | ... | |
39 | 38 |
''', |
40 | 39 |
tab_id, url) |
41 | 40 |
|
41 |
""" |
|
42 |
tab_id_responder is meant to be appended to background script of a test |
|
43 |
extension. |
|
44 |
""" |
|
45 |
tab_id_responder = ''' |
|
46 |
function tell_tab_id(msg, sender, respond_cb) { |
|
47 |
if (msg[0] === "learn_tab_id") |
|
48 |
respond_cb(sender.tab.id); |
|
49 |
} |
|
50 |
browser.runtime.onMessage.addListener(tell_tab_id); |
|
51 |
''' |
|
52 |
|
|
53 |
""" |
|
54 |
tab_id_asker is meant to be appended to content script of a test extension. |
|
55 |
""" |
|
56 |
tab_id_asker = ''' |
|
57 |
browser.runtime.sendMessage(["learn_tab_id"]) |
|
58 |
.then(tid => window.wrappedJSObject.haketilo_tab = tid); |
|
59 |
''' |
|
60 |
|
|
61 |
def run_content_script_in_new_window(driver, url): |
|
62 |
""" |
|
63 |
Expect an extension to be loaded which had tab_id_responder and tab_id_asker |
|
64 |
appended to its background and content scripts, respectively. |
|
65 |
Open the provided url in a new tab, find its tab id and return it, with |
|
66 |
current window changed back to the initial one. |
|
67 |
""" |
|
68 |
initial_handle = driver.current_window_handle |
|
69 |
handles = driver.window_handles |
|
70 |
driver.execute_script('window.open(arguments[0], "_blank");', url) |
|
71 |
WebDriverWait(driver, 10).until(lambda d: d.window_handles is not handles) |
|
72 |
new_handle = [h for h in driver.window_handles if h not in handles][0] |
|
73 |
|
|
74 |
driver.switch_to.window(new_handle) |
|
75 |
|
|
76 |
get_tab_id = lambda d: d.execute_script('return window.haketilo_tab;') |
|
77 |
tab_id = WebDriverWait(driver, 10).until(get_tab_id) |
|
78 |
|
|
79 |
driver.switch_to.window(initial_handle) |
|
80 |
return tab_id |
|
81 |
|
|
42 | 82 |
@pytest.mark.ext_data({ |
43 | 83 |
'content_script': content_script, |
44 | 84 |
'background_script': lambda: bypass_js() + ';' + tab_id_responder |
Also available in: Unified diff
add a repo querying HTML interface