summaryrefslogtreecommitdiff
path: root/test/unit/test_broadcast.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/test_broadcast.py')
-rw-r--r--test/unit/test_broadcast.py54
1 files changed, 25 insertions, 29 deletions
diff --git a/test/unit/test_broadcast.py b/test/unit/test_broadcast.py
index 11a61b0..1213b17 100644
--- a/test/unit/test_broadcast.py
+++ b/test/unit/test_broadcast.py
@@ -21,12 +21,9 @@ import pytest
from ..script_loader import load_script
-def broker_js():
- js = load_script('background/broadcast_broker.js', ['common', 'background'])
- return js + ';start_broadcast_broker();'
+broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-def broadcast_js():
- return load_script('common/broadcast.js', ['common'])
+broadcast_js = lambda: load_script('common/broadcast.js')
test_page_html = '''
<!DOCTYPE html>
@@ -53,7 +50,6 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
API and implemented in `background/broadcast_broker.js` and
`common/broadcast.js` works correctly.
"""
-
# The broadcast facility is meant to enable message distribution between
# multiple contexts (e.g. different tabs/windows). Let's open the same
# extension's test page in a second window.
@@ -71,15 +67,15 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
'''
const divs = [0, 1, 2].map(n => document.getElementById("d" + n));
let appender = n => (t => divs[n].append("\\n" + `[${t[0]}, ${t[1]}]`));
- let listener0 = broadcast.listener_connection(appender(0));
- broadcast.subscribe(listener0, "somebodyoncetoldme");
+ let listener0 = listener_connection(appender(0));
+ subscribe(listener0, "somebodyoncetoldme");
''')
driver.switch_to.window(windows[1])
execute_in_page(
'''
- let sender0 = broadcast.sender_connection();
- broadcast.out(sender0, "somebodyoncetoldme", "iaintthesharpesttool");
+ let sender0 = sender_connection();
+ out(sender0, "somebodyoncetoldme", "iaintthesharpesttool");
''')
driver.switch_to.window(windows[0])
@@ -89,11 +85,11 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
driver.switch_to.window(windows[0])
execute_in_page(
'''
- let listener1 = broadcast.listener_connection(appender(1));
- broadcast.subscribe(listener1, "worldisgonnarollme");
- let listener2 = broadcast.listener_connection(appender(2));
- broadcast.subscribe(listener2, "worldisgonnarollme");
- broadcast.subscribe(listener2, "somebodyoncetoldme");
+ let listener1 = listener_connection(appender(1));
+ subscribe(listener1, "worldisgonnarollme");
+ let listener2 = listener_connection(appender(2));
+ subscribe(listener2, "worldisgonnarollme");
+ subscribe(listener2, "somebodyoncetoldme");
''')
# Let's send one message to one channel and one to the other. Verify they
@@ -101,8 +97,8 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
driver.switch_to.window(windows[1])
execute_in_page(
'''
- broadcast.out(sender0, "somebodyoncetoldme", "intheshed");
- broadcast.out(sender0, "worldisgonnarollme", "shewaslooking");
+ out(sender0, "somebodyoncetoldme", "intheshed");
+ out(sender0, "worldisgonnarollme", "shewaslooking");
''')
driver.switch_to.window(windows[0])
@@ -121,9 +117,9 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
driver.switch_to.window(windows[2])
execute_in_page(
'''
- let sender1 = broadcast.sender_connection();
- broadcast.prepare(sender1, "somebodyoncetoldme", "kindadumb");
- broadcast.out(sender1, "worldisgonnarollme", "withherfinger");
+ let sender1 = sender_connection();
+ prepare(sender1, "somebodyoncetoldme", "kindadumb");
+ out(sender1, "worldisgonnarollme", "withherfinger");
''')
driver.switch_to.window(windows[0])
@@ -132,7 +128,7 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
assert 'kindadumb' not in text
driver.switch_to.window(windows[2])
- execute_in_page('broadcast.flush(sender1);')
+ execute_in_page('flush(sender1);')
driver.switch_to.window(windows[0])
wait_elem_text('d0', 'kindadumb')
@@ -142,10 +138,10 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
driver.switch_to.window(windows[2])
execute_in_page(
'''
- broadcast.prepare(sender1, "somebodyoncetoldme", "andherthumb");
- broadcast.discard(sender1);
- broadcast.prepare(sender1, "somebodyoncetoldme", "andhermiddlefinger");
- broadcast.flush(sender1);
+ prepare(sender1, "somebodyoncetoldme", "andherthumb");
+ discard(sender1);
+ prepare(sender1, "somebodyoncetoldme", "andhermiddlefinger");
+ flush(sender1);
''')
driver.switch_to.window(windows[0])
@@ -158,7 +154,7 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
driver.switch_to.window(windows[2])
execute_in_page(
'''
- broadcast.prepare(sender1, "worldisgonnarollme", "intheshape", 500);
+ prepare(sender1, "worldisgonnarollme", "intheshape", 500);
''')
driver.close()
@@ -166,11 +162,11 @@ def test_broadcast(driver, execute_in_page, wait_elem_text):
wait_elem_text('d2', 'intheshape')
# Verify listener's connection gets closed properly.
- execute_in_page('broadcast.close(listener0); broadcast.close(listener1);')
+ execute_in_page('close(listener0); close(listener1);')
driver.switch_to.window(windows[1])
- execute_in_page('broadcast.out(sender0, "worldisgonnarollme", "ofanL");')
- execute_in_page('broadcast.out(sender0, "somebodyoncetoldme", "forehead");')
+ execute_in_page('out(sender0, "worldisgonnarollme", "ofanL");')
+ execute_in_page('out(sender0, "somebodyoncetoldme", "forehead");')
driver.switch_to.window(windows[0])
wait_elem_text('d2', 'ofanL')