-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4196 from ghostoy/issue-4143
test case for issue #4143
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
test/remoting/issue4143-chrome-sockets-permission/http-server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
test/remoting/issue4143-chrome-sockets-permission/index.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
4 changes: 4 additions & 0 deletions
4
test/remoting/issue4143-chrome-sockets-permission/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "chrome-sockets-permission", | ||
"main": "index.html" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|