Project

General

Profile

« Previous | Next » 

Revision 7218849a

Added by koszko over 1 year ago

add a mapping/resources installation dialog

View differences:

test/unit/utils.py
26 26
# proprietary program, I am not going to enforce this in court.
27 27

  
28 28
from hashlib import sha256
29
from selenium.webdriver.support.ui import WebDriverWait
29 30

  
30 31
from ..script_loader import load_script
31 32

  
......
200 201
            return document.haketilo_scripts_allowed;
201 202
            ''',
202 203
            nonce)
204

  
205
"""
206
tab_id_responder is meant to be appended to background script of a test
207
extension.
208
"""
209
tab_id_responder = '''
210
function tell_tab_id(msg, sender, respond_cb) {
211
    if (msg[0] === "learn_tab_id")
212
        respond_cb(sender.tab.id);
213
}
214
browser.runtime.onMessage.addListener(tell_tab_id);
215
'''
216

  
217
"""
218
tab_id_asker is meant to be appended to content script of a test extension.
219
"""
220
tab_id_asker = '''
221
browser.runtime.sendMessage(["learn_tab_id"])
222
    .then(tid => window.wrappedJSObject.haketilo_tab = tid);
223
'''
224

  
225
def run_content_script_in_new_window(driver, url):
226
    """
227
    Expect an extension to be loaded which had tab_id_responder and tab_id_asker
228
    appended to its background and content scripts, respectively.
229
    Open the provided url in a new tab, find its tab id and return it, with
230
    current window changed back to the initial one.
231
    """
232
    initial_handle = driver.current_window_handle
233
    handles = driver.window_handles
234
    driver.execute_script('window.open(arguments[0], "_blank");', url)
235
    WebDriverWait(driver, 10).until(lambda d: d.window_handles is not handles)
236
    new_handle = [h for h in driver.window_handles if h not in handles][0]
237

  
238
    driver.switch_to.window(new_handle)
239

  
240
    get_tab_id = lambda d: d.execute_script('return window.haketilo_tab;')
241
    tab_id = WebDriverWait(driver, 10).until(get_tab_id)
242

  
243
    driver.switch_to.window(initial_handle)
244
    return tab_id

Also available in: Unified diff