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.
5 // This file contains various mock objects for the chrome platform to make
6 // unit testing easier.
12 chromeMocks.Event = function() {
16 chromeMocks.Event.prototype.addListener = function(callback) {
17 this.listeners_.push(callback);
20 chromeMocks.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);
29 chromeMocks.Event.prototype.mock$fire = function(data) {
30 this.listeners_.forEach(function(listener){
35 chromeMocks.runtime = {};
37 chromeMocks.runtime.Port = function() {
38 this.onMessage = new chromeMocks.Event();
39 this.onDisconnect = new chromeMocks.Event();
45 chromeMocks.runtime.Port.prototype.disconnect = function() {};
46 chromeMocks.runtime.Port.prototype.postMessage = function() {};
48 scope.chromeMocks = chromeMocks;