forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-mockup.js
More file actions
225 lines (204 loc) · 4.6 KB
/
test-mockup.js
File metadata and controls
225 lines (204 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
/**
* This file is for use by unit tests for isolated debugger components that do
* not need to interact with the redux store. When these tests need to construct
* debugger objects, these interfaces should be used instead of plain object
* literals.
*/
import type {
ActorId,
Breakpoint,
Expression,
Frame,
FrameId,
Scope,
Source,
SourceId,
SourceWithContentAndType,
SourceWithContent,
TextSourceContent,
WasmSourceContent,
Why
} from "../types";
import * as asyncValue from "./async-value";
function makeMockSource(url: string = "url", id: SourceId = "source"): Source {
return {
id,
url,
isBlackBoxed: false,
isPrettyPrinted: false,
relativeUrl: url,
introductionUrl: null,
introductionType: undefined,
isWasm: false,
isExtension: false
};
}
function makeMockSourceWithContent(
url?: string,
id?: SourceId,
contentType?: string = "text/javascript",
text?: string = ""
): SourceWithContent {
const source = makeMockSource(url, id);
return {
source,
content: text
? asyncValue.fulfilled({
type: "text",
value: text,
contentType
})
: null
};
}
function makeMockSourceAndContent(
url?: string,
id?: SourceId,
contentType?: string = "text/javascript",
text: string = ""
): { source: Source, content: TextSourceContent } {
const source = makeMockSource(url, id);
return {
source,
content: {
type: "text",
value: text,
contentType
}
};
}
function makeMockWasmSource(): Source {
return {
id: "wasm-source-id",
url: "url",
isBlackBoxed: false,
isPrettyPrinted: false,
relativeUrl: "url",
introductionUrl: null,
introductionType: undefined,
isWasm: true,
isExtension: false
};
}
function makeMockWasmSourceWithContent(text: {|
binary: Object
|}): SourceWithContentAndType<WasmSourceContent> {
const source = makeMockWasmSource();
return {
source,
content: asyncValue.fulfilled({
type: "wasm",
value: text
})
};
}
function makeMockScope(
actor: ActorId = "scope-actor",
type: string = "block",
parent: ?Scope = null
): Scope {
return {
actor,
parent,
bindings: {
arguments: [],
variables: {}
},
object: null,
function: null,
type
};
}
function mockScopeAddVariable(scope: Scope, name: string) {
if (!scope.bindings) {
throw new Error("no scope bindings");
}
scope.bindings.variables[name] = { value: null };
}
function makeMockBreakpoint(
source: Source = makeMockSource(),
line: number = 1,
column: ?number
): Breakpoint {
const location = column
? { sourceId: source.id, line, column }
: { sourceId: source.id, line };
return {
id: "breakpoint",
location,
astLocation: null,
generatedLocation: location,
disabled: false,
text: "text",
originalText: "text",
options: {}
};
}
function makeMockFrame(
id: FrameId = "frame",
source: Source = makeMockSource("url"),
scope: Scope = makeMockScope(),
line: number = 4,
displayName: string = `display-${id}`
): Frame {
const location = { sourceId: source.id, line };
return {
id,
thread: "FakeThread",
displayName,
location,
generatedLocation: location,
source,
scope,
this: {}
};
}
function makeMockFrameWithURL(url: string): Frame {
return makeMockFrame(undefined, makeMockSource(url));
}
function makeWhyNormal(frameReturnValue: any = undefined): Why {
if (frameReturnValue) {
return { type: "why-normal", frameFinished: { return: frameReturnValue } };
}
return { type: "why-normal" };
}
function makeWhyThrow(frameThrowValue: any): Why {
return { type: "why-throw", frameFinished: { throw: frameThrowValue } };
}
function makeMockExpression(value: Object): Expression {
return {
input: "input",
value,
from: "from",
updating: false
};
}
// Mock contexts for use in tests that do not create a redux store.
const mockcx = { navigateCounter: 0 };
const mockthreadcx = {
navigateCounter: 0,
thread: "FakeThread",
pauseCounter: 0,
isPaused: false
};
export {
makeMockSource,
makeMockSourceWithContent,
makeMockSourceAndContent,
makeMockWasmSource,
makeMockWasmSourceWithContent,
makeMockScope,
mockScopeAddVariable,
makeMockBreakpoint,
makeMockFrame,
makeMockFrameWithURL,
makeWhyNormal,
makeWhyThrow,
makeMockExpression,
mockcx,
mockthreadcx
};