mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
Bug 1239437 - xpcshell tests for responsive.html. r=pbrosset
This commit is contained in:
parent
482e796bd3
commit
bc17ebb4d3
@ -5,6 +5,7 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini']
|
||||
|
||||
DevToolsModules(
|
||||
'attach-thread.js',
|
||||
|
@ -9,6 +9,7 @@ support-files =
|
||||
code_math.js
|
||||
head.js
|
||||
shared-head.js
|
||||
shared-redux-head.js
|
||||
helper_disable_cache.js
|
||||
doc_theme.css
|
||||
doc_viewsource.html
|
||||
|
83
devtools/client/framework/test/shared-redux-head.js
Normal file
83
devtools/client/framework/test/shared-redux-head.js
Normal file
@ -0,0 +1,83 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* eslint no-unused-vars: [2, {"vars": "local"}] */
|
||||
// Currently this file expects "promise" to be imported into scope.
|
||||
/* globals promise */
|
||||
|
||||
// Common utility functions for working with Redux stores. The file is meant
|
||||
// to be safe to load in both mochitest and xpcshell environments.
|
||||
|
||||
/**
|
||||
* A logging function that can be used from xpcshell and browser mochitest
|
||||
* environments.
|
||||
*/
|
||||
function commonLog(message) {
|
||||
let log;
|
||||
if (Services && Services.appinfo && Services.appinfo.name &&
|
||||
Services.appinfo.name == "Firefox") {
|
||||
log = info;
|
||||
} else {
|
||||
log = do_print;
|
||||
}
|
||||
log(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the store has reached a state that matches the predicate.
|
||||
* @param Store store
|
||||
* The Redux store being used.
|
||||
* @param function predicate
|
||||
* A function that returns true when the store has reached the expected
|
||||
* state.
|
||||
* @return Promise
|
||||
* Resolved once the store reaches the expected state.
|
||||
*/
|
||||
function waitUntilState(store, predicate) {
|
||||
let deferred = promise.defer();
|
||||
let unsubscribe = store.subscribe(check);
|
||||
|
||||
commonLog(`Waiting for state predicate "${predicate}"`);
|
||||
function check() {
|
||||
if (predicate(store.getState())) {
|
||||
commonLog(`Found state predicate "${predicate}"`);
|
||||
unsubscribe();
|
||||
deferred.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the check immediately in case the action has already occurred
|
||||
check();
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until a particular action has been emitted by the store.
|
||||
* @param Store store
|
||||
* The Redux store being used.
|
||||
* @param string actionType
|
||||
* The expected action to wait for.
|
||||
* @return Promise
|
||||
* Resolved once the expected action is emitted by the store.
|
||||
*/
|
||||
function waitUntilAction(store, actionType) {
|
||||
let deferred = promise.defer();
|
||||
let unsubscribe = store.subscribe(check);
|
||||
let history = store.history;
|
||||
let index = history.length;
|
||||
|
||||
commonLog(`Waiting for action "${actionType}"`);
|
||||
function check() {
|
||||
let action = history[index++];
|
||||
if (action && action.type === actionType) {
|
||||
commonLog(`Found action "${actionType}"`);
|
||||
unsubscribe();
|
||||
deferred.resolve(store.getState());
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
7
devtools/client/framework/test/xpcshell.ini
Normal file
7
devtools/client/framework/test/xpcshell.ini
Normal file
@ -0,0 +1,7 @@
|
||||
[DEFAULT]
|
||||
tags = devtools
|
||||
head =
|
||||
tail =
|
||||
firefox-appdir = browser
|
||||
support-files =
|
||||
shared-redux-head.js
|
@ -8,6 +8,11 @@ Services.scriptloader.loadSubScript(
|
||||
"chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js",
|
||||
this);
|
||||
|
||||
// Load the shared Redux helpers into this compartment.
|
||||
Services.scriptloader.loadSubScript(
|
||||
"chrome://mochitests/content/browser/devtools/client/framework/test/shared-redux-head.js",
|
||||
this);
|
||||
|
||||
var { snapshotState: states } = require("devtools/client/memory/constants");
|
||||
var { breakdownEquals, breakdownNameToSpec } = require("devtools/client/memory/utils");
|
||||
|
||||
@ -67,24 +72,6 @@ function makeMemoryTest(url, generator) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function waitUntilState (store, predicate) {
|
||||
let deferred = promise.defer();
|
||||
let unsubscribe = store.subscribe(check);
|
||||
|
||||
function check () {
|
||||
if (predicate(store.getState())) {
|
||||
unsubscribe();
|
||||
deferred.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the check immediately incase the action has already occurred
|
||||
check();
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitUntilSnapshotState (store, expected) {
|
||||
let predicate = () => {
|
||||
let snapshots = store.getState().snapshots;
|
||||
|
@ -62,42 +62,6 @@ StubbedMemoryFront.prototype.stopRecordingAllocations = expectState("attached",
|
||||
this.recordingAllocations = false;
|
||||
}));
|
||||
|
||||
function waitUntilState (store, predicate) {
|
||||
let deferred = promise.defer();
|
||||
let unsubscribe = store.subscribe(check);
|
||||
|
||||
function check () {
|
||||
if (predicate(store.getState())) {
|
||||
unsubscribe();
|
||||
deferred.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the check immediately incase the action has already occurred
|
||||
check();
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitUntilAction (store, actionType) {
|
||||
let deferred = promise.defer();
|
||||
let unsubscribe = store.subscribe(check);
|
||||
let history = store.history;
|
||||
let index = history.length;
|
||||
|
||||
do_print(`Waiting for action "${actionType}"`);
|
||||
function check () {
|
||||
let action = history[index++];
|
||||
if (action && action.type === actionType) {
|
||||
do_print(`Found action "${actionType}"`);
|
||||
unsubscribe();
|
||||
deferred.resolve(store.getState());
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitUntilSnapshotState (store, expected) {
|
||||
let predicate = () => {
|
||||
let snapshots = store.getState().snapshots;
|
||||
|
@ -1,6 +1,6 @@
|
||||
[DEFAULT]
|
||||
tags = devtools devtools-memory
|
||||
head = head.js
|
||||
head = head.js ../../../framework/test/shared-redux-head.js
|
||||
tail =
|
||||
firefox-appdir = browser
|
||||
skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||
|
@ -18,3 +18,5 @@ DevToolsModules(
|
||||
'store.js',
|
||||
'types.js',
|
||||
)
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
|
||||
|
4
devtools/client/responsive.html/test/unit/.eslintrc
Normal file
4
devtools/client/responsive.html/test/unit/.eslintrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
// Extend from the shared list of defined globals for xpcshell.
|
||||
"extends": "../../../../.eslintrc.xpcshell"
|
||||
}
|
19
devtools/client/responsive.html/test/unit/head.js
Normal file
19
devtools/client/responsive.html/test/unit/head.js
Normal file
@ -0,0 +1,19 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* eslint no-unused-vars: [2, {"vars": "local"}] */
|
||||
|
||||
const { utils: Cu } = Components;
|
||||
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
||||
|
||||
const promise = require("promise");
|
||||
const { Task } = require("resource://gre/modules/Task.jsm");
|
||||
const Store = require("devtools/client/responsive.html/store");
|
||||
|
||||
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
DevToolsUtils.testing = true;
|
||||
do_register_cleanup(() => {
|
||||
DevToolsUtils.testing = false;
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test adding viewports to the page.
|
||||
|
||||
const { addViewport } =
|
||||
require("devtools/client/responsive.html/actions/viewports");
|
||||
|
||||
add_task(function*() {
|
||||
let store = Store();
|
||||
const { getState, dispatch } = store;
|
||||
|
||||
equal(getState().viewports.length, 0, "Defaults to no viewpots at startup");
|
||||
|
||||
dispatch(addViewport());
|
||||
equal(getState().viewports.length, 1, "One viewport total");
|
||||
|
||||
// For the moment, there can be at most one viewport.
|
||||
dispatch(addViewport());
|
||||
equal(getState().viewports.length, 1, "One viewport total, again");
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Test changing the location of the displayed page.
|
||||
|
||||
const { changeLocation } =
|
||||
require("devtools/client/responsive.html/actions/location");
|
||||
|
||||
const TEST_URL = "http://example.com";
|
||||
|
||||
add_task(function*() {
|
||||
let store = Store();
|
||||
const { getState, dispatch } = store;
|
||||
|
||||
equal(getState().location, "about:blank",
|
||||
"Defaults to about:blank at startup");
|
||||
|
||||
dispatch(changeLocation(TEST_URL));
|
||||
equal(getState().location, TEST_URL, "Location changed to TEST_URL");
|
||||
});
|
8
devtools/client/responsive.html/test/unit/xpcshell.ini
Normal file
8
devtools/client/responsive.html/test/unit/xpcshell.ini
Normal file
@ -0,0 +1,8 @@
|
||||
[DEFAULT]
|
||||
tags = devtools
|
||||
head = head.js ../../../framework/test/shared-redux-head.js
|
||||
tail =
|
||||
firefox-appdir = browser
|
||||
|
||||
[test_add_viewport.js]
|
||||
[test_change_location.js]
|
Loading…
Reference in New Issue
Block a user