2016-05-02 18:09:28 +03:00
|
|
|
/* 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';
|
|
|
|
|
2016-11-19 07:29:10 +03:00
|
|
|
/* exported initPromise, shutdownPromise, waitForEvent, setE10sPrefs,
|
|
|
|
unsetE10sPrefs, forceGC */
|
2016-05-02 18:09:28 +03:00
|
|
|
|
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Set e10s related preferences in the test environment.
|
|
|
|
* @return {Promise} promise that resolves when preferences are set.
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function setE10sPrefs() {
|
|
|
|
return new Promise(resolve =>
|
|
|
|
SpecialPowers.pushPrefEnv({
|
|
|
|
set: [
|
|
|
|
['browser.tabs.remote.autostart', true],
|
|
|
|
['browser.tabs.remote.force-enable', true],
|
|
|
|
['extensions.e10sBlocksEnabling', false]
|
|
|
|
]
|
|
|
|
}, resolve));
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Unset e10s related preferences in the test environment.
|
|
|
|
* @return {Promise} promise that resolves when preferences are unset.
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function unsetE10sPrefs() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
SpecialPowers.popPrefEnv(resolve);
|
|
|
|
});
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
2016-08-23 21:27:23 +03:00
|
|
|
// Load the shared-head file first.
|
2017-04-27 14:07:04 +03:00
|
|
|
/* import-globals-from shared-head.js */
|
2016-08-23 21:27:23 +03:00
|
|
|
Services.scriptloader.loadSubScript(
|
|
|
|
'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js',
|
|
|
|
this);
|
|
|
|
|
2016-05-02 18:09:28 +03:00
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Returns a promise that resolves when 'a11y-init-or-shutdown' event is fired.
|
|
|
|
* @return {Promise} event promise evaluating to event's data
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function a11yInitOrShutdownPromise() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let observe = (subject, topic, data) => {
|
|
|
|
Services.obs.removeObserver(observe, 'a11y-init-or-shutdown');
|
|
|
|
resolve(data);
|
|
|
|
};
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(observe, 'a11y-init-or-shutdown');
|
2016-08-23 21:27:23 +03:00
|
|
|
});
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Returns a promise that resolves when 'a11y-init-or-shutdown' event is fired
|
|
|
|
* in content.
|
|
|
|
* @param {Object} browser current "tabbrowser" element
|
|
|
|
* @return {Promise} event promise evaluating to event's data
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function contentA11yInitOrShutdownPromise(browser) {
|
|
|
|
return ContentTask.spawn(browser, {}, a11yInitOrShutdownPromise);
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* A helper function that maps 'a11y-init-or-shutdown' event to a promise that
|
|
|
|
* resovles or rejects depending on whether accessibility service is expected to
|
|
|
|
* be initialized or shut down.
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function promiseOK(promise, expected) {
|
|
|
|
return promise.then(flag =>
|
|
|
|
flag === expected ? Promise.resolve() : Promise.reject());
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Checks and returns a promise that resolves when accessibility service is
|
|
|
|
* initialized with the correct flag.
|
|
|
|
* @param {?Object} contentBrowser optinal remove browser object that indicates
|
|
|
|
* that accessibility service is expected to be
|
|
|
|
* initialized in content process.
|
|
|
|
* @return {Promise} promise that resolves when the accessibility
|
|
|
|
* service initialized correctly.
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function initPromise(contentBrowser) {
|
|
|
|
let a11yInitPromise = contentBrowser ?
|
|
|
|
contentA11yInitOrShutdownPromise(contentBrowser) :
|
|
|
|
a11yInitOrShutdownPromise();
|
|
|
|
return promiseOK(a11yInitPromise, '1').then(
|
|
|
|
() => ok(true, 'Service initialized correctly'),
|
|
|
|
() => ok(false, 'Service shutdown incorrectly'));
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Checks and returns a promise that resolves when accessibility service is
|
|
|
|
* shut down with the correct flag.
|
|
|
|
* @param {?Object} contentBrowser optinal remove browser object that indicates
|
|
|
|
* that accessibility service is expected to be
|
|
|
|
* shut down in content process.
|
|
|
|
* @return {Promise} promise that resolves when the accessibility
|
|
|
|
* service shuts down correctly.
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function shutdownPromise(contentBrowser) {
|
|
|
|
let a11yShutdownPromise = contentBrowser ?
|
|
|
|
contentA11yInitOrShutdownPromise(contentBrowser) :
|
|
|
|
a11yInitOrShutdownPromise();
|
|
|
|
return promiseOK(a11yShutdownPromise, '0').then(
|
|
|
|
() => ok(true, 'Service shutdown correctly'),
|
|
|
|
() => ok(false, 'Service initialized incorrectly'));
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|
|
|
|
|
2016-11-19 07:29:10 +03:00
|
|
|
/**
|
|
|
|
* Simpler verions of waitForEvent defined in
|
2017-05-30 21:31:05 +03:00
|
|
|
* accessible/tests/browser/events.js
|
2016-11-19 07:29:10 +03:00
|
|
|
*/
|
|
|
|
function waitForEvent(eventType, expectedId) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let eventObserver = {
|
|
|
|
observe(subject) {
|
|
|
|
let event = subject.QueryInterface(Ci.nsIAccessibleEvent);
|
|
|
|
if (event.eventType === eventType &&
|
|
|
|
event.accessible.id === expectedId) {
|
|
|
|
Services.obs.removeObserver(this, 'accessible-event');
|
|
|
|
resolve(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(eventObserver, 'accessible-event');
|
2016-11-19 07:29:10 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-02 18:09:28 +03:00
|
|
|
/**
|
2016-08-23 21:27:23 +03:00
|
|
|
* Force garbage collection.
|
2016-05-02 18:09:28 +03:00
|
|
|
*/
|
2016-08-23 21:27:23 +03:00
|
|
|
function forceGC() {
|
2016-11-19 07:29:10 +03:00
|
|
|
SpecialPowers.gc();
|
2017-06-03 18:29:17 +03:00
|
|
|
SpecialPowers.forceShrinkingGC();
|
2016-11-19 07:29:10 +03:00
|
|
|
SpecialPowers.forceCC();
|
|
|
|
SpecialPowers.gc();
|
2017-06-03 18:29:17 +03:00
|
|
|
SpecialPowers.forceShrinkingGC();
|
2016-11-19 07:29:10 +03:00
|
|
|
SpecialPowers.forceCC();
|
2016-05-02 18:09:28 +03:00
|
|
|
}
|