Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(912)

Side by Side Diff: chrome/test/data/extensions/api_test/networking/test.js

Issue 12220113: Next phase for chrome.networkingPrivate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review changes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 //Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 //Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 //found in the LICENSE file.
4 4
5 var callbackPass = chrome.test.callbackPass; 5 var callbackPass = chrome.test.callbackPass;
6 var callbackFail = chrome.test.callbackFail; 6 var callbackFail = chrome.test.callbackFail;
7 var assertTrue = chrome.test.assertTrue; 7 var assertTrue = chrome.test.assertTrue;
8 var assertEq = chrome.test.assertEq; 8 var assertEq = chrome.test.assertEq;
9 9
10 chrome.test.runTests([ 10 var privateHelpers = {
not at google - send to devlin 2013/02/12 23:36:09 I think that if the tests were in a "tests" object
11 function getVisibleNetworks() { 11 connectListener: function(network, done) {
12 chrome.networkingPrivate.getVisibleNetworks( 12 var self = this;
13 "All", 13 var collectProperties = function(testingConnectTransition, properties) {
not at google - send to devlin 2013/02/12 23:36:09 Ok, I'd make it a string (connect vs disconnect) b
Greg Spencer (Chromium) 2013/02/12 23:57:42 That's a nice solution. I'll do that.
14 callbackPass(function(result) { 14 var finishTest = function() {
15 assertTrue(!!result); 15 chrome.networkingPrivate.onNetworksChanged.removeListener(
16 assertEq(4, result.length); 16 self.watchForConnect);
17 assertEq([{ "Name": "eth0", 17 done();
18 "GUID": "stub_ethernet", 18 };
19 "ConnectionState": "Connected", 19 var startDisconnect = function() {
20 "Type": "Ethernet" 20 chrome.networkingPrivate.startDisconnect(
21 }, 21 network,
22 { "Name": "wifi1", 22 callbackPass(function() {}));
23 "GUID": "stub_wifi1", 23 };
24 "ConnectionState": "Connected", 24 var startConnect = function() {
25 "Type": "WiFi", 25 chrome.networkingPrivate.startConnect(
26 "WiFi": { 26 network,
27 "SSID": "stub_wifi1", 27 callbackPass(function() {}));
28 "Type": "WiFi" 28 };
29 } 29 if (properties.ConnectionState == "NotConnected") {
30 }, 30 if (testingConnectTransition)
31 { "Name": "wifi2_PSK", 31 finishTest();
32 "GUID": "stub_wifi2", 32 else
33 "ConnectionState": "NotConnected", 33 startConnect();
34 "Type": "WiFi", 34 }
35 "WiFi": { 35 if (properties.ConnectionState == "Connected") {
36 "SSID": "stub_wifi2", 36 if (testingConnectTransition)
37 "Type": "WiFi" 37 startDisconnect();
38 } 38 else
39 }, 39 finishTest();
40 { "Name": "cellular1", 40 }
41 "GUID": "stub_cellular1", 41 }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
42 "ConnectionState": "NotConnected", 42 this.watchForConnect = function(changes) {
43 "Type": "Cellular" 43 assertEq([network], changes);
44 }], result); 44 chrome.networkingPrivate.getProperties(
45 })); 45 network, collectProperties.bind(undefined, true /* Testing connect */));
46 }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
47 this.watchForDisconnect = function(changes) {
48 assertEq([network], changes);
49 chrome.networkingPrivate.getProperties(
50 network, collectProperties.bind(undefined,
51 false /* Testing disconnect */));
52 }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
46 }, 53 },
47 function getVisibleNetworksWifi() { 54 listListener: function(network, expected, done) {
48 chrome.networkingPrivate.getVisibleNetworks( 55 var self = this;
49 "WiFi", 56 this.listenForChanges = function(list) {
50 callbackPass(function(result) { 57 assertEq(expected, list);
51 assertTrue(!!result); 58 chrome.networkingPrivate.onNetworkListChanged.removeListener(
52 assertEq(2, result.length); 59 self.listenForChanges);
53 assertEq([{ "Name": "wifi1", 60 done();
54 "GUID": "stub_wifi1", 61 }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
55 "ConnectionState": "Connected",
56 "Type": "WiFi",
57 "WiFi": {
58 "SSID": "stub_wifi1",
59 "Type":"WiFi"
60 }
61 },
62 { "Name": "wifi2_PSK",
63 "GUID": "stub_wifi2",
64 "ConnectionState": "NotConnected",
65 "Type": "WiFi",
66 "WiFi": {
67 "SSID": "stub_wifi2",
68 "Type": "WiFi"
69 }
70 }], result);
71 }));
72 },
73 function getProperties() {
74 chrome.networkingPrivate.getProperties(
75 "stub_wifi2",
76 callbackPass(function(result) {
77 assertTrue(!!result);
78 assertEq("wifi2_PSK", result.Name);
79 assertEq("NotConnected", result.ConnectionState);
80 assertEq("WiFi", result.Type);
81 }));
82 },
83 function startConnect() {
84 chrome.networkingPrivate.startConnect("stub_wifi2",
85 callbackPass(function() {}));
86 },
87 function startDisconnect() {
88 chrome.networkingPrivate.startDisconnect("stub_wifi2",
89 callbackPass(function() {}));
90 },
91 function startConnectNonexistent() {
92 // Make sure we get an error when we try to connect to a nonexistent
93 // network.
94 chrome.networkingPrivate.startConnect(
95 "nonexistent_path",
96 callbackFail("Error.InvalidService", function() {}));
97 } 62 }
98 ]); 63 };
64
65 /////////////////////////////////////////////////////
66 // Tests
67
68 function startConnect() {
69 chrome.networkingPrivate.startConnect("stub_wifi2",
70 callbackPass(function() {}));
71 }
72
73 function startDisconnect() {
74 chrome.networkingPrivate.startDisconnect("stub_wifi2",
75 callbackPass(function() {}));
76 }
77
78 function startConnectNonexistent() {
79 // Make sure we get an error when we try to connect to a nonexistent
80 // network.
81 chrome.networkingPrivate.startConnect(
82 "nonexistent_path",
83 callbackFail("Error.InvalidService", function() {}));
84 }
85
86 function getVisibleNetworks() {
87 chrome.networkingPrivate.getVisibleNetworks(
88 "All",
89 callbackPass(function(result) {
90 assertTrue(!!result);
91 assertEq(4, result.length);
92 assertEq([{
93 "ConnectionState": "Connected",
94 "GUID": "stub_ethernet",
95 "Name": "eth0",
96 "Type": "Ethernet"
97 },
98 {
99 "ConnectionState": "Connected",
100 "GUID": "stub_wifi1",
101 "Name": "wifi1",
102 "Type": "WiFi",
103 "WiFi": {
104 "SSID": "stub_wifi1",
105 "Type": "WiFi"
106 }
107 },
108 {
109 "ConnectionState": "NotConnected",
110 "GUID": "stub_wifi2",
111 "Name": "wifi2_PSK",
112 "Type": "WiFi",
113 "WiFi": {
114 "SSID": "stub_wifi2",
115 "Type": "WiFi"
116 }
117 },
118 {
119 "ConnectionState": "NotConnected",
120 "GUID": "stub_cellular1",
121 "Name": "cellular1",
122 "Type": "Cellular"
123 }
124 ], result);
125 }));
126 }
127
128 function getVisibleNetworksWifi() {
129 chrome.networkingPrivate.getVisibleNetworks(
130 "WiFi",
131 callbackPass(function(result) {
132 assertTrue(!!result);
133 assertEq(2, result.length);
134 assertEq([{
135 "ConnectionState": "Connected",
136 "GUID": "stub_wifi1",
137 "Name": "wifi1",
138 "Type": "WiFi",
139 "WiFi": {
140 "SSID": "stub_wifi1",
141 "Type": "WiFi"
142 }
143 },
144 {
145 "ConnectionState": "NotConnected",
146 "GUID": "stub_wifi2",
147 "Name": "wifi2_PSK",
148 "Type": "WiFi",
149 "WiFi": {
150 "SSID": "stub_wifi2",
151 "Type": "WiFi"
152 }
153 }
154 ], result);
155 }));
156 }
157
158 function getProperties() {
159 chrome.networkingPrivate.getProperties(
160 "stub_wifi2",
161 callbackPass(function(result) {
162 assertTrue(!!result);
163 assertEq("wifi2_PSK", result.Name);
164 assertEq("NotConnected", result.ConnectionState);
165 assertEq("WiFi", result.Type);
166 }));
167 }
168
169 function onNetworksChangedEvent() {
170 var network = "stub_wifi2";
171 var done = chrome.test.callbackAdded();
172 var listener = new privateHelpers.connectListener(network, done);
173 chrome.networkingPrivate.onNetworksChanged.addListener(
174 listener.watchForConnect);
175 chrome.networkingPrivate.startConnect(network,
176 callbackPass(function() {}));
177 }
178
179 function onNetworkListChangedEvent() {
180 var network = "stub_wifi2";
181 var expected = ["stub_wifi2","stub_ethernet", "stub_wifi1", "stub_cellular1"];
182 var done = chrome.test.callbackAdded();
183 var listener = new privateHelpers.listListener(network, expected, done);
184 chrome.networkingPrivate.onNetworkListChanged.addListener(
185 listener.listenForChanges);
186 chrome.networkingPrivate.startConnect(network,
187 callbackPass(function() {}));
188 }
189
190 var testToRun = window.location.search.substring(1);
191 chrome.test.runTests([window[testToRun]]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698