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

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: Fixed spaces in copyright header 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 = {
11 function getVisibleNetworks() { 11 connectListener: function(network, done) {
12 chrome.networkingPrivate.getVisibleNetworks( 12 var self = this;
13 "All", 13 var collectProperties = function(transition, properties) {
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 (transition == "connect")
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 (transition == "connect")
37 "Type": "WiFi" 37 startDisconnect();
38 } 38 else
39 }, 39 finishTest();
40 { "Name": "cellular1", 40 }
41 "GUID": "stub_cellular1", 41 };
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, "connect"));
46 };
47 this.watchForDisconnect = function(changes) {
48 assertEq([network], changes);
49 chrome.networkingPrivate.getProperties(
50 network, collectProperties.bind(undefined, "disconnect"));
51 };
46 }, 52 },
47 function getVisibleNetworksWifi() { 53 listListener: function(network, expected, done) {
48 chrome.networkingPrivate.getVisibleNetworks( 54 var self = this;
49 "WiFi", 55 this.listenForChanges = function(list) {
50 callbackPass(function(result) { 56 assertEq(expected, list);
51 assertTrue(!!result); 57 chrome.networkingPrivate.onNetworkListChanged.removeListener(
52 assertEq(2, result.length); 58 self.listenForChanges);
53 assertEq([{ "Name": "wifi1", 59 done();
54 "GUID": "stub_wifi1", 60 };
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 } 61 }
98 ]); 62 };
63
64 /////////////////////////////////////////////////////
65 // Tests
66
67 function startConnect() {
68 chrome.networkingPrivate.startConnect("stub_wifi2",
69 callbackPass(function() {}));
70 }
71
72 function startDisconnect() {
73 chrome.networkingPrivate.startDisconnect("stub_wifi2",
74 callbackPass(function() {}));
75 }
76
77 function startConnectNonexistent() {
78 // Make sure we get an error when we try to connect to a nonexistent
79 // network.
80 chrome.networkingPrivate.startConnect(
81 "nonexistent_path",
82 callbackFail("Error.InvalidService", function() {}));
83 }
84
85 function getVisibleNetworks() {
86 chrome.networkingPrivate.getVisibleNetworks(
87 "All",
88 callbackPass(function(result) {
89 assertTrue(!!result);
90 assertEq(4, result.length);
91 assertEq([{
92 "ConnectionState": "Connected",
93 "GUID": "stub_ethernet",
94 "Name": "eth0",
95 "Type": "Ethernet"
96 },
97 {
98 "ConnectionState": "Connected",
99 "GUID": "stub_wifi1",
100 "Name": "wifi1",
101 "Type": "WiFi",
102 "WiFi": {
103 "SSID": "stub_wifi1",
104 "Type": "WiFi"
105 }
106 },
107 {
108 "ConnectionState": "NotConnected",
109 "GUID": "stub_wifi2",
110 "Name": "wifi2_PSK",
111 "Type": "WiFi",
112 "WiFi": {
113 "SSID": "stub_wifi2",
114 "Type": "WiFi"
115 }
116 },
117 {
118 "ConnectionState": "NotConnected",
119 "GUID": "stub_cellular1",
120 "Name": "cellular1",
121 "Type": "Cellular"
122 }
123 ], result);
124 }));
125 }
126
127 function getVisibleNetworksWifi() {
128 chrome.networkingPrivate.getVisibleNetworks(
129 "WiFi",
130 callbackPass(function(result) {
131 assertTrue(!!result);
132 assertEq(2, result.length);
133 assertEq([{
134 "ConnectionState": "Connected",
135 "GUID": "stub_wifi1",
136 "Name": "wifi1",
137 "Type": "WiFi",
138 "WiFi": {
139 "SSID": "stub_wifi1",
140 "Type": "WiFi"
141 }
142 },
143 {
144 "ConnectionState": "NotConnected",
145 "GUID": "stub_wifi2",
146 "Name": "wifi2_PSK",
147 "Type": "WiFi",
148 "WiFi": {
149 "SSID": "stub_wifi2",
150 "Type": "WiFi"
151 }
152 }
153 ], result);
154 }));
155 }
156
157 function getProperties() {
158 chrome.networkingPrivate.getProperties(
159 "stub_wifi2",
160 callbackPass(function(result) {
161 assertTrue(!!result);
162 assertEq("wifi2_PSK", result.Name);
163 assertEq("NotConnected", result.ConnectionState);
164 assertEq("WiFi", result.Type);
165 }));
166 }
167
168 function onNetworksChangedEvent() {
169 var network = "stub_wifi2";
170 var done = chrome.test.callbackAdded();
171 var listener = new privateHelpers.connectListener(network, done);
172 chrome.networkingPrivate.onNetworksChanged.addListener(
173 listener.watchForConnect);
174 chrome.networkingPrivate.startConnect(network,
175 callbackPass(function() {}));
176 }
177
178 function onNetworkListChangedEvent() {
179 var network = "stub_wifi2";
180 var expected = ["stub_wifi2","stub_ethernet", "stub_wifi1", "stub_cellular1"];
181 var done = chrome.test.callbackAdded();
182 var listener = new privateHelpers.listListener(network, expected, done);
183 chrome.networkingPrivate.onNetworkListChanged.addListener(
184 listener.listenForChanges);
185 chrome.networkingPrivate.startConnect(network,
186 callbackPass(function() {}));
187 }
188
189 var testToRun = window.location.search.substring(1);
190 chrome.test.runTests([window[testToRun]]);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/networking/manifest.json ('k') | chromeos/dbus/shill_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698