Debian Codegraph @

closure-library/closure/goog/testing/events/onlinehandler.js

raw
1 // Copyright 2012 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview NetworkStatusMonitor test double.
17 * @author [email protected] (David Barrett-Kahn)
18 */
19
20 goog.setTestOnly('goog.testing.events.OnlineHandler');
21 goog.provide('goog.testing.events.OnlineHandler');
22
23 goog.require('goog.events.EventTarget');
24 goog.require('goog.net.NetworkStatusMonitor');
25
26
27
28 /**
29 * NetworkStatusMonitor test double.
30 * @param {boolean} initialState The initial online state of the mock.
31 * @constructor
32 * @extends {goog.events.EventTarget}
33 * @implements {goog.net.NetworkStatusMonitor}
34 * @final
35 */
36 goog.testing.events.OnlineHandler = function(initialState) {
37 goog.testing.events.OnlineHandler.base(this, 'constructor');
38
39 /**
40 * Whether the mock is online.
41 * @private {boolean}
42 */
43 this.online_ = initialState;
44 };
45 goog.inherits(goog.testing.events.OnlineHandler, goog.events.EventTarget);
46
47
48 /** @override */
49 goog.testing.events.OnlineHandler.prototype.isOnline = function() {
50 return this.online_;
51 };
52
53
54 /**
55 * Sets the online state.
56 * @param {boolean} newOnlineState The new online state.
57 */
58 goog.testing.events.OnlineHandler.prototype.setOnline = function(
59 newOnlineState) {
60 if (newOnlineState != this.online_) {
61 this.online_ = newOnlineState;
62 this.dispatchEvent(
63 newOnlineState ? goog.net.NetworkStatusMonitor.EventType.ONLINE :
64 goog.net.NetworkStatusMonitor.EventType.OFFLINE);
65 }
66 };