| 1 |
// Copyright 2007 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 Definition of goog.ui.MockActivityMonitor. |
| 17 |
*/ |
| 18 |
|
| 19 |
goog.provide('goog.ui.MockActivityMonitor'); |
| 20 |
|
| 21 |
goog.require('goog.events.EventType'); |
| 22 |
goog.require('goog.ui.ActivityMonitor'); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* A mock implementation of goog.ui.ActivityMonitor for unit testing. Clients |
| 28 |
* of this class should override goog.now to return a synthetic time from |
| 29 |
* the unit test. |
| 30 |
* @constructor |
| 31 |
* @extends {goog.ui.ActivityMonitor} |
| 32 |
* @final |
| 33 |
*/ |
| 34 |
goog.ui.MockActivityMonitor = function() { |
| 35 |
goog.ui.MockActivityMonitor.base(this, 'constructor'); |
| 36 |
|
| 37 |
/** |
| 38 |
* Tracks whether an event has been fired. Used by simulateEvent. |
| 39 |
* @type {boolean} |
| 40 |
* @private |
| 41 |
*/ |
| 42 |
this.eventFired_ = false; |
| 43 |
}; |
| 44 |
goog.inherits(goog.ui.MockActivityMonitor, goog.ui.ActivityMonitor); |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* Simulates an event that updates the user to being non-idle. |
| 49 |
* @param {goog.events.EventType=} opt_type The type of event that made the user |
| 50 |
* not idle. If not specified, defaults to MOUSEMOVE. |
| 51 |
*/ |
| 52 |
goog.ui.MockActivityMonitor.prototype.simulateEvent = function(opt_type) { |
| 53 |
var eventTime = goog.now(); |
| 54 |
var eventType = opt_type || goog.events.EventType.MOUSEMOVE; |
| 55 |
|
| 56 |
this.eventFired_ = false; |
| 57 |
this.updateIdleTime(eventTime, eventType); |
| 58 |
|
| 59 |
if (!this.eventFired_) { |
| 60 |
this.dispatchEvent(goog.ui.ActivityMonitor.Event.ACTIVITY); |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
/** |
| 66 |
* @override |
| 67 |
*/ |
| 68 |
goog.ui.MockActivityMonitor.prototype.dispatchEvent = function(e) { |
| 69 |
var rv = goog.ui.MockActivityMonitor.base(this, 'dispatchEvent', e); |
| 70 |
this.eventFired_ = true; |
| 71 |
return rv; |
| 72 |
}; |