Skip to content

Commit

Permalink
Merge pull request #4196 from ghostoy/issue-4143
Browse files Browse the repository at this point in the history
test case for issue #4143
  • Loading branch information
rogerwang committed Jan 11, 2016
2 parents 67b29e9 + 0d40c74 commit 6c580f9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/remoting/issue4143-chrome-sockets-permission/http-server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

import SimpleHTTPServer
import SocketServer
import sys

PORT = int(sys.argv[1])

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

31 changes: 31 additions & 0 deletions test/remoting/issue4143-chrome-sockets-permission/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>chrome.sockets.tcp</title>
</head>
<body>
<button id="socket-connect" type="button" onclick="socketConnect('result')">Connect</button>
<script>
function out(id, msg) {
var result = document.createElement('h1');
result.setAttribute('id', id);
result.innerHTML = msg;
document.body.appendChild(result);
}
function socketConnect(id) {
chrome.sockets.tcp.create(function(obj) {
chrome.sockets.tcp.connect(obj.socketId, 'localhost', {port}, function(r) {
if (chrome.runtime.lastError) {
out(id, 'failed');
} else {
out(id, 'success');
}
});
});
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "chrome-sockets-permission",
"main": "index.html"
}
39 changes: 39 additions & 0 deletions test/remoting/issue4143-chrome-sockets-permission/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import time
import os
import subprocess

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

chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
chrome_options.add_argument("mixed-context")

testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)

port = str(utils.free_port())
server = subprocess.Popen(['python', 'http-server.py', 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, service_log_path="log", service_args=["--verbose"])
time.sleep(1)
try:
print driver.current_url
driver.implicitly_wait(10)
driver.find_element_by_id('socket-connect').click()
result = driver.find_element_by_id('result').get_attribute('innerHTML')
print result
assert("success" in result)
finally:
server.terminate()
driver.quit()

0 comments on commit 6c580f9

Please sign in to comment.