OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Fake implementation of chrome.networkingPrivate for testing. |
| 7 */ |
| 8 cr.define('settings', function() { |
| 9 /** |
| 10 * @constructor |
| 11 * @implements {NetworkingPrivate} |
| 12 */ |
| 13 function FakeNetworkingPrivate() { |
| 14 /** @type {!Object<chrome.networkingPrivate.DeviceStateProperties>} */ |
| 15 this.deviceStates_ = {}; |
| 16 |
| 17 /** @type {!Array<!CrOnc.NetworkStateProperties>} */ |
| 18 this.networkStates_ = []; |
| 19 |
| 20 /** @type {!{chrome.networkingPrivate.GlobalPolicy}} */ |
| 21 this.globalPolicy_ = {}; |
| 22 |
| 23 this.resetForTest(); |
| 24 } |
| 25 |
| 26 FakeNetworkingPrivate.prototype = { |
| 27 resetForTest() { |
| 28 this.deviceStates_ = { |
| 29 Ethernet: {Type: 'Ethernet', State: 'Enabled'}, |
| 30 WiFi: {Type: 'WiFi', State: ''}, |
| 31 Cellular: {Type: 'Cellular', State: ''}, |
| 32 WiMAX: {Type: 'WiMAX', State: ''}, |
| 33 }; |
| 34 |
| 35 this.networkStates_ = [ |
| 36 {GUID: 'eth0_guid', Type: 'Ethernet'}, |
| 37 ]; |
| 38 |
| 39 this.globalPolicy_ = {}; |
| 40 }, |
| 41 |
| 42 /** @param {!Array<!CrOnc.NetworkStateProperties>} network */ |
| 43 addNetworksForTest: function(networks) { |
| 44 this.networkStates_ = this.networkStates_.concat(networks); |
| 45 }, |
| 46 |
| 47 /** |
| 48 * @param {string} type |
| 49 * @return {?chrome.networkingPrivate.DeviceStateProperties} |
| 50 */ |
| 51 getDeviceStateForTest: function(type) { |
| 52 return this.deviceStates_[type] || null; |
| 53 }, |
| 54 |
| 55 /** @override */ |
| 56 getProperties: assertNotReached, |
| 57 |
| 58 /** @override */ |
| 59 getManagedProperties: assertNotReached, |
| 60 |
| 61 /** @override */ |
| 62 getState: assertNotReached, |
| 63 |
| 64 /** @override */ |
| 65 setProperties: assertNotReached, |
| 66 |
| 67 /** @override */ |
| 68 createNetwork: assertNotReached, |
| 69 |
| 70 /** @override */ |
| 71 forgetNetwork: assertNotReached, |
| 72 |
| 73 /** @override */ |
| 74 getNetworks: function(filter, callback) { |
| 75 callback(this.networkStates_); |
| 76 }, |
| 77 |
| 78 /** @override */ |
| 79 getDeviceStates: function(callback) { |
| 80 var devices = []; |
| 81 Object.keys(this.deviceStates_).forEach(function(type) { |
| 82 var state = this.deviceStates_[type]; |
| 83 if (state.State != '') |
| 84 devices.push(state); |
| 85 }.bind(this)); |
| 86 callback(devices); |
| 87 }, |
| 88 |
| 89 /** @override */ |
| 90 enableNetworkType: function(type) { |
| 91 this.deviceStates_[type].State = 'Enabled'; |
| 92 this.onDeviceStateListChanged.callListeners(); |
| 93 }, |
| 94 |
| 95 /** @override */ |
| 96 disableNetworkType: function(type) { |
| 97 this.deviceStates_[type].State = 'Disabled'; |
| 98 this.onDeviceStateListChanged.callListeners(); |
| 99 }, |
| 100 |
| 101 /** @override */ |
| 102 requestNetworkScan: function() {}, |
| 103 |
| 104 /** @override */ |
| 105 startConnect: assertNotReached, |
| 106 |
| 107 /** @override */ |
| 108 startDisconnect: assertNotReached, |
| 109 |
| 110 /** @override */ |
| 111 startActivate: assertNotReached, |
| 112 |
| 113 /** @override */ |
| 114 verifyDestination: assertNotReached, |
| 115 |
| 116 /** @override */ |
| 117 verifyAndEncryptCredentials: assertNotReached, |
| 118 |
| 119 /** @override */ |
| 120 verifyAndEncryptData: assertNotReached, |
| 121 |
| 122 /** @override */ |
| 123 setWifiTDLSEnabledState: assertNotReached, |
| 124 |
| 125 /** @override */ |
| 126 getWifiTDLSStatus: assertNotReached, |
| 127 |
| 128 /** @override */ |
| 129 getCaptivePortalStatus: assertNotReached, |
| 130 |
| 131 /** @override */ |
| 132 unlockCellularSim: assertNotReached, |
| 133 |
| 134 /** @override */ |
| 135 setCellularSimState: assertNotReached, |
| 136 |
| 137 /** @override */ |
| 138 getGlobalPolicy: function(callback) { |
| 139 callback(this.globalPolicy_); |
| 140 }, |
| 141 |
| 142 /** @type {!FakeChromeEvent} */ |
| 143 onNetworksChanged: new FakeChromeEvent(), |
| 144 |
| 145 /** @type {!FakeChromeEvent} */ |
| 146 onNetworkListChanged: new FakeChromeEvent(), |
| 147 |
| 148 /** @type {!FakeChromeEvent} */ |
| 149 onDeviceStateListChanged: new FakeChromeEvent(), |
| 150 |
| 151 /** @type {!FakeChromeEvent} */ |
| 152 onPortalDetectionCompleted: new FakeChromeEvent(), |
| 153 }; |
| 154 |
| 155 return {FakeNetworkingPrivate: FakeNetworkingPrivate}; |
| 156 }); |
OLD | NEW |