OLD | NEW |
1 <script> | 1 <!-- |
2 var hostname = '127.0.0.1'; | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
3 var port = -1; | 3 * source code is governed by a BSD-style license that can be found in the |
4 | 4 * LICENSE file. |
5 function testModernApi() { | 5 --> |
6 function gotMessage(msg) { | 6 <script src="background.js"></script> |
7 chrome.test.assertEq(msg.data, window.btoa("aloha\n")); | |
8 } | |
9 | |
10 function gotUrl(url) { | |
11 var url_regex = /^ws:\/\// | |
12 chrome.test.assertEq(0, url.search(url_regex)); | |
13 ws = new WebSocket(url); | |
14 | |
15 function gotMessage(msg) { | |
16 // chrome.test.callbackPass envelope works only once, remove it. | |
17 ws.onmessage = gotMessage; | |
18 } | |
19 | |
20 // We should get response from HTTP test server. | |
21 ws.onmessage = chrome.test.callbackPass(gotMessage); | |
22 | |
23 ws.onopen = function() { | |
24 var request = ["GET / HTTP/1.1", | |
25 "Host: 127.0.0.1:" + port, | |
26 "Connection: keep-alive", | |
27 "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/
535.2 (KHTML, like Gecko) Chrome/15.0.874.54 Safari/535.2", | |
28 "Accept: text/html,application/xhtml+xml,application/xml;
q=0.9,*/*;q=0.8", | |
29 "", ""].join("\r\n"); | |
30 ws.send(window.btoa(request)); | |
31 }; | |
32 } | |
33 | |
34 chrome.webSocketProxyPrivate.getURLForTCP( | |
35 hostname, port, { "tls": false }, chrome.test.callbackPass(gotUrl)); | |
36 } | |
37 | |
38 function testObsoleteApi() { | |
39 function gotPassport(passport) { | |
40 chrome.test.assertEq('string', typeof(passport)); | |
41 chrome.test.assertTrue(passport.length > 5); // Short one is insecure. | |
42 } | |
43 | |
44 chrome.webSocketProxyPrivate.getPassportForTCP( | |
45 hostname, port, chrome.test.callbackPass(gotPassport)); | |
46 } | |
47 | |
48 function setTestServerPortAndProceed(testConfig) { | |
49 port = testConfig.testServer.port; | |
50 chrome.test.runTests([testModernApi, testObsoleteApi]); | |
51 } | |
52 | |
53 chrome.test.getConfig(setTestServerPortAndProceed); | |
54 </script> | |
OLD | NEW |