diff --git a/test/tests.js b/test/tests.js index 83f28d3..26163b6 100644 --- a/test/tests.js +++ b/test/tests.js @@ -19,14 +19,14 @@ * */ -exports.defineAutoTests = function() { +exports.defineAutoTests = function () { describe('Network (navigator.connection)', function () { - it("network.spec.1 should exist", function() { + it("network.spec.1 should exist", function () { expect(navigator.network && navigator.network.connection).toBeDefined(); expect(navigator.connection).toBeDefined(); }); - it("network.spec.2 should be set to a valid value", function() { + it("network.spec.2 should be set to a valid value", function () { var validValues = { 'unknown': 1, 'ethernet': 1, @@ -40,11 +40,11 @@ exports.defineAutoTests = function() { expect(validValues[navigator.connection.type]).toBe(1); }); - it("network.spec.3 should have the same value in deprecated and non-deprecated apis", function() { + it("network.spec.3 should have the same value in deprecated and non-deprecated apis", function () { expect(navigator.network.connection.type).toBe(navigator.connection.type); }); - it("network.spec.4 should define constants for connection status", function() { + it("network.spec.4 should define constants for connection status", function () { expect(Connection.UNKNOWN).toBe("unknown"); expect(Connection.ETHERNET).toBe("ethernet"); expect(Connection.WIFI).toBe("wifi"); @@ -56,3 +56,43 @@ exports.defineAutoTests = function() { }); }); }; + +/******************************************************************************/ +/******************************************************************************/ +/******************************************************************************/ + +exports.defineManualTests = function (contentEl, createActionButton) { + function eventOutput(s) { + var el = document.getElementById("results"); + el.innerHTML = el.innerHTML + s + "
"; + } + + function printNetwork() { + eventOutput("navigator.connection.type=" + navigator.connection.type); + eventOutput("navigator.network.connection.type=" + navigator.network.connection.type); + } + + function onEvent(e) { + eventOutput('Event of type: ' + e.type); + printNetwork(); + } + + /******************************************************************************/ + + var html = '
' + + 'Results:
' + + '' + + '
'; + + document.addEventListener("online", onEvent, false); + document.addEventListener("offline", onEvent, false); + contentEl.innerHTML = html; + + createActionButton('Show Network Connection', function () { + printNetwork(); + }, 'actions'); + + createActionButton('Clear Log', function () { + document.getElementById('results').innerHTML = ''; + }, 'actions'); +};