| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains various mock objects for the chrome platform to make | 5 // This file contains various mock objects for the chrome platform to make |
| 6 // unit testing easier. | 6 // unit testing easier. |
| 7 | 7 |
| 8 Entry = function() {}; | 8 Entry = function() {}; |
| 9 | 9 |
| 10 (function(scope){ | 10 (function(scope){ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 chromeMocks.Event.prototype.removeListener = function(callback) { | 22 chromeMocks.Event.prototype.removeListener = function(callback) { |
| 23 for (var i = 0; i < this.listeners_.length; i++) { | 23 for (var i = 0; i < this.listeners_.length; i++) { |
| 24 if (this.listeners_[i] === callback) { | 24 if (this.listeners_[i] === callback) { |
| 25 this.listeners_.splice(i, 1); | 25 this.listeners_.splice(i, 1); |
| 26 break; | 26 break; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 chromeMocks.Event.prototype.mock$fire = function(data) { | 31 chromeMocks.Event.prototype.mock$fire = function(var_args) { |
| 32 var params = Array.prototype.slice.call(arguments); |
| 32 this.listeners_.forEach(function(listener){ | 33 this.listeners_.forEach(function(listener){ |
| 33 listener(data); | 34 listener.apply(null, params); |
| 34 }); | 35 }); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 chromeMocks.runtime = {}; | 38 chromeMocks.runtime = {}; |
| 38 | 39 |
| 39 chromeMocks.runtime.Port = function() { | 40 chromeMocks.runtime.Port = function() { |
| 40 this.onMessage = new chromeMocks.Event(); | 41 this.onMessage = new chromeMocks.Event(); |
| 41 this.onDisconnect = new chromeMocks.Event(); | 42 this.onDisconnect = new chromeMocks.Event(); |
| 42 | 43 |
| 43 this.name = ''; | 44 this.name = ''; |
| 44 this.sender = null; | 45 this.sender = null; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 chromeMocks.runtime.Port.prototype.disconnect = function() {}; | 48 chromeMocks.runtime.Port.prototype.disconnect = function() {}; |
| 48 chromeMocks.runtime.Port.prototype.postMessage = function() {}; | 49 chromeMocks.runtime.Port.prototype.postMessage = function() {}; |
| 49 | 50 |
| 51 chromeMocks.runtime.onMessage = new chromeMocks.Event(); |
| 52 chromeMocks.runtime.sendMessage = function(extensionId, message, |
| 53 responseCallback) { |
| 54 if (!extensionId) { |
| 55 extensionId = chromeMocks.runtime.id; |
| 56 } |
| 57 |
| 58 window.requestAnimationFrame(function(){ |
| 59 chromeMocks.runtime.onMessage.mock$fire(message, {id: extensionId}, |
| 60 responseCallback); |
| 61 }); |
| 62 }; |
| 63 |
| 64 chromeMocks.runtime.id = 'extensionId'; |
| 65 |
| 50 chromeMocks.storage = {}; | 66 chromeMocks.storage = {}; |
| 51 | 67 |
| 52 // Sample implementation of chrome.StorageArea according to | 68 // Sample implementation of chrome.StorageArea according to |
| 53 // https://developer.chrome.com/apps/storage#type-StorageArea | 69 // https://developer.chrome.com/apps/storage#type-StorageArea |
| 54 chromeMocks.StorageArea = function() { | 70 chromeMocks.StorageArea = function() { |
| 55 this.storage_ = {}; | 71 this.storage_ = {}; |
| 56 }; | 72 }; |
| 57 | 73 |
| 58 function deepCopy(value) { | 74 function deepCopy(value) { |
| 59 return JSON.parse(JSON.stringify(value)); | 75 return JSON.parse(JSON.stringify(value)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 143 } |
| 128 for (var components in originals_) { | 144 for (var components in originals_) { |
| 129 chrome[components] = originals_[components]; | 145 chrome[components] = originals_[components]; |
| 130 } | 146 } |
| 131 originals_ = null; | 147 originals_ = null; |
| 132 }; | 148 }; |
| 133 | 149 |
| 134 scope.chromeMocks = chromeMocks; | 150 scope.chromeMocks = chromeMocks; |
| 135 | 151 |
| 136 })(window); | 152 })(window); |
| OLD | NEW |