Skip to content

Commit

Permalink
[test] Add test for issue5622
Browse files Browse the repository at this point in the history
- Add test for issue nwjs#5622
- This test is failed on v0.19.5, passed on v0.30.0
  • Loading branch information
wanghongjuan committed Apr 26, 2018
1 parent c25a5a0 commit 3793e7c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/sanity/issue5622-setTimeout-webview-node-vm/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<webview id="sandbox" allownw src="about:blank"></webview>
<script>
const sandbox = document.getElementById('sandbox');
setTimeout(function() {
sandbox.showDevTools(true);
sandbox.setAttribute('src', 'http://localhost:{port}/sandbox.html');
}, 100);
</script>
4 changes: 4 additions & 0 deletions test/sanity/issue5622-setTimeout-webview-node-vm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "5622",
"main": "index.html"
}
19 changes: 19 additions & 0 deletions test/sanity/issue5622-setTimeout-webview-node-vm/sandbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<title>5622</title>
<meta charset="UTF-8">
<script> window.name = 'webview0' </script>
</head>
<body>
<h1 id="result"></h1>
<script>
const vm = require('vm');
vm.runInNewContext('setTimeout(function(){document.getElementById("result").innerHTML="in sandbox"}, 10)', {
console: console,
document: document,
setTimeout: setTimeout
});
</script>
</body>
</html>
47 changes: 47 additions & 0 deletions test/sanity/issue5622-setTimeout-webview-node-vm/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import time
import os
import sys
import subprocess

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from nw_util import *

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common import utils

chrome_options = Options()
testdir = os.path.dirname(os.path.abspath(__file__))
chrome_options.add_argument("nwapp=" + testdir)
chrome_options.add_experimental_option("windowTypes", ["webview"])

capabilities = {"pageLoadStrategy": "none"}

port = str(utils.free_port())
server_file = os.path.join(testdir, "../", "http-server.py")
server = subprocess.Popen(['python', server_file, port])

tpl = open('index.tpl', 'r')
content = tpl.read().replace('{port}', port)
tpl.close()

html = open('index.html', 'w')
html.write(content)
html.close()

driver = webdriver.Chrome(executable_path=os.environ["CHROMEDRIVER"], chrome_options=chrome_options, desired_capabilities = capabilities, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(5)
time.sleep(1)
try:
print driver.current_url
print 'wait for window open'
print driver.window_handles
wait_window_handles(driver, 3)
print 'switch to webview window'
wait_switch_window_name(driver, 'webview0')
res = wait_for_element_id(driver, "result")
print res
assert("in sandbox" in res)
finally:
server.terminate()
driver.quit()

0 comments on commit 3793e7c

Please sign in to comment.