forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nwjs#916: support pac_url and auto proxy detection
Add test cases for pac url. (cherry picked from commit 206df0d)
- Loading branch information
Showing
7 changed files
with
126 additions
and
26 deletions.
There are no files selected for viewing
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
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
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
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,19 @@ | ||
(function(){ | ||
const http = require('http'); | ||
let id = 1; | ||
|
||
// Create an HTTP server | ||
var srv = http.createServer( (req, res) => { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.write('function FindProxyForURL(url, host) {\n'); | ||
res.write(' if (host == \'www.port3128.com\')\n'); | ||
res.write(' return \'PROXY localhost:3128\';\n'); | ||
res.write(' else if (host == \'www.port4040.com\')\n'); | ||
res.write(' return \'PROXY localhost:4040\';\n'); | ||
res.write(' return "DIRECT";\n'); | ||
res.write('}'); | ||
res.end(); | ||
}); | ||
|
||
srv.listen(nw.App.manifest.port, '127.0.0.1'); | ||
})() |
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 |
---|---|---|
@@ -1,20 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>App.getProxyForURL</title> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>App.getProxyForURL</title> | ||
</head> | ||
<body> | ||
<script> | ||
nw.App.setProxyConfig('dummy:8080'); | ||
var proxy = nw.App.getProxyForURL('http://www.example.com/'); | ||
var expect = 'PROXY dummy:8080'; | ||
if (proxy === expect) { | ||
document.write('<h1 id="result">success</h1>'); | ||
} else { | ||
document.write('<h1 id="result">failure: expect "' + expect + '" but get ' + proxy +'</h1>'); | ||
} | ||
</script> | ||
<button id="pac" onclick="requestPac()">Request pac</button> | ||
<button id="open-devtools" onclick="openDevTools()">Open DevTools</button> | ||
<script> | ||
nw.App.setProxyConfig('dummy:8080'); | ||
var proxy = nw.App.getProxyForURL('http://www.example.com/'); | ||
var expect = 'PROXY dummy:8080'; | ||
if (proxy === expect) { | ||
document.write('<h1 id="result">success</h1>'); | ||
} else { | ||
document.write('<h1 id="result">failure: expect "' + expect + '" but get ' + proxy +'</h1>'); | ||
} | ||
|
||
// Reset Proxy | ||
nw.App.setProxyConfig("", "<direct>"); | ||
|
||
function requestPac() { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', `http://localhost:${nw.App.manifest.port}/`, true); | ||
xhr.send(); | ||
xhr.onload = ()=>{ | ||
var b = new Buffer(xhr.responseText); | ||
var encodedUrl = "data:application/x-ns-proxy-autoconfig;base64," + b.toString('base64'); | ||
nw.App.setProxyConfig('dummy:8080', encodedUrl); | ||
var proxy = nw.App.getProxyForURL('http://www.port3128.com/'); | ||
var expect = 'PROXY localhost:3128'; | ||
if (proxy === expect) { | ||
document.write('<h1 id="result2">success</h1>'); | ||
} else { | ||
document.write('<h1 id="result2">failure: expect "' + expect + '" but get ' + proxy +'</h1>'); | ||
} | ||
var proxy = nw.App.getProxyForURL('http://www.port4040.com/'); | ||
var expect = 'PROXY localhost:4040'; | ||
if (proxy === expect) { | ||
document.write('<h1 id="result3">success</h1>'); | ||
} else { | ||
document.write('<h1 id="result3">failure: expect "' + expect + '" but get ' + proxy +'</h1>'); | ||
} | ||
}; | ||
} | ||
|
||
function openDevTools() { | ||
chrome.developerPrivate.openDevTools({renderProcessId: -1, renderViewId: -1, extensionId: chrome.runtime.id}); | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
</html> |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,50 @@ | ||
import time | ||
import os | ||
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 | ||
from selenium.webdriver.common import utils | ||
|
||
test_dir = os.path.dirname(os.path.abspath(__file__)) | ||
chrome_options = Options() | ||
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__))) | ||
chrome_options.add_argument("nwapp=" + test_dir) | ||
|
||
port = str(utils.free_port()) | ||
|
||
pkgjson = ''' | ||
{ | ||
"name": "app-getproxyforurl", | ||
"main": "index.html", | ||
"bg-script": "bg.js", | ||
"port": "%s" | ||
} | ||
''' % port | ||
|
||
with open(os.path.join(test_dir, 'package.json'), 'w') as bg: | ||
bg.write(pkgjson) | ||
|
||
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options) | ||
driver.implicitly_wait(2) | ||
time.sleep(1) | ||
try: | ||
print driver.current_url | ||
|
||
time.sleep(1) | ||
result = driver.find_element_by_id('result') | ||
print result.get_attribute('innerHTML') | ||
assert("success" in result.get_attribute('innerHTML')) | ||
|
||
wait_window_handles(driver, 1) | ||
switch_to_app(driver) | ||
driver.find_element_by_id('pac').click() | ||
wait_window_handles(driver, 1) | ||
result2 = driver.find_element_by_id('result2') | ||
assert("success" in result2.get_attribute('innerHTML')) | ||
wait_window_handles(driver, 1) | ||
result3 = driver.find_element_by_id('result3') | ||
assert("success" in result3.get_attribute('innerHTML')) | ||
finally: | ||
driver.quit() |