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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {
updateCanDebugWorkers,
updateWorkers,
} = require("resource://devtools/client/application/src/actions/workers.js");
const {
START_WORKER,
UNREGISTER_WORKER,
} = require("resource://devtools/client/application/src/constants.js");
const {
workersReducer,
WorkersState,
} = require("resource://devtools/client/application/src/reducers/workers-state.js");
add_task(async function () {
info("Test workers reducer: UPDATE_CAN_DEBUG_WORKERS action");
function testUpdateCanDebugWorkers(flagValue) {
const state = WorkersState();
const action = updateCanDebugWorkers(flagValue);
const newState = workersReducer(state, action);
equal(
newState.canDebugWorkers,
flagValue,
"canDebugWorkers contains the expected value"
);
}
testUpdateCanDebugWorkers(false);
testUpdateCanDebugWorkers(true);
});
add_task(async function () {
info("Test workers reducer: UPDATE_WORKERS action");
const state = WorkersState();
const rawData = [
{
registration: {
scope: "lorem-ipsum",
lastUpdateTime: 42,
id: "r1",
},
workers: [
{
id: "w1",
state: Ci.nsIServiceWorkerInfo.STATE_ACTIVATED,
url: "https://example.com/w1.js",
workerDescriptorFront: { foo: "bar" },
stateText: "activated",
},
{
id: "w2",
state: Ci.nsIServiceWorkerInfo.STATE_INSTALLED,
url: "https://example.com/w2.js",
workerDescriptorFront: undefined,
stateText: "installed",
},
],
},
];
const expectedData = [
{
id: "r1",
lastUpdateTime: 42,
registrationFront: rawData[0].registration,
scope: "lorem-ipsum",
workers: [
{
id: "w1",
url: "https://example.com/w1.js",
workerDescriptorFront: rawData[0].workers[0].workerDescriptorFront,
registrationFront: rawData[0].registration,
state: Ci.nsIServiceWorkerInfo.STATE_ACTIVATED,
stateText: "activated",
},
{
id: "w2",
url: "https://example.com/w2.js",
workerDescriptorFront: undefined,
registrationFront: rawData[0].registration,
state: Ci.nsIServiceWorkerInfo.STATE_INSTALLED,
stateText: "installed",
},
],
},
];
const action = updateWorkers(rawData);
const newState = workersReducer(state, action);
deepEqual(newState.list, expectedData, "workers contains the expected list");
});
add_task(async function () {
info("Test workers reducer: START_WORKER action");
const state = WorkersState();
const action = { type: START_WORKER };
const newState = workersReducer(state, action);
deepEqual(state, newState, "workers state stays the same");
});
add_task(async function () {
info("Test workers reducer: UNREGISTER_WORKER action");
const state = WorkersState();
const action = { type: UNREGISTER_WORKER };
const newState = workersReducer(state, action);
deepEqual(state, newState, "workers state stays the same");
});
|