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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/networking/test.js
diff --git a/chrome/test/data/extensions/api_test/networking/test.js b/chrome/test/data/extensions/api_test/networking/test.js
index 5503ced293932998012d9546437436cd5d410326..3928166cd75efec27b4042f07a73d8b47b5ea71d 100644
--- a/chrome/test/data/extensions/api_test/networking/test.js
+++ b/chrome/test/data/extensions/api_test/networking/test.js
@@ -1,98 +1,191 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+//Copyright (c) 2013 The Chromium Authors. All rights reserved.
+//Use of this source code is governed by a BSD-style license that can be
+//found in the LICENSE file.
var callbackPass = chrome.test.callbackPass;
var callbackFail = chrome.test.callbackFail;
var assertTrue = chrome.test.assertTrue;
var assertEq = chrome.test.assertEq;
-chrome.test.runTests([
- function getVisibleNetworks() {
- chrome.networkingPrivate.getVisibleNetworks(
- "All",
- callbackPass(function(result) {
- assertTrue(!!result);
- assertEq(4, result.length);
- assertEq([{ "Name": "eth0",
- "GUID": "stub_ethernet",
- "ConnectionState": "Connected",
- "Type": "Ethernet"
- },
- { "Name": "wifi1",
- "GUID": "stub_wifi1",
- "ConnectionState": "Connected",
- "Type": "WiFi",
- "WiFi": {
- "SSID": "stub_wifi1",
- "Type": "WiFi"
- }
- },
- { "Name": "wifi2_PSK",
- "GUID": "stub_wifi2",
- "ConnectionState": "NotConnected",
- "Type": "WiFi",
- "WiFi": {
- "SSID": "stub_wifi2",
- "Type": "WiFi"
- }
- },
- { "Name": "cellular1",
- "GUID": "stub_cellular1",
- "ConnectionState": "NotConnected",
- "Type": "Cellular"
- }], result);
- }));
+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
+ connectListener: function(network, done) {
+ var self = this;
+ 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.
+ var finishTest = function() {
+ chrome.networkingPrivate.onNetworksChanged.removeListener(
+ self.watchForConnect);
+ done();
+ };
+ var startDisconnect = function() {
+ chrome.networkingPrivate.startDisconnect(
+ network,
+ callbackPass(function() {}));
+ };
+ var startConnect = function() {
+ chrome.networkingPrivate.startConnect(
+ network,
+ callbackPass(function() {}));
+ };
+ if (properties.ConnectionState == "NotConnected") {
+ if (testingConnectTransition)
+ finishTest();
+ else
+ startConnect();
+ }
+ if (properties.ConnectionState == "Connected") {
+ if (testingConnectTransition)
+ startDisconnect();
+ else
+ finishTest();
+ }
+ }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
+ this.watchForConnect = function(changes) {
+ assertEq([network], changes);
+ chrome.networkingPrivate.getProperties(
+ network, collectProperties.bind(undefined, true /* Testing connect */));
+ }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
+ this.watchForDisconnect = function(changes) {
+ assertEq([network], changes);
+ chrome.networkingPrivate.getProperties(
+ network, collectProperties.bind(undefined,
+ false /* Testing disconnect */));
+ }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
},
- function getVisibleNetworksWifi() {
- chrome.networkingPrivate.getVisibleNetworks(
- "WiFi",
- callbackPass(function(result) {
- assertTrue(!!result);
- assertEq(2, result.length);
- assertEq([{ "Name": "wifi1",
- "GUID": "stub_wifi1",
- "ConnectionState": "Connected",
- "Type": "WiFi",
- "WiFi": {
- "SSID": "stub_wifi1",
- "Type":"WiFi"
- }
- },
- { "Name": "wifi2_PSK",
- "GUID": "stub_wifi2",
- "ConnectionState": "NotConnected",
- "Type": "WiFi",
- "WiFi": {
- "SSID": "stub_wifi2",
- "Type": "WiFi"
- }
- }], result);
- }));
- },
- function getProperties() {
- chrome.networkingPrivate.getProperties(
- "stub_wifi2",
- callbackPass(function(result) {
- assertTrue(!!result);
- assertEq("wifi2_PSK", result.Name);
- assertEq("NotConnected", result.ConnectionState);
- assertEq("WiFi", result.Type);
- }));
- },
- function startConnect() {
- chrome.networkingPrivate.startConnect("stub_wifi2",
- callbackPass(function() {}));
- },
- function startDisconnect() {
- chrome.networkingPrivate.startDisconnect("stub_wifi2",
- callbackPass(function() {}));
- },
- function startConnectNonexistent() {
- // Make sure we get an error when we try to connect to a nonexistent
- // network.
- chrome.networkingPrivate.startConnect(
- "nonexistent_path",
- callbackFail("Error.InvalidService", function() {}));
+ listListener: function(network, expected, done) {
+ var self = this;
+ this.listenForChanges = function(list) {
+ assertEq(expected, list);
+ chrome.networkingPrivate.onNetworkListChanged.removeListener(
+ self.listenForChanges);
+ done();
+ }
not at google - send to devlin 2013/02/12 23:36:09 semicolon
Greg Spencer (Chromium) 2013/02/12 23:57:42 Done.
}
-]);
+};
+
+/////////////////////////////////////////////////////
+// Tests
+
+function startConnect() {
+ chrome.networkingPrivate.startConnect("stub_wifi2",
+ callbackPass(function() {}));
+}
+
+function startDisconnect() {
+ chrome.networkingPrivate.startDisconnect("stub_wifi2",
+ callbackPass(function() {}));
+}
+
+function startConnectNonexistent() {
+ // Make sure we get an error when we try to connect to a nonexistent
+ // network.
+ chrome.networkingPrivate.startConnect(
+ "nonexistent_path",
+ callbackFail("Error.InvalidService", function() {}));
+}
+
+function getVisibleNetworks() {
+ chrome.networkingPrivate.getVisibleNetworks(
+ "All",
+ callbackPass(function(result) {
+ assertTrue(!!result);
+ assertEq(4, result.length);
+ assertEq([{
+ "ConnectionState": "Connected",
+ "GUID": "stub_ethernet",
+ "Name": "eth0",
+ "Type": "Ethernet"
+ },
+ {
+ "ConnectionState": "Connected",
+ "GUID": "stub_wifi1",
+ "Name": "wifi1",
+ "Type": "WiFi",
+ "WiFi": {
+ "SSID": "stub_wifi1",
+ "Type": "WiFi"
+ }
+ },
+ {
+ "ConnectionState": "NotConnected",
+ "GUID": "stub_wifi2",
+ "Name": "wifi2_PSK",
+ "Type": "WiFi",
+ "WiFi": {
+ "SSID": "stub_wifi2",
+ "Type": "WiFi"
+ }
+ },
+ {
+ "ConnectionState": "NotConnected",
+ "GUID": "stub_cellular1",
+ "Name": "cellular1",
+ "Type": "Cellular"
+ }
+ ], result);
+ }));
+}
+
+function getVisibleNetworksWifi() {
+ chrome.networkingPrivate.getVisibleNetworks(
+ "WiFi",
+ callbackPass(function(result) {
+ assertTrue(!!result);
+ assertEq(2, result.length);
+ assertEq([{
+ "ConnectionState": "Connected",
+ "GUID": "stub_wifi1",
+ "Name": "wifi1",
+ "Type": "WiFi",
+ "WiFi": {
+ "SSID": "stub_wifi1",
+ "Type": "WiFi"
+ }
+ },
+ {
+ "ConnectionState": "NotConnected",
+ "GUID": "stub_wifi2",
+ "Name": "wifi2_PSK",
+ "Type": "WiFi",
+ "WiFi": {
+ "SSID": "stub_wifi2",
+ "Type": "WiFi"
+ }
+ }
+ ], result);
+ }));
+}
+
+function getProperties() {
+ chrome.networkingPrivate.getProperties(
+ "stub_wifi2",
+ callbackPass(function(result) {
+ assertTrue(!!result);
+ assertEq("wifi2_PSK", result.Name);
+ assertEq("NotConnected", result.ConnectionState);
+ assertEq("WiFi", result.Type);
+ }));
+}
+
+function onNetworksChangedEvent() {
+ var network = "stub_wifi2";
+ var done = chrome.test.callbackAdded();
+ var listener = new privateHelpers.connectListener(network, done);
+ chrome.networkingPrivate.onNetworksChanged.addListener(
+ listener.watchForConnect);
+ chrome.networkingPrivate.startConnect(network,
+ callbackPass(function() {}));
+}
+
+function onNetworkListChangedEvent() {
+ var network = "stub_wifi2";
+ var expected = ["stub_wifi2","stub_ethernet", "stub_wifi1", "stub_cellular1"];
+ var done = chrome.test.callbackAdded();
+ var listener = new privateHelpers.listListener(network, expected, done);
+ chrome.networkingPrivate.onNetworkListChanged.addListener(
+ listener.listenForChanges);
+ chrome.networkingPrivate.startConnect(network,
+ callbackPass(function() {}));
+}
+
+var testToRun = window.location.search.substring(1);
+chrome.test.runTests([window[testToRun]]);

Powered by Google App Engine
This is Rietveld 408576698