Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] fix test 6229 #6478

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/sanity/issue6229-webview-executeScript/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>issue6229-webview-executeScript</title>
</head>
<body>
<webview partition="trusted" class="browser" style="position: fixed;top: 0;left: 0;right: 0;width: 100%;height: 50%;" src=""></webview>
<div style="position: fixed;bottom: 0;left: 0;right: 0;width: 100%;height: 50%;" class="log">
<p>Current behaviour: logs an empty window object to devtools</p>
<p>Expected behaviour: it should log the window object to devtools</p>
<input type="text" name="" value="Object.keys(window)" /><button onclick="exec(document.querySelector('input').value)">Run</button>
</div>
</body>
</html>


<script type="text/javascript">
let wv = document.querySelector('.browser');
wv.addEventListener('contentload', function () {
wv.showDevTools(true)
});

function exec(val) {
wv.executeScript({code: val, mainWorld: true}, function (res) {
document.querySelector('.log').appendChild(document.createTextNode(res))
});
}
setTimeout(function () {
wv.src = 'file://' + global.__dirname + '/site.html';
}, 750)
</script>
20 changes: 20 additions & 0 deletions test/sanity/issue6229-webview-executeScript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "issue6229-webview-executeScript",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"webview": {
"partitions": [
{
"name": "trusted",
"accessible_resources": [ "<all_urls>" ]
}
]
}
}

15 changes: 15 additions & 0 deletions test/sanity/issue6229-webview-executeScript/site.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
</html>


<script type="text/javascript">
window.test = 'DEFAULT';

setInterval(function () {
document.querySelector('h1').textContent = window.test;
}, 250);
</script>
31 changes: 31 additions & 0 deletions test/sanity/issue6229-webview-executeScript/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import time
import os
import platform
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

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

chrome_options = Options()
testdir = os.path.dirname(os.path.abspath(__file__))
chrome_options.add_argument("nwapp=" + testdir)

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(2)
try:
print driver.current_url
print 'wait for devtools open'
wait_window_handles(driver,2)
handles = driver.window_handles
print handles
driver.switch_to_window(handles[0])
print 'click button to execute code'
driver.find_element_by_tag_name('button').click()
print 'get all keys in window'
result = driver.find_element_by_class_name('log').get_attribute('innerText')
assert('postMessage' in result)
finally:
driver.quit()