Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Basthon
Basthon Kernel
Commits
3112e216
Commit
3112e216
authored
Jan 31, 2021
by
Romain Casati
Browse files
Testing now support detaching -> hacked input is now tested.
parent
d54dc7ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
conftest.py
View file @
3112e216
...
...
@@ -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
...
...
tests/test_hack_builtins.py
View file @
3112e216
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment