1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | exports.defineAutoTests = function () {
|
26 | describe('Network (navigator.connection)', function () {
|
27 | it("network.spec.1 should exist", function () {
|
28 | expect(navigator.network && navigator.network.connection).toBeDefined();
|
29 | expect(navigator.connection).toBeDefined();
|
30 | });
|
31 |
|
32 | it("network.spec.2 should be set to a valid value", function () {
|
33 | var validValues = {
|
34 | 'unknown': 1,
|
35 | 'ethernet': 1,
|
36 | 'wifi': 1,
|
37 | '2g': 1,
|
38 | 'cellular': 1,
|
39 | '3g': 1,
|
40 | '4g': 1,
|
41 | 'none': 1
|
42 | };
|
43 | expect(validValues[navigator.connection.type]).toBe(1);
|
44 | });
|
45 |
|
46 | it("network.spec.3 should have the same value in deprecated and non-deprecated apis", function () {
|
47 | expect(navigator.network.connection.type).toBe(navigator.connection.type);
|
48 | });
|
49 |
|
50 | it("network.spec.4 should define constants for connection status", function () {
|
51 | expect(Connection.UNKNOWN).toBe("unknown");
|
52 | expect(Connection.ETHERNET).toBe("ethernet");
|
53 | expect(Connection.WIFI).toBe("wifi");
|
54 | expect(Connection.CELL_2G).toBe("2g");
|
55 | expect(Connection.CELL_3G).toBe("3g");
|
56 | expect(Connection.CELL_4G).toBe("4g");
|
57 | expect(Connection.NONE).toBe("none");
|
58 | expect(Connection.CELL).toBe("cellular");
|
59 | });
|
60 | });
|
61 | };
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | exports.defineManualTests = function (contentEl, createActionButton) {
|
68 | function eventOutput(s) {
|
69 | var el = document.getElementById("results");
|
70 | el.innerHTML = el.innerHTML + s + "<br>";
|
71 | }
|
72 |
|
73 | function printNetwork() {
|
74 | eventOutput("navigator.connection.type=" + navigator.connection.type);
|
75 | eventOutput("navigator.network.connection.type=" + navigator.network.connection.type);
|
76 | }
|
77 |
|
78 | function onEvent(e) {
|
79 | eventOutput('Event of type: ' + e.type);
|
80 | printNetwork();
|
81 | }
|
82 |
|
83 |
|
84 |
|
85 | var html = '<div id="info">' +
|
86 | '<b>Results:</b><br>' +
|
87 | '<span id="results"></span>' +
|
88 | '</div><div id="connection"></div>' +
|
89 | 'Expected result: Status box will update with type of connection using two different methods. Both values must match.' +
|
90 | ' The result will be unknown, ethernet, wifi, 2g, 3g, 4g, none, or cellular. Make sure it matches what the device is connected to.' +
|
91 | '</p> <div id="actions"></div>';
|
92 |
|
93 | document.addEventListener("online", onEvent, false);
|
94 | document.addEventListener("offline", onEvent, false);
|
95 | contentEl.innerHTML = html;
|
96 |
|
97 | createActionButton('Show Network Connection', function () {
|
98 | printNetwork();
|
99 | }, 'connection');
|
100 |
|
101 | createActionButton('Clear Log', function () {
|
102 | document.getElementById('results').innerHTML = '';
|
103 | }, 'actions');
|
104 | };
|