mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1098071 - Move uitour.js library out of test directory. r=MattN
--HG-- rename : browser/modules/test/uitour.js => browser/components/uitour/UITour-lib.js rename : browser/modules/UITour.jsm => browser/components/uitour/UITour.jsm rename : browser/base/content/content-UITour.js => browser/components/uitour/content-UITour.js rename : browser/modules/test/browser_UITour.js => browser/components/uitour/test/browser_UITour.js rename : browser/modules/test/browser_UITour2.js => browser/components/uitour/test/browser_UITour2.js rename : browser/modules/test/browser_UITour3.js => browser/components/uitour/test/browser_UITour3.js rename : browser/modules/test/browser_UITour_annotation_size_attributes.js => browser/components/uitour/test/browser_UITour_annotation_size_attributes.js rename : browser/modules/test/browser_UITour_availableTargets.js => browser/components/uitour/test/browser_UITour_availableTargets.js rename : browser/modules/test/browser_UITour_detach_tab.js => browser/components/uitour/test/browser_UITour_detach_tab.js rename : browser/modules/test/browser_UITour_loop.js => browser/components/uitour/test/browser_UITour_loop.js rename : browser/modules/test/browser_UITour_modalDialog.js => browser/components/uitour/test/browser_UITour_modalDialog.js rename : browser/modules/test/browser_UITour_observe.js => browser/components/uitour/test/browser_UITour_observe.js rename : browser/modules/test/browser_UITour_panel_close_annotation.js => browser/components/uitour/test/browser_UITour_panel_close_annotation.js rename : browser/modules/test/browser_UITour_registerPageID.js => browser/components/uitour/test/browser_UITour_registerPageID.js rename : browser/modules/test/browser_UITour_resetProfile.js => browser/components/uitour/test/browser_UITour_resetProfile.js rename : browser/modules/test/browser_UITour_sync.js => browser/components/uitour/test/browser_UITour_sync.js rename : browser/modules/test/head.js => browser/components/uitour/test/head.js rename : browser/modules/test/image.png => browser/components/uitour/test/image.png rename : browser/modules/test/uitour.html => browser/components/uitour/test/uitour.html
This commit is contained in:
parent
ee09e97412
commit
7ad50645fe
@ -77,7 +77,6 @@ browser.jar:
|
||||
* content/browser/browser-tabPreviews.xml (content/browser-tabPreviews.xml)
|
||||
* content/browser/chatWindow.xul (content/chatWindow.xul)
|
||||
content/browser/content.js (content/content.js)
|
||||
content/browser/content-UITour.js (content/content-UITour.js)
|
||||
content/browser/defaultthemes/1.footer.jpg (content/defaultthemes/1.footer.jpg)
|
||||
content/browser/defaultthemes/1.header.jpg (content/defaultthemes/1.header.jpg)
|
||||
content/browser/defaultthemes/1.icon.jpg (content/defaultthemes/1.icon.jpg)
|
||||
|
@ -11,6 +11,7 @@ DIRS += [
|
||||
'downloads',
|
||||
'feeds',
|
||||
'loop',
|
||||
'migration',
|
||||
'places',
|
||||
'preferences',
|
||||
'privatebrowsing',
|
||||
@ -20,8 +21,8 @@ DIRS += [
|
||||
'selfsupport',
|
||||
'sidebar',
|
||||
'tabview',
|
||||
'uitour',
|
||||
'translation',
|
||||
'migration',
|
||||
]
|
||||
|
||||
DIRS += ['build']
|
||||
|
@ -1,3 +1,7 @@
|
||||
/* 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/. */
|
||||
|
||||
let {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
const PREF_TEST_WHITELIST = "browser.uitour.testingOrigins";
|
6
browser/components/uitour/jar.mn
Normal file
6
browser/components/uitour/jar.mn
Normal file
@ -0,0 +1,6 @@
|
||||
# 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/.
|
||||
|
||||
browser.jar:
|
||||
content/browser/content-UITour.js
|
13
browser/components/uitour/moz.build
Normal file
13
browser/components/uitour/moz.build
Normal file
@ -0,0 +1,13 @@
|
||||
# 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/.
|
||||
|
||||
EXTRA_PP_JS_MODULES += [
|
||||
'UITour.jsm',
|
||||
]
|
||||
|
||||
JAR_MANIFESTS += ['jar.mn']
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += [
|
||||
'test/browser.ini',
|
||||
]
|
34
browser/components/uitour/test/browser.ini
Normal file
34
browser/components/uitour/test/browser.ini
Normal file
@ -0,0 +1,34 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
head.js
|
||||
image.png
|
||||
uitour.html
|
||||
../UITour-lib.js
|
||||
|
||||
[browser_UITour.js]
|
||||
skip-if = os == "linux" || e10s # Intermittent failures, bug 951965
|
||||
[browser_UITour2.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour3.js]
|
||||
skip-if = os == "linux" || e10s # Linux: Bug 986760, Bug 989101; e10s: Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_availableTargets.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_detach_tab.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_annotation_size_attributes.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_loop.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_modalDialog.js]
|
||||
run-if = os == "mac" # modal dialog disabling only working on OS X
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_observe.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_panel_close_annotation.js]
|
||||
skip-if = true # Disabled due to frequent failures, bugs 1026310 and 1032137
|
||||
[browser_UITour_registerPageID.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_sync.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_resetProfile.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
274
browser/components/uitour/test/head.js
Normal file
274
browser/components/uitour/test/head.js
Normal file
@ -0,0 +1,274 @@
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UITour",
|
||||
"resource:///modules/UITour.jsm");
|
||||
|
||||
|
||||
const SINGLE_TRY_TIMEOUT = 100;
|
||||
const NUMBER_OF_TRIES = 30;
|
||||
|
||||
function waitForConditionPromise(condition, timeoutMsg, tryCount=NUMBER_OF_TRIES) {
|
||||
let defer = Promise.defer();
|
||||
let tries = 0;
|
||||
function checkCondition() {
|
||||
if (tries >= tryCount) {
|
||||
defer.reject(timeoutMsg);
|
||||
}
|
||||
var conditionPassed;
|
||||
try {
|
||||
conditionPassed = condition();
|
||||
} catch (e) {
|
||||
return defer.reject(e);
|
||||
}
|
||||
if (conditionPassed) {
|
||||
return defer.resolve();
|
||||
}
|
||||
tries++;
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
}
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return defer.promise;
|
||||
}
|
||||
|
||||
function waitForCondition(condition, nextTest, errorMsg) {
|
||||
waitForConditionPromise(condition, errorMsg).then(nextTest, (reason) => {
|
||||
ok(false, reason + (reason.stack ? "\n" + e.stack : ""));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to partially transition tests to Task.
|
||||
*/
|
||||
function taskify(fun) {
|
||||
return (done) => {
|
||||
return Task.spawn(fun).then(done, (reason) => {
|
||||
ok(false, reason);
|
||||
done();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function is_hidden(element) {
|
||||
var style = element.ownerDocument.defaultView.getComputedStyle(element, "");
|
||||
if (style.display == "none")
|
||||
return true;
|
||||
if (style.visibility != "visible")
|
||||
return true;
|
||||
if (style.display == "-moz-popup")
|
||||
return ["hiding","closed"].indexOf(element.state) != -1;
|
||||
|
||||
// Hiding a parent element will hide all its children
|
||||
if (element.parentNode != element.ownerDocument)
|
||||
return is_hidden(element.parentNode);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_visible(element) {
|
||||
var style = element.ownerDocument.defaultView.getComputedStyle(element, "");
|
||||
if (style.display == "none")
|
||||
return false;
|
||||
if (style.visibility != "visible")
|
||||
return false;
|
||||
if (style.display == "-moz-popup" && element.state != "open")
|
||||
return false;
|
||||
|
||||
// Hiding a parent element will hide all its children
|
||||
if (element.parentNode != element.ownerDocument)
|
||||
return is_visible(element.parentNode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function is_element_visible(element, msg) {
|
||||
isnot(element, null, "Element should not be null, when checking visibility");
|
||||
ok(is_visible(element), msg);
|
||||
}
|
||||
|
||||
function waitForElementToBeVisible(element, nextTest, msg) {
|
||||
waitForCondition(() => is_visible(element),
|
||||
() => {
|
||||
ok(true, msg);
|
||||
nextTest();
|
||||
},
|
||||
"Timeout waiting for visibility: " + msg);
|
||||
}
|
||||
|
||||
function waitForElementToBeHidden(element, nextTest, msg) {
|
||||
waitForCondition(() => is_hidden(element),
|
||||
() => {
|
||||
ok(true, msg);
|
||||
nextTest();
|
||||
},
|
||||
"Timeout waiting for invisibility: " + msg);
|
||||
}
|
||||
|
||||
function elementVisiblePromise(element, msg) {
|
||||
return waitForConditionPromise(() => is_visible(element), "Timeout waiting for visibility: " + msg);
|
||||
}
|
||||
|
||||
function elementHiddenPromise(element, msg) {
|
||||
return waitForConditionPromise(() => is_hidden(element), "Timeout waiting for invisibility: " + msg);
|
||||
}
|
||||
|
||||
function waitForPopupAtAnchor(popup, anchorNode, nextTest, msg) {
|
||||
waitForCondition(() => is_visible(popup) && popup.popupBoxObject.anchorNode == anchorNode,
|
||||
() => {
|
||||
ok(true, msg);
|
||||
is_element_visible(popup, "Popup should be visible");
|
||||
nextTest();
|
||||
},
|
||||
"Timeout waiting for popup at anchor: " + msg);
|
||||
}
|
||||
|
||||
function hideInfoPromise(...args) {
|
||||
let popup = document.getElementById("UITourTooltip");
|
||||
gContentAPI.hideInfo.apply(gContentAPI, args);
|
||||
return promisePanelElementHidden(window, popup);
|
||||
}
|
||||
|
||||
function showInfoPromise(...args) {
|
||||
let popup = document.getElementById("UITourTooltip");
|
||||
gContentAPI.showInfo.apply(gContentAPI, args);
|
||||
return promisePanelElementShown(window, popup);
|
||||
}
|
||||
|
||||
function showMenuPromise(name) {
|
||||
return new Promise(resolve => {
|
||||
gContentAPI.showMenu(name, () => resolve());
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCallbackResultPromise() {
|
||||
return waitForConditionPromise(() => {
|
||||
return gContentWindow.callbackResult;
|
||||
}, "callback should be called");
|
||||
}
|
||||
|
||||
function addPinnedTabPromise() {
|
||||
gContentAPI.addPinnedTab();
|
||||
return waitForConditionPromise(() => {
|
||||
let tabInfo = UITour.pinnedTabs.get(window);
|
||||
if (!tabInfo) {
|
||||
return false;
|
||||
}
|
||||
return tabInfo.tab.pinned;
|
||||
});
|
||||
}
|
||||
|
||||
function removePinnedTabPromise() {
|
||||
gContentAPI.removePinnedTab();
|
||||
return waitForConditionPromise(() => {
|
||||
let tabInfo = UITour.pinnedTabs.get(window);
|
||||
return tabInfo == null;
|
||||
});
|
||||
}
|
||||
|
||||
function promisePanelShown(win) {
|
||||
let panelEl = win.PanelUI.panel;
|
||||
return promisePanelElementShown(win, panelEl);
|
||||
}
|
||||
|
||||
function promisePanelElementEvent(win, aPanel, aEvent) {
|
||||
let deferred = Promise.defer();
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
deferred.reject("Panel did not show within 5 seconds.");
|
||||
}, 5000);
|
||||
aPanel.addEventListener(aEvent, function onPanelEvent(e) {
|
||||
aPanel.removeEventListener(aEvent, onPanelEvent);
|
||||
win.clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promisePanelElementShown(win, aPanel) {
|
||||
return promisePanelElementEvent(win, aPanel, "popupshown");
|
||||
}
|
||||
|
||||
function promisePanelElementHidden(win, aPanel) {
|
||||
return promisePanelElementEvent(win, aPanel, "popuphidden");
|
||||
}
|
||||
|
||||
function is_element_hidden(element, msg) {
|
||||
isnot(element, null, "Element should not be null, when checking visibility");
|
||||
ok(is_hidden(element), msg);
|
||||
}
|
||||
|
||||
function loadUITourTestPage(callback, host = "https://example.com/") {
|
||||
if (gTestTab)
|
||||
gBrowser.removeTab(gTestTab);
|
||||
|
||||
let url = getRootDirectory(gTestPath) + "uitour.html";
|
||||
url = url.replace("chrome://mochitests/content/", host);
|
||||
|
||||
gTestTab = gBrowser.addTab(url);
|
||||
gBrowser.selectedTab = gTestTab;
|
||||
|
||||
gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
|
||||
gTestTab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
|
||||
gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
|
||||
gContentAPI = gContentWindow.Mozilla.UITour;
|
||||
|
||||
waitForFocus(callback, gContentWindow);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function UITourTest() {
|
||||
Services.prefs.setBoolPref("browser.uitour.enabled", true);
|
||||
let testUri = Services.io.newURI("http://example.com", null, null);
|
||||
Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
|
||||
|
||||
waitForExplicitFinish();
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
delete window.UITour;
|
||||
delete window.UITourMetricsProvider;
|
||||
delete window.gContentWindow;
|
||||
delete window.gContentAPI;
|
||||
if (gTestTab)
|
||||
gBrowser.removeTab(gTestTab);
|
||||
delete window.gTestTab;
|
||||
Services.prefs.clearUserPref("browser.uitour.enabled", true);
|
||||
Services.perms.remove("example.com", "uitour");
|
||||
});
|
||||
|
||||
function done() {
|
||||
executeSoon(() => {
|
||||
if (gTestTab)
|
||||
gBrowser.removeTab(gTestTab);
|
||||
gTestTab = null;
|
||||
|
||||
let highlight = document.getElementById("UITourHighlightContainer");
|
||||
is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
|
||||
|
||||
let tooltip = document.getElementById("UITourTooltip");
|
||||
is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
|
||||
|
||||
ok(!PanelUI.panel.hasAttribute("noautohide"), "@noautohide on the menu panel should have been cleaned up");
|
||||
ok(!PanelUI.panel.hasAttribute("panelopen"), "The panel shouldn't have @panelopen");
|
||||
isnot(PanelUI.panel.state, "open", "The panel shouldn't be open");
|
||||
is(document.getElementById("PanelUI-menu-button").hasAttribute("open"), false, "Menu button should know that the menu is closed");
|
||||
|
||||
is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
|
||||
|
||||
executeSoon(nextTest);
|
||||
});
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length == 0) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
let test = tests.shift();
|
||||
info("Starting " + test.name);
|
||||
waitForFocus(function() {
|
||||
loadUITourTestPage(function() {
|
||||
test(done);
|
||||
});
|
||||
});
|
||||
}
|
||||
nextTest();
|
||||
}
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>UITour test</title>
|
||||
<script type="application/javascript" src="uitour.js">
|
||||
<script type="application/javascript" src="UITour-lib.js">
|
||||
</script>
|
||||
<script type="application/javascript">
|
||||
var callbackResult, callbackData;
|
@ -50,7 +50,6 @@ EXTRA_PP_JS_MODULES += [
|
||||
'AboutHome.jsm',
|
||||
'PluginContent.jsm',
|
||||
'RecentWindow.jsm',
|
||||
'UITour.jsm',
|
||||
'webrtcUI.jsm',
|
||||
]
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
head.js
|
||||
image.png
|
||||
uitour.*
|
||||
|
||||
[browser_BrowserUITelemetry_buckets.js]
|
||||
[browser_ContentSearch.js]
|
||||
@ -16,33 +14,6 @@ support-files =
|
||||
skip-if = e10s # Bug 666804 - Support NetworkPrioritizer in e10s
|
||||
[browser_SignInToWebsite.js]
|
||||
skip-if = e10s # Bug 941426 - SignIntoWebsite.jsm not e10s friendly
|
||||
[browser_UITour.js]
|
||||
skip-if = os == "linux" || e10s # Intermittent failures, bug 951965
|
||||
[browser_UITour2.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour3.js]
|
||||
skip-if = os == "linux" || e10s # Linux: Bug 986760, Bug 989101; e10s: Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_availableTargets.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_detach_tab.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_annotation_size_attributes.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_loop.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_modalDialog.js]
|
||||
run-if = os == "mac" # modal dialog disabling only working on OS X
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_observe.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
|
||||
[browser_UITour_panel_close_annotation.js]
|
||||
skip-if = true # Disabled due to frequent failures, bugs 1026310 and 1032137
|
||||
[browser_UITour_registerPageID.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_sync.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_UITour_resetProfile.js]
|
||||
skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
|
||||
[browser_taskbar_preview.js]
|
||||
run-if = os == "win"
|
||||
skip-if = e10s # Bug 666808 - AeroPeek support for e10s
|
||||
|
@ -1,10 +1,4 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UITour",
|
||||
"resource:///modules/UITour.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
|
||||
const SINGLE_TRY_TIMEOUT = 100;
|
||||
const NUMBER_OF_TRIES = 30;
|
||||
@ -37,240 +31,3 @@ function waitForCondition(condition, nextTest, errorMsg) {
|
||||
ok(false, reason + (reason.stack ? "\n" + e.stack : ""));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to partially transition tests to Task.
|
||||
*/
|
||||
function taskify(fun) {
|
||||
return (done) => {
|
||||
return Task.spawn(fun).then(done, (reason) => {
|
||||
ok(false, reason);
|
||||
done();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function is_hidden(element) {
|
||||
var style = element.ownerDocument.defaultView.getComputedStyle(element, "");
|
||||
if (style.display == "none")
|
||||
return true;
|
||||
if (style.visibility != "visible")
|
||||
return true;
|
||||
if (style.display == "-moz-popup")
|
||||
return ["hiding","closed"].indexOf(element.state) != -1;
|
||||
|
||||
// Hiding a parent element will hide all its children
|
||||
if (element.parentNode != element.ownerDocument)
|
||||
return is_hidden(element.parentNode);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_visible(element) {
|
||||
var style = element.ownerDocument.defaultView.getComputedStyle(element, "");
|
||||
if (style.display == "none")
|
||||
return false;
|
||||
if (style.visibility != "visible")
|
||||
return false;
|
||||
if (style.display == "-moz-popup" && element.state != "open")
|
||||
return false;
|
||||
|
||||
// Hiding a parent element will hide all its children
|
||||
if (element.parentNode != element.ownerDocument)
|
||||
return is_visible(element.parentNode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function is_element_visible(element, msg) {
|
||||
isnot(element, null, "Element should not be null, when checking visibility");
|
||||
ok(is_visible(element), msg);
|
||||
}
|
||||
|
||||
function waitForElementToBeVisible(element, nextTest, msg) {
|
||||
waitForCondition(() => is_visible(element),
|
||||
() => {
|
||||
ok(true, msg);
|
||||
nextTest();
|
||||
},
|
||||
"Timeout waiting for visibility: " + msg);
|
||||
}
|
||||
|
||||
function waitForElementToBeHidden(element, nextTest, msg) {
|
||||
waitForCondition(() => is_hidden(element),
|
||||
() => {
|
||||
ok(true, msg);
|
||||
nextTest();
|
||||
},
|
||||
"Timeout waiting for invisibility: " + msg);
|
||||
}
|
||||
|
||||
function elementVisiblePromise(element, msg) {
|
||||
return waitForConditionPromise(() => is_visible(element), "Timeout waiting for visibility: " + msg);
|
||||
}
|
||||
|
||||
function elementHiddenPromise(element, msg) {
|
||||
return waitForConditionPromise(() => is_hidden(element), "Timeout waiting for invisibility: " + msg);
|
||||
}
|
||||
|
||||
function waitForPopupAtAnchor(popup, anchorNode, nextTest, msg) {
|
||||
waitForCondition(() => is_visible(popup) && popup.popupBoxObject.anchorNode == anchorNode,
|
||||
() => {
|
||||
ok(true, msg);
|
||||
is_element_visible(popup, "Popup should be visible");
|
||||
nextTest();
|
||||
},
|
||||
"Timeout waiting for popup at anchor: " + msg);
|
||||
}
|
||||
|
||||
function hideInfoPromise(...args) {
|
||||
let popup = document.getElementById("UITourTooltip");
|
||||
gContentAPI.hideInfo.apply(gContentAPI, args);
|
||||
return promisePanelElementHidden(window, popup);
|
||||
}
|
||||
|
||||
function showInfoPromise(...args) {
|
||||
let popup = document.getElementById("UITourTooltip");
|
||||
gContentAPI.showInfo.apply(gContentAPI, args);
|
||||
return promisePanelElementShown(window, popup);
|
||||
}
|
||||
|
||||
function showMenuPromise(name) {
|
||||
return new Promise(resolve => {
|
||||
gContentAPI.showMenu(name, () => resolve());
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCallbackResultPromise() {
|
||||
return waitForConditionPromise(() => {
|
||||
return gContentWindow.callbackResult;
|
||||
}, "callback should be called");
|
||||
}
|
||||
|
||||
function addPinnedTabPromise() {
|
||||
gContentAPI.addPinnedTab();
|
||||
return waitForConditionPromise(() => {
|
||||
let tabInfo = UITour.pinnedTabs.get(window);
|
||||
if (!tabInfo) {
|
||||
return false;
|
||||
}
|
||||
return tabInfo.tab.pinned;
|
||||
});
|
||||
}
|
||||
|
||||
function removePinnedTabPromise() {
|
||||
gContentAPI.removePinnedTab();
|
||||
return waitForConditionPromise(() => {
|
||||
let tabInfo = UITour.pinnedTabs.get(window);
|
||||
return tabInfo == null;
|
||||
});
|
||||
}
|
||||
|
||||
function promisePanelShown(win) {
|
||||
let panelEl = win.PanelUI.panel;
|
||||
return promisePanelElementShown(win, panelEl);
|
||||
}
|
||||
|
||||
function promisePanelElementEvent(win, aPanel, aEvent) {
|
||||
let deferred = Promise.defer();
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
deferred.reject("Panel did not show within 5 seconds.");
|
||||
}, 5000);
|
||||
aPanel.addEventListener(aEvent, function onPanelEvent(e) {
|
||||
aPanel.removeEventListener(aEvent, onPanelEvent);
|
||||
win.clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promisePanelElementShown(win, aPanel) {
|
||||
return promisePanelElementEvent(win, aPanel, "popupshown");
|
||||
}
|
||||
|
||||
function promisePanelElementHidden(win, aPanel) {
|
||||
return promisePanelElementEvent(win, aPanel, "popuphidden");
|
||||
}
|
||||
|
||||
function is_element_hidden(element, msg) {
|
||||
isnot(element, null, "Element should not be null, when checking visibility");
|
||||
ok(is_hidden(element), msg);
|
||||
}
|
||||
|
||||
function loadUITourTestPage(callback, host = "https://example.com/") {
|
||||
if (gTestTab)
|
||||
gBrowser.removeTab(gTestTab);
|
||||
|
||||
let url = getRootDirectory(gTestPath) + "uitour.html";
|
||||
url = url.replace("chrome://mochitests/content/", host);
|
||||
|
||||
gTestTab = gBrowser.addTab(url);
|
||||
gBrowser.selectedTab = gTestTab;
|
||||
|
||||
gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
|
||||
gTestTab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
|
||||
gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
|
||||
gContentAPI = gContentWindow.Mozilla.UITour;
|
||||
|
||||
waitForFocus(callback, gContentWindow);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function UITourTest() {
|
||||
Services.prefs.setBoolPref("browser.uitour.enabled", true);
|
||||
let testUri = Services.io.newURI("http://example.com", null, null);
|
||||
Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
|
||||
|
||||
waitForExplicitFinish();
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
delete window.UITour;
|
||||
delete window.UITourMetricsProvider;
|
||||
delete window.gContentWindow;
|
||||
delete window.gContentAPI;
|
||||
if (gTestTab)
|
||||
gBrowser.removeTab(gTestTab);
|
||||
delete window.gTestTab;
|
||||
Services.prefs.clearUserPref("browser.uitour.enabled", true);
|
||||
Services.perms.remove("example.com", "uitour");
|
||||
});
|
||||
|
||||
function done() {
|
||||
executeSoon(() => {
|
||||
if (gTestTab)
|
||||
gBrowser.removeTab(gTestTab);
|
||||
gTestTab = null;
|
||||
|
||||
let highlight = document.getElementById("UITourHighlightContainer");
|
||||
is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
|
||||
|
||||
let tooltip = document.getElementById("UITourTooltip");
|
||||
is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
|
||||
|
||||
ok(!PanelUI.panel.hasAttribute("noautohide"), "@noautohide on the menu panel should have been cleaned up");
|
||||
ok(!PanelUI.panel.hasAttribute("panelopen"), "The panel shouldn't have @panelopen");
|
||||
isnot(PanelUI.panel.state, "open", "The panel shouldn't be open");
|
||||
is(document.getElementById("PanelUI-menu-button").hasAttribute("open"), false, "Menu button should know that the menu is closed");
|
||||
|
||||
is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
|
||||
|
||||
executeSoon(nextTest);
|
||||
});
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
if (tests.length == 0) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
let test = tests.shift();
|
||||
info("Starting " + test.name);
|
||||
waitForFocus(function() {
|
||||
loadUITourTestPage(function() {
|
||||
test(done);
|
||||
});
|
||||
});
|
||||
}
|
||||
nextTest();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user