1// Copyright 2014 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// This file contains various mock objects for the chrome platform to make
6// unit testing easier.
7
8(function(scope){
9
10var chromeMocks = {};
11
12chromeMocks.Event = function() {
13  this.listeners_ = [];
14};
15
16chromeMocks.Event.prototype.addListener = function(callback) {
17  this.listeners_.push(callback);
18};
19
20chromeMocks.Event.prototype.removeListener = function(callback) {
21  for (var i = 0; i < this.listeners_.length; i++) {
22    if (this.listeners_[i] === callback) {
23      this.listeners_.splice(i, 1);
24      break;
25    }
26  }
27};
28
29chromeMocks.Event.prototype.mock$fire = function(data) {
30  this.listeners_.forEach(function(listener){
31    listener(data);
32  });
33};
34
35chromeMocks.runtime = {};
36
37chromeMocks.runtime.Port = function() {
38  this.onMessage = new chromeMocks.Event();
39  this.onDisconnect = new chromeMocks.Event();
40
41  this.name = '';
42  this.sender = null;
43};
44
45chromeMocks.runtime.Port.prototype.disconnect = function() {};
46chromeMocks.runtime.Port.prototype.postMessage = function() {};
47
48scope.chromeMocks = chromeMocks;
49
50})(window);
51