Skip to content

Commit

Permalink
extension: fix potential race condition with defensive sidebar inject…
Browse files Browse the repository at this point in the history
…ion (regression)

demos: minor fixes & enhancements
  • Loading branch information
karlicoss committed May 18, 2020
1 parent c79a632 commit 71306d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
12 changes: 8 additions & 4 deletions extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,19 @@ async function updateState (tab: chrome$Tab) {
const opts = await get_options_async();
// TODO this should be executed as an atomic block?

const inject = chromeTabsExecuteScriptAsync(tabId, {file: 'sidebar.js'})
.then(chromeTabsInsertCSS(tabId, {file: 'sidebar-outer.css'}))
.then(chromeTabsInsertCSS(tabId, {code: opts.position_css}));
const inject = () => chromeTabsExecuteScriptAsync(tabId, {file: 'sidebar.js'})
// TODO hmm. in theory script and CSS injections commute, but css order on the othe hand might matter?
// not sure, but using deferred promises just in case
.then(() => chromeTabsInsertCSS(tabId, {file: 'sidebar-outer.css'}))
.then(() => chromeTabsInsertCSS(tabId, {code: opts.position_css}));


// NOTE: if the page is unreachable, we can't inject stuf in it
// not sure how to detect it? tab doesn't have any interesting attributes
// firefox sets tab.title to "Server Not Found"? (TODO also see isOk logic below)
// TODO in this case, could set browser action to open a new tab (i.e. search) or something?
await defensify(inject, 'sidebar injection');
await defensify(inject, 'sidebar injection')();
// TODO crap, at first I forgot () at the end, and flow didn't complain which resulted in flakiness wtf??

const visits = await getVisits(url);
let {icon, title, text} = getIconStyle(visits);
Expand Down
13 changes: 11 additions & 2 deletions tests/demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ def demo_helper(*, tmp_path, browser, path: Path, indexer=real_db, before=None,
}[subs_position]

position = f'''
.promnesia {{
#promnesia-sidebar {{
--right: 1;
--size: {size};
background-color: rgba(236, 236, 236, 0.8);
}}
#promnesia-sidebar .src {{
font-weight: bold;
}}
'''
# TODO hmm. not sure if the whole sidebar should have a background instead??

Expand Down Expand Up @@ -132,6 +136,7 @@ def set_geometry(wid: str):
host=None, port=None, # TODO meh
notification=False,
position=position,
verbose_errors=False,
**extras,
)

Expand Down Expand Up @@ -572,14 +577,18 @@ def before(driver):
@browsers(FF, CH)
def test_demo_how_did_i_get_here(tmp_path, browser):
path = demos / 'how_did_i_get_here'

def before(driver):
driver.get('https://www.amazon.co.uk/Topoi-Categorial-Analysis-Logic-Mathematics/dp/0486450260')

with demo_helper(
tmp_path=tmp_path,
browser=browser,
path=path,
subs_position='bottomleft',
before=before,
) as (helper, annotate):
driver = helper.driver
driver.get('https://www.amazon.co.uk/Topoi-Categorial-Analysis-Logic-Mathematics/dp/0486450260')

annotate('''
I found this link in my bookmarks.
Expand Down
11 changes: 9 additions & 2 deletions tests/end2end_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def configure(
blacklist=None,
notification: Optional[bool]=None,
position: Optional[str]=None,
verbose_errors: bool=True,
):
def set_checkbox(cid: str, value: bool):
cb = driver.find_element_by_id(cid)
Expand All @@ -191,7 +192,7 @@ def set_checkbox(cid: str, value: bool):
# assert dots.is_selected() == show_dots

# TODO not sure, should be False for demos?
set_checkbox('verbose_errors_id', True)
set_checkbox('verbose_errors_id', verbose_errors)

if highlights is not None:
set_checkbox('highlight_id', highlights)
Expand Down Expand Up @@ -398,11 +399,12 @@ def set_position(driver, settings: str):
# ugh... for some reason wouldn't send the keys...
field.click()
import pyautogui # type: ignore
# it usually ends up in the middle of the area...
pyautogui.press(['backspace'] * 500 + ['delete'] * 500)
pyautogui.typewrite(settings, interval=0.05)
else:
area = field.find_element_by_xpath('.//textarea')
area.send_keys([Keys.DELETE] * 500)
area.send_keys([Keys.DELETE] * 1000)
area.send_keys(settings)


Expand Down Expand Up @@ -688,3 +690,8 @@ def test_duplicate_background_pages(tmp_path, browser):
# at notifyError (VM2056 notifications.js:41)



# TODO FIXME need to test racey conditions _while_ page is loading, results in this 'unexpected error occured'?


# TODO shit, sometimes I have 'bindSidebarData is not defined'? with vebose errors on demo_how_did_i_get_here
1 change: 1 addition & 0 deletions tests/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def record(output: Optional[Path]=None, wid: Optional[str]=None, quality: Option

cmd: List[Union[Path, str]] = [
'ffmpeg',
'-hide_banner', '-loglevel', 'panic', # less spam in the terminal
'-f', 'x11grab',
'-y',
'-r', '30',
Expand Down

0 comments on commit 71306d1

Please sign in to comment.