mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 08:18:41 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
17
devtools/client/shared/redux/middleware/test/.eslintrc.js
Normal file
17
devtools/client/shared/redux/middleware/test/.eslintrc.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
// Extend from the shared list of defined globals for mochitests.
|
||||
"extends": "../../../../../.eslintrc.mochitests.js",
|
||||
"globals": {
|
||||
"run_test": true,
|
||||
"run_next_test": true,
|
||||
"equal": true,
|
||||
"do_print": true,
|
||||
"waitUntilState": true
|
||||
},
|
||||
"rules": {
|
||||
// Stop giving errors for run_test
|
||||
"camelcase": "off"
|
||||
}
|
||||
};
|
||||
27
devtools/client/shared/redux/middleware/test/head.js
Normal file
27
devtools/client/shared/redux/middleware/test/head.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* 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/. */
|
||||
|
||||
/* exported waitUntilState */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const flags = require("devtools/shared/flags");
|
||||
|
||||
flags.testing = true;
|
||||
|
||||
function waitUntilState(store, predicate) {
|
||||
return new Promise(resolve => {
|
||||
let unsubscribe = store.subscribe(check);
|
||||
function check() {
|
||||
if (predicate(store.getState())) {
|
||||
unsubscribe();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the check immediately incase the action has already occurred
|
||||
check();
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { createStore, applyMiddleware } = require("devtools/client/shared/vendor/redux");
|
||||
const { task } = require("devtools/client/shared/redux/middleware/task");
|
||||
|
||||
/**
|
||||
* Tests that task middleware allows dispatching generators, promises and objects
|
||||
* that return actions;
|
||||
*/
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
let store = applyMiddleware(task)(createStore)(reducer);
|
||||
|
||||
store.dispatch(fetch1("generator"));
|
||||
yield waitUntilState(store, () => store.getState().length === 1);
|
||||
equal(store.getState()[0].data, "generator",
|
||||
"task middleware async dispatches an action via generator");
|
||||
|
||||
store.dispatch(fetch2("sync"));
|
||||
yield waitUntilState(store, () => store.getState().length === 2);
|
||||
equal(store.getState()[1].data, "sync",
|
||||
"task middleware sync dispatches an action via sync");
|
||||
});
|
||||
|
||||
function fetch1(data) {
|
||||
return function* (dispatch, getState) {
|
||||
equal(getState().length, 0, "`getState` is accessible in a generator action");
|
||||
let moreData = yield new Promise(resolve => resolve(data));
|
||||
// Ensure it handles more than one yield
|
||||
moreData = yield new Promise(resolve => resolve(data));
|
||||
dispatch({ type: "fetch1", data: moreData });
|
||||
};
|
||||
}
|
||||
|
||||
function fetch2(data) {
|
||||
return {
|
||||
type: "fetch2",
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
function reducer(state = [], action) {
|
||||
do_print("Action called: " + action.type);
|
||||
if (["fetch1", "fetch2"].includes(action.type)) {
|
||||
state.push(action);
|
||||
}
|
||||
return [...state];
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Tests that task middleware allows dispatching generators that dispatch
|
||||
* additional sync and async actions.
|
||||
*/
|
||||
|
||||
const { createStore, applyMiddleware } = require("devtools/client/shared/vendor/redux");
|
||||
const { task } = require("devtools/client/shared/redux/middleware/task");
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
let store = applyMiddleware(task)(createStore)(reducer);
|
||||
|
||||
store.dispatch(comboAction());
|
||||
yield waitUntilState(store, () => store.getState().length === 3);
|
||||
|
||||
equal(store.getState()[0].type, "fetchAsync-start",
|
||||
"Async dispatched actions in a generator task are fired");
|
||||
equal(store.getState()[1].type, "fetchAsync-end",
|
||||
"Async dispatched actions in a generator task are fired");
|
||||
equal(store.getState()[2].type, "fetchSync",
|
||||
"Return values of yielded sync dispatched actions are correct");
|
||||
equal(store.getState()[3].type, "fetch-done",
|
||||
"Return values of yielded async dispatched actions are correct");
|
||||
equal(store.getState()[3].data.sync.data, "sync",
|
||||
"Return values of dispatched sync values are correct");
|
||||
equal(store.getState()[3].data.async, "async",
|
||||
"Return values of dispatched async values are correct");
|
||||
});
|
||||
|
||||
function comboAction() {
|
||||
return function* (dispatch, getState) {
|
||||
let data = {};
|
||||
data.async = yield dispatch(fetchAsync("async"));
|
||||
data.sync = yield dispatch(fetchSync("sync"));
|
||||
dispatch({ type: "fetch-done", data });
|
||||
};
|
||||
}
|
||||
|
||||
function fetchSync(data) {
|
||||
return { type: "fetchSync", data };
|
||||
}
|
||||
|
||||
function fetchAsync(data) {
|
||||
return function* (dispatch) {
|
||||
dispatch({ type: "fetchAsync-start" });
|
||||
let val = yield new Promise(resolve => resolve(data));
|
||||
dispatch({ type: "fetchAsync-end" });
|
||||
return val;
|
||||
};
|
||||
}
|
||||
|
||||
function reducer(state = [], action) {
|
||||
do_print("Action called: " + action.type);
|
||||
if (/fetch/.test(action.type)) {
|
||||
state.push(action);
|
||||
}
|
||||
return [...state];
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { createStore, applyMiddleware } = require("devtools/client/shared/vendor/redux");
|
||||
const { task, ERROR_TYPE } = require("devtools/client/shared/redux/middleware/task");
|
||||
|
||||
/**
|
||||
* Tests that the middleware handles errors thrown in tasks, and rejected promises.
|
||||
*/
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
let store = applyMiddleware(task)(createStore)(reducer);
|
||||
|
||||
store.dispatch(generatorError());
|
||||
yield waitUntilState(store, () => store.getState().length === 1);
|
||||
equal(store.getState()[0].type, ERROR_TYPE,
|
||||
"generator errors dispatch ERROR_TYPE actions");
|
||||
equal(store.getState()[0].error, "task-middleware-error-generator",
|
||||
"generator errors dispatch ERROR_TYPE actions with error");
|
||||
});
|
||||
|
||||
function generatorError() {
|
||||
return function* (dispatch, getState) {
|
||||
let error = "task-middleware-error-generator";
|
||||
throw error;
|
||||
};
|
||||
}
|
||||
|
||||
function reducer(state = [], action) {
|
||||
do_print("Action called: " + action.type);
|
||||
if (action.type === ERROR_TYPE) {
|
||||
state.push(action);
|
||||
}
|
||||
return [...state];
|
||||
}
|
||||
10
devtools/client/shared/redux/middleware/test/xpcshell.ini
Normal file
10
devtools/client/shared/redux/middleware/test/xpcshell.ini
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[DEFAULT]
|
||||
tags = devtools
|
||||
head = head.js
|
||||
tail =
|
||||
firefox-appdir = browser
|
||||
skip-if = toolkit == 'android'
|
||||
|
||||
[test_middleware-task-01.js]
|
||||
[test_middleware-task-02.js]
|
||||
[test_middleware-task-03.js]
|
||||
Loading…
Add table
Add a link
Reference in a new issue