mockactivitymonitor.js 2.1 KB

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