comparison js/modules/mocks.js @ 99:544d339d2b4c

Added the beginnings of a black-box app that can be used to generate/run functional tests.
author Atul Varma <avarma@mozilla.com>
date Tue, 27 Apr 2010 09:59:15 -0700
parents 51c1829956d9
children c486d35fad27
comparison
equal deleted inserted replaced
98:97fc889dbed4 99:544d339d2b4c
1 Require.modules["mocks"] = function(exports, require) { 1 Require.modules["mocks/cache"] = function(exports, require) {
2 function copy(obj) {
3 return JSON.parse(JSON.stringify(obj));
4 }
5
6 function MockCache() {
7 this.cache = {};
8 };
9
10 MockCache.prototype = {
11 get: function get(key) {
12 console.log("cache get", key);
13 if (key in this.cache)
14 return copy(this.cache[key]);
15 return null;
16 },
17 set: function set(key, value) {
18 console.log("cache set", key);
19 this.cache[key] = copy(value);
20 },
21 clear: function clear(key, value) {
22 this.cache = {};
23 }
24 };
25
26 exports.create = function create() {
27 return new MockCache();
28 };
29 };
30
31 Require.modules["mocks/bugzilla"] = function(exports, require) {
32 exports.create = function create(Bugzilla) {
33 function MockBugzilla() {
34 this.ajax = function ajax(options) {
35 console.log(options);
36 throw new Error("MockBugzilla.ajax() not implemented");
37 };
38 };
39
40 MockBugzilla.prototype = Bugzilla;
41
42 return new MockBugzilla();
43 };
44 };
45
46 Require.modules["mocks/xhr"] = function(exports, require) {
2 function MockXMLHttpRequest(delegate) { 47 function MockXMLHttpRequest(delegate) {
3 var self = this; 48 var self = this;
4 49
5 var listeners = { 50 var listeners = {
6 "load": [], 51 "load": [],
48 listener(event); 93 listener(event);
49 }); 94 });
50 }; 95 };
51 } 96 }
52 97
53 exports.xhr = function xhr(delegate) { 98 exports.create = function create(delegate) {
54 return new MockXMLHttpRequest(delegate); 99 return new MockXMLHttpRequest(delegate);
55 }; 100 };
56 }; 101 };