aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/testing/events/onlinehandler.js
blob: b135a0558e37cc2d9cf88ba730be025b0bf5d9ea (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
//
// Licensed 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.

/**
 * @fileoverview Mock of OnlineHandler for unit testing.
 * @author dbk@google.com (David Barrett-Kahn)
 */

goog.provide('goog.testing.events.OnlineHandler');

goog.require('goog.events.EventTarget');
goog.require('goog.events.OnlineHandler.EventType');



/**
 * Mock implementation of goog.events.OnlineHandler.
 * @param {boolean} initialState The initial online state of the mock.
 * @constructor
 * @extends {goog.events.EventTarget}
 */
goog.testing.events.OnlineHandler = function(initialState) {
  goog.base(this);

  /**
   * Whether the mock is online.
   * @type {boolean}
   * @private
   */
  this.online_ = initialState;
};
goog.inherits(goog.testing.events.OnlineHandler, goog.events.EventTarget);


/**
 * Mock implementation of goog.events.OnlineHandler.isOnline.
 * @return {boolean} Whether the mock is online.
 */
goog.testing.events.OnlineHandler.prototype.isOnline = function() {
  return this.online_;
};


/**
 * Sets the online state.
 * @param {boolean} newOnlineState The new online state.
 */
goog.testing.events.OnlineHandler.prototype.setOnline =
    function(newOnlineState) {
  if (newOnlineState != this.online_) {
    this.online_ = newOnlineState;
    this.dispatchEvent(newOnlineState ?
        goog.events.OnlineHandler.EventType.ONLINE :
        goog.events.OnlineHandler.EventType.OFFLINE);
  }
};