Commit 3112e216 authored by Romain Casati's avatar Romain Casati
Browse files

Testing now support detaching -> hacked input is now tested.

parent d54dc7ca
......@@ -98,7 +98,9 @@ class SeleniumWrapper:
Basthon.addEventListener("eval.finished", function (data) {
window._basthon_eval_data.result = data;
window._basthon_done();
window._basthon_eval_data.done = true;
if( window._basthon_done != null )
window._basthon_done();
});
""")
......@@ -154,22 +156,33 @@ class SeleniumWrapper:
else:
raise JavascriptException(retval[1], retval[2])
def run_basthon(self, code):
self.driver.execute_async_script("""
def run_basthon_detach(self, code):
self.driver.execute_script("""
const code = arguments[0];
const done = arguments[arguments.length - 1];
window._basthon_eval_data = {
result: undefined,
stdout: "",
stderr: "",
display: undefined,
done: false,
};
window._basthon_done = done;
window._basthon_done = null;
Basthon.dispatchEvent("eval.request", {code: code});""", code)
def run_basthon_reattach(self):
self.driver.execute_async_script("""
const done = arguments[arguments.length - 1];
window._basthon_done = done;
if( window._basthon_eval_data.done )
done();""")
return self.run_js("return window._basthon_eval_data;")
def run_basthon(self, code):
self.run_basthon_detach(code)
return self.run_basthon_reattach()
def run_webworker(self, code):
if isinstance(code, str) and code.startswith("\n"):
# we have a multiline string, fix indentation
......
from pathlib import Path
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
def test_hack_input(selenium):
#assert False
pass
selenium.run_basthon_detach("int(input('How old are you?'))")
driver = selenium.driver
wait = WebDriverWait(driver, 10)
wait.until(expected_conditions.alert_is_present())
alert = driver.switch_to.alert
alert.send_keys("42")
alert.accept()
result = selenium.run_basthon_reattach()['result']['result']['text/plain']
assert result == "42"
def test_hack_modules(selenium):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment