114 lines
4.0 KiB
Python
114 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercises the default build, which has no "tabs" permission.
|
|
|
|
The main driver adds "tabs" so it can identify tabs by URL. This one builds
|
|
without it and identifies tabs by id, which is the shipped configuration.
|
|
|
|
Run with: DISPLAY=:99 python3 test/harness/no-tabs.py
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import threading
|
|
import time
|
|
from http.server import ThreadingHTTPServer
|
|
|
|
from driver import (BASE, BUILD, CHECKS, PORT, Handler, build, check, hook,
|
|
launch, state, wait_uuid)
|
|
|
|
|
|
def active_id(driver):
|
|
return next(tab['id'] for tab in state(driver) if tab['active'])
|
|
|
|
|
|
def by_id(tabs, tab_id):
|
|
return next(tab for tab in tabs if tab['id'] == tab_id)
|
|
|
|
|
|
def main():
|
|
os.environ['TU_NO_TABS'] = '1'
|
|
build()
|
|
|
|
server = ThreadingHTTPServer(('127.0.0.1', PORT), Handler)
|
|
threading.Thread(target=server.serve_forever, daemon=True).start()
|
|
|
|
driver = launch()
|
|
handles = {}
|
|
ids = {}
|
|
try:
|
|
addon_id = driver.install_addon(str(BUILD), temporary=True)
|
|
wait_uuid(driver, addon_id)
|
|
print(f'installed {addon_id} without the tabs permission', flush=True)
|
|
|
|
driver.get(BASE + '/p1')
|
|
handles['/p1'] = driver.current_window_handle
|
|
ids['/p1'] = active_id(driver)
|
|
for i in (2, 3):
|
|
driver.switch_to.new_window('tab')
|
|
driver.get(BASE + f'/p{i}')
|
|
handles[f'/p{i}'] = driver.current_window_handle
|
|
ids[f'/p{i}'] = active_id(driver)
|
|
time.sleep(0.5)
|
|
|
|
tabs = state(driver)
|
|
check('three tabs open without the tabs permission', len(tabs) == 3, str(len(tabs)))
|
|
|
|
hook(driver, 'pin', tabId=ids['/p1'])
|
|
hook(driver, 'activate', tabId=ids['/p2'])
|
|
time.sleep(0.3)
|
|
# switch_to activates p1, so re-activate p2 before the bulk unload
|
|
driver.switch_to.window(handles['/p1'])
|
|
hook(driver, 'activate', tabId=ids['/p2'])
|
|
time.sleep(0.3)
|
|
|
|
count = hook(driver, 'unload-others', tabId=ids['/p2'])
|
|
time.sleep(0.5)
|
|
tabs = state(driver)
|
|
check('unload-others reports one tab', count == 1, f'count={count}')
|
|
check('unload-others keeps the tab count', len(tabs) == 3, f'{len(tabs)} tabs')
|
|
check('the pinned tab survives', not by_id(tabs, ids['/p1'])['discarded'])
|
|
check('the kept tab survives', not by_id(tabs, ids['/p2'])['discarded'])
|
|
check('p3 is discarded', by_id(tabs, ids['/p3'])['discarded'])
|
|
|
|
hook(driver, 'activate', tabId=ids['/p3'])
|
|
time.sleep(0.8)
|
|
hook(driver, 'unload-current')
|
|
time.sleep(0.5)
|
|
tabs = state(driver)
|
|
check('unload-current discards the tab it left', by_id(tabs, ids['/p3'])['discarded'])
|
|
active = next(tab for tab in tabs if tab['active'])
|
|
check('unload-current lands on a loaded tab', not active['discarded'])
|
|
|
|
hook(driver, 'protect', tabId=ids['/p2'], value=True)
|
|
hook(driver, 'unload-others', tabId=ids['/p1'])
|
|
time.sleep(0.4)
|
|
tabs = state(driver)
|
|
check('unload-others skips the protected tab', not by_id(tabs, ids['/p2'])['discarded'])
|
|
|
|
hook(driver, 'protect', tabId=ids['/p2'], value=False)
|
|
hook(driver, 'unload-others', tabId=ids['/p1'])
|
|
time.sleep(0.4)
|
|
tabs = state(driver)
|
|
check('unload-others discards it once unprotected', by_id(tabs, ids['/p2'])['discarded'])
|
|
|
|
parked = hook(driver, 'park')
|
|
check('the parking tab is created', bool(parked and parked.get('id')))
|
|
hook(driver, 'activate', tabId=parked['id'])
|
|
time.sleep(0.3)
|
|
result = hook(driver, 'unload-current')
|
|
check('unload-current refuses the parking tab', result is False, str(result))
|
|
finally:
|
|
driver.quit()
|
|
server.shutdown()
|
|
|
|
failed = [name for name, ok in CHECKS if not ok]
|
|
print(f'\n{len(CHECKS) - len(failed)}/{len(CHECKS)} checks passed', flush=True)
|
|
if failed:
|
|
print('failed: ' + ', '.join(failed), flush=True)
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|