def test_fuzz(tmp_path, browser): # TODO ugh. this still results in 'tab permissions' pages, but perhaps because of closed tabs? # dunno if it's worth fixing.. urls = { 'https://www.iana.org/domains/reserved': 'IANA', 'iana.org/domains/reserved': 'IANA2', } with _test_helper(tmp_path, index_urls(urls), 'https://example.com', browser=browser) as helper: driver = helper.driver tabs = 30 for _ in range(tabs): driver.find_element(By.TAG_NAME, 'a').send_keys(Keys.CONTROL + Keys.RETURN) sleep(5) for _ in range(tabs - 2): driver.close() sleep(0.1) driver.switch_to.window(driver.window_handles[0]) def cb(): for _ in range(10): send_key('Ctrl+Shift+t') sleep(0.1) trigger_callback(driver, cb) # FIXME shows quite a bunch of notifications here... confirm( "shouldn't result in 'unexpected error occured'; show only show single notification per page" )
def test_duplicate_background_pages(tmp_path, browser): url = PYTHON_DOC_URL with _test_helper(tmp_path, index_urls({'whatever.coom': '123'}), url, browser=browser) as helper: driver = helper.driver trigger_command(driver, Command.ACTIVATE) # TODO separate test just for buttons from extension confirm('sidebar opened?') trigger_sidebar_search(driver) sleep(1) driver.switch_to.window(driver.window_handles[0]) sleep(1) trigger_sidebar_search(driver) sleep(1) driver.switch_to.window(driver.window_handles[0]) sleep(1) confirm('only two search pages should be opened') trigger_command(driver, Command.ACTIVATE) confirm('sidebar should be closed now')
def test_sidebar(tmp_path, browser, url: str) -> None: visited = { url: 'whatever', } indexer = index_urls(visited, source_name='ælso test unicode 💩') with _test_helper(tmp_path, indexer, url, show_dots=True, browser=browser) as helper: trigger_command(helper.driver, Command.ACTIVATE) confirm( "You should see green icon, also one visit in sidebar. Make sure the unicode is displayed correctly." )
def test_visits_hier(tdir): test_url = 'https://www.reddit.com/r/QuantifiedSelf/comments/d6m7bd/android_app_to_track_and_export_application_use/' urls = { test_url: 'parent url', 'https://reddit.com/r/QuantifiedSelf/comments/d6m7bd/android_app_to_track_and_export_application_use/f0vem56': 'Some context', 'https://reddit.com/r/QuantifiedSelf/comments/d6m7bd/android_app_to_track_and_export_application_use/whatever': None, # no context so should be ignored.. } indexer = index_urls(urls) indexer(tdir) with wserver(db=tdir / 'promnesia.sqlite') as helper: response = post(f'http://localhost:{helper.port}/visits', f'url={test_url}') assert {v['context'] for v in response['visits']} == {'parent url', 'Some context'}
def test_stress(tmp_path, browser) -> None: url = 'https://www.reddit.com/' urls = [(f'{url}/subpath/{i}.html', f'context {i}' if i > 10000 else None) for i in range(50000)] with _test_helper(tmp_path, index_urls(urls), url, browser=browser) as helper: if has_x(): helper.activate() manual.confirm(''' Is performance reasonable? The sidebar should show up, and update gradually. You should be able to scroll the page, trigger tooltips, etc., without any lags. '''.strip())
def test_unreachable(tmp_path, browser): url = 'https://somenonexist1ngurl.com' urls = { url: 'some context', } with _test_helper(tmp_path, index_urls(urls), 'about:blank', browser=browser) as helper: try: helper.driver.get(url) except: # results in exception because it's unreachable pass confirm('green icon, no errors, desktop notification with contexts')
def test_show_visited_marks(tmp_path, browser): visited = { 'https://en.wikipedia.org/wiki/Special_linear_group': None, 'http://en.wikipedia.org/wiki/Unitary_group': None, 'en.wikipedia.org/wiki/Transpose': None, } test_url = "https://en.wikipedia.org/wiki/Symplectic_group" with _test_helper(tmp_path, index_urls(visited), test_url, show_dots=True, browser=browser) as helper: trigger_command(helper.driver, Command.MARK_VISITED) confirm( "You should see visited marks near special linear group, Unitary group, Transpose" )
def test_stress(tmp_path, browser): page = tmp_path / 'dummy.html' page.write_text(''' <html> <head>HI</head> <body>test</body> </html> ''') url = f'file://{page}' urls = [(url, f'ctx {i}' if i < 20 else None) for i in range(10000)] with _test_helper(tmp_path, index_urls(urls), url, browser=browser) as helper: # TODO so, should the response be immediate? # TODO shouldn't do any work if we don't open the sidebar confirm('is performance reasonable?')
def test_local_page(tmp_path, browser): tutorial = 'file:///usr/share/doc/python3/html/tutorial/index.html' urls = { tutorial: 'TODO read this', 'file:///usr/share/doc/python3/html/reference/index.html': None, } url = PYTHON_DOC_URL with _test_helper(tmp_path, index_urls(urls), url, browser=browser) as helper: confirm('grey icon') helper.driver.get(tutorial) confirm( 'green icon. MANUALLY: ACTIVATE SIDEBAR!. It should open sidebar with one visit' ) helper.driver.back() # TODO it's always guaranteed to work? https://stackoverflow.com/questions/27626783/python-selenium-browser-driver-back confirm('grey icon, should be no sidebar') helper.driver.forward() confirm('green icon, sidebar visible')
def test_unreachable(tmp_path, browser) -> None: url = 'https://somenonexist1ngurl.com' urls = { url: 'some context', } with _test_helper( tmp_path, index_urls(urls), 'about:blank', browser=browser, notify_contexts=True, verbose_errors=False, ) as helper: try: helper.driver.get(url) except: # results in exception because it's unreachable pass # TODO maybe in this case it could instead open the sidebar in a separate tab? manual.confirm( 'green icon, no errors, desktop notification with contexts')