aboutsummaryrefslogtreecommitdiff
path: root/node_modules/selenium-webdriver/test/net
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-03 01:33:53 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-03 01:33:53 +0100
commitd1291f67551c58168af43698a359cb5ddfd266b0 (patch)
tree55a13ed29fe1915e3f42f1b1b7038dafa2e975a7 /node_modules/selenium-webdriver/test/net
parentd0a0695fb5d34996850723f7d4b1b59c3df909c2 (diff)
node_modules
Diffstat (limited to 'node_modules/selenium-webdriver/test/net')
-rw-r--r--node_modules/selenium-webdriver/test/net/index_test.js60
-rw-r--r--node_modules/selenium-webdriver/test/net/portprober_test.js129
2 files changed, 189 insertions, 0 deletions
diff --git a/node_modules/selenium-webdriver/test/net/index_test.js b/node_modules/selenium-webdriver/test/net/index_test.js
new file mode 100644
index 000000000..88c52c063
--- /dev/null
+++ b/node_modules/selenium-webdriver/test/net/index_test.js
@@ -0,0 +1,60 @@
+// Licensed to the Software Freedom Conservancy (SFC) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The SFC licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+'use strict';
+
+var assert = require('assert');
+
+var net = require('../../net');
+
+describe('net.splitHostAndPort', function() {
+ it('hostname with no port', function() {
+ assert.deepEqual(
+ net.splitHostAndPort('www.example.com'),
+ {host: 'www.example.com', port: null});
+ });
+
+ it('hostname with port', function() {
+ assert.deepEqual(
+ net.splitHostAndPort('www.example.com:80'),
+ {host: 'www.example.com', port: 80});
+ });
+
+ it('IPv4 with no port', function() {
+ assert.deepEqual(
+ net.splitHostAndPort('127.0.0.1'),
+ {host: '127.0.0.1', port: null});
+ });
+
+ it('IPv4 with port', function() {
+ assert.deepEqual(
+ net.splitHostAndPort('127.0.0.1:1234'),
+ {host: '127.0.0.1', port: 1234});
+ });
+
+ it('IPv6 with no port', function() {
+ assert.deepEqual(
+ net.splitHostAndPort('1234:0:1000:5768:1234:5678:90'),
+ {host: '1234:0:1000:5768:1234:5678:90', port: null});
+ });
+
+ it('IPv6 with port', function() {
+ assert.deepEqual(
+ net.splitHostAndPort('[1234:0:1000:5768:1234:5678:90]:1234'),
+ {host: '1234:0:1000:5768:1234:5678:90', port: 1234});
+ });
+});
diff --git a/node_modules/selenium-webdriver/test/net/portprober_test.js b/node_modules/selenium-webdriver/test/net/portprober_test.js
new file mode 100644
index 000000000..03a2f7a10
--- /dev/null
+++ b/node_modules/selenium-webdriver/test/net/portprober_test.js
@@ -0,0 +1,129 @@
+// Licensed to the Software Freedom Conservancy (SFC) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The SFC licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+'use strict';
+
+var assert = require('assert'),
+ net = require('net');
+
+var promise = require('../..').promise,
+ portprober = require('../../net/portprober');
+
+describe('isFree', function() {
+
+ var server;
+
+ beforeEach(function() {
+ server = net.createServer(function(){});
+ })
+
+ afterEach(function(done) {
+ if (!server) return done();
+ server.close(function() {
+ done();
+ });
+ });
+
+ it('should work for INADDR_ANY', function(done) {
+ server.listen(0, function() {
+ var port = server.address().port;
+ assertPortNotfree(port).then(function() {
+ var done = promise.defer();
+ server.close(function() {
+ server = null;
+ done.fulfill(assertPortIsFree(port));
+ });
+ return done.promise;
+ }).then(function() { done(); }, done);
+ });
+ });
+
+ it('should work for a specific host', function(done) {
+ var host = '127.0.0.1';
+ server.listen(0, host, function() {
+ var port = server.address().port;
+ assertPortNotfree(port, host).then(function() {
+ var done = promise.defer();
+ server.close(function() {
+ server = null;
+ done.fulfill(assertPortIsFree(port, host));
+ });
+ return done.promise;
+ }).then(function() { done(); }, done);
+ });
+ });
+});
+
+describe('findFreePort', function() {
+ var server;
+
+ beforeEach(function() {
+ server = net.createServer(function(){});
+ })
+
+ afterEach(function(done) {
+ if (!server) return done();
+ server.close(function() {
+ done();
+ });
+ });
+
+ it('should work for INADDR_ANY', function(done) {
+ portprober.findFreePort().then(function(port) {
+ server.listen(port, function() {
+ assertPortNotfree(port).then(function() {
+ var done = promise.defer();
+ server.close(function() {
+ server = null;
+ done.fulfill(assertPortIsFree(port));
+ });
+ return done.promise;
+ }).then(function() { done(); }, done);
+ });
+ });
+ });
+
+ it('should work for a specific host', function(done) {
+ var host = '127.0.0.1';
+ portprober.findFreePort(host).then(function(port) {
+ server.listen(port, host, function() {
+ assertPortNotfree(port, host).then(function() {
+ var done = promise.defer();
+ server.close(function() {
+ server = null;
+ done.fulfill(assertPortIsFree(port, host));
+ });
+ return done.promise;
+ }).then(function() { done(); }, done);
+ });
+ });
+ });
+});
+
+
+function assertPortIsFree(port, opt_host) {
+ return portprober.isFree(port, opt_host).then(function(free) {
+ assert.ok(free, 'port should be free');
+ });
+}
+
+
+function assertPortNotfree(port, opt_host) {
+ return portprober.isFree(port, opt_host).then(function(free) {
+ assert.ok(!free, 'port should is not free');
+ });
+}