Remove browser tests - Part 1: The Tests (except for experiments)

This commit is contained in:
NTD 2018-02-03 06:00:38 -05:00 • committed by Roy Tam
commit 261374f310
1697 changed files with 0 additions and 144364 deletions

View file

@ -1,11 +0,0 @@
"use strict";
module.exports = {
"extends": [
"../../../../../testing/mochitest/browser.eslintrc.js"
],
"rules": {
"no-undef": "error"
}
};

View file

@ -1,30 +0,0 @@
[DEFAULT]
support-files =
empty_file.html
file_reflect_cookie_into_title.html
favicon-normal32.png
file_set_storages.html
serviceworker.html
worker.js
[browser_aboutURLs.js]
[browser_eme.js]
[browser_favicon.js]
[browser_forgetaboutsite.js]
[browser_forgetAPI_cookie_getCookiesWithOriginAttributes.js]
[browser_forgetAPI_EME_forgetThisSite.js]
[browser_forgetAPI_quota_clearStoragesForPrincipal.js]
[browser_newtabButton.js]
[browser_usercontext.js]
[browser_usercontextid_tabdrop.js]
skip-if = os == "mac" || os == "win" # Intermittent failure - bug 1268276
[browser_windowName.js]
tags = openwindow
[browser_windowOpen.js]
tags = openwindow
[browser_serviceworkers.js]
[browser_broadcastchannel.js]
[browser_blobUrl.js]
[browser_middleClick.js]
[browser_imageCache.js]
[browser_count_and_remove.js]

View file

@ -1,49 +0,0 @@
"use strict";
// For some about: URLs, they will take more time to load and cause timeout.
// See Bug 1270998.
requestLongerTimeout(2);
add_task(function* () {
let aboutURLs = [];
// List of about: URLs that will initiate network requests.
let networkURLs = [
"credits",
"telemetry" // about:telemetry will fetch Telemetry asynchrounously and takes
// longer, we skip this for now.
];
let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
for (let cid in Cc) {
let result = cid.match(/@mozilla.org\/network\/protocol\/about;1\?what\=(.*)$/);
if (!result) {
continue;
}
let aboutType = result[1];
let contract = "@mozilla.org/network/protocol/about;1?what=" + aboutType;
try {
let am = Cc[contract].getService(Ci.nsIAboutModule);
let uri = ios.newURI("about:"+aboutType, null, null);
let flags = am.getURIFlags(uri);
if (!(flags & Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT) &&
networkURLs.indexOf(aboutType) == -1) {
aboutURLs.push(aboutType);
}
} catch (e) {
// getService might have thrown if the component doesn't actually
// implement nsIAboutModule
}
}
for (let url of aboutURLs) {
info("Loading about:" + url);
let tab = gBrowser.addTab("about:"+url, {userContextId: 1});
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
ok(true, "Done loading about:" + url);
yield BrowserTestUtils.removeTab(tab);
}
});

View file

@ -1,78 +0,0 @@
"use strict";
// Here we want to test that blob URLs are not available cross containers.
const BASE_URI = "http://mochi.test:8888/browser/browser/components/"
+ "contextualidentity/test/browser/empty_file.html";
add_task(function* setup() {
yield new Promise((resolve) => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true]
]}, resolve);
});
});
add_task(function* test() {
info("Creating a tab with UCI = 1...");
let tab1 = gBrowser.addTab(BASE_URI, {userContextId: 1});
is(tab1.getAttribute('usercontextid'), 1, "New tab has UCI equal 1");
let browser1 = gBrowser.getBrowserForTab(tab1);
yield BrowserTestUtils.browserLoaded(browser1);
let blobURL;
info("Creating a blob URL...");
yield ContentTask.spawn(browser1, null, function() {
return Promise.resolve(content.window.URL.createObjectURL(new content.window.Blob([123])));
}).then(newURL => { blobURL = newURL });
info("Blob URL: " + blobURL);
info("Creating a tab with UCI = 2...");
let tab2 = gBrowser.addTab(BASE_URI, {userContextId: 2});
is(tab2.getAttribute('usercontextid'), 2, "New tab has UCI equal 2");
let browser2 = gBrowser.getBrowserForTab(tab2);
yield BrowserTestUtils.browserLoaded(browser2);
yield ContentTask.spawn(browser2, blobURL, function(url) {
return new Promise(resolve => {
var xhr = new content.window.XMLHttpRequest();
xhr.onerror = function() { resolve("SendErrored"); }
xhr.onload = function() { resolve("SendLoaded"); }
xhr.open("GET", url);
xhr.send();
});
}).then(status => {
is(status, "SendErrored", "Using a blob URI from one user context id in another should not work");
});
info("Creating a tab with UCI = 1...");
let tab3 = gBrowser.addTab(BASE_URI, {userContextId: 1});
is(tab3.getAttribute('usercontextid'), 1, "New tab has UCI equal 1");
let browser3 = gBrowser.getBrowserForTab(tab3);
yield BrowserTestUtils.browserLoaded(browser3);
yield ContentTask.spawn(browser3, blobURL, function(url) {
return new Promise(resolve => {
var xhr = new content.window.XMLHttpRequest();
xhr.open("GET", url);
try {
xhr.send();
resolve("SendSucceeded");
} catch (e) {
resolve("SendThrew");
}
});
}).then(status => {
is(status, "SendSucceeded", "Using a blob URI within a single user context id should work");
});
yield BrowserTestUtils.removeTab(tab1);
yield BrowserTestUtils.removeTab(tab2);
yield BrowserTestUtils.removeTab(tab3);
});

View file

@ -1,80 +0,0 @@
let { classes: Cc, interfaces: Ci } = Components;
const BASE_ORIGIN = "http://example.com";
const URI = BASE_ORIGIN +
"/browser/browser/components/contextualidentity/test/browser/empty_file.html";
// opens `uri' in a new tab with the provided userContextId and focuses it.
// returns the newly opened tab
function* openTabInUserContext(uri, userContextId) {
// open the tab in the correct userContextId
let tab = gBrowser.addTab(uri, {userContextId});
// select tab and make sure its browser is focused
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
add_task(function* setup() {
// make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true]
]}, resolve);
});
});
add_task(function* test() {
let receiver = yield* openTabInUserContext(URI, 2);
let channelName = "contextualidentity-broadcastchannel";
// reflect the received message on title
yield ContentTask.spawn(receiver.browser, channelName,
function (name) {
content.window.testPromise = new content.window.Promise(resolve => {
content.window.bc = new content.window.BroadcastChannel(name);
content.window.bc.onmessage = function (e) {
content.document.title += e.data;
resolve();
}
});
}
);
let sender1 = yield* openTabInUserContext(URI, 1);
let sender2 = yield* openTabInUserContext(URI, 2);
sender1.message = "Message from user context #1";
sender2.message = "Message from user context #2";
// send a message from a tab in different user context first
// then send a message from a tab in the same user context
for (let sender of [sender1, sender2]) {
yield ContentTask.spawn(
sender.browser,
{ name: channelName, message: sender.message },
function (opts) {
let bc = new content.window.BroadcastChannel(opts.name);
bc.postMessage(opts.message);
});
}
// Since sender1 sends before sender2, if the title is exactly
// sender2's message, sender1's message must've been blocked
yield ContentTask.spawn(receiver.browser, sender2.message,
function* (message) {
yield content.window.testPromise.then(function() {
is(content.document.title, message,
"should only receive messages from the same user context");
});
}
);
gBrowser.removeTab(sender1.tab);
gBrowser.removeTab(sender2.tab);
gBrowser.removeTab(receiver.tab);
});

View file

@ -1,34 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/ContextualIdentityService.jsm");
function openTabInUserContext(userContextId) {
let tab = gBrowser.addTab("about:blank", {userContextId});
gBrowser.selectedTab = tab;
}
add_task(function* setup() {
// make sure userContext is enabled.
yield SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true]
]});
});
add_task(function* test() {
is(ContextualIdentityService.countContainerTabs(), 0, "0 container tabs by default.");
openTabInUserContext(1);
is(ContextualIdentityService.countContainerTabs(), 1, "1 container tab created");
openTabInUserContext(1);
is(ContextualIdentityService.countContainerTabs(), 2, "2 container tab created");
openTabInUserContext(2);
is(ContextualIdentityService.countContainerTabs(), 3, "3 container tab created");
ContextualIdentityService.closeAllContainerTabs();
is(ContextualIdentityService.countContainerTabs(), 0, "0 container tab at the end.");
});

View file

@ -1,186 +0,0 @@
/*
* Bug 1283325 - A test case to test the EME is originAttributes aware or not.
*/
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
const TEST_HOST = "example.com";
const TEST_URL = "http://" + TEST_HOST + "/browser/browser/components/contextualidentity/test/browser/";
const TESTKEY = {
initDataType: 'keyids',
initData: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A"], "type":"persistent-license"}',
kid: "LwVHf8JLtPrv2GUXFW2v_A",
key: "97b9ddc459c8d5ff23c1f2754c95abe8",
sessionType: 'persistent-license',
};
const USER_ID_DEFAULT = 0;
const USER_ID_PERSONAL = 1;
function* openTabInUserContext(uri, userContextId) {
// Open the tab in the correct userContextId.
let tab = gBrowser.addTab(uri, {userContextId});
// Select tab and make sure its browser is focused.
gBrowser.selectedTab = tab;
tab.ownerDocument.defaultView.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
function HexToBase64(hex)
{
var bin = "";
for (var i = 0; i < hex.length; i += 2) {
bin += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return window.btoa(bin).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
}
function Base64ToHex(str)
{
var bin = window.atob(str.replace(/-/g, "+").replace(/_/g, "/"));
var res = "";
for (var i = 0; i < bin.length; i++) {
res += ("0" + bin.charCodeAt(i).toString(16)).substr(-2);
}
return res;
}
function ByteArrayToHex(array) {
let bin = String.fromCharCode.apply(null, new Uint8Array(array));
let res = "";
for (let i = 0; i < bin.length; i++) {
res += ("0" + bin.charCodeAt(i).toString(16)).substr(-2);
}
return res;
}
function generateKeyObject(aKid, aKey) {
let keyObj = {
kty: 'oct',
kid: aKid,
k: HexToBase64(aKey),
};
return new TextEncoder().encode(JSON.stringify({
keys: [keyObj]
}));
}
function generateKeyInfo(aData) {
let keyInfo = {
initDataType: aData.initDataType,
initData: new TextEncoder().encode(aData.initData),
sessionType: aData.sessionType,
keyObj: generateKeyObject(aData.kid, aData.key),
};
return keyInfo;
}
add_task(function* setup() {
// Make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
[ "privacy.userContext.enabled", true ],
[ "media.mediasource.enabled", true ],
[ "media.eme.apiVisible", true ],
[ "media.mediasource.webm.enabled", true ],
[ "media.clearkey.persistent-license.enabled", true ],
]}, resolve);
});
});
add_task(function* test() {
// Open a tab with the default container.
let defaultContainer = yield openTabInUserContext(TEST_URL + "empty_file.html", USER_ID_DEFAULT);
// Generate the key info for the default container.
let keyInfo = generateKeyInfo(TESTKEY);
// Update the media key for the default container.
let result = yield ContentTask.spawn(defaultContainer.browser, keyInfo, function* (aKeyInfo) {
let access = yield content.navigator.requestMediaKeySystemAccess('org.w3.clearkey',
[{
initDataTypes: [aKeyInfo.initDataType],
videoCapabilities: [{contentType: 'video/webm'}],
sessionTypes: ['persistent-license'],
persistentState: 'required',
}]);
let mediaKeys = yield access.createMediaKeys();
let session = mediaKeys.createSession(aKeyInfo.sessionType);
let res = {};
// Insert the media key.
yield new Promise(resolve => {
session.addEventListener("message", function(event) {
session.update(aKeyInfo.keyObj).then(
() => { resolve(); }
).catch(
() => {
ok(false, "Update the media key fail.");
resolve();
}
);
});
session.generateRequest(aKeyInfo.initDataType, aKeyInfo.initData);
});
let map = session.keyStatuses;
is(map.size, 1, "One media key has been added.");
if (map.size === 1) {
res.keyId = map.keys().next().value;
res.sessionId = session.sessionId;
}
// Close the session.
session.close();
yield session.closed;
return res;
});
// Check the media key ID.
is(ByteArrayToHex(result.keyId), Base64ToHex(TESTKEY.kid), "The key Id of the default container is correct.");
// Store the sessionId for the further checking.
keyInfo.sessionId = result.sessionId;
// Open a tab with personal container.
let personalContainer = yield openTabInUserContext(TEST_URL + "empty_file.html", USER_ID_PERSONAL);
yield ContentTask.spawn(personalContainer.browser, keyInfo, function* (aKeyInfo) {
let access = yield content.navigator.requestMediaKeySystemAccess('org.w3.clearkey',
[{
initDataTypes: [aKeyInfo.initDataType],
videoCapabilities: [{contentType: 'video/webm'}],
sessionTypes: ['persistent-license'],
persistentState: 'required',
}]);
let mediaKeys = yield access.createMediaKeys();
let session = mediaKeys.createSession(aKeyInfo.sessionType);
// First, load the session to check that mediakeys do not share with
// default container.
yield session.load(aKeyInfo.sessionId);
let map = session.keyStatuses;
// Check that there is no media key here.
is(map.size, 0, "No media key should be here for the personal container.");
});
// Close default container tab.
yield BrowserTestUtils.removeTab(defaultContainer.tab);
// Close personal container tab.
yield BrowserTestUtils.removeTab(personalContainer.tab);
});

View file

@ -1,140 +0,0 @@
/*
* Bug 1270678 - A test case to test does the favicon obey originAttributes.
*/
let { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
let {HttpServer} = Cu.import("resource://testing-common/httpd.js", {});
const USER_CONTEXTS = [
"default",
"personal",
"work",
];
let gHttpServer = null;
let gUserContextId;
let gFaviconData;
function getIconFile() {
new Promise(resolve => {
NetUtil.asyncFetch({
uri: "http://www.example.com/browser/browser/components/contextualidentity/test/browser/favicon-normal32.png",
loadUsingSystemPrincipal: true,
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON
}, function(inputStream, status) {
let size = inputStream.available();
gFaviconData = NetUtil.readInputStreamToString(inputStream, size);
resolve();
});
});
}
function* openTabInUserContext(uri, userContextId) {
// open the tab in the correct userContextId
let tab = gBrowser.addTab(uri, {userContextId});
// select tab and make sure its browser is focused
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
function loadIndexHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 200, "Ok");
response.setHeader("Content-Type", "text/html", false);
let body = `
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<title>Favicon Test</title>
</head>
<body>
Favicon!!
</body>
</html>`;
response.bodyOutputStream.write(body, body.length);
}
function loadFaviconHandler(metadata, response) {
let expectedCookie = "userContext=" + USER_CONTEXTS[gUserContextId];
if (metadata.hasHeader("Cookie")) {
is(metadata.getHeader("Cookie"), expectedCookie, "The cookie has matched with the expected cookie.");
} else {
ok(false, "The request should have a cookie.");
}
response.setStatusLine(metadata.httpVersion, 200, "Ok");
response.setHeader("Content-Type", "image/png", false);
response.bodyOutputStream.write(gFaviconData, gFaviconData.length);
}
add_task(function* setup() {
// Make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true]
]}, resolve);
});
// Create a http server for the image cache test.
if (!gHttpServer) {
gHttpServer = new HttpServer();
gHttpServer.registerPathHandler('/', loadIndexHandler);
gHttpServer.registerPathHandler('/favicon.png', loadFaviconHandler);
gHttpServer.start(-1);
}
});
registerCleanupFunction(() => {
gHttpServer.stop(() => {
gHttpServer = null;
});
});
add_task(function* test() {
waitForExplicitFinish();
// First, get the icon data.
yield getIconFile();
let serverPort = gHttpServer.identity.primaryPort;
let testURL = "http://localhost:" + serverPort + "/";
let testFaviconURL = "http://localhost:" + serverPort + "/favicon.png";
for (let userContextId of Object.keys(USER_CONTEXTS)) {
gUserContextId = userContextId;
// Load the page in 3 different contexts and set a cookie
// which should only be visible in that context.
// Open our tab in the given user context.
let tabInfo = yield* openTabInUserContext(testURL, userContextId);
// Write a cookie according to the userContext.
yield ContentTask.spawn(tabInfo.browser, { userContext: USER_CONTEXTS[userContextId] }, function (arg) {
content.document.cookie = "userContext=" + arg.userContext;
});
let pageURI = NetUtil.newURI(testURL);
let favIconURI = NetUtil.newURI(testFaviconURL);
yield new Promise(resolve => {
PlacesUtils.favicons.setAndFetchFaviconForPage(pageURI, favIconURI,
true, PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, {
onComplete() {
resolve();
},
},
tabInfo.browser.contentPrincipal);
});
yield BrowserTestUtils.removeTab(tabInfo.tab);
}
});

View file

@ -1,219 +0,0 @@
/*
* Bug 1278037 - A Test case for checking whether forgetting APIs are working for the media key.
*/
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
const TEST_HOST = "example.com";
const TEST_URL = "http://" + TEST_HOST + "/browser/browser/components/contextualidentity/test/browser/";
const USER_CONTEXTS = [
"default",
"personal",
];
const TEST_EME_KEY = {
initDataType: 'keyids',
initData: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A"], "type":"persistent-license"}',
kid: "LwVHf8JLtPrv2GUXFW2v_A",
key: "97b9ddc459c8d5ff23c1f2754c95abe8",
sessionType: 'persistent-license',
};
//
// Support functions.
//
function* openTabInUserContext(uri, userContextId) {
// Open the tab in the correct userContextId.
let tab = gBrowser.addTab(uri, {userContextId});
// Select tab and make sure its browser is focused.
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
function HexToBase64(hex) {
var bin = "";
for (var i = 0; i < hex.length; i += 2) {
bin += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return window.btoa(bin).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
}
function Base64ToHex(str) {
var bin = window.atob(str.replace(/-/g, "+").replace(/_/g, "/"));
var res = "";
for (var i = 0; i < bin.length; i++) {
res += ("0" + bin.charCodeAt(i).toString(16)).substr(-2);
}
return res;
}
function ByteArrayToHex(array) {
let bin = String.fromCharCode.apply(null, new Uint8Array(array));
let res = "";
for (let i = 0; i < bin.length; i++) {
res += ("0" + bin.charCodeAt(i).toString(16)).substr(-2);
}
return res;
}
function generateKeyObject(aKid, aKey) {
let keyObj = {
kty: 'oct',
kid: aKid,
k: HexToBase64(aKey),
};
return new TextEncoder().encode(JSON.stringify({
keys: [keyObj]
}));
}
function generateKeyInfo(aData) {
let keyInfo = {
initDataType: aData.initDataType,
initData: new TextEncoder().encode(aData.initData),
sessionType: aData.sessionType,
keyObj: generateKeyObject(aData.kid, aData.key),
};
return keyInfo;
}
// Setup a EME key for the given browser, and return the sessionId.
function* setupEMEKey(browser) {
// Generate the key info.
let keyInfo = generateKeyInfo(TEST_EME_KEY);
// Setup the EME key.
let result = yield ContentTask.spawn(browser, keyInfo, function* (aKeyInfo) {
let access = yield content.navigator.requestMediaKeySystemAccess('org.w3.clearkey',
[{
initDataTypes: [aKeyInfo.initDataType],
videoCapabilities: [{contentType: 'video/webm'}],
sessionTypes: ['persistent-license'],
persistentState: 'required',
}]);
let mediaKeys = yield access.createMediaKeys();
let session = mediaKeys.createSession(aKeyInfo.sessionType);
let res = {};
// Insert the EME key.
yield new Promise(resolve => {
session.addEventListener("message", function(event) {
session.update(aKeyInfo.keyObj).then(
() => { resolve(); }
).catch(
() => {
ok(false, "Update the EME key fail.");
resolve();
}
);
});
session.generateRequest(aKeyInfo.initDataType, aKeyInfo.initData);
});
let map = session.keyStatuses;
is(map.size, 1, "One EME key has been added.");
if (map.size === 1) {
res.keyId = map.keys().next().value;
res.sessionId = session.sessionId;
}
// Close the session.
session.close();
yield session.closed;
return res;
});
// Check the EME key ID.
is(ByteArrayToHex(result.keyId), Base64ToHex(TEST_EME_KEY.kid), "The key Id is correct.");
return result.sessionId;
}
// Check whether the EME key has been cleared.
function* checkEMEKey(browser, emeSessionId) {
// Generate the key info.
let keyInfo = generateKeyInfo(TEST_EME_KEY);
keyInfo.sessionId = emeSessionId;
yield ContentTask.spawn(browser, keyInfo, function* (aKeyInfo) {
let access = yield content.navigator.requestMediaKeySystemAccess('org.w3.clearkey',
[{
initDataTypes: [aKeyInfo.initDataType],
videoCapabilities: [{contentType: 'video/webm'}],
sessionTypes: ['persistent-license'],
persistentState: 'required',
}]);
let mediaKeys = yield access.createMediaKeys();
let session = mediaKeys.createSession(aKeyInfo.sessionType);
// First, load the session with the sessionId.
yield session.load(aKeyInfo.sessionId);
let map = session.keyStatuses;
// Check that there is no media key here.
is(map.size, 0, "No media key should be here after forgetThisSite() was called.");
});
}
//
// Test functions.
//
add_task(function* setup() {
// Make sure userContext is enabled.
yield SpecialPowers.pushPrefEnv({"set": [
[ "privacy.userContext.enabled", true ],
[ "media.mediasource.enabled", true ],
[ "media.eme.apiVisible", true ],
[ "media.mediasource.webm.enabled", true ],
[ "media.clearkey.persistent-license.enabled", true ],
]});
});
add_task(function* test_EME_forgetThisSite() {
let tabs = [];
let emeSessionIds = [];
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context.
tabs[userContextId] = yield* openTabInUserContext(TEST_URL+ "empty_file.html", userContextId);
// Setup EME Key.
emeSessionIds[userContextId] = yield setupEMEKey(tabs[userContextId].browser);
// Close this tab.
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
// Clear all EME data for a given domain with originAttributes pattern.
let mps = Cc["@mozilla.org/gecko-media-plugin-service;1"].
getService(Ci.mozIGeckoMediaPluginChromeService);
mps.forgetThisSite(TEST_HOST, JSON.stringify({}));
// Open tabs again to check EME keys have been cleared.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context.
tabs[userContextId] = yield* openTabInUserContext(TEST_URL+ "empty_file.html", userContextId);
// Check whether EME Key has been cleared.
yield checkEMEKey(tabs[userContextId].browser, emeSessionIds[userContextId]);
// Close this tab.
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
});

View file

@ -1,86 +0,0 @@
/*
* Bug 1278037 - A Test case for checking whether forgetting APIs are working for cookies.
*/
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
const TEST_HOST = "example.com";
const TEST_URL = "http://" + TEST_HOST + "/browser/browser/components/contextualidentity/test/browser/";
const USER_CONTEXTS = [
"default",
"personal",
];
//
// Support functions.
//
function* openTabInUserContext(uri, userContextId) {
// Open the tab in the correct userContextId.
let tab = gBrowser.addTab(uri, {userContextId});
// Select tab and make sure its browser is focused.
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
function getCookiesForOA(host, userContextId) {
return Services.cookies.getCookiesFromHost(host, {userContextId});
}
//
// Test functions.
//
add_task(function* setup() {
// Make sure userContext is enabled.
yield SpecialPowers.pushPrefEnv({"set": [
[ "privacy.userContext.enabled", true ],
]});
});
add_task(function* test_cookie_getCookiesWithOriginAttributes() {
let tabs = [];
let cookieName = "userContextId";
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Load the page in 2 different contexts and set a cookie
// which should only be visible in that context.
let value = USER_CONTEXTS[userContextId];
// Open our tab in the given user context.
tabs[userContextId] = yield* openTabInUserContext(TEST_URL+ "file_reflect_cookie_into_title.html?" + value, userContextId);
// Close this tab.
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
// Check that cookies have been set properly.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
let enumerator = getCookiesForOA(TEST_HOST, userContextId);
ok(enumerator.hasMoreElements(), "Cookies available");
let foundCookie = enumerator.getNext().QueryInterface(Ci.nsICookie2);
is(foundCookie["name"], cookieName, "Check cookie name");
is(foundCookie["value"], USER_CONTEXTS[userContextId], "Check cookie value");
}
// Using getCookiesWithOriginAttributes() to get all cookies for a certain
// domain by using the originAttributes pattern, and clear all these cookies.
let enumerator = Services.cookies.getCookiesWithOriginAttributes(JSON.stringify({}), TEST_HOST);
while (enumerator.hasMoreElements()) {
let cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
Services.cookies.remove(cookie.host, cookie.name, cookie.path, false, cookie.originAttributes);
}
// Check that whether cookies has been cleared.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
let enumerator = getCookiesForOA(TEST_HOST, userContextId);
ok(!enumerator.hasMoreElements(), "No Cookie should be here");
}
});

View file

@ -1,147 +0,0 @@
/*
* Bug 1278037 - A Test case for checking whether forgetting APIs are working for the quota manager.
*/
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
const TEST_HOST = "example.com";
const TEST_URL = "http://" + TEST_HOST + "/browser/browser/components/contextualidentity/test/browser/";
const USER_CONTEXTS = [
"default",
"personal",
];
//
// Support functions.
//
function* openTabInUserContext(uri, userContextId) {
// Open the tab in the correct userContextId.
let tab = gBrowser.addTab(uri, {userContextId});
// Select tab and make sure its browser is focused.
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
// Setup an entry for the indexedDB.
function* setupIndexedDB(browser) {
yield ContentTask.spawn(browser, { input: "TestForgetAPIs" }, function* (arg) {
let request = content.indexedDB.open("idb", 1);
request.onerror = function() {
throw new Error("error opening db connection");
};
request.onupgradeneeded = event => {
let db = event.target.result;
let store = db.createObjectStore("obj", { keyPath: "id" });
store.createIndex("userContext", "userContext", { unique: false });
};
let db = yield new Promise(resolve => {
request.onsuccess = event => {
resolve(event.target.result);
};
});
// Add an entry into the indexedDB.
let transaction = db.transaction(["obj"], "readwrite");
let store = transaction.objectStore("obj");
store.add({id: 1, userContext: arg.input});
yield new Promise(resolve => {
transaction.oncomplete = () => {
resolve();
};
});
// Check the indexedDB has been set properly.
transaction = db.transaction(["obj"], "readonly");
store = transaction.objectStore("obj");
let getRequest = store.get(1);
yield new Promise(resolve => {
getRequest.onsuccess = () => {
let res = getRequest.result;
is(res.userContext, arg.input, "Check the indexedDB value");
resolve();
};
});
});
}
// Check whether the indexedDB has been cleared.
function* checkIndexedDB(browser) {
yield ContentTask.spawn(browser, null, function* () {
let request = content.indexedDB.open("idb", 1);
let db = yield new Promise(done => {
request.onsuccess = event => {
done(event.target.result);
};
});
try {
db.transaction(["obj"], "readonly");
ok(false, "The indexedDB should not exist");
} catch (e) {
is(e.name, "NotFoundError", "The indexedDB does not exist as expected");
}
});
}
//
// Test functions.
//
add_task(function* setup() {
// Make sure userContext is enabled.
yield SpecialPowers.pushPrefEnv({"set": [
[ "privacy.userContext.enabled", true ],
]});
});
add_task(function* test_quota_clearStoragesForPrincipal() {
let tabs = [];
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context.
tabs[userContextId] = yield* openTabInUserContext(TEST_URL+ "empty_file.html", userContextId);
// Setup an entry for the indexedDB.
yield setupIndexedDB(tabs[userContextId].browser);
// Close this tab.
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
// Using quota manager to clear all indexed DB for a given domain.
let qms = Cc["@mozilla.org/dom/quota-manager-service;1"].
getService(Ci.nsIQuotaManagerService);
let caUtils = {};
let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
scriptLoader.loadSubScript("chrome://global/content/contentAreaUtils.js",
caUtils);
let httpURI = caUtils.makeURI("http://" + TEST_HOST);
let httpPrincipal = Services.scriptSecurityManager
.createCodebasePrincipal(httpURI, {});
qms.clearStoragesForPrincipal(httpPrincipal, null, true);
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context.
tabs[userContextId] = yield* openTabInUserContext(TEST_URL+ "empty_file.html", userContextId);
// Check whether indexed DB has been cleared.
yield checkIndexedDB(tabs[userContextId].browser);
// Close this tab.
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
});

View file

@ -1,352 +0,0 @@
/*
* Bug 1238183 - Test cases for forgetAboutSite with userContextId.
*/
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/ForgetAboutSite.jsm");
Cu.import("resource://gre/modules/Services.jsm");
let {HttpServer} = Cu.import("resource://testing-common/httpd.js", {});
let LoadContextInfo = Cc["@mozilla.org/load-context-info-factory;1"]
.getService(Ci.nsILoadContextInfoFactory);
let css = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
const USER_CONTEXTS = [
"default",
"personal",
];
const TEST_HOST = "example.com";
const TEST_URL = "http://" + TEST_HOST + "/browser/browser/components/contextualidentity/test/browser/";
const COOKIE_NAME = "userContextId";
// Counter for image load hits.
let gHits = 0;
let gHttpServer = null;
function imageHandler(metadata, response) {
// A 1x1 PNG image.
// Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
"ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=");
gHits++;
response.setHeader("Cache-Control", "max-age=10000", false);
response.setStatusLine(metadata.httpVersion, 200, "OK");
response.setHeader("Content-Type", "image/png", false);
response.write(IMAGE);
}
function loadImagePageHandler(metadata, response) {
response.setHeader("Cache-Control", "max-age=10000", false);
response.setStatusLine(metadata.httpVersion, 200, "Ok");
response.setHeader("Content-Type", "text/html", false);
let body = "<!DOCTYPE HTML>\
<html>\
<head>\
<meta charset='utf-8'>\
<title>Load Image</title>\
</head>\
<body>\
<img src='image.png'>\
</body>\
</html>";
response.bodyOutputStream.write(body, body.length);
}
function* openTabInUserContext(uri, userContextId) {
// Open the tab in the correct userContextId.
let tab = gBrowser.addTab(uri, {userContextId});
// Select tab and make sure its browser is focused.
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return {tab, browser};
}
function getCookiesForOA(host, userContextId) {
return Services.cookies.getCookiesFromHost(host, {userContextId});
}
function createURI(uri)
{
let ioServ = Cc["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return ioServ.newURI(uri, null, null);
}
function getCacheStorage(where, lci, appcache)
{
if (!lci) lci = LoadContextInfo.default;
switch (where) {
case "disk": return css.diskCacheStorage(lci, false);
case "memory": return css.memoryCacheStorage(lci);
case "appcache": return css.appCacheStorage(lci, appcache);
case "pin": return css.pinningCacheStorage(lci);
}
return null;
}
function OpenCacheEntry(key, where, flags, lci)
{
return new Promise(resolve => {
key = createURI(key);
function CacheListener() { }
CacheListener.prototype = {
_appCache: null,
QueryInterface: function (iid) {
if (iid.equals(Components.interfaces.nsICacheEntryOpenCallback) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
onCacheEntryCheck: function(entry, appCache) {
return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
},
onCacheEntryAvailable: function (entry, isnew, appCache, status) {
resolve();
},
run: function () {
let storage = getCacheStorage(where, lci, this._appCache);
storage.asyncOpenURI(key, "", flags, this);
}
};
(new CacheListener()).run();
});
}
//
// Test functions.
//
// Cookies
function* test_cookie_cleared() {
let tabs = [];
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Load the page in 2 different contexts and set a cookie
// which should only be visible in that context.
let value = USER_CONTEXTS[userContextId];
// Open our tab in the given user context.
tabs[userContextId] = yield* openTabInUserContext(TEST_URL+ "file_reflect_cookie_into_title.html?" + value, userContextId);
// Close this tab.
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
// Check that cookies have been set properly.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
let enumerator = getCookiesForOA(TEST_HOST, userContextId);
ok(enumerator.hasMoreElements(), "Cookies available");
let foundCookie = enumerator.getNext().QueryInterface(Ci.nsICookie2);
Assert.equal(foundCookie["name"], COOKIE_NAME, "Check cookie name");
Assert.equal(foundCookie["value"], USER_CONTEXTS[userContextId], "Check cookie value");
}
// Forget the site.
ForgetAboutSite.removeDataFromDomain(TEST_HOST);
// Check that whether cookies has been cleared or not.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
let enumerator = getCookiesForOA(TEST_HOST, userContextId);
ok(!enumerator.hasMoreElements(), "No Cookie should be here");
}
}
// Cache
function* test_cache_cleared() {
// First, add some caches.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
yield OpenCacheEntry("http://" + TEST_HOST + "/",
"disk",
Ci.nsICacheStorage.OPEN_NORMALLY,
LoadContextInfo.custom(false, {userContextId}));
yield OpenCacheEntry("http://" + TEST_HOST + "/",
"memory",
Ci.nsICacheStorage.OPEN_NORMALLY,
LoadContextInfo.custom(false, {userContextId}));
}
// Check that caches have been set correctly.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
let mem = getCacheStorage("memory", LoadContextInfo.custom(false, {userContextId}));
let disk = getCacheStorage("disk", LoadContextInfo.custom(false, {userContextId}));
Assert.ok(mem.exists(createURI("http://" + TEST_HOST + "/"), ""), "The memory cache has been set correctly");
Assert.ok(disk.exists(createURI("http://" + TEST_HOST + "/"), ""), "The disk cache has been set correctly");
}
// Forget the site.
ForgetAboutSite.removeDataFromDomain(TEST_HOST);
// Check that do caches be removed or not?
for (let userContextId of Object.keys(USER_CONTEXTS)) {
let mem = getCacheStorage("memory", LoadContextInfo.custom(false, {userContextId}));
let disk = getCacheStorage("disk", LoadContextInfo.custom(false, {userContextId}));
Assert.ok(!mem.exists(createURI("http://" + TEST_HOST + "/"), ""), "The memory cache is cleared");
Assert.ok(!disk.exists(createURI("http://" + TEST_HOST + "/"), ""), "The disk cache is cleared");
}
}
// Image Cache
function* test_image_cache_cleared() {
let tabs = [];
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context to cache image.
tabs[userContextId] = yield* openTabInUserContext('http://localhost:' + gHttpServer.identity.primaryPort + '/loadImage.html',
userContextId);
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
let expectedHits = USER_CONTEXTS.length;
// Check that image cache works with the userContextId.
is(gHits, expectedHits, "The image should be loaded" + expectedHits + "times.");
// Reset the cache count.
gHits = 0;
// Forget the site.
ForgetAboutSite.removeDataFromDomain("localhost:" + gHttpServer.identity.primaryPort + "/");
// Load again.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context to cache image.
tabs[userContextId] = yield* openTabInUserContext('http://localhost:' + gHttpServer.identity.primaryPort + '/loadImage.html',
userContextId);
yield BrowserTestUtils.removeTab(tabs[userContextId].tab);
}
// Check that image cache was cleared and the server gets another two hits.
is(gHits, expectedHits, "The image should be loaded" + expectedHits + "times.");
}
// Offline Storage
function* test_storage_cleared() {
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Load the page in 2 different contexts and set the local storage
// which should only be visible in that context.
let value = USER_CONTEXTS[userContextId];
// Open our tab in the given user context.
let tabInfo = yield* openTabInUserContext(TEST_URL+ "file_set_storages.html?" + value, userContextId);
// Check that the storages has been set correctly.
yield ContentTask.spawn(tabInfo.browser, { userContext: USER_CONTEXTS[userContextId] }, function* (arg) {
// Check that the local storage has been set correctly.
Assert.equal(content.localStorage.getItem("userContext"), arg.userContext, "Check the local storage value");
// Check that the session storage has been set correctly.
Assert.equal(content.sessionStorage.getItem("userContext"), arg.userContext, "Check the session storage value");
// Check that the indexedDB has been set correctly.
let request = content.indexedDB.open("idb", 1);
let db = yield new Promise(done => {
request.onsuccess = event => {
done(event.target.result);
};
});
let transaction = db.transaction(["obj"], "readonly");
let store = transaction.objectStore("obj");
let storeRequest = store.get(1);
yield new Promise(done => {
storeRequest.onsuccess = event => {
let res = storeRequest.result;
Assert.equal(res.userContext, arg.userContext, "Check the indexedDB value");
done();
};
});
});
// Close this tab.
yield BrowserTestUtils.removeTab(tabInfo.tab);
}
// Forget the site.
ForgetAboutSite.removeDataFromDomain(TEST_HOST);
// Open the tab again without setting the localStorage and check that the
// local storage has been cleared or not.
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Open our tab in the given user context without setting local storage.
let tabInfo = yield* openTabInUserContext(TEST_URL+ "file_set_storages.html", userContextId);
// Check that do storages be cleared or not.
yield ContentTask.spawn(tabInfo.browser, null, function* () {
// Check that does the local storage be cleared or not.
Assert.ok(!content.localStorage.getItem("userContext"), "The local storage has been cleared");
// Check that does the session storage be cleared or not.
Assert.ok(!content.sessionStorage.getItem("userContext"), "The session storage has been cleared");
// Check that does the indexedDB be cleared or not.
let request = content.indexedDB.open("idb", 1);
let db = yield new Promise(done => {
request.onsuccess = event => {
done(event.target.result);
};
});
try {
db.transaction(["obj"], "readonly");
Assert.ok(false, "The indexedDB should not exist");
} catch (e) {
Assert.equal(e.name, "NotFoundError", "The indexedDB does not exist as expected");
}
});
// Close the tab.
yield BrowserTestUtils.removeTab(tabInfo.tab);
}
}
add_task(function* setup() {
// Make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true]
]}, resolve);
});
// Create a http server for the image cache test.
if (!gHttpServer) {
gHttpServer = new HttpServer();
gHttpServer.registerPathHandler('/image.png', imageHandler);
gHttpServer.registerPathHandler('/loadImage.html', loadImagePageHandler);
gHttpServer.start(-1);
}
});
let tests = [
test_cookie_cleared,
test_cache_cleared,
test_image_cache_cleared,
test_storage_cleared,
];
add_task(function* test() {
for (let i = 0; i < tests.length; i++)
add_task(tests[i]);
});
registerCleanupFunction(() => {
gHttpServer.stop(() => {
gHttpServer = null;
});
});

View file

@ -1,59 +0,0 @@
let Cu = Components.utils;
let {HttpServer} = Cu.import("resource://testing-common/httpd.js", {});
const NUM_USER_CONTEXTS = 3;
let gHits = 0;
let server = new HttpServer();
server.registerPathHandler('/image.png', imageHandler);
server.registerPathHandler('/file.html', fileHandler);
server.start(-1);
let BASE_URI = 'http://localhost:' + server.identity.primaryPort;
let IMAGE_URI = BASE_URI + '/image.png';
let FILE_URI = BASE_URI + '/file.html';
function imageHandler(metadata, response) {
gHits++;
response.setHeader("Cache-Control", "max-age=10000", false);
response.setStatusLine(metadata.httpVersion, 200, "OK");
response.setHeader("Content-Type", "image/png", false);
var body = "iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAEUlEQVQImWP4z8AAQTAamQkAhpcI+DeMzFcAAAAASUVORK5CYII=";
response.bodyOutputStream.write(body, body.length);
}
function fileHandler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 200, "OK");
response.setHeader("Content-Type", "text/html", false);
let body = `<html><body><image src=${IMAGE_URI}></body></html>`;
response.bodyOutputStream.write(body, body.length);
}
add_task(function* setup() {
// make sure userContext is enabled.
yield SpecialPowers.pushPrefEnv({"set": [["privacy.userContext.enabled", true]]});
});
// opens `uri' in a new tab with the provided userContextId and focuses it.
// returns the newly opened tab
function* openTabInUserContext(uri, userContextId) {
// open the tab in the correct userContextId
let tab = gBrowser.addTab(uri, {userContextId});
// select tab and make sure its browser is focused
gBrowser.selectedTab = tab;
tab.ownerDocument.defaultView.focus();
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
return tab;
}
add_task(function* test() {
for (let userContextId = 0; userContextId < NUM_USER_CONTEXTS; userContextId++) {
let tab = yield* openTabInUserContext(FILE_URI, userContextId);
gBrowser.removeTab(tab);
}
is(gHits, NUM_USER_CONTEXTS, "should get an image request for each user contexts");
});

View file

@ -1,41 +0,0 @@
"use strict";
const BASE_ORIGIN = "http://example.com";
const URI = BASE_ORIGIN +
"/browser/browser/components/contextualidentity/test/browser/empty_file.html";
add_task(function* () {
info("Opening a new container tab...");
let tab = gBrowser.addTab(URI, { userContextId: 1 });
gBrowser.selectedTab = tab;
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
info("Create a HTMLAnchorElement...");
yield ContentTask.spawn(browser, URI,
function(URI) {
let anchor = content.document.createElement("a");
anchor.setAttribute('id', 'clickMe');
anchor.setAttribute("href", URI);
anchor.appendChild(content.document.createTextNode("click me!"));
content.document.body.appendChild(anchor);
}
);
info("Synthesize a mouse click and wait for a new tab...");
let newTab = yield new Promise((resolve, reject) => {
gBrowser.tabContainer.addEventListener("TabOpen", function onTabOpen(openEvent) {
gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen);
resolve(openEvent.target);
})
BrowserTestUtils.synthesizeMouseAtCenter("#clickMe", { button: 1 }, browser);
});
is(newTab.getAttribute("usercontextid"), 1, "Correct UserContextId?");
yield BrowserTestUtils.removeTab(tab);
yield BrowserTestUtils.removeTab(newTab);
});

View file

@ -1,35 +0,0 @@
"use strict";
// Testing that when the user opens the add tab menu and clicks menu items
// the correct context id is opened
add_task(function* test() {
yield SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true]
]});
let newTab = document.getElementById('tabbrowser-tabs');
let newTabButton = document.getAnonymousElementByAttribute(newTab, "anonid", "tabs-newtab-button");
ok(newTabButton, "New tab button exists");
ok(!newTabButton.hidden, "New tab button is visible");
yield BrowserTestUtils.waitForCondition(() => !!document.getAnonymousElementByAttribute(newTab, "anonid", "newtab-popup"), "Wait for popup to exist");
let popup = document.getAnonymousElementByAttribute(newTab, "anonid", "newtab-popup");
for (let i = 1; i <= 4; i++) {
let popupShownPromise = BrowserTestUtils.waitForEvent(popup, "popupshown");
EventUtils.synthesizeMouseAtCenter(newTabButton, {type: "mousedown"});
yield popupShownPromise;
let contextIdItem = popup.querySelector(`menuitem[data-usercontextid="${i}"]`);
ok(contextIdItem, `User context id ${i} exists`);
let waitForTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
EventUtils.synthesizeMouseAtCenter(contextIdItem, {});
let tab = yield waitForTabPromise;
is(tab.getAttribute('usercontextid'), i, `New tab has UCI equal ${i}`);
yield BrowserTestUtils.removeTab(tab);
}
});

View file

@ -1,108 +0,0 @@
let { classes: Cc, interfaces: Ci } = Components;
let swm = Cc["@mozilla.org/serviceworkers/manager;1"].
getService(Ci.nsIServiceWorkerManager);
const BASE_ORIGIN = "https://example.com";
const URI = BASE_ORIGIN +
"/browser/browser/components/contextualidentity/test/browser/serviceworker.html";
const NUM_USER_CONTEXTS = 3;
// opens `uri' in a new tab with the provided userContextId and focuses it.
// returns the newly opened tab
function openTabInUserContext(uri, userContextId) {
// open the tab in the correct userContextId
let tab = gBrowser.addTab(uri, {userContextId});
// select tab and make sure its browser is focused
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
return tab;
}
add_task(function* setup() {
// make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.openWindow.enabled", true],
["dom.ipc.processCount", 1]
]}, resolve);
});
});
let infos = [];
add_task(function* test() {
// Open the same URI in multiple user contexts, and make sure we have a
// separate service worker in each of the contexts
for (let userContextId = 0; userContextId < NUM_USER_CONTEXTS; userContextId++) {
// Open a tab in given user contexts
let tab = openTabInUserContext(URI, userContextId);
// wait for tab load
yield BrowserTestUtils.browserLoaded(gBrowser.getBrowserForTab(tab));
// remove the tab
gBrowser.removeTab(tab);
}
if (!allRegistered()) {
yield promiseAllRegistered();
}
ok(true, "all service workers are registered");
// Unregistered all service workers added in this test
for (let info of infos) {
yield promiseUnregister(info);
}
});
function allRegistered() {
let results = [];
let registrations = swm.getAllRegistrations();
for (let i = 0; i < registrations.length; i++) {
let info = registrations.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
let principal = info.principal;
if (principal.originNoSuffix === BASE_ORIGIN) {
results[principal.userContextId] = true;
infos[principal.userContextId] = info;
}
}
for (let userContextId = 0; userContextId < NUM_USER_CONTEXTS; userContextId++) {
if (!results[userContextId]) {
return false;
}
}
return true;
}
function promiseAllRegistered() {
return new Promise(function(resolve) {
let listener = {
onRegister: function() {
if (allRegistered()) {
swm.removeListener(listener);
resolve();
}
}
}
swm.addListener(listener);
});
}
function promiseUnregister(info) {
return new Promise(function(resolve) {
swm.unregister(info.principal, {
unregisterSucceeded: function(aState) {
ok(aState, "ServiceWorkerRegistration exists");
resolve();
},
unregisterFailed: function(aState) {
ok(false, "unregister should succeed");
}
}, info.scope);
});
}

View file

@ -1,86 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const USER_CONTEXTS = [
"default",
"personal",
"work",
];
const BASE_URI = "http://mochi.test:8888/browser/browser/components/"
+ "contextualidentity/test/browser/file_reflect_cookie_into_title.html";
// opens `uri' in a new tab with the provided userContextId and focuses it.
// returns the newly opened tab
function openTabInUserContext(uri, userContextId) {
// open the tab in the correct userContextId
let tab = gBrowser.addTab(uri, {userContextId});
// select tab and make sure its browser is focused
gBrowser.selectedTab = tab;
tab.ownerGlobal.focus();
return tab;
}
add_task(function* setup() {
// make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true],
["dom.ipc.processCount", 1]
]}, resolve);
});
});
add_task(function* test() {
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// load the page in 3 different contexts and set a cookie
// which should only be visible in that context
let cookie = USER_CONTEXTS[userContextId];
// open our tab in the given user context
let tab = openTabInUserContext(BASE_URI+"?"+cookie, userContextId);
// wait for tab load
yield BrowserTestUtils.browserLoaded(gBrowser.getBrowserForTab(tab));
// remove the tab
gBrowser.removeTab(tab);
}
{
// Set a cookie in a different context so we can detect if that affects
// cross-context properly. If we don't do that, we get an UNEXPECTED-PASS
// for the localStorage case for the last tab we set.
let tab = openTabInUserContext(BASE_URI+"?foo", 9999);
yield BrowserTestUtils.browserLoaded(gBrowser.getBrowserForTab(tab));
gBrowser.removeTab(tab);
}
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Load the page without setting the cookie this time
let expectedContext = USER_CONTEXTS[userContextId];
let tab = openTabInUserContext(BASE_URI, userContextId);
// wait for load
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
// get the title
let title = browser.contentDocument.title.trim().split("|");
// check each item in the title and validate it meets expectatations
for (let part of title) {
let [storageMethodName, value] = part.split("=");
is(value, expectedContext,
"the title reflects the expected contextual identity of " +
expectedContext + " for method " + storageMethodName + ": " + value);
}
gBrowser.removeTab(tab);
}
});

View file

@ -1,134 +0,0 @@
"use strict";
let EventUtils = {};
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
/**
* Dragging an URL to a tab without userContextId set.
*/
add_task(function* () {
let tab = gBrowser.addTab("http://example.com/");
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let awaitDrop = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "drop");
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "http://test1.example.com/");
// A drop type of "link" onto an existing tab would normally trigger a
// load in that same tab, but tabbrowser code in _getDragTargetTab treats
// drops on the outer edges of a tab differently (loading a new tab
// instead). Make events created by synthesizeDrop have all of their
// coordinates set to 0 (screenX/screenY), so they're treated as drops
// on the outer edge of the tab, thus they open new tabs.
let event = {
clientX: 0,
clientY: 0,
screenX: 0,
screenY: 0,
};
EventUtils.synthesizeDrop(tab, tab, [[{type: "text/plain", data: "http://test1.example.com/"}]], "link", window, undefined, event);
yield awaitDrop;
let tab2 = yield newTabPromise;
Assert.ok(!tab2.hasAttribute("usercontextid"), "Tab shouldn't have usercontextid attribute");
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
yield ContentTask.spawn(tab2.linkedBrowser, {}, function* () {
Assert.equal(content.document.documentURI, "http://test1.example.com/");
Assert.equal(content.document.nodePrincipal.originAttributes.userContextId, 0);
// referrer is empty when urls are dragged to new or existing tabs.
// If this changes in the future, it would be okay to send the referrer
// in this case because we are creating a new tab with the default
// usercontextid as the original tab.
Assert.equal(content.document.referrer, "", "referrer should be empty");
});
yield BrowserTestUtils.removeTab(tab);
yield BrowserTestUtils.removeTab(tab2);
});
/**
* When dragging an URL to a new tab, the new tab should have the same
* userContextId as the original tab.
*/
add_task(function* () {
let tab = gBrowser.addTab("http://example.com/", {userContextId: 1});
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let awaitDrop = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "drop");
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "http://test1.example.com/");
// A drop type of "link" onto an existing tab would normally trigger a
// load in that same tab, but tabbrowser code in _getDragTargetTab treats
// drops on the outer edges of a tab differently (loading a new tab
// instead). Make events created by synthesizeDrop have all of their
// coordinates set to 0 (screenX/screenY), so they're treated as drops
// on the outer edge of the tab, thus they open new tabs.
let event = {
clientX: 0,
clientY: 0,
screenX: 0,
screenY: 0,
};
EventUtils.synthesizeDrop(tab, tab, [[{type: "text/plain", data: "http://test1.example.com/"}]], "link", window, undefined, event);
yield awaitDrop;
let tab2 = yield newTabPromise;
Assert.equal(tab2.getAttribute("usercontextid"), 1);
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
yield ContentTask.spawn(tab2.linkedBrowser, {}, function* () {
Assert.equal(content.document.documentURI, "http://test1.example.com/");
Assert.equal(content.document.nodePrincipal.originAttributes.userContextId, 1);
// referrer is empty when urls are dragged to new or existing tabs.
// If this changes in the future, it would be okay to send the referrer
// in this case because we are creating a new tab with the same
// usercontextid as the original tab.
Assert.equal(content.document.referrer, "", "referrer should be empty");
});
yield BrowserTestUtils.removeTab(tab);
yield BrowserTestUtils.removeTab(tab2);
});
/**
* When dragging a URL from one tab or link on a tab to an existing tab, the
* existing tab should not change its userContextId.
* Ex: if you drag a link from tab 1 with userContext 1 to tab 2 with
* userContext 2, the link will open in tab 2 with userContext 2.
*/
add_task(function* () {
let tab = gBrowser.addTab("http://example.com/", {userContextId: 1});
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let tab2 = gBrowser.addTab("http://example.org/", {userContextId: 2});
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
let awaitDrop = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "drop");
EventUtils.synthesizeDrop(tab, tab2, [[{type: "text/plain", data: "http://test1.example.com/"}]], "link", window);
yield awaitDrop;
Assert.equal(tab2.getAttribute("usercontextid"), 2);
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
yield ContentTask.spawn(tab2.linkedBrowser, {}, function* () {
Assert.equal(content.document.documentURI, "http://test1.example.com/");
Assert.equal(content.document.nodePrincipal.originAttributes.userContextId, 2);
// referrer is empty when urls are dragged to new or existing tabs.
// If this changes in the future, we should ensure that we are not sending
// a referrer for this case! When opening links across user contexts, we
// don't want the referrer to follow the user from one context to another.
Assert.equal(content.document.referrer, "", "referrer should be empty");
});
yield BrowserTestUtils.removeTab(tab);
yield BrowserTestUtils.removeTab(tab2);
});

View file

@ -1,74 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const USER_CONTEXTS = [
"default",
"personal",
"work",
];
const BASE_URI = "http://mochi.test:8888/browser/browser/components/"
+ "contextualidentity/test/browser/empty_file.html";
add_task(function* setup() {
// make sure userContext is enabled.
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true],
["browser.link.open_newwindow", 3],
]}, resolve);
});
});
add_task(function* test() {
info("Creating first tab...");
let tab1 = gBrowser.addTab(BASE_URI + '?old', {userContextId: 1});
let browser1 = gBrowser.getBrowserForTab(tab1);
yield BrowserTestUtils.browserLoaded(browser1);
yield ContentTask.spawn(browser1, null, function(opts) {
content.window.name = 'tab-1';
});
info("Creating second tab...");
let tab2 = gBrowser.addTab(BASE_URI + '?old', {userContextId: 2});
let browser2 = gBrowser.getBrowserForTab(tab2);
yield BrowserTestUtils.browserLoaded(browser2);
yield ContentTask.spawn(browser2, null, function(opts) {
content.window.name = 'tab-2';
});
// Let's try to open a window from tab1 with a name 'tab-2'.
info("Opening a window from the first tab...");
yield ContentTask.spawn(browser1, { url: BASE_URI + '?new' }, function* (opts) {
yield (new content.window.wrappedJSObject.Promise(resolve => {
let w = content.window.wrappedJSObject.open(opts.url, 'tab-2');
w.onload = function() { resolve(); }
}));
});
is(browser1.contentTitle, '?old', "Tab1 title must be 'old'");
is(browser1.contentPrincipal.userContextId, 1, "Tab1 UCI must be 1");
is(browser2.contentTitle, '?old', "Tab2 title must be 'old'");
is(browser2.contentPrincipal.userContextId, 2, "Tab2 UCI must be 2");
let found = false;
for (let i = 0; i < gBrowser.tabContainer.childNodes.length; ++i) {
let tab = gBrowser.tabContainer.childNodes[i];
let browser = gBrowser.getBrowserForTab(tab);
if (browser.contentTitle == '?new') {
is(browser.contentPrincipal.userContextId, 1, "Tab3 UCI must be 1");
isnot(browser, browser1, "Tab3 is not browser 1");
isnot(browser, browser2, "Tab3 is not browser 2");
gBrowser.removeTab(tab);
found = true;
break;
}
}
ok(found, "We have tab3");
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
});

View file

@ -1,41 +0,0 @@
"use strict";
// Here we want to test that a new opened window shows the same UI of the
// parent one if this has been loaded from a particular container.
const BASE_URI = "http://mochi.test:8888/browser/browser/components/"
+ "contextualidentity/test/browser/empty_file.html";
add_task(function* setup() {
yield new Promise((resolve) => {
SpecialPowers.pushPrefEnv({"set": [
["privacy.userContext.enabled", true],
["browser.link.open_newwindow", 2],
]}, resolve);
});
});
add_task(function* test() {
info("Creating a tab with UCI = 1...");
let tab = gBrowser.addTab(BASE_URI, {userContextId: 1});
is(tab.getAttribute('usercontextid'), 1, "New tab has UCI equal 1");
let browser = gBrowser.getBrowserForTab(tab);
yield BrowserTestUtils.browserLoaded(browser);
info("Opening a new window from this tab...");
ContentTask.spawn(browser, BASE_URI, function(url) {
content.window.newWindow = content.window.open(url, "_blank");
});
let newWin = yield BrowserTestUtils.waitForNewWindow();
let newTab = newWin.gBrowser.selectedTab;
yield BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
is(newTab.getAttribute('usercontextid'), 1, "New tab has UCI equal 1");
info("Closing the new window and tab...");
yield BrowserTestUtils.closeWindow(newWin);
yield BrowserTestUtils.removeTab(tab);
});

View file

@ -1,5 +0,0 @@
<html><body>
<script>
document.title = window.location.search;
</script>
</body></html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 B

View file

@ -1,23 +0,0 @@
<html>
<head>
<meta charset="UTF-8">
<title>title not set</title>
<script>
// if we have a query string, use it to set the cookie and localStorage
if (window.location.search.length > 0) {
let context_name = window.location.search.substr(1);
document.cookie = "userContextId=" + context_name;
localStorage.setItem("userContext", context_name);
}
// get the cookie
let [name, val] = document.cookie.split("=");
// set the title to reflect the cookie and local storage values we find
document.title = "cookie=" + val + "|"
+ "local=" + localStorage.getItem("userContext");
</script>
</head>
<body></body>
</html>

View file

@ -1,41 +0,0 @@
<html>
<head>
<meta charset="UTF-8">
<title>Bug 1238183</title>
</head>
<body>
<script type="application/javascript;version=1.7">
"use strict";
// if we have a query string, use it to set storages
if (window.location.search.length > 0) {
let context_name = window.location.search.substr(1);
localStorage.setItem("userContext", context_name);
sessionStorage.setItem("userContext", context_name);
let request = indexedDB.open("idb", 1);
request.onerror = function() {
throw new Error("error opening db connection");
};
request.onupgradeneeded = event => {
let db = event.target.result;
let store = db.createObjectStore("obj", { keyPath: "id" });
store.createIndex("userContext", "userContext", { unique: false });
};
request.onsuccess = event => {
let db = request.result;
let transaction = db.transaction(["obj"], "readwrite");
let store = transaction.objectStore("obj");
store.add({id: 1, userContext: context_name});
transaction.oncomplete = () => {
db.close();
};
};
}
</script>
</body>
</html>

View file

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
navigator.serviceWorker.register("worker.js");
</script>
</head>
<body>
This is a test page.
</body>
<html>

View file

@ -1 +0,0 @@
// empty worker, always succeed!

View file

@ -1,7 +0,0 @@
"use strict";
module.exports = {
"extends": [
"../../../../testing/mochitest/browser.eslintrc.js"
]
};

View file

@ -1,154 +0,0 @@
[DEFAULT]
support-files =
head.js
support/test_967000_charEncoding_page.html
support/feeds_test_page.html
support/test-feed.xml
[browser_873501_handle_specials.js]
[browser_876926_customize_mode_wrapping.js]
[browser_876944_customize_mode_create_destroy.js]
[browser_877006_missing_view.js]
[browser_877178_unregisterArea.js]
[browser_877447_skip_missing_ids.js]
[browser_878452_drag_to_panel.js]
[browser_880164_customization_context_menus.js]
[browser_880382_drag_wide_widgets_in_panel.js]
[browser_884402_customize_from_overflow.js]
skip-if = os == "linux"
[browser_885052_customize_mode_observers_disabed.js]
tags = fullscreen
# Bug 951403 - Disabled on OSX for frequent failures
skip-if = os == "mac"
[browser_885530_showInPrivateBrowsing.js]
[browser_886323_buildArea_removable_nodes.js]
[browser_887438_currentset_shim.js]
[browser_888817_currentset_updating.js]
[browser_890140_orphaned_placeholders.js]
[browser_890262_destroyWidget_after_add_to_panel.js]
[browser_892955_isWidgetRemovable_for_removed_widgets.js]
[browser_892956_destroyWidget_defaultPlacements.js]
[browser_909779_overflow_toolbars_new_window.js]
skip-if = os == "linux"
[browser_901207_searchbar_in_panel.js]
[browser_913972_currentset_overflow.js]
skip-if = os == "linux"
[browser_914138_widget_API_overflowable_toolbar.js]
skip-if = os == "linux"
[browser_914863_disabled_help_quit_buttons.js]
[browser_918049_skipintoolbarset_dnd.js]
[browser_923857_customize_mode_event_wrapping_during_reset.js]
[browser_927717_customize_drag_empty_toolbar.js]
# Bug 1163231 - Causes failures on Developer Edition on Windows 7.
# [browser_932928_show_notice_when_palette_empty.js]
[browser_934113_menubar_removable.js]
# Because this test is about the menubar, it can't be run on mac
skip-if = os == "mac"
[browser_934951_zoom_in_toolbar.js]
[browser_938980_navbar_collapsed.js]
[browser_938995_indefaultstate_nonremovable.js]
[browser_940013_registerToolbarNode_calls_registerArea.js]
[browser_940307_panel_click_closure_handling.js]
[browser_940946_removable_from_navbar_customizemode.js]
[browser_941083_invalidate_wrapper_cache_createWidget.js]
[browser_942581_unregisterArea_keeps_placements.js]
[browser_943683_migration_test.js]
[browser_944887_destroyWidget_should_destroy_in_palette.js]
[browser_945739_showInPrivateBrowsing_customize_mode.js]
[browser_947914_button_addons.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_copy.js]
subsuite = clipboard
skip-if = os == "linux" # Intermittent failures on Linux
[browser_947914_button_cut.js]
subsuite = clipboard
skip-if = os == "linux" # Intermittent failures on Linux
[browser_947914_button_find.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_history.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_newPrivateWindow.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_newWindow.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_paste.js]
subsuite = clipboard
skip-if = os == "linux" # Intermittent failures on Linux
[browser_947914_button_print.js]
skip-if = os == "linux" # Intermittent failures on Linux
[browser_947914_button_savePage.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_zoomIn.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_zoomOut.js]
skip-if = os == "linux" # Intermittent failures
[browser_947914_button_zoomReset.js]
skip-if = os == "linux" # Intermittent failures
[browser_947987_removable_default.js]
[browser_948985_non_removable_defaultArea.js]
[browser_952963_areaType_getter_no_area.js]
[browser_956602_remove_special_widget.js]
[browser_962069_drag_to_overflow_chevron.js]
[browser_962884_opt_in_disable_hyphens.js]
[browser_963639_customizing_attribute_non_customizable_toolbar.js]
[browser_967000_button_charEncoding.js]
[browser_967000_button_feeds.js]
[browser_967000_button_sync.js]
[browser_968447_bookmarks_toolbar_items_in_panel.js]
skip-if = os == "linux" # Intemittent failures - bug 979207
[browser_968565_insert_before_hidden_items.js]
[browser_969427_recreate_destroyed_widget_after_reset.js]
[browser_969661_character_encoding_navbar_disabled.js]
[browser_970511_undo_restore_default.js]
[browser_972267_customizationchange_events.js]
[browser_973641_button_addon.js]
[browser_973932_addonbar_currentset.js]
[browser_975719_customtoolbars_behaviour.js]
[browser_976792_insertNodeInWindow.js]
skip-if = os == "linux"
[browser_978084_dragEnd_after_move.js]
[browser_980155_add_overflow_toolbar.js]
[browser_981305_separator_insertion.js]
[browser_981418-widget-onbeforecreated-handler.js]
[browser_982656_restore_defaults_builtin_widgets.js]
[browser_984455_bookmarks_items_reparenting.js]
skip-if = os == "linux"
[browser_985815_propagate_setToolbarVisibility.js]
[browser_987177_destroyWidget_xul.js]
[browser_987177_xul_wrapper_updating.js]
[browser_987185_syncButton.js]
[browser_987492_window_api.js]
[browser_987640_charEncoding.js]
[browser_988072_sidebar_events.js]
[browser_989338_saved_placements_not_resaved.js]
[browser_989751_subviewbutton_class.js]
[browser_992747_toggle_noncustomizable_toolbar.js]
[browser_993322_widget_notoolbar.js]
[browser_995164_registerArea_during_customize_mode.js]
[browser_996364_registerArea_different_properties.js]
[browser_996635_remove_non_widgets.js]
[browser_1003588_no_specials_in_panel.js]
[browser_1007336_lwthemes_in_customize_mode.js]
skip-if = os == "linux" # crashing on Linux due to bug 1271683
[browser_1008559_anchor_undo_restore.js]
[browser_1042100_default_placements_update.js]
[browser_1058573_showToolbarsDropdown.js]
[browser_1087303_button_fullscreen.js]
tags = fullscreen
skip-if = os == "mac"
[browser_1087303_button_preferences.js]
[browser_1089591_still_customizable_after_reset.js]
[browser_1096763_seen_widgets_post_reset.js]
[browser_1161838_inserted_new_default_buttons.js]
[browser_bootstrapped_custom_toolbar.js]
[browser_customizemode_contextmenu_menubuttonstate.js]
[browser_panel_toggle.js]
[browser_switch_to_customize_mode.js]
[browser_check_tooltips_in_navbar.js]

View file

@ -1,107 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function simulateItemDragAndEnd(aToDrag, aTarget) {
var ds = Components.classes["@mozilla.org/widget/dragservice;1"].
getService(Components.interfaces.nsIDragService);
ds.startDragSession();
try {
var [result, dataTransfer] = EventUtils.synthesizeDragOver(aToDrag.parentNode, aTarget);
EventUtils.synthesizeDropAfterDragOver(result, dataTransfer, aTarget);
// Send dragend to move dragging item back to initial place.
EventUtils.sendDragEvent({ type: "dragend", dataTransfer: dataTransfer },
aToDrag.parentNode);
} finally {
ds.endDragSession(true);
}
}
add_task(function* checkNoAddingToPanel() {
let area = CustomizableUI.AREA_PANEL;
let previousPlacements = getAreaWidgetIds(area);
CustomizableUI.addWidgetToArea("separator", area);
CustomizableUI.addWidgetToArea("spring", area);
CustomizableUI.addWidgetToArea("spacer", area);
assertAreaPlacements(area, previousPlacements);
let oldNumberOfItems = previousPlacements.length;
if (getAreaWidgetIds(area).length != oldNumberOfItems) {
CustomizableUI.reset();
}
});
add_task(function* checkAddingToToolbar() {
let area = CustomizableUI.AREA_NAVBAR;
let previousPlacements = getAreaWidgetIds(area);
CustomizableUI.addWidgetToArea("separator", area);
CustomizableUI.addWidgetToArea("spring", area);
CustomizableUI.addWidgetToArea("spacer", area);
let expectedPlacements = [...previousPlacements].concat([
/separator/,
/spring/,
/spacer/
]);
assertAreaPlacements(area, expectedPlacements);
let newlyAddedElements = getAreaWidgetIds(area).slice(-3);
while (newlyAddedElements.length) {
CustomizableUI.removeWidgetFromArea(newlyAddedElements.shift());
}
assertAreaPlacements(area, previousPlacements);
let oldNumberOfItems = previousPlacements.length;
if (getAreaWidgetIds(area).length != oldNumberOfItems) {
CustomizableUI.reset();
}
});
add_task(function* checkDragging() {
let startArea = CustomizableUI.AREA_NAVBAR;
let targetArea = CustomizableUI.AREA_PANEL;
let startingToolbarPlacements = getAreaWidgetIds(startArea);
let startingTargetPlacements = getAreaWidgetIds(targetArea);
CustomizableUI.addWidgetToArea("separator", startArea);
CustomizableUI.addWidgetToArea("spring", startArea);
CustomizableUI.addWidgetToArea("spacer", startArea);
let placementsWithSpecials = getAreaWidgetIds(startArea);
let elementsToMove = [];
for (let id of placementsWithSpecials) {
if (CustomizableUI.isSpecialWidget(id)) {
elementsToMove.push(id);
}
}
is(elementsToMove.length, 3, "Should have 3 elements to try and drag.");
yield startCustomizing();
for (let id of elementsToMove) {
simulateItemDragAndEnd(document.getElementById(id), PanelUI.contents);
}
assertAreaPlacements(startArea, placementsWithSpecials);
assertAreaPlacements(targetArea, startingTargetPlacements);
for (let id of elementsToMove) {
simulateItemDrag(document.getElementById(id), gCustomizeMode.visiblePalette);
}
assertAreaPlacements(startArea, startingToolbarPlacements);
assertAreaPlacements(targetArea, startingTargetPlacements);
ok(!gCustomizeMode.visiblePalette.querySelector("toolbarspring,toolbarseparator,toolbarspacer"),
"No specials should make it to the palette alive.");
yield endCustomizing();
});
add_task(function* asyncCleanup() {
yield endCustomizing();
CustomizableUI.reset();
});

View file

@ -1,108 +0,0 @@
/* 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 DEFAULT_THEME_ID = "{972ce4c6-7e08-4474-a285-3208198ce6fd}";
const {LightweightThemeManager} = Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", {});
add_task(function* () {
Services.prefs.clearUserPref("lightweightThemes.usedThemes");
Services.prefs.clearUserPref("lightweightThemes.recommendedThemes");
LightweightThemeManager.clearBuiltInThemes();
yield startCustomizing();
let themesButton = document.getElementById("customization-lwtheme-button");
let popup = document.getElementById("customization-lwtheme-menu");
let popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button");
yield popupShownPromise;
// close current tab and re-open Customize menu to confirm correct number of Themes
yield endCustomizing();
info("Exited customize mode");
yield startCustomizing();
info("Started customizing a second time");
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a second time");
yield popupShownPromise;
let header = document.getElementById("customization-lwtheme-menu-header");
let recommendedHeader = document.getElementById("customization-lwtheme-menu-recommended");
is(header.nextSibling.nextSibling, recommendedHeader,
"There should only be one theme (default) in the 'My Themes' section by default");
is(header.nextSibling.theme.id, DEFAULT_THEME_ID, "That theme should be the default theme");
let firstLWTheme = recommendedHeader.nextSibling;
let firstLWThemeId = firstLWTheme.theme.id;
let themeChangedPromise = promiseObserverNotified("lightweight-theme-changed");
firstLWTheme.doCommand();
info("Clicked on first theme");
yield themeChangedPromise;
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button");
yield popupShownPromise;
is(header.nextSibling.theme.id, DEFAULT_THEME_ID, "The first theme should be the Default theme");
let installedThemeId = header.nextSibling.nextSibling.theme.id;
ok(installedThemeId.startsWith(firstLWThemeId),
"The second theme in the 'My Themes' section should be the newly installed theme: " +
"Installed theme id: " + installedThemeId + "; First theme ID: " + firstLWThemeId);
is(header.nextSibling.nextSibling.nextSibling, recommendedHeader,
"There should be two themes in the 'My Themes' section");
let defaultTheme = header.nextSibling;
defaultTheme.doCommand();
is(Services.prefs.getCharPref("lightweightThemes.selectedThemeID"), "", "No lwtheme should be selected");
// ensure current theme isn't set to "Default"
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a second time");
yield popupShownPromise;
firstLWTheme = recommendedHeader.nextSibling;
themeChangedPromise = promiseObserverNotified("lightweight-theme-changed");
firstLWTheme.doCommand();
info("Clicked on first theme again");
yield themeChangedPromise;
// check that "Restore Defaults" button resets theme
yield gCustomizeMode.reset();
is(LightweightThemeManager.currentTheme, null, "Current theme reset to default");
yield endCustomizing();
Services.prefs.setCharPref("lightweightThemes.usedThemes", "[]");
Services.prefs.setCharPref("lightweightThemes.recommendedThemes", "[]");
info("Removed all recommended themes");
yield startCustomizing();
popupShownPromise = popupShown(popup);
EventUtils.synthesizeMouseAtCenter(themesButton, {});
info("Clicked on themes button a second time");
yield popupShownPromise;
header = document.getElementById("customization-lwtheme-menu-header");
is(header.hidden, false, "Header should never be hidden");
is(header.nextSibling.theme.id, DEFAULT_THEME_ID, "The first theme should be the Default theme");
is(header.nextSibling.hidden, false, "The default theme should never be hidden");
recommendedHeader = document.getElementById("customization-lwtheme-menu-recommended");
is(header.nextSibling.nextSibling, recommendedHeader,
"There should only be one theme (default) in the 'My Themes' section by default");
let footer = document.getElementById("customization-lwtheme-menu-footer");
is(recommendedHeader.nextSibling.id, footer.id, "There should be no recommended themes in the menu");
is(recommendedHeader.hidden, true, "The recommendedHeader should be hidden since there are no recommended themes");
});
add_task(function* asyncCleanup() {
yield endCustomizing();
Services.prefs.clearUserPref("lightweightThemes.usedThemes");
Services.prefs.clearUserPref("lightweightThemes.recommendedThemes");
});

View file

@ -1,71 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const kAnchorAttribute = "cui-anchorid";
/**
* Check that anchor gets set correctly when moving an item from the panel to the toolbar
* using 'undo'
*/
add_task(function*() {
yield startCustomizing();
let button = document.getElementById("history-panelmenu");
is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
"Button (" + button.id + ") starts out with correct anchor");
let navbar = document.getElementById("nav-bar").customizationTarget;
simulateItemDrag(button, navbar);
is(CustomizableUI.getPlacementOfWidget(button.id).area, "nav-bar",
"Button (" + button.id + ") ends up in nav-bar");
ok(!button.hasAttribute(kAnchorAttribute),
"Button (" + button.id + ") has no anchor in toolbar");
let resetButton = document.getElementById("customization-reset-button");
ok(!resetButton.hasAttribute("disabled"), "Should be able to reset now.");
yield gCustomizeMode.reset();
is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
"Button (" + button.id + ") has anchor again");
let undoButton = document.getElementById("customization-undo-reset-button");
ok(!undoButton.hasAttribute("disabled"), "Should be able to undo now.");
yield gCustomizeMode.undoReset();
ok(!button.hasAttribute(kAnchorAttribute),
"Button (" + button.id + ") once again has no anchor in toolbar");
yield gCustomizeMode.reset();
yield endCustomizing();
});
/**
* Check that anchor gets set correctly when moving an item from the panel to the toolbar
* using 'reset'
*/
add_task(function*() {
yield startCustomizing();
let button = document.getElementById("bookmarks-menu-button");
ok(!button.hasAttribute(kAnchorAttribute),
"Button (" + button.id + ") has no anchor in toolbar");
let panel = document.getElementById("PanelUI-contents");
simulateItemDrag(button, panel);
is(CustomizableUI.getPlacementOfWidget(button.id).area, "PanelUI-contents",
"Button (" + button.id + ") ends up in panel");
is(button.getAttribute(kAnchorAttribute), "PanelUI-menu-button",
"Button (" + button.id + ") has correct anchor in the panel");
let resetButton = document.getElementById("customization-reset-button");
ok(!resetButton.hasAttribute("disabled"), "Should be able to reset now.");
yield gCustomizeMode.reset();
ok(!button.hasAttribute(kAnchorAttribute),
"Button (" + button.id + ") once again has no anchor in toolbar");
yield endCustomizing();
});

View file

@ -1,107 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// NB: This uses some ugly hacks to get into the CUI module from elsewhere...
// don't try this at home, kids.
function test() {
// Customize something to make sure stuff changed:
CustomizableUI.addWidgetToArea("feed-button", CustomizableUI.AREA_NAVBAR);
// Check what version we're on:
let CustomizableUIBSPass = Cu.import("resource:///modules/CustomizableUI.jsm", {});
is(CustomizableUIBSPass.gFuturePlacements.size, 0,
"All future placements should be dealt with by now.");
let {CustomizableUIInternal, gFuturePlacements, gPalette} = CustomizableUIBSPass;
CustomizableUIInternal._introduceNewBuiltinWidgets();
is(gFuturePlacements.size, 0,
"No change to future placements initially.");
let currentVersion = CustomizableUIBSPass.kVersion;
// Add our widget to the defaults:
let testWidgetNew = {
id: "test-messing-with-default-placements-new",
label: "Test messing with default placements - should be inserted",
defaultArea: CustomizableUI.AREA_NAVBAR,
introducedInVersion: currentVersion + 1,
};
let normalizedWidget = CustomizableUIInternal.normalizeWidget(testWidgetNew,
CustomizableUI.SOURCE_BUILTIN);
ok(normalizedWidget, "Widget should be normalizable");
if (!normalizedWidget) {
return;
}
CustomizableUIBSPass.gPalette.set(testWidgetNew.id, normalizedWidget);
let testWidgetOld = {
id: "test-messing-with-default-placements-old",
label: "Test messing with default placements - should NOT be inserted",
defaultArea: CustomizableUI.AREA_NAVBAR,
introducedInVersion: currentVersion,
};
normalizedWidget = CustomizableUIInternal.normalizeWidget(testWidgetOld,
CustomizableUI.SOURCE_BUILTIN);
ok(normalizedWidget, "Widget should be normalizable");
if (!normalizedWidget) {
return;
}
CustomizableUIBSPass.gPalette.set(testWidgetOld.id, normalizedWidget);
// Now increase the version in the module:
CustomizableUIBSPass.kVersion++;
let hadSavedState = !!CustomizableUIBSPass.gSavedState
if (!hadSavedState) {
CustomizableUIBSPass.gSavedState = {currentVersion: CustomizableUIBSPass.kVersion - 1};
}
// Then call the re-init routine so we re-add the builtin widgets
CustomizableUIInternal._introduceNewBuiltinWidgets();
is(gFuturePlacements.size, 1,
"Should have 1 more future placement");
let haveNavbarPlacements = gFuturePlacements.has(CustomizableUI.AREA_NAVBAR);
ok(haveNavbarPlacements, "Should have placements for nav-bar");
if (haveNavbarPlacements) {
let placements = [...gFuturePlacements.get(CustomizableUI.AREA_NAVBAR)];
// Ignore widgets that are placed using the pref facility and not the
// versioned facility. They're independent of kVersion and the saved
// state's current version, so they may be present in the placements.
for (let i = 0; i < placements.length; ) {
if (placements[i] == testWidgetNew.id) {
i++;
continue;
}
let pref = "browser.toolbarbuttons.introduced." + placements[i];
let introduced = false;
try {
introduced = Services.prefs.getBoolPref(pref);
} catch (ex) {}
if (!introduced) {
i++;
continue;
}
placements.splice(i, 1);
}
is(placements.length, 1, "Should have 1 newly placed widget in nav-bar");
is(placements[0], testWidgetNew.id, "Should have our test widget to be placed in nav-bar");
}
gFuturePlacements.delete(CustomizableUI.AREA_NAVBAR);
CustomizableUIBSPass.kVersion--;
gPalette.delete(testWidgetNew.id);
gPalette.delete(testWidgetOld.id);
if (!hadSavedState) {
CustomizableUIBSPass.gSavedState = null;
}
}

View file

@ -1,25 +0,0 @@
/* 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";
add_task(function*() {
info("Check that toggleable toolbars dropdown in always shown");
info("Remove all possible custom toolbars");
yield removeCustomToolbars();
info("Enter customization mode");
yield startCustomizing();
let toolbarsToggle = document.getElementById("customization-toolbar-visibility-button");
ok(toolbarsToggle, "The toolbars toggle dropdown exists");
ok(!toolbarsToggle.hasAttribute("hidden"),
"The toolbars toggle dropdown is displayed");
});
add_task(function* asyncCleanup() {
info("Exit customization mode");
yield endCustomizing();
});

View file

@ -1,46 +0,0 @@
/* 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";
add_task(function*() {
info("Check fullscreen button existence and functionality");
yield PanelUI.show();
let fullscreenButton = document.getElementById("fullscreen-button");
ok(fullscreenButton, "Fullscreen button appears in Panel Menu");
let fullscreenPromise = promiseFullscreenChange();
fullscreenButton.click();
yield fullscreenPromise;
ok(window.fullScreen, "Fullscreen mode was opened");
// exit full screen mode
fullscreenPromise = promiseFullscreenChange();
window.fullScreen = !window.fullScreen;
yield fullscreenPromise;
ok(!window.fullScreen, "Successfully exited fullscreen");
});
function promiseFullscreenChange() {
let deferred = Promise.defer();
info("Wait for fullscreen change");
let timeoutId = setTimeout(() => {
window.removeEventListener("fullscreen", onFullscreenChange, true);
deferred.reject("Fullscreen change did not happen within " + 20000 + "ms");
}, 20000);
function onFullscreenChange(event) {
clearTimeout(timeoutId);
window.removeEventListener("fullscreen", onFullscreenChange, true);
info("Fullscreen event received");
deferred.resolve();
}
window.addEventListener("fullscreen", onFullscreenChange, true);
return deferred.promise;
}

View file

@ -1,50 +0,0 @@
/* 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";
var newTab = null;
add_task(function*() {
info("Check preferences button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
let preferencesButton = document.getElementById("preferences-button");
ok(preferencesButton, "Preferences button exists in Panel Menu");
preferencesButton.click();
newTab = gBrowser.selectedTab;
yield waitForPageLoad(newTab);
let openedPage = gBrowser.currentURI.spec;
is(openedPage, "about:preferences", "Preferences page was opened");
});
add_task(function asyncCleanup() {
if (gBrowser.tabs.length == 1)
gBrowser.addTab("about:blank");
gBrowser.removeTab(gBrowser.selectedTab);
info("Tabs were restored");
});
function waitForPageLoad(aTab) {
let deferred = Promise.defer();
let timeoutId = setTimeout(() => {
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
deferred.reject("Page didn't load within " + 20000 + "ms");
}, 20000);
function onTabLoad(event) {
clearTimeout(timeoutId);
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
info("Tab event received: " + "load");
deferred.resolve();
}
aTab.linkedBrowser.addEventListener("load", onTabLoad, true, true);
return deferred.promise;
}

View file

@ -1,24 +0,0 @@
"use strict";
// Dragging the elements again after a reset should work
add_task(function* () {
yield startCustomizing();
let historyButton = document.getElementById("wrapper-history-panelmenu");
let devButton = document.getElementById("wrapper-developer-button");
ok(historyButton && devButton, "Draggable elements should exist");
simulateItemDrag(historyButton, devButton);
yield gCustomizeMode.reset();
ok(CustomizableUI.inDefaultState, "Should be back in default state");
historyButton = document.getElementById("wrapper-history-panelmenu");
devButton = document.getElementById("wrapper-developer-button");
ok(historyButton && devButton, "Draggable elements should exist");
simulateItemDrag(historyButton, devButton);
yield endCustomizing();
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,31 +0,0 @@
"use strict";
const BUTTONID = "test-seenwidget-post-reset";
add_task(function*() {
CustomizableUI.createWidget({
id: BUTTONID,
label: "Test widget seen post reset",
defaultArea: CustomizableUI.AREA_NAVBAR
});
const kPrefCustomizationState = "browser.uiCustomization.state";
let bsPass = Cu.import("resource:///modules/CustomizableUI.jsm", {});
ok(bsPass.gSeenWidgets.has(BUTTONID), "Widget should be seen after createWidget is called.");
CustomizableUI.reset();
ok(bsPass.gSeenWidgets.has(BUTTONID), "Widget should still be seen after reset.");
ok(!Services.prefs.prefHasUserValue(kPrefCustomizationState), "Pref shouldn't be set right now, because that'd break undo.");
CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR);
gCustomizeMode.removeFromArea(document.getElementById(BUTTONID));
let hasUserValue = Services.prefs.prefHasUserValue(kPrefCustomizationState);
ok(hasUserValue, "Pref should be set right now.");
if (hasUserValue) {
let seenArray = JSON.parse(Services.prefs.getCharPref(kPrefCustomizationState)).seen;
isnot(seenArray.indexOf(BUTTONID), -1, "Widget should be in saved 'seen' list.");
}
});
registerCleanupFunction(function() {
CustomizableUI.destroyWidget(BUTTONID);
CustomizableUI.reset();
});

View file

@ -1,78 +0,0 @@
"use strict";
// NB: This uses some ugly hacks to get into the CUI module from elsewhere...
// don't try this at home, kids.
function test() {
// Customize something to make sure stuff changed:
CustomizableUI.addWidgetToArea("feed-button", CustomizableUI.AREA_NAVBAR);
let CustomizableUIBSPass = Cu.import("resource:///modules/CustomizableUI.jsm", {});
is(CustomizableUIBSPass.gFuturePlacements.size, 0,
"All future placements should be dealt with by now.");
let {CustomizableUIInternal, gFuturePlacements, gPalette} = CustomizableUIBSPass;
// Force us to have a saved state:
CustomizableUIInternal.saveState();
CustomizableUIInternal.loadSavedState();
CustomizableUIInternal._introduceNewBuiltinWidgets();
is(gFuturePlacements.size, 0,
"No change to future placements initially.");
// Add our widget to the defaults:
let testWidgetNew = {
id: "test-messing-with-default-placements-new-pref",
label: "Test messing with default placements - pref-based",
defaultArea: CustomizableUI.AREA_NAVBAR,
introducedInVersion: "pref",
};
let normalizedWidget = CustomizableUIInternal.normalizeWidget(testWidgetNew,
CustomizableUI.SOURCE_BUILTIN);
ok(normalizedWidget, "Widget should be normalizable");
if (!normalizedWidget) {
return;
}
CustomizableUIBSPass.gPalette.set(testWidgetNew.id, normalizedWidget);
// Now adjust default placements for area:
let navbarArea = CustomizableUIBSPass.gAreas.get(CustomizableUI.AREA_NAVBAR);
let navbarPlacements = navbarArea.get("defaultPlacements");
navbarPlacements.splice(navbarPlacements.indexOf("bookmarks-menu-button") + 1, 0, testWidgetNew.id);
let savedPlacements = CustomizableUIBSPass.gSavedState.placements[CustomizableUI.AREA_NAVBAR];
// Then call the re-init routine so we re-add the builtin widgets
CustomizableUIInternal._introduceNewBuiltinWidgets();
is(gFuturePlacements.size, 1,
"Should have 1 more future placement");
let futureNavbarPlacements = gFuturePlacements.get(CustomizableUI.AREA_NAVBAR);
ok(futureNavbarPlacements, "Should have placements for nav-bar");
if (futureNavbarPlacements) {
ok(futureNavbarPlacements.has(testWidgetNew.id), "widget should be in future placements");
}
CustomizableUIInternal._placeNewDefaultWidgetsInArea(CustomizableUI.AREA_NAVBAR);
let indexInSavedPlacements = savedPlacements.indexOf(testWidgetNew.id);
info("Saved placements: " + savedPlacements.join(', '));
isnot(indexInSavedPlacements, -1, "Widget should have been inserted");
is(indexInSavedPlacements, savedPlacements.indexOf("bookmarks-menu-button") + 1,
"Widget should be in the right place.");
if (futureNavbarPlacements) {
ok(!futureNavbarPlacements.has(testWidgetNew.id), "widget should be out of future placements");
}
if (indexInSavedPlacements != -1) {
savedPlacements.splice(indexInSavedPlacements, 1);
}
gFuturePlacements.delete(CustomizableUI.AREA_NAVBAR);
let indexInDefaultPlacements = navbarPlacements.indexOf(testWidgetNew.id);
if (indexInDefaultPlacements != -1) {
navbarPlacements.splice(indexInDefaultPlacements, 1);
}
gPalette.delete(testWidgetNew.id);
CustomizableUI.reset();
}

View file

@ -1,79 +0,0 @@
/* 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 kToolbarName = "test-specials-toolbar";
registerCleanupFunction(removeCustomToolbars);
// Add a toolbar with two springs and the downloads button.
add_task(function* addToolbarWith2SpringsAndDownloadsButton() {
// Create the toolbar with a single spring:
createToolbarWithPlacements(kToolbarName, ["spring"]);
ok(document.getElementById(kToolbarName), "Toolbar should be created.");
// Check it's there with a generated ID:
assertAreaPlacements(kToolbarName, [/customizableui-special-spring\d+/]);
let [springId] = getAreaWidgetIds(kToolbarName);
// Add a second spring, check if that's there and doesn't share IDs
CustomizableUI.addWidgetToArea("spring", kToolbarName);
assertAreaPlacements(kToolbarName, [springId,
/customizableui-special-spring\d+/]);
let [, spring2Id] = getAreaWidgetIds(kToolbarName);
isnot(springId, spring2Id, "Springs shouldn't have identical IDs.");
// Try moving the downloads button to this new toolbar, between the two springs:
CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1);
assertAreaPlacements(kToolbarName, [springId, "downloads-button", spring2Id]);
yield removeCustomToolbars();
});
// Add separators around the downloads button.
add_task(function* addSeparatorsAroundDownloadsButton() {
createToolbarWithPlacements(kToolbarName, ["separator"]);
ok(document.getElementById(kToolbarName), "Toolbar should be created.");
// Check it's there with a generated ID:
assertAreaPlacements(kToolbarName, [/customizableui-special-separator\d+/]);
let [separatorId] = getAreaWidgetIds(kToolbarName);
CustomizableUI.addWidgetToArea("separator", kToolbarName);
assertAreaPlacements(kToolbarName, [separatorId,
/customizableui-special-separator\d+/]);
let [, separator2Id] = getAreaWidgetIds(kToolbarName);
isnot(separatorId, separator2Id, "Separator ids shouldn't be equal.");
CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1);
assertAreaPlacements(kToolbarName, [separatorId, "downloads-button", separator2Id]);
yield removeCustomToolbars();
});
// Add spacers around the downloads button.
add_task(function* addSpacersAroundDownloadsButton() {
createToolbarWithPlacements(kToolbarName, ["spacer"]);
ok(document.getElementById(kToolbarName), "Toolbar should be created.");
// Check it's there with a generated ID:
assertAreaPlacements(kToolbarName, [/customizableui-special-spacer\d+/]);
let [spacerId] = getAreaWidgetIds(kToolbarName);
CustomizableUI.addWidgetToArea("spacer", kToolbarName);
assertAreaPlacements(kToolbarName, [spacerId,
/customizableui-special-spacer\d+/]);
let [, spacer2Id] = getAreaWidgetIds(kToolbarName);
isnot(spacerId, spacer2Id, "Spacer ids shouldn't be equal.");
CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1);
assertAreaPlacements(kToolbarName, [spacerId, "downloads-button", spacer2Id]);
yield removeCustomToolbars();
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,185 +0,0 @@
/* 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 kXULWidgetId = "a-test-button"; // we'll create a button with this ID.
const kAPIWidgetId = "feed-button";
const kPanel = CustomizableUI.AREA_PANEL;
const kToolbar = CustomizableUI.AREA_NAVBAR;
const kVisiblePalette = "customization-palette";
const kPlaceholderClass = "panel-customization-placeholder";
function checkWrapper(id) {
is(document.querySelectorAll("#wrapper-" + id).length, 1, "There should be exactly 1 wrapper for " + id + " in the customizing window.");
}
var move = {
"drag": function(id, target) {
let targetNode = document.getElementById(target);
if (targetNode.customizationTarget) {
targetNode = targetNode.customizationTarget;
}
simulateItemDrag(document.getElementById(id), targetNode);
},
"dragToItem": function(id, target) {
let targetNode = document.getElementById(target);
if (targetNode.customizationTarget) {
targetNode = targetNode.customizationTarget;
}
let items = targetNode.querySelectorAll("toolbarpaletteitem:not(." + kPlaceholderClass + ")");
if (target == kPanel) {
targetNode = items[items.length - 1];
} else {
targetNode = items[0];
}
simulateItemDrag(document.getElementById(id), targetNode);
},
"API": function(id, target) {
if (target == kVisiblePalette) {
return CustomizableUI.removeWidgetFromArea(id);
}
return CustomizableUI.addWidgetToArea(id, target, null);
}
};
function isLast(containerId, defaultPlacements, id) {
assertAreaPlacements(containerId, defaultPlacements.concat([id]));
is(document.getElementById(containerId).customizationTarget.lastChild.firstChild.id, id,
"Widget " + id + " should be in " + containerId + " in customizing window.");
is(otherWin.document.getElementById(containerId).customizationTarget.lastChild.id, id,
"Widget " + id + " should be in " + containerId + " in other window.");
}
function getLastVisibleNodeInToolbar(containerId, win=window) {
let container = win.document.getElementById(containerId).customizationTarget;
let rv = container.lastChild;
while (rv && (rv.getAttribute('hidden') == 'true' || (rv.firstChild && rv.firstChild.getAttribute('hidden') == 'true'))) {
rv = rv.previousSibling;
}
return rv;
}
function isLastVisibleInToolbar(containerId, defaultPlacements, id) {
let newPlacements;
for (let i = defaultPlacements.length - 1; i >= 0; i--) {
let el = document.getElementById(defaultPlacements[i]);
if (el && el.getAttribute('hidden') != 'true') {
newPlacements = [...defaultPlacements];
newPlacements.splice(i + 1, 0, id);
break;
}
}
if (!newPlacements) {
assertAreaPlacements(containerId, defaultPlacements.concat([id]));
} else {
assertAreaPlacements(containerId, newPlacements);
}
is(getLastVisibleNodeInToolbar(containerId).firstChild.id, id,
"Widget " + id + " should be in " + containerId + " in customizing window.");
is(getLastVisibleNodeInToolbar(containerId, otherWin).id, id,
"Widget " + id + " should be in " + containerId + " in other window.");
}
function isFirst(containerId, defaultPlacements, id) {
assertAreaPlacements(containerId, [id].concat(defaultPlacements));
is(document.getElementById(containerId).customizationTarget.firstChild.firstChild.id, id,
"Widget " + id + " should be in " + containerId + " in customizing window.");
is(otherWin.document.getElementById(containerId).customizationTarget.firstChild.id, id,
"Widget " + id + " should be in " + containerId + " in other window.");
}
function checkToolbar(id, method) {
// Place at start of the toolbar:
let toolbarPlacements = getAreaWidgetIds(kToolbar);
move[method](id, kToolbar);
if (method == "dragToItem") {
isFirst(kToolbar, toolbarPlacements, id);
} else if (method == "drag") {
isLastVisibleInToolbar(kToolbar, toolbarPlacements, id);
} else {
isLast(kToolbar, toolbarPlacements, id);
}
checkWrapper(id);
}
function checkPanel(id, method) {
let panelPlacements = getAreaWidgetIds(kPanel);
move[method](id, kPanel);
let children = document.getElementById(kPanel).querySelectorAll("toolbarpaletteitem:not(." + kPlaceholderClass + ")");
let otherChildren = otherWin.document.getElementById(kPanel).children;
let newPlacements = panelPlacements.concat([id]);
// Relative position of the new item from the end:
let position = -1;
// For the drag to item case, we drag to the last item, making the dragged item the
// penultimate item. We can't well use the first item because the panel has complicated
// rules about rearranging wide items (which, by default, the first two items are).
if (method == "dragToItem") {
newPlacements.pop();
newPlacements.splice(panelPlacements.length - 1, 0, id);
position = -2;
}
assertAreaPlacements(kPanel, newPlacements);
is(children[children.length + position].firstChild.id, id,
"Widget " + id + " should be in " + kPanel + " in customizing window.");
is(otherChildren[otherChildren.length + position].id, id,
"Widget " + id + " should be in " + kPanel + " in other window.");
checkWrapper(id);
}
function checkPalette(id, method) {
// Move back to palette:
move[method](id, kVisiblePalette);
ok(CustomizableUI.inDefaultState, "Should end in default state");
let visibleChildren = gCustomizeMode.visiblePalette.children;
let expectedChild = method == "dragToItem" ? visibleChildren[0] : visibleChildren[visibleChildren.length - 1];
is(expectedChild.firstChild.id, id, "Widget " + id + " was moved using " + method + " and should now be wrapped in palette in customizing window.");
if (id == kXULWidgetId) {
ok(otherWin.gNavToolbox.palette.querySelector("#" + id), "Widget " + id + " should be in invisible palette in other window.");
}
checkWrapper(id);
}
// This test needs a XUL button that's in the palette by default. No such
// button currently exists, so we create a simple one.
function createXULButtonForWindow(win) {
createDummyXULButton(kXULWidgetId, "test-button", win);
}
function removeXULButtonForWindow(win) {
win.gNavToolbox.palette.querySelector(`#${kXULWidgetId}`).remove();
}
var otherWin;
// Moving widgets in two windows, one with customize mode and one without, should work.
add_task(function* MoveWidgetsInTwoWindows() {
yield startCustomizing();
otherWin = yield openAndLoadWindow(null, true);
yield otherWin.PanelUI.ensureReady();
// Create the XUL button to use in the test in both windows.
createXULButtonForWindow(window);
createXULButtonForWindow(otherWin);
ok(CustomizableUI.inDefaultState, "Should start in default state");
for (let widgetId of [kXULWidgetId, kAPIWidgetId]) {
for (let method of ["API", "drag", "dragToItem"]) {
info("Moving widget " + widgetId + " using " + method);
checkToolbar(widgetId, method);
checkPanel(widgetId, method);
checkPalette(widgetId, method);
checkPanel(widgetId, method);
checkToolbar(widgetId, method);
checkPalette(widgetId, method);
}
}
yield promiseWindowClosed(otherWin);
otherWin = null;
yield endCustomizing();
removeXULButtonForWindow(window);
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,61 +0,0 @@
/* 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 kTestWidget1 = "test-customize-mode-create-destroy1";
const kTestWidget2 = "test-customize-mode-create-destroy2";
// Creating and destroying a widget should correctly wrap/unwrap stuff
add_task(function* testWrapUnwrap() {
yield startCustomizing();
CustomizableUI.createWidget({id: kTestWidget1, label: 'Pretty label', tooltiptext: 'Pretty tooltip'});
let elem = document.getElementById(kTestWidget1);
let wrapper = document.getElementById("wrapper-" + kTestWidget1);
ok(elem, "There should be an item");
ok(wrapper, "There should be a wrapper");
is(wrapper.firstChild.id, kTestWidget1, "Wrapper should have test widget");
is(wrapper.parentNode.id, "customization-palette", "Wrapper should be in palette");
CustomizableUI.destroyWidget(kTestWidget1);
wrapper = document.getElementById("wrapper-" + kTestWidget1);
ok(!wrapper, "There should be a wrapper");
let item = document.getElementById(kTestWidget1);
ok(!item, "There should no longer be an item");
});
// Creating and destroying a widget should correctly deal with panel placeholders
add_task(function* testPanelPlaceholders() {
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
// The value of expectedPlaceholders depends on the default palette layout.
// Bug 1229236 is for these tests to be smarter so the test doesn't need to
// change when the default placements change.
let expectedPlaceholders = 1 + (isInDevEdition() ? 1 : 0);
is(panel.querySelectorAll(".panel-customization-placeholder").length, expectedPlaceholders, "The number of placeholders should be correct.");
CustomizableUI.createWidget({id: kTestWidget2, label: 'Pretty label', tooltiptext: 'Pretty tooltip', defaultArea: CustomizableUI.AREA_PANEL});
let elem = document.getElementById(kTestWidget2);
let wrapper = document.getElementById("wrapper-" + kTestWidget2);
ok(elem, "There should be an item");
ok(wrapper, "There should be a wrapper");
is(wrapper.firstChild.id, kTestWidget2, "Wrapper should have test widget");
is(wrapper.parentNode, panel, "Wrapper should be in panel");
expectedPlaceholders = isInDevEdition() ? 1 : 3;
is(panel.querySelectorAll(".panel-customization-placeholder").length, expectedPlaceholders, "The number of placeholders should be correct.");
CustomizableUI.destroyWidget(kTestWidget2);
wrapper = document.getElementById("wrapper-" + kTestWidget2);
ok(!wrapper, "There should be a wrapper");
let item = document.getElementById(kTestWidget2);
ok(!item, "There should no longer be an item");
yield endCustomizing();
});
add_task(function* asyncCleanup() {
yield endCustomizing();
try {
CustomizableUI.destroyWidget(kTestWidget1);
} catch (ex) {}
try {
CustomizableUI.destroyWidget(kTestWidget2);
} catch (ex) {}
yield resetCustomization();
});

View file

@ -1,41 +0,0 @@
/* 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";
// Should be able to add broken view widget
add_task(function testAddbrokenViewWidget() {
const kWidgetId = 'test-877006-broken-widget';
let widgetSpec = {
id: kWidgetId,
type: 'view',
viewId: 'idontexist',
/* Empty handler so we try to attach it maybe? */
onViewShowing: function() {
}
};
let noError = true;
try {
CustomizableUI.createWidget(widgetSpec);
CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_NAVBAR);
} catch (ex) {
Cu.reportError(ex);
noError = false;
}
ok(noError, "Should not throw an exception trying to add a broken view widget.");
noError = true;
try {
CustomizableUI.destroyWidget(kWidgetId);
} catch (ex) {
Cu.reportError(ex);
noError = false;
}
ok(noError, "Should not throw an exception trying to remove the broken view widget.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,50 +0,0 @@
/* 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";
registerCleanupFunction(removeCustomToolbars);
// Sanity checks
add_task(function sanityChecks() {
SimpleTest.doesThrow(() => CustomizableUI.registerArea("@foo"),
"Registering areas with an invalid ID should throw.");
SimpleTest.doesThrow(() => CustomizableUI.registerArea([]),
"Registering areas with an invalid ID should throw.");
SimpleTest.doesThrow(() => CustomizableUI.unregisterArea("@foo"),
"Unregistering areas with an invalid ID should throw.");
SimpleTest.doesThrow(() => CustomizableUI.unregisterArea([]),
"Unregistering areas with an invalid ID should throw.");
SimpleTest.doesThrow(() => CustomizableUI.unregisterArea("unknown"),
"Unregistering an area that's not registered should throw.");
});
// Check areas are loaded with their default placements.
add_task(function checkLoadedAres() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
});
// Check registering and unregistering a new area.
add_task(function checkRegisteringAndUnregistering() {
const kToolbarId = "test-registration-toolbar";
const kButtonId = "test-registration-button";
createDummyXULButton(kButtonId);
createToolbarWithPlacements(kToolbarId, ["spring", kButtonId, "spring"]);
assertAreaPlacements(kToolbarId,
[/customizableui-special-spring\d+/,
kButtonId,
/customizableui-special-spring\d+/]);
ok(!CustomizableUI.inDefaultState, "With a new toolbar it is no longer in a default state.");
removeCustomToolbars(); // Will call unregisterArea for us
ok(CustomizableUI.inDefaultState, "When the toolbar is unregistered, " +
"everything will return to the default state.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,25 +0,0 @@
/* 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";
registerCleanupFunction(removeCustomToolbars);
add_task(function skipMissingIDS() {
const kButtonId = "look-at-me-disappear-button";
CustomizableUI.reset();
ok(CustomizableUI.inDefaultState, "Should be in the default state.");
let btn = createDummyXULButton(kButtonId, "Gone!");
CustomizableUI.addWidgetToArea(kButtonId, CustomizableUI.AREA_NAVBAR);
ok(!CustomizableUI.inDefaultState, "Should no longer be in the default state.");
is(btn.parentNode.parentNode.id, CustomizableUI.AREA_NAVBAR, "Button should be in navbar");
btn.remove();
is(btn.parentNode, null, "Button is no longer in the navbar");
ok(CustomizableUI.inDefaultState, "Should be back in the default state, " +
"despite unknown button ID in placements.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,65 +0,0 @@
/* 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";
// Dragging an item from the palette to another button in the panel should work.
add_task(function*() {
yield startCustomizing();
let btn = document.getElementById("feed-button");
let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
let lastButtonIndex = placements.length - 1;
let lastButton = placements[lastButtonIndex];
let placementsAfterInsert = placements.slice(0, lastButtonIndex).concat(["feed-button", lastButton]);
let lastButtonNode = document.getElementById(lastButton);
simulateItemDrag(btn, lastButtonNode);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterInsert);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let palette = document.getElementById("customization-palette");
simulateItemDrag(btn, palette);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging an item from the palette to the panel itself should also work.
add_task(function*() {
yield startCustomizing();
let btn = document.getElementById("feed-button");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
let placementsAfterAppend = placements.concat(["feed-button"]);
simulateItemDrag(btn, panel);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let palette = document.getElementById("customization-palette");
simulateItemDrag(btn, palette);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging an item from the palette to an empty panel should also work.
add_task(function*() {
let widgetIds = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
while (widgetIds.length) {
CustomizableUI.removeWidgetFromArea(widgetIds.shift());
}
yield startCustomizing();
let btn = document.getElementById("feed-button");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
assertAreaPlacements(panel.id, []);
let placementsAfterAppend = ["feed-button"];
simulateItemDrag(btn, panel);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let palette = document.getElementById("customization-palette");
simulateItemDrag(btn, palette);
assertAreaPlacements(panel.id, []);
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,414 +0,0 @@
/* 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";
requestLongerTimeout(2);
const isOSX = (Services.appinfo.OS === "Darwin");
// Right-click on the home button should
// show a context menu with options to move it.
add_task(function*() {
let contextMenu = document.getElementById("toolbar-context-menu");
let shownPromise = popupShown(contextMenu);
let homeButton = document.getElementById("home-button");
EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2 });
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToPanel", true],
[".customize-context-removeFromToolbar", true],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
});
// Right-click on an empty bit of tabstrip should
// show a context menu without options to move it,
// but with tab-specific options instead.
add_task(function*() {
// ensure there are tabs to reload/bookmark:
let extraTab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(extraTab, "http://example.com/");
let contextMenu = document.getElementById("toolbar-context-menu");
let shownPromise = popupShown(contextMenu);
let tabstrip = document.getElementById("tabbrowser-tabs");
let rect = tabstrip.getBoundingClientRect();
EventUtils.synthesizeMouse(tabstrip, rect.width - 2, 2, {type: "contextmenu", button: 2 });
yield shownPromise;
let closedTabsAvailable = SessionStore.getClosedTabCount(window) == 0;
info("Closed tabs: " + closedTabsAvailable);
let expectedEntries = [
["#toolbar-context-reloadAllTabs", true],
["#toolbar-context-bookmarkAllTabs", true],
["#toolbar-context-undoCloseTab", !closedTabsAvailable],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
gBrowser.removeTab(extraTab);
});
// Right-click on an empty bit of extra toolbar should
// show a context menu with moving options disabled,
// and a toggle option for the extra toolbar
add_task(function*() {
let contextMenu = document.getElementById("toolbar-context-menu");
let shownPromise = popupShown(contextMenu);
let toolbar = createToolbarWithPlacements("880164_empty_toolbar", []);
toolbar.setAttribute("context", "toolbar-context-menu");
toolbar.setAttribute("toolbarname", "Fancy Toolbar for Context Menu");
EventUtils.synthesizeMouseAtCenter(toolbar, {type: "contextmenu", button: 2 });
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToPanel", false],
[".customize-context-removeFromToolbar", false],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["#toggle_880164_empty_toolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
removeCustomToolbars();
});
// Right-click on the urlbar-container should
// show a context menu with disabled options to move it.
add_task(function*() {
let contextMenu = document.getElementById("toolbar-context-menu");
let shownPromise = popupShown(contextMenu);
let urlBarContainer = document.getElementById("urlbar-container");
// Need to make sure not to click within an edit field.
EventUtils.synthesizeMouse(urlBarContainer, 100, 1, {type: "contextmenu", button: 2 });
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToPanel", false],
[".customize-context-removeFromToolbar", false],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
});
// Right-click on the searchbar and moving it to the menu
// and back should move the search-container instead.
add_task(function*() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
let shownPanelPromise = promisePanelShown(window);
PanelUI.toggle({type: "command"});
yield shownPanelPromise;
let hiddenPanelPromise = promisePanelHidden(window);
PanelUI.toggle({type: "command"});
yield hiddenPanelPromise;
gCustomizeMode.addToToolbar(searchbar);
placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
gCustomizeMode.removeFromArea(searchbar);
placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement, null, "Should be in palette");
CustomizableUI.reset();
placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
});
// Right-click on an item within the menu panel should
// show a context menu with options to move it.
add_task(function*() {
let shownPanelPromise = promisePanelShown(window);
PanelUI.toggle({type: "command"});
yield shownPanelPromise;
let contextMenu = document.getElementById("customizationPanelItemContextMenu");
let shownContextPromise = popupShown(contextMenu);
let newWindowButton = document.getElementById("new-window-button");
ok(newWindowButton, "new-window-button was found");
EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
yield shownContextPromise;
is(PanelUI.panel.state, "open", "The PanelUI should still be open.");
let expectedEntries = [
[".customize-context-moveToToolbar", true],
[".customize-context-removeFromPanel", true],
["---"],
[".viewCustomizeToolbar", true]
];
checkContextMenu(contextMenu, expectedEntries);
let hiddenContextPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenContextPromise;
let hiddenPromise = promisePanelHidden(window);
PanelUI.toggle({type: "command"});
yield hiddenPromise;
});
// Right-click on the home button while in customization mode
// should show a context menu with options to move it.
add_task(function*() {
yield startCustomizing();
let contextMenu = document.getElementById("toolbar-context-menu");
let shownPromise = popupShown(contextMenu);
let homeButton = document.getElementById("wrapper-home-button");
EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2});
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToPanel", true],
[".customize-context-removeFromToolbar", true],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", false]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenContextPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenContextPromise;
});
// Right-click on an item in the palette should
// show a context menu with options to move it.
add_task(function*() {
let contextMenu = document.getElementById("customizationPaletteItemContextMenu");
let shownPromise = popupShown(contextMenu);
let openFileButton = document.getElementById("wrapper-open-file-button");
EventUtils.synthesizeMouse(openFileButton, 2, 2, {type: "contextmenu", button: 2});
yield shownPromise;
let expectedEntries = [
[".customize-context-addToToolbar", true],
[".customize-context-addToPanel", true]
];
checkContextMenu(contextMenu, expectedEntries);
let hiddenContextPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenContextPromise;
});
// Right-click on an item in the panel while in customization mode
// should show a context menu with options to move it.
add_task(function*() {
let contextMenu = document.getElementById("customizationPanelItemContextMenu");
let shownPromise = popupShown(contextMenu);
let newWindowButton = document.getElementById("wrapper-new-window-button");
EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToToolbar", true],
[".customize-context-removeFromPanel", true],
["---"],
[".viewCustomizeToolbar", false]
];
checkContextMenu(contextMenu, expectedEntries);
let hiddenContextPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenContextPromise;
yield endCustomizing();
});
// Test the toolbarbutton panel context menu in customization mode
// without opening the panel before customization mode
add_task(function*() {
this.otherWin = yield openAndLoadWindow(null, true);
yield new Promise(resolve => waitForFocus(resolve, this.otherWin));
yield startCustomizing(this.otherWin);
let contextMenu = this.otherWin.document.getElementById("customizationPanelItemContextMenu");
let shownPromise = popupShown(contextMenu);
let newWindowButton = this.otherWin.document.getElementById("wrapper-new-window-button");
EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}, this.otherWin);
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToToolbar", true],
[".customize-context-removeFromPanel", true],
["---"],
[".viewCustomizeToolbar", false]
];
checkContextMenu(contextMenu, expectedEntries, this.otherWin);
let hiddenContextPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenContextPromise;
yield endCustomizing(this.otherWin);
yield promiseWindowClosed(this.otherWin);
this.otherWin = null;
yield new Promise(resolve => waitForFocus(resolve, window));
});
// Bug 945191 - Combined buttons show wrong context menu options
// when they are in the toolbar.
add_task(function*() {
yield startCustomizing();
let contextMenu = document.getElementById("customizationPanelItemContextMenu");
let shownPromise = popupShown(contextMenu);
let zoomControls = document.getElementById("wrapper-zoom-controls");
EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
yield shownPromise;
// Execute the command to move the item from the panel to the toolbar.
contextMenu.childNodes[0].doCommand();
let hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
yield endCustomizing();
zoomControls = document.getElementById("zoom-controls");
is(zoomControls.parentNode.id, "nav-bar-customization-target", "Zoom-controls should be on the nav-bar");
contextMenu = document.getElementById("toolbar-context-menu");
shownPromise = popupShown(contextMenu);
EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2});
yield shownPromise;
let expectedEntries = [
[".customize-context-moveToPanel", true],
[".customize-context-removeFromToolbar", true],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
hiddenPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenPromise;
yield resetCustomization();
});
// Bug 947586 - After customization, panel items show wrong context menu options
add_task(function*() {
yield startCustomizing();
yield endCustomizing();
yield PanelUI.show();
let contextMenu = document.getElementById("customizationPanelItemContextMenu");
let shownContextPromise = popupShown(contextMenu);
let newWindowButton = document.getElementById("new-window-button");
ok(newWindowButton, "new-window-button was found");
EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2});
yield shownContextPromise;
is(PanelUI.panel.state, "open", "The PanelUI should still be open.");
let expectedEntries = [
[".customize-context-moveToToolbar", true],
[".customize-context-removeFromPanel", true],
["---"],
[".viewCustomizeToolbar", true]
];
checkContextMenu(contextMenu, expectedEntries);
let hiddenContextPromise = popupHidden(contextMenu);
contextMenu.hidePopup();
yield hiddenContextPromise;
let hiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield hiddenPromise;
});
// Bug 982027 - moving icon around removes custom context menu.
add_task(function*() {
let widgetId = "custom-context-menu-toolbarbutton";
let expectedContext = "myfancycontext";
let widget = createDummyXULButton(widgetId, "Test ctxt menu");
widget.setAttribute("context", expectedContext);
CustomizableUI.addWidgetToArea(widgetId, CustomizableUI.AREA_NAVBAR);
is(widget.getAttribute("context"), expectedContext, "Should have context menu when added to the toolbar.");
yield startCustomizing();
is(widget.getAttribute("context"), "", "Should not have own context menu in the toolbar now that we're customizing.");
is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped when in toolbar.");
let panel = PanelUI.contents;
simulateItemDrag(widget, panel);
is(widget.getAttribute("context"), "", "Should not have own context menu when in the panel.");
is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're in the panel.");
simulateItemDrag(widget, document.getElementById("nav-bar").customizationTarget);
is(widget.getAttribute("context"), "", "Should not have own context menu when back in toolbar because we're still customizing.");
is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're back in the toolbar.");
yield endCustomizing();
is(widget.getAttribute("context"), expectedContext, "Should have context menu again now that we're out of customize mode.");
CustomizableUI.removeWidgetFromArea(widgetId);
widget.remove();
ok(CustomizableUI.inDefaultState, "Should be in default state after removing button.");
});

View file

@ -1,497 +0,0 @@
/* 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";
requestLongerTimeout(5);
// Dragging the zoom controls to be before the print button should not move any controls.
add_task(function*() {
yield startCustomizing();
let zoomControls = document.getElementById("zoom-controls");
let printButton = document.getElementById("print-button");
let placementsAfterMove = ["edit-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"zoom-controls",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(zoomControls, printButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let newWindowButton = document.getElementById("new-window-button");
simulateItemDrag(zoomControls, newWindowButton);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging the zoom controls to be before the save button should not move any controls.
add_task(function*() {
yield startCustomizing();
let zoomControls = document.getElementById("zoom-controls");
let savePageButton = document.getElementById("save-page-button");
let placementsAfterMove = ["edit-controls",
"zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(zoomControls, savePageButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
ok(CustomizableUI.inDefaultState, "Should be in default state.");
});
// Dragging the zoom controls to be before the new-window button should not move any widgets.
add_task(function*() {
yield startCustomizing();
let zoomControls = document.getElementById("zoom-controls");
let newWindowButton = document.getElementById("new-window-button");
let placementsAfterMove = ["edit-controls",
"zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(zoomControls, newWindowButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the zoom controls to be before the history-panelmenu should move the zoom-controls in to the row higher than the history-panelmenu.
add_task(function*() {
yield startCustomizing();
let zoomControls = document.getElementById("zoom-controls");
let historyPanelMenu = document.getElementById("history-panelmenu");
let placementsAfterMove = ["edit-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"zoom-controls",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(zoomControls, historyPanelMenu);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let newWindowButton = document.getElementById("new-window-button");
simulateItemDrag(zoomControls, newWindowButton);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging the zoom controls to be before the preferences-button should move the zoom-controls
// in to the row higher than the preferences-button.
add_task(function*() {
yield startCustomizing();
let zoomControls = document.getElementById("zoom-controls");
let preferencesButton = document.getElementById("preferences-button");
let placementsAfterMove = ["edit-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"zoom-controls",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(zoomControls, preferencesButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let newWindowButton = document.getElementById("new-window-button");
simulateItemDrag(zoomControls, newWindowButton);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging an item from the palette to before the zoom-controls should move it and two other buttons before the zoom controls.
add_task(function*() {
yield startCustomizing();
let openFileButton = document.getElementById("open-file-button");
let zoomControls = document.getElementById("zoom-controls");
let placementsAfterInsert = ["edit-controls",
"open-file-button",
"new-window-button",
"privatebrowsing-button",
"zoom-controls",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterInsert);
simulateItemDrag(openFileButton, zoomControls);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterInsert);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let palette = document.getElementById("customization-palette");
// Check that the palette items are re-wrapped correctly.
let feedWrapper = document.getElementById("wrapper-feed-button");
let feedButton = document.getElementById("feed-button");
is(feedButton.parentNode, feedWrapper,
"feed-button should be a child of wrapper-feed-button");
is(feedWrapper.getAttribute("place"), "palette",
"The feed-button wrapper should have it's place set to 'palette'");
simulateItemDrag(openFileButton, palette);
is(openFileButton.parentNode.tagName, "toolbarpaletteitem",
"The open-file-button should be wrapped by a toolbarpaletteitem");
let newWindowButton = document.getElementById("new-window-button");
simulateItemDrag(zoomControls, newWindowButton);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging an item from the palette to before the edit-controls
// should move it and two other buttons before the edit and zoom controls.
add_task(function*() {
yield startCustomizing();
let openFileButton = document.getElementById("open-file-button");
let editControls = document.getElementById("edit-controls");
let placementsAfterInsert = ["open-file-button",
"new-window-button",
"privatebrowsing-button",
"edit-controls",
"zoom-controls",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterInsert);
simulateItemDrag(openFileButton, editControls);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterInsert);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
let palette = document.getElementById("customization-palette");
// Check that the palette items are re-wrapped correctly.
let feedWrapper = document.getElementById("wrapper-feed-button");
let feedButton = document.getElementById("feed-button");
is(feedButton.parentNode, feedWrapper,
"feed-button should be a child of wrapper-feed-button");
is(feedWrapper.getAttribute("place"), "palette",
"The feed-button wrapper should have it's place set to 'palette'");
simulateItemDrag(openFileButton, palette);
is(openFileButton.parentNode.tagName, "toolbarpaletteitem",
"The open-file-button should be wrapped by a toolbarpaletteitem");
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Dragging the edit-controls to be before the zoom-controls button
// should not move any widgets.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let zoomControls = document.getElementById("zoom-controls");
let placementsAfterMove = ["edit-controls",
"zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, zoomControls);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the edit-controls to be before the new-window-button should
// move the zoom-controls before the edit-controls.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let newWindowButton = document.getElementById("new-window-button");
let placementsAfterMove = ["zoom-controls",
"edit-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, newWindowButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(editControls, zoomControls);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the edit-controls to be before the privatebrowsing-button
// should move the edit-controls in to the row higher than the
// privatebrowsing-button.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let privateBrowsingButton = document.getElementById("privatebrowsing-button");
let placementsAfterMove = ["zoom-controls",
"edit-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, privateBrowsingButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(editControls, zoomControls);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the edit-controls to be before the save-page-button
// should move the edit-controls in to the row higher than the
// save-page-button.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let savePageButton = document.getElementById("save-page-button");
let placementsAfterMove = ["zoom-controls",
"edit-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, savePageButton);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(editControls, zoomControls);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the edit-controls to the panel itself should append
// the edit controls to the bottom of the panel.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let placementsAfterMove = ["zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"edit-controls",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, panel);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(editControls, zoomControls);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the edit-controls to the customization-palette and
// back should work.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let palette = document.getElementById("customization-palette");
let placementsAfterMove = ["zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"developer-button",
"sync-button",
];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
let paletteChildElementCount = palette.childElementCount;
simulateItemDrag(editControls, palette);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
is(paletteChildElementCount + 1, palette.childElementCount,
"The palette should have a new child, congratulations!");
is(editControls.parentNode.id, "wrapper-edit-controls",
"The edit-controls should be properly wrapped.");
is(editControls.parentNode.getAttribute("place"), "palette",
"The edit-controls should have the place of 'palette'.");
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(editControls, zoomControls);
is(paletteChildElementCount, palette.childElementCount,
"The palette child count should have returned to its prior value.");
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging the edit-controls to each of the panel placeholders
// should append the edit-controls to the bottom of the panel.
add_task(function*() {
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let numPlaceholders = 2;
for (let i = 0; i < numPlaceholders; i++) {
// This test relies on there being a specific number of widgets in the
// panel. The addition of sync-button screwed this up, so we remove it
// here. We should either fix the tests to not rely on the specific layout,
// or fix bug 1007910 which would change the placeholder logic in different
// ways. Bug 1229236 is for these tests to be smarter.
CustomizableUI.removeWidgetFromArea("sync-button");
// NB: We can't just iterate over all of the placeholders
// because each drag-drop action recreates them.
let placeholder = panel.getElementsByClassName("panel-customization-placeholder")[i];
let placementsAfterMove = ["zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"edit-controls",
"developer-button"];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, placeholder);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(editControls, zoomControls);
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
}
});
// Dragging the open-file-button back on to itself should work.
add_task(function*() {
yield startCustomizing();
let openFileButton = document.getElementById("open-file-button");
is(openFileButton.parentNode.tagName, "toolbarpaletteitem",
"open-file-button should be wrapped by a toolbarpaletteitem");
simulateItemDrag(openFileButton, openFileButton);
is(openFileButton.parentNode.tagName, "toolbarpaletteitem",
"open-file-button should be wrapped by a toolbarpaletteitem");
let editControls = document.getElementById("edit-controls");
is(editControls.parentNode.tagName, "toolbarpaletteitem",
"edit-controls should be wrapped by a toolbarpaletteitem");
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
// Dragging a small button onto the last big button should work.
add_task(function*() {
// Bug 1007910 requires there be a placeholder on the final row for this
// test to work as written. The addition of sync-button meant that's not true
// so we remove it from here. Bug 1229236 is for these tests to be smarter.
CustomizableUI.removeWidgetFromArea("sync-button");
yield startCustomizing();
let editControls = document.getElementById("edit-controls");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let target = panel.getElementsByClassName("panel-customization-placeholder")[0];
let placementsAfterMove = ["zoom-controls",
"new-window-button",
"privatebrowsing-button",
"save-page-button",
"print-button",
"history-panelmenu",
"fullscreen-button",
"find-button",
"preferences-button",
"add-ons-button",
"edit-controls",
"developer-button"];
removeDeveloperButtonIfDevEdition(placementsAfterMove);
simulateItemDrag(editControls, target);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
let itemToDrag = "email-link-button"; // any button in the palette by default.
let button = document.getElementById(itemToDrag);
placementsAfterMove.splice(11, 0, itemToDrag);
simulateItemDrag(button, editControls);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterMove);
// Put stuff back:
let palette = document.getElementById("customization-palette");
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(button, palette);
simulateItemDrag(editControls, zoomControls);
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,81 +0,0 @@
"use strict";
var overflowPanel = document.getElementById("widget-overflow");
const isOSX = (Services.appinfo.OS === "Darwin");
var originalWindowWidth;
registerCleanupFunction(function() {
overflowPanel.removeAttribute("animate");
window.resizeTo(originalWindowWidth, window.outerHeight);
});
// Right-click on an item within the overflow panel should
// show a context menu with options to move it.
add_task(function*() {
overflowPanel.setAttribute("animate", "false");
originalWindowWidth = window.outerWidth;
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
let chevron = document.getElementById("nav-bar-overflow-button");
let shownPanelPromise = promisePanelElementShown(window, overflowPanel);
chevron.click();
yield shownPanelPromise;
let contextMenu = document.getElementById("toolbar-context-menu");
let shownContextPromise = popupShown(contextMenu);
let homeButton = document.getElementById("home-button");
ok(homeButton, "home-button was found");
is(homeButton.getAttribute("overflowedItem"), "true", "Home button is overflowing");
EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2});
yield shownContextPromise;
is(overflowPanel.state, "open", "The widget overflow panel should still be open.");
let expectedEntries = [
[".customize-context-moveToPanel", true],
[".customize-context-removeFromToolbar", true],
["---"]
];
if (!isOSX) {
expectedEntries.push(["#toggle_toolbar-menubar", true]);
}
expectedEntries.push(
["#toggle_PersonalToolbar", true],
["---"],
[".viewCustomizeToolbar", true]
);
checkContextMenu(contextMenu, expectedEntries);
let hiddenContextPromise = popupHidden(contextMenu);
let hiddenPromise = promisePanelElementHidden(window, overflowPanel);
let moveToPanel = contextMenu.querySelector(".customize-context-moveToPanel");
if (moveToPanel) {
moveToPanel.click();
}
contextMenu.hidePopup();
yield hiddenContextPromise;
yield hiddenPromise;
let homeButtonPlacement = CustomizableUI.getPlacementOfWidget("home-button");
ok(homeButtonPlacement, "Home button should still have a placement");
is(homeButtonPlacement && homeButtonPlacement.area, "PanelUI-contents", "Home button should be in the panel now");
CustomizableUI.reset();
// In some cases, it can take a tick for the navbar to overflow again. Wait for it:
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
homeButtonPlacement = CustomizableUI.getPlacementOfWidget("home-button");
ok(homeButtonPlacement, "Home button should still have a placement");
is(homeButtonPlacement && homeButtonPlacement.area, "nav-bar", "Home button should be back in the navbar now");
is(homeButton.getAttribute("overflowedItem"), "true", "Home button should still be overflowed");
});

View file

@ -1,45 +0,0 @@
/* 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";
function isFullscreenSizeMode() {
let sizemode = document.documentElement.getAttribute("sizemode");
return sizemode == "fullscreen";
}
// Observers should be disabled when in customization mode.
add_task(function*() {
// Open and close the panel to make sure that the
// area is generated before getting a child of the area.
let shownPanelPromise = promisePanelShown(window);
PanelUI.toggle({type: "command"});
yield shownPanelPromise;
let hiddenPanelPromise = promisePanelHidden(window);
PanelUI.toggle({type: "command"});
yield hiddenPanelPromise;
let fullscreenButton = document.getElementById("fullscreen-button");
ok(!fullscreenButton.checked, "Fullscreen button should not be checked when not in fullscreen.")
ok(!isFullscreenSizeMode(), "Should not be in fullscreen sizemode before we enter fullscreen.");
BrowserFullScreen();
yield waitForCondition(() => isFullscreenSizeMode());
ok(fullscreenButton.checked, "Fullscreen button should be checked when in fullscreen.")
yield startCustomizing();
let fullscreenButtonWrapper = document.getElementById("wrapper-fullscreen-button");
ok(fullscreenButtonWrapper.hasAttribute("itemobserves"), "Observer should be moved to wrapper");
fullscreenButton = document.getElementById("fullscreen-button");
ok(!fullscreenButton.hasAttribute("observes"), "Observer should be removed from button");
ok(!fullscreenButton.checked, "Fullscreen button should no longer be checked during customization mode");
yield endCustomizing();
BrowserFullScreen();
fullscreenButton = document.getElementById("fullscreen-button");
yield waitForCondition(() => !isFullscreenSizeMode());
ok(!fullscreenButton.checked, "Fullscreen button should not be checked when not in fullscreen.")
});

View file

@ -1,134 +0,0 @@
/* 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 kWidgetId = "some-widget";
function assertWidgetExists(aWindow, aExists) {
if (aExists) {
ok(aWindow.document.getElementById(kWidgetId),
"Should have found test widget in the window");
} else {
is(aWindow.document.getElementById(kWidgetId), null,
"Should not have found test widget in the window");
}
}
// A widget that is created with showInPrivateBrowsing undefined should
// have that value default to true.
add_task(function() {
let wrapper = CustomizableUI.createWidget({
id: kWidgetId
});
ok(wrapper.showInPrivateBrowsing,
"showInPrivateBrowsing should have defaulted to true.");
CustomizableUI.destroyWidget(kWidgetId);
});
// Add a widget via the API with showInPrivateBrowsing set to false
// and ensure it does not appear in pre-existing or newly created
// private windows.
add_task(function*() {
let plain1 = yield openAndLoadWindow();
let private1 = yield openAndLoadWindow({private: true});
CustomizableUI.createWidget({
id: kWidgetId,
removable: true,
showInPrivateBrowsing: false
});
CustomizableUI.addWidgetToArea(kWidgetId,
CustomizableUI.AREA_NAVBAR);
assertWidgetExists(plain1, true);
assertWidgetExists(private1, false);
// Now open up some new windows. The widget should exist in the new
// plain window, but not the new private window.
let plain2 = yield openAndLoadWindow();
let private2 = yield openAndLoadWindow({private: true});
assertWidgetExists(plain2, true);
assertWidgetExists(private2, false);
// Try moving the widget around and make sure it doesn't get added
// to the private windows. We'll start by appending it to the tabstrip.
CustomizableUI.addWidgetToArea(kWidgetId,
CustomizableUI.AREA_TABSTRIP);
assertWidgetExists(plain1, true);
assertWidgetExists(plain2, true);
assertWidgetExists(private1, false);
assertWidgetExists(private2, false);
// And then move it to the beginning of the tabstrip.
CustomizableUI.moveWidgetWithinArea(kWidgetId, 0);
assertWidgetExists(plain1, true);
assertWidgetExists(plain2, true);
assertWidgetExists(private1, false);
assertWidgetExists(private2, false);
CustomizableUI.removeWidgetFromArea("some-widget");
assertWidgetExists(plain1, false);
assertWidgetExists(plain2, false);
assertWidgetExists(private1, false);
assertWidgetExists(private2, false);
yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed));
CustomizableUI.destroyWidget("some-widget");
});
// Add a widget via the API with showInPrivateBrowsing set to true,
// and ensure that it appears in pre-existing or newly created
// private browsing windows.
add_task(function*() {
let plain1 = yield openAndLoadWindow();
let private1 = yield openAndLoadWindow({private: true});
CustomizableUI.createWidget({
id: kWidgetId,
removable: true,
showInPrivateBrowsing: true
});
CustomizableUI.addWidgetToArea(kWidgetId,
CustomizableUI.AREA_NAVBAR);
assertWidgetExists(plain1, true);
assertWidgetExists(private1, true);
// Now open up some new windows. The widget should exist in the new
// plain window, but not the new private window.
let plain2 = yield openAndLoadWindow();
let private2 = yield openAndLoadWindow({private: true});
assertWidgetExists(plain2, true);
assertWidgetExists(private2, true);
// Try moving the widget around and make sure it doesn't get added
// to the private windows. We'll start by appending it to the tabstrip.
CustomizableUI.addWidgetToArea(kWidgetId,
CustomizableUI.AREA_TABSTRIP);
assertWidgetExists(plain1, true);
assertWidgetExists(plain2, true);
assertWidgetExists(private1, true);
assertWidgetExists(private2, true);
// And then move it to the beginning of the tabstrip.
CustomizableUI.moveWidgetWithinArea(kWidgetId, 0);
assertWidgetExists(plain1, true);
assertWidgetExists(plain2, true);
assertWidgetExists(private1, true);
assertWidgetExists(private2, true);
CustomizableUI.removeWidgetFromArea("some-widget");
assertWidgetExists(plain1, false);
assertWidgetExists(plain2, false);
assertWidgetExists(private1, false);
assertWidgetExists(private2, false);
yield Promise.all([plain1, plain2, private1, private2].map(promiseWindowClosed));
CustomizableUI.destroyWidget("some-widget");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,46 +0,0 @@
/* 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 kButtonId = "test-886323-removable-moved-node";
const kLazyAreaId = "test-886323-lazy-area-for-removability-testing";
var gNavBar = document.getElementById(CustomizableUI.AREA_NAVBAR);
var gLazyArea;
// Removable nodes shouldn't be moved by buildArea
add_task(function*() {
let dummyBtn = createDummyXULButton(kButtonId, "Dummy");
dummyBtn.setAttribute("removable", "true");
gNavBar.customizationTarget.appendChild(dummyBtn);
let popupSet = document.getElementById("mainPopupSet");
gLazyArea = document.createElementNS(kNSXUL, "panel");
gLazyArea.id = kLazyAreaId;
gLazyArea.setAttribute("hidden", "true");
popupSet.appendChild(gLazyArea);
CustomizableUI.registerArea(kLazyAreaId, {
type: CustomizableUI.TYPE_MENU_PANEL,
defaultPlacements: []
});
CustomizableUI.addWidgetToArea(kButtonId, kLazyAreaId);
assertAreaPlacements(kLazyAreaId, [kButtonId],
"Placements should have changed because widget is removable.");
let btn = document.getElementById(kButtonId);
btn.setAttribute("removable", "false");
gLazyArea.customizationTarget = gLazyArea;
CustomizableUI.registerToolbarNode(gLazyArea, []);
assertAreaPlacements(kLazyAreaId, [], "Placements should no longer include widget.");
is(btn.parentNode.id, gNavBar.customizationTarget.id,
"Button shouldn't actually have moved as it's not removable");
btn = document.getElementById(kButtonId);
if (btn) btn.remove();
CustomizableUI.removeWidgetFromArea(kButtonId);
CustomizableUI.unregisterArea(kLazyAreaId);
gLazyArea.remove();
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,75 +0,0 @@
/* 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";
var navbar = document.getElementById("nav-bar");
var navbarCT = navbar.customizationTarget;
var overflowPanelList = document.getElementById("widget-overflow-list");
// Reading currentset
add_task(function() {
let nodeIds = [];
for (let node of navbarCT.childNodes) {
if (node.getAttribute("skipintoolbarset") != "true") {
nodeIds.push(node.id);
}
}
for (let node of overflowPanelList.childNodes) {
if (node.getAttribute("skipintoolbarset") != "true") {
nodeIds.push(node.id);
}
}
let currentSet = navbar.currentSet;
is(currentSet.split(',').length, nodeIds.length, "Should be just as many nodes as there are.");
is(currentSet, nodeIds.join(','), "Current set and node IDs should match.");
});
// Insert, then remove items
add_task(function() {
let currentSet = navbar.currentSet;
let newCurrentSet = currentSet.replace('home-button', 'feed-button,sync-button,home-button');
navbar.currentSet = newCurrentSet;
is(newCurrentSet, navbar.currentSet, "Current set should match expected current set.");
let feedBtn = document.getElementById("feed-button");
let syncBtn = document.getElementById("sync-button");
ok(feedBtn, "Feed button should have been added.");
ok(syncBtn, "Sync button should have been added.");
if (feedBtn && syncBtn) {
let feedParent = feedBtn.parentNode;
let syncParent = syncBtn.parentNode;
ok(feedParent == navbarCT || feedParent == overflowPanelList,
"Feed button should be in navbar or overflow");
ok(syncParent == navbarCT || syncParent == overflowPanelList,
"Feed button should be in navbar or overflow");
is(feedBtn.nextElementSibling, syncBtn, "Feed button should be next to sync button.");
let homeBtn = document.getElementById("home-button");
is(syncBtn.nextElementSibling, homeBtn, "Sync button should be next to home button.");
}
navbar.currentSet = currentSet;
is(currentSet, navbar.currentSet, "Should be able to remove the added items.");
});
// Simultaneous insert/remove:
add_task(function() {
let currentSet = navbar.currentSet;
let newCurrentSet = currentSet.replace('home-button', 'feed-button');
navbar.currentSet = newCurrentSet;
is(newCurrentSet, navbar.currentSet, "Current set should match expected current set.");
let feedBtn = document.getElementById("feed-button");
ok(feedBtn, "Feed button should have been added.");
let homeBtn = document.getElementById("home-button");
ok(!homeBtn, "Home button should have been removed.");
if (feedBtn) {
let feedParent = feedBtn.parentNode;
ok(feedParent == navbarCT || feedParent == overflowPanelList,
"Feed button should be in navbar or overflow");
}
navbar.currentSet = currentSet;
is(currentSet, navbar.currentSet, "Should be able to return to original state.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,57 +0,0 @@
/* 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";
// Adding, moving and removing items should update the relevant currentset attributes
add_task(function*() {
ok(CustomizableUI.inDefaultState, "Should be in the default state when we start");
let personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
setToolbarVisibility(personalbar, true);
ok(!CustomizableUI.inDefaultState, "Making the bookmarks toolbar visible takes it out of the default state");
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
let navbarCurrentset = navbar.getAttribute("currentset") || navbar.currentSet;
let personalbarCurrentset = personalbar.getAttribute("currentset") || personalbar.currentSet;
let otherWin = yield openAndLoadWindow();
let otherNavbar = otherWin.document.getElementById(CustomizableUI.AREA_NAVBAR);
let otherPersonalbar = otherWin.document.getElementById(CustomizableUI.AREA_BOOKMARKS);
CustomizableUI.moveWidgetWithinArea("home-button", 0);
navbarCurrentset = "home-button," + navbarCurrentset.replace(",home-button", "");
is(navbar.getAttribute("currentset"), navbarCurrentset,
"Should have updated currentSet after move.");
is(otherNavbar.getAttribute("currentset"), navbarCurrentset,
"Should have updated other window's currentSet after move.");
CustomizableUI.addWidgetToArea("home-button", CustomizableUI.AREA_BOOKMARKS);
navbarCurrentset = navbarCurrentset.replace("home-button,", "");
personalbarCurrentset = personalbarCurrentset + ",home-button";
is(navbar.getAttribute("currentset"), navbarCurrentset,
"Should have updated navbar currentSet after implied remove.");
is(otherNavbar.getAttribute("currentset"), navbarCurrentset,
"Should have updated other window's navbar currentSet after implied remove.");
is(personalbar.getAttribute("currentset"), personalbarCurrentset,
"Should have updated personalbar currentSet after add.");
is(otherPersonalbar.getAttribute("currentset"), personalbarCurrentset,
"Should have updated other window's personalbar currentSet after add.");
CustomizableUI.removeWidgetFromArea("home-button");
personalbarCurrentset = personalbarCurrentset.replace(",home-button", "");
is(personalbar.getAttribute("currentset"), personalbarCurrentset,
"Should have updated currentSet after remove.");
is(otherPersonalbar.getAttribute("currentset"), personalbarCurrentset,
"Should have updated other window's currentSet after remove.");
yield promiseWindowClosed(otherWin);
// Reset in asyncCleanup will put our button back for us.
});
add_task(function* asyncCleanup() {
let personalbar = document.getElementById(CustomizableUI.AREA_BOOKMARKS);
setToolbarVisibility(personalbar, false);
yield resetCustomization();
});

View file

@ -1,210 +0,0 @@
/* 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";
requestLongerTimeout(2);
// One orphaned item should have two placeholders next to it.
add_task(function*() {
yield startCustomizing();
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
}
if (!isInDevEdition()) {
ok(CustomizableUI.inDefaultState, "Should be in default state.");
} else {
ok(!CustomizableUI.inDefaultState, "Should not be in default state if on DevEdition.");
}
// This test relies on an exact number of widgets being in the panel.
// Remove the sync-button to satisfy that. (bug 1229236)
CustomizableUI.removeWidgetFromArea("sync-button");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting");
yield endCustomizing();
yield startCustomizing();
is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering");
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
}
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Two orphaned items should have one placeholder next to them (case 1).
add_task(function*() {
yield startCustomizing();
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
}
// This test relies on an exact number of widgets being in the panel.
// Remove the sync-button to satisfy that. (bug 1229236)
CustomizableUI.removeWidgetFromArea("sync-button");
let btn = document.getElementById("open-file-button");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
let placementsAfterAppend = placements;
placementsAfterAppend = placements.concat(["open-file-button"]);
simulateItemDrag(btn, panel);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
ok(!CustomizableUI.inDefaultState, "Should not be in default state.");
is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
yield endCustomizing();
yield startCustomizing();
is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
let palette = document.getElementById("customization-palette");
simulateItemDrag(btn, palette);
btn = document.getElementById("open-file-button");
simulateItemDrag(btn, palette);
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
}
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// Two orphaned items should have one placeholder next to them (case 2).
add_task(function*() {
yield startCustomizing();
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
}
// This test relies on an exact number of widgets being in the panel.
// Remove the sync-button to satisfy that. (bug 1229236)
CustomizableUI.removeWidgetFromArea("sync-button");
let btn = document.getElementById("add-ons-button");
let btn2 = document.getElementById("developer-button");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let palette = document.getElementById("customization-palette");
let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id);
simulateItemDrag(btn, palette);
simulateItemDrag(btn2, palette);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting");
yield endCustomizing();
yield startCustomizing();
is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering");
simulateItemDrag(btn, panel);
simulateItemDrag(btn2, panel);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placements);
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
}
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// A wide widget at the bottom of the panel should have three placeholders after it.
add_task(function*() {
yield startCustomizing();
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_PANEL);
}
// This test relies on an exact number of widgets being in the panel.
// Remove the sync-button to satisfy that. (bug 1229236)
CustomizableUI.removeWidgetFromArea("sync-button");
let btn = document.getElementById("edit-controls");
let btn2 = document.getElementById("developer-button");
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
let palette = document.getElementById("customization-palette");
let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL);
placements.pop();
simulateItemDrag(btn2, palette);
let placementsAfterAppend = placements.concat([placements.shift()]);
simulateItemDrag(btn, panel);
assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend);
ok(!CustomizableUI.inDefaultState, "Should no longer be in default state.");
is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting");
yield endCustomizing();
yield startCustomizing();
is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering");
simulateItemDrag(btn2, panel);
let zoomControls = document.getElementById("zoom-controls");
simulateItemDrag(btn, zoomControls);
if (isInDevEdition()) {
CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR, 2);
}
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should be in default state again.");
});
// The default placements should have two placeholders at the bottom (or 1 in win8).
add_task(function*() {
yield startCustomizing();
let numPlaceholders = -1;
if (isInDevEdition()) {
numPlaceholders = 3;
} else {
numPlaceholders = 2;
}
let panel = document.getElementById(CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should be in default state.");
// This test relies on an exact number of widgets being in the panel.
// Remove the sync-button to satisfy that. (bug 1229236)
CustomizableUI.removeWidgetFromArea("sync-button");
is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting");
yield endCustomizing();
yield startCustomizing();
is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering");
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_PANEL);
ok(CustomizableUI.inDefaultState, "Should still be in default state.");
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});
function getVisiblePlaceholderCount(aPanel) {
let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])");
return visiblePlaceholders.length;
}

View file

@ -1,68 +0,0 @@
/* 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 kLazyAreaId = "test-890262-lazy-area";
const kWidget1Id = "test-890262-widget1";
const kWidget2Id = "test-890262-widget2";
setupArea();
// Destroying a widget after defaulting it to a non-legacy area should work.
add_task(function() {
CustomizableUI.createWidget({
id: kWidget1Id,
removable: true,
defaultArea: kLazyAreaId
});
let noError = true;
try {
CustomizableUI.destroyWidget(kWidget1Id);
} catch (ex) {
Cu.reportError(ex);
noError = false;
}
ok(noError, "Shouldn't throw an exception for a widget that was created in a not-yet-constructed area");
});
// Destroying a widget after moving it to a non-legacy area should work.
add_task(function() {
CustomizableUI.createWidget({
id: kWidget2Id,
removable: true,
defaultArea: CustomizableUI.AREA_NAVBAR
});
CustomizableUI.addWidgetToArea(kWidget2Id, kLazyAreaId);
let noError = true;
try {
CustomizableUI.destroyWidget(kWidget2Id);
} catch (ex) {
Cu.reportError(ex);
noError = false;
}
ok(noError, "Shouldn't throw an exception for a widget that was added to a not-yet-constructed area");
});
add_task(function* asyncCleanup() {
let lazyArea = document.getElementById(kLazyAreaId);
if (lazyArea) {
lazyArea.remove();
}
try {
CustomizableUI.unregisterArea(kLazyAreaId);
} catch (ex) {} // If we didn't register successfully for some reason
yield resetCustomization();
});
function setupArea() {
let lazyArea = document.createElementNS(kNSXUL, "hbox");
lazyArea.id = kLazyAreaId;
document.getElementById("nav-bar").appendChild(lazyArea);
CustomizableUI.registerArea(kLazyAreaId, {
type: CustomizableUI.TYPE_TOOLBAR,
defaultPlacements: []
});
}

View file

@ -1,30 +0,0 @@
/* 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 kWidgetId = "test-892955-remove-widget";
// Removing a destroyed widget should work.
add_task(function*() {
let widgetSpec = {
id: kWidgetId,
defaultArea: CustomizableUI.AREA_NAVBAR
};
CustomizableUI.createWidget(widgetSpec);
CustomizableUI.destroyWidget(kWidgetId);
let noError = true;
try {
CustomizableUI.removeWidgetFromArea(kWidgetId);
} catch (ex) {
noError = false;
Cu.reportError(ex);
}
ok(noError, "Shouldn't throw an error removing a destroyed widget.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,24 +0,0 @@
/* 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 kWidgetId = "test-892956-destroyWidget-defaultPlacement";
// destroyWidget should clean up defaultPlacements if the widget had a defaultArea
add_task(function*() {
ok(CustomizableUI.inDefaultState, "Should be in the default state when we start");
let widgetSpec = {
id: kWidgetId,
defaultArea: CustomizableUI.AREA_NAVBAR
};
CustomizableUI.createWidget(widgetSpec);
CustomizableUI.destroyWidget(kWidgetId);
ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,113 +0,0 @@
/* 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";
logActiveElement();
function* waitForSearchBarFocus()
{
let searchbar = document.getElementById("searchbar");
yield waitForCondition(function () {
logActiveElement();
return document.activeElement === searchbar.textbox.inputField;
});
}
// Ctrl+K should open the menu panel and focus the search bar if the search bar is in the panel.
add_task(function*() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
let shownPanelPromise = promisePanelShown(window);
sendWebSearchKeyCommand();
yield shownPanelPromise;
yield waitForSearchBarFocus();
let hiddenPanelPromise = promisePanelHidden(window);
EventUtils.synthesizeKey("VK_ESCAPE", {});
yield hiddenPanelPromise;
CustomizableUI.reset();
});
// Ctrl+K should give focus to the searchbar when the searchbar is in the menupanel and the panel is already opened.
add_task(function*() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
let shownPanelPromise = promisePanelShown(window);
PanelUI.toggle({type: "command"});
yield shownPanelPromise;
sendWebSearchKeyCommand();
yield waitForSearchBarFocus();
let hiddenPanelPromise = promisePanelHidden(window);
EventUtils.synthesizeKey("VK_ESCAPE", {});
yield hiddenPanelPromise;
CustomizableUI.reset();
});
// Ctrl+K should open the overflow panel and focus the search bar if the search bar is overflowed.
add_task(function*() {
this.originalWindowWidth = window.outerWidth;
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(360, window.outerHeight);
yield waitForCondition(() => navbar.getAttribute("overflowing") == "true");
ok(!navbar.querySelector("#search-container"), "Search container should be overflowing");
let shownPanelPromise = promiseOverflowShown(window);
sendWebSearchKeyCommand();
yield shownPanelPromise;
let chevron = document.getElementById("nav-bar-overflow-button");
yield waitForCondition(() => chevron.open);
yield waitForSearchBarFocus();
let hiddenPanelPromise = promiseOverflowHidden(window);
EventUtils.synthesizeKey("VK_ESCAPE", {});
yield hiddenPanelPromise;
navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
window.resizeTo(this.originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
});
// Ctrl+K should focus the search bar if it is in the navbar and not overflowing.
add_task(function*() {
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar");
sendWebSearchKeyCommand();
yield waitForSearchBarFocus();
});
function sendWebSearchKeyCommand() {
if (Services.appinfo.OS === "Darwin")
EventUtils.synthesizeKey("k", { accelKey: true });
else
EventUtils.synthesizeKey("k", { ctrlKey: true });
}
function logActiveElement() {
let element = document.activeElement;
let str = "";
while (element && element.parentNode) {
str = " (" + element.localName + "#" + element.id + "." + [...element.classList].join(".") + ") >" + str;
element = element.parentNode;
}
info("Active element: " + element ? str : "null");
}

View file

@ -1,31 +0,0 @@
/* 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";
// Resize to a small window, open a new window, check that new window handles overflow properly
add_task(function*() {
let originalWindowWidth = window.outerWidth;
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
let oldChildCount = navbar.customizationTarget.childElementCount;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(navbar.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");
let newWindow = yield openAndLoadWindow();
let otherNavBar = newWindow.document.getElementById(CustomizableUI.AREA_NAVBAR);
yield waitForCondition(() => otherNavBar.hasAttribute("overflowing"));
ok(otherNavBar.hasAttribute("overflowing"), "Other window should have an overflowing toolbar.");
yield promiseWindowClosed(newWindow);
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
ok(!navbar.hasAttribute("overflowing"), "Should no longer have an overflowing toolbar.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,55 +0,0 @@
/* 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";
var navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
// Resize to a small window, resize back, shouldn't affect currentSet
add_task(function*() {
let originalWindowWidth = window.outerWidth;
let oldCurrentSet = navbar.currentSet;
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
let oldChildCount = navbar.customizationTarget.childElementCount;
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
is(navbar.currentSet, oldCurrentSet, "Currentset should be the same when overflowing.");
ok(CustomizableUI.inDefaultState, "Should still be in default state when overflowing.");
ok(navbar.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
ok(!navbar.hasAttribute("overflowing"), "Should no longer have an overflowing toolbar.");
is(navbar.currentSet, oldCurrentSet, "Currentset should still be the same now we're no longer overflowing.");
ok(CustomizableUI.inDefaultState, "Should still be in default state now we're no longer overflowing.");
// Verify actual physical placements match those of the placement array:
let placementCounter = 0;
let placements = CustomizableUI.getWidgetIdsInArea(CustomizableUI.AREA_NAVBAR);
for (let node of navbar.customizationTarget.childNodes) {
if (node.getAttribute("skipintoolbarset") == "true") {
continue;
}
is(placements[placementCounter++], node.id, "Nodes should match after overflow");
}
is(placements.length, placementCounter, "Should have as many nodes as expected");
is(navbar.customizationTarget.childElementCount, oldChildCount, "Number of nodes should match");
});
// Enter and exit customization mode, check that currentSet works
add_task(function*() {
let oldCurrentSet = navbar.currentSet;
ok(CustomizableUI.inDefaultState, "Should start in default state.");
yield startCustomizing();
ok(CustomizableUI.inDefaultState, "Should be in default state in customization mode.");
is(navbar.currentSet, oldCurrentSet, "Currentset should be the same in customization mode.");
yield endCustomizing();
ok(CustomizableUI.inDefaultState, "Should be in default state after customization mode.");
is(navbar.currentSet, oldCurrentSet, "Currentset should be the same after customization mode.");
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,131 +0,0 @@
/* 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";
var navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
var overflowList = document.getElementById(navbar.getAttribute("overflowtarget"));
const kTestBtn1 = "test-addWidgetToArea-overflow";
const kTestBtn2 = "test-removeWidgetFromArea-overflow";
const kTestBtn3 = "test-createWidget-overflow";
const kHomeBtn = "home-button";
const kDownloadsBtn = "downloads-button";
const kSearchBox = "search-container";
const kStarBtn = "bookmarks-menu-button";
var originalWindowWidth;
// Adding a widget should add it next to the widget it's being inserted next to.
add_task(function*() {
originalWindowWidth = window.outerWidth;
createDummyXULButton(kTestBtn1, "Test");
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(!navbar.querySelector("#" + kHomeBtn), "Home button should no longer be in the navbar");
let homeBtnNode = overflowList.querySelector("#" + kHomeBtn);
ok(homeBtnNode, "Home button should be overflowing");
ok(homeBtnNode && homeBtnNode.getAttribute("overflowedItem") == "true", "Home button should have overflowedItem attribute");
let placementOfHomeButton = CustomizableUI.getWidgetIdsInArea(navbar.id).indexOf(kHomeBtn);
CustomizableUI.addWidgetToArea(kTestBtn1, navbar.id, placementOfHomeButton);
ok(!navbar.querySelector("#" + kTestBtn1), "New button should not be in the navbar");
let newButtonNode = overflowList.querySelector("#" + kTestBtn1);
ok(newButtonNode, "New button should be overflowing");
ok(newButtonNode && newButtonNode.getAttribute("overflowedItem") == "true", "New button should have overflowedItem attribute");
let nextEl = newButtonNode && newButtonNode.nextSibling;
is(nextEl && nextEl.id, kHomeBtn, "Test button should be next to home button.");
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
ok(navbar.querySelector("#" + kHomeBtn), "Home button should be in the navbar");
ok(homeBtnNode && (homeBtnNode.getAttribute("overflowedItem") != "true"), "Home button should no longer have overflowedItem attribute");
ok(!overflowList.querySelector("#" + kHomeBtn), "Home button should no longer be overflowing");
ok(navbar.querySelector("#" + kTestBtn1), "Test button should be in the navbar");
ok(!overflowList.querySelector("#" + kTestBtn1), "Test button should no longer be overflowing");
ok(newButtonNode && (newButtonNode.getAttribute("overflowedItem") != "true"), "New button should no longer have overflowedItem attribute");
let el = document.getElementById(kTestBtn1);
if (el) {
CustomizableUI.removeWidgetFromArea(kTestBtn1);
el.remove();
}
window.resizeTo(originalWindowWidth, window.outerHeight);
});
// Removing a widget should remove it from the overflow list if that is where it is, and update it accordingly.
add_task(function*() {
createDummyXULButton(kTestBtn2, "Test");
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
CustomizableUI.addWidgetToArea(kTestBtn2, navbar.id);
ok(!navbar.hasAttribute("overflowing"), "Should still have a non-overflowing toolbar.");
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar");
ok(overflowList.querySelector("#" + kTestBtn2), "Test button should be overflowing");
CustomizableUI.removeWidgetFromArea(kTestBtn2);
ok(!overflowList.querySelector("#" + kTestBtn2), "Test button should not be overflowing.");
ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar");
ok(gNavToolbox.palette.querySelector("#" + kTestBtn2), "Test button should be in the palette");
window.resizeTo(originalWindowWidth, window.outerHeight);
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
let el = document.getElementById(kTestBtn2);
if (el) {
CustomizableUI.removeWidgetFromArea(kTestBtn2);
el.remove();
}
window.resizeTo(originalWindowWidth, window.outerHeight);
});
// Constructing a widget while overflown should set the right class on it.
add_task(function*() {
originalWindowWidth = window.outerWidth;
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(!navbar.querySelector("#" + kHomeBtn), "Home button should no longer be in the navbar");
let homeBtnNode = overflowList.querySelector("#" + kHomeBtn);
ok(homeBtnNode, "Home button should be overflowing");
ok(homeBtnNode && homeBtnNode.getAttribute("overflowedItem") == "true", "Home button should have overflowedItem class");
let testBtnSpec = {id: kTestBtn3, label: "Overflowable widget test", defaultArea: "nav-bar"};
CustomizableUI.createWidget(testBtnSpec);
let testNode = overflowList.querySelector("#" + kTestBtn3);
ok(testNode, "Test button should be overflowing");
ok(testNode && testNode.getAttribute("overflowedItem") == "true", "Test button should have overflowedItem class");
CustomizableUI.destroyWidget(kTestBtn3);
testNode = document.getElementById(kTestBtn3);
ok(!testNode, "Test button should be gone");
CustomizableUI.createWidget(testBtnSpec);
testNode = overflowList.querySelector("#" + kTestBtn3);
ok(testNode, "Test button should be overflowing");
ok(testNode && testNode.getAttribute("overflowedItem") == "true", "Test button should have overflowedItem class");
CustomizableUI.removeWidgetFromArea(kTestBtn3);
testNode = document.getElementById(kTestBtn3);
ok(!testNode, "Test button should be gone");
CustomizableUI.destroyWidget(kTestBtn3);
window.resizeTo(originalWindowWidth, window.outerHeight);
});
add_task(function* asyncCleanup() {
window.resizeTo(originalWindowWidth, window.outerHeight);
yield resetCustomization();
});

View file

@ -1,16 +0,0 @@
/* 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/. */
// Entering then exiting customization mode should reenable the Help and Exit buttons.
add_task(function*() {
yield startCustomizing();
let helpButton = document.getElementById("PanelUI-help");
let quitButton = document.getElementById("PanelUI-quit");
ok(helpButton.getAttribute("disabled") == "true", "Help button should be disabled while in customization mode.");
ok(quitButton.getAttribute("disabled") == "true", "Quit button should be disabled while in customization mode.");
yield endCustomizing();
ok(!helpButton.hasAttribute("disabled"), "Help button should not be disabled.");
ok(!quitButton.hasAttribute("disabled"), "Quit button should not be disabled.");
});

View file

@ -1,38 +0,0 @@
/* 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";
var navbar;
var skippedItem;
// Attempting to drag a skipintoolbarset item should work.
add_task(function*() {
navbar = document.getElementById("nav-bar");
skippedItem = document.createElement("toolbarbutton");
skippedItem.id = "test-skipintoolbarset-item";
skippedItem.setAttribute("label", "Test");
skippedItem.setAttribute("skipintoolbarset", "true");
skippedItem.setAttribute("removable", "true");
navbar.customizationTarget.appendChild(skippedItem);
let downloadsButton = document.getElementById("downloads-button");
yield startCustomizing();
ok(CustomizableUI.inDefaultState, "Should still be in default state");
simulateItemDrag(skippedItem, downloadsButton);
ok(CustomizableUI.inDefaultState, "Should still be in default state");
let skippedItemWrapper = skippedItem.parentNode;
is(skippedItemWrapper.nextSibling && skippedItemWrapper.nextSibling.id,
downloadsButton.parentNode.id, "Should be next to downloads button");
simulateItemDrag(downloadsButton, skippedItem);
let downloadWrapper = downloadsButton.parentNode;
is(downloadWrapper.nextSibling && downloadWrapper.nextSibling.id,
skippedItem.parentNode.id, "Should be next to skipintoolbarset item");
ok(CustomizableUI.inDefaultState, "Should still be in default state");
});
add_task(function* asyncCleanup() {
yield endCustomizing();
skippedItem.remove();
yield resetCustomization();
});

View file

@ -1,24 +0,0 @@
/* 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";
// Customize mode reset button should revert correctly
add_task(function*() {
yield startCustomizing();
let devButton = document.getElementById("developer-button");
let downloadsButton = document.getElementById("downloads-button");
let searchBox = document.getElementById("search-container");
let palette = document.getElementById("customization-palette");
ok(devButton && downloadsButton && searchBox && palette, "Stuff should exist");
simulateItemDrag(devButton, downloadsButton);
simulateItemDrag(searchBox, palette);
yield gCustomizeMode.reset();
ok(CustomizableUI.inDefaultState, "Should be back in default state");
yield endCustomizing();
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,26 +0,0 @@
/* 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 kTestToolbarId = "test-empty-drag";
// Attempting to drag an item to an empty container should work.
add_task(function*() {
yield createToolbarWithPlacements(kTestToolbarId, []);
yield startCustomizing();
let downloadButton = document.getElementById("downloads-button");
let customToolbar = document.getElementById(kTestToolbarId);
simulateItemDrag(downloadButton, customToolbar);
assertAreaPlacements(kTestToolbarId, ["downloads-button"]);
ok(downloadButton.parentNode && downloadButton.parentNode.parentNode == customToolbar,
"Button should really be in toolbar");
yield endCustomizing();
removeCustomToolbars();
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,35 +0,0 @@
/* 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";
// There should be an advert to get more addons when the palette is empty.
add_task(function*() {
yield startCustomizing();
let visiblePalette = document.getElementById("customization-palette");
let emptyPaletteNotice = document.getElementById("customization-empty");
is(emptyPaletteNotice.hidden, true, "The empty palette notice should not be shown when there are items in the palette.");
while (visiblePalette.childElementCount) {
gCustomizeMode.addToToolbar(visiblePalette.children[0]);
}
is(visiblePalette.childElementCount, 0, "There shouldn't be any items remaining in the visible palette.");
is(emptyPaletteNotice.hidden, false, "The empty palette notice should be shown when there are no items in the palette.");
yield endCustomizing();
yield startCustomizing();
visiblePalette = document.getElementById("customization-palette");
emptyPaletteNotice = document.getElementById("customization-empty");
is(emptyPaletteNotice.hidden, false,
"The empty palette notice should be shown when there are no items in the palette and cust. mode is re-entered.");
gCustomizeMode.removeFromArea(document.getElementById("wrapper-home-button"));
is(emptyPaletteNotice.hidden, true,
"The empty palette notice should not be shown when there is at least one item in the palette.");
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,30 +0,0 @@
/* 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";
// Attempting to drag the menubar to the navbar shouldn't work.
add_task(function*() {
yield startCustomizing();
let menuItems = document.getElementById("menubar-items");
let navbar = document.getElementById("nav-bar");
let menubar = document.getElementById("toolbar-menubar");
// Force the menu to be shown.
const kAutohide = menubar.getAttribute("autohide");
menubar.setAttribute("autohide", "false");
simulateItemDrag(menuItems, navbar.customizationTarget);
is(getAreaWidgetIds("nav-bar").indexOf("menubar-items"), -1, "Menu bar shouldn't be in the navbar.");
ok(!navbar.querySelector("#menubar-items"), "Shouldn't find menubar items in the navbar.");
ok(menubar.querySelector("#menubar-items"), "Should find menubar items in the menubar.");
isnot(getAreaWidgetIds("toolbar-menubar").indexOf("menubar-items"), -1,
"Menubar items shouldn't be missing from the navbar.");
menubar.setAttribute("autohide", kAutohide);
yield endCustomizing();
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,89 +0,0 @@
/* 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 kTimeoutInMS = 20000;
// Bug 934951 - Zoom controls percentage label doesn't update when it's in the toolbar and you navigate.
add_task(function*() {
CustomizableUI.addWidgetToArea("zoom-controls", CustomizableUI.AREA_NAVBAR);
let tab1 = gBrowser.addTab("about:mozilla");
yield BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
let tab2 = gBrowser.addTab("about:robots");
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
gBrowser.selectedTab = tab1;
let zoomResetButton = document.getElementById("zoom-reset-button");
registerCleanupFunction(() => {
info("Cleaning up.");
CustomizableUI.reset();
gBrowser.removeTab(tab2);
gBrowser.removeTab(tab1);
});
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
FullZoom.enlarge();
yield zoomChangePromise;
is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
let tabSelectPromise = promiseTabSelect();
gBrowser.selectedTab = tab2;
yield tabSelectPromise;
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:robots");
gBrowser.selectedTab = tab1;
let zoomResetPromise = promiseObserverNotification("browser-fullZoom:zoomReset");
FullZoom.reset();
yield zoomResetPromise;
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
// Test zoom label updates while navigating pages in the same tab.
FullZoom.enlarge();
yield zoomChangePromise;
is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
let attributeChangePromise = promiseAttributeMutation(zoomResetButton, "label", (v) => {
return parseInt(v, 10) == 100;
});
yield promiseTabLoadEvent(tab1, "about:home");
yield attributeChangePromise;
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home");
yield promiseTabHistoryNavigation(-1, function() {
return parseInt(zoomResetButton.label, 10) == 110;
});
is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla");
FullZoom.reset();
});
function promiseObserverNotification(aObserver) {
let deferred = Promise.defer();
function notificationCallback(e) {
Services.obs.removeObserver(notificationCallback, aObserver, false);
clearTimeout(timeoutId);
deferred.resolve();
}
let timeoutId = setTimeout(() => {
Services.obs.removeObserver(notificationCallback, aObserver, false);
deferred.reject("Notification '" + aObserver + "' did not happen within 20 seconds.");
}, kTimeoutInMS);
Services.obs.addObserver(notificationCallback, aObserver, false);
return deferred.promise;
}
function promiseTabSelect() {
let deferred = Promise.defer();
let container = window.gBrowser.tabContainer;
let timeoutId = setTimeout(() => {
container.removeEventListener("TabSelect", callback);
deferred.reject("TabSelect did not happen within 20 seconds");
}, kTimeoutInMS);
function callback(e) {
container.removeEventListener("TabSelect", callback);
clearTimeout(timeoutId);
executeSoon(deferred.resolve);
}
container.addEventListener("TabSelect", callback);
return deferred.promise;
}

View file

@ -1,121 +0,0 @@
/* 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";
requestLongerTimeout(2);
var bookmarksToolbar = document.getElementById("PersonalToolbar");
var navbar = document.getElementById("nav-bar");
var tabsToolbar = document.getElementById("TabsToolbar");
// Customization reset should restore visibility to default-visible toolbars.
add_task(function*() {
is(navbar.collapsed, false, "Test should start with navbar visible");
setToolbarVisibility(navbar, false);
is(navbar.collapsed, true, "navbar should be hidden now");
yield resetCustomization();
is(navbar.collapsed, false, "Customization reset should restore visibility to the navbar");
});
// Customization reset should restore collapsed-state to default-collapsed toolbars.
add_task(function*() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
is(bookmarksToolbar.collapsed, true, "Test should start with bookmarks toolbar collapsed");
ok(bookmarksToolbar.collapsed, "bookmarksToolbar should be collapsed");
ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
is(navbar.collapsed, false, "The nav-bar should be shown by default");
setToolbarVisibility(bookmarksToolbar, true);
setToolbarVisibility(navbar, false);
ok(!bookmarksToolbar.collapsed, "bookmarksToolbar should be visible now");
ok(navbar.collapsed, "navbar should be collapsed");
is(CustomizableUI.inDefaultState, false, "Should no longer be in default state");
yield startCustomizing();
yield gCustomizeMode.reset();
yield endCustomizing();
is(bookmarksToolbar.collapsed, true, "Customization reset should restore collapsed-state to the bookmarks toolbar");
ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
ok(bookmarksToolbar.collapsed, "The bookmarksToolbar should be collapsed after reset");
ok(CustomizableUI.inDefaultState, "Everything should be back to default state");
});
// Check that the menubar will be collapsed by resetting, if the platform supports it.
add_task(function*() {
let menubar = document.getElementById("toolbar-menubar");
const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(menubar.id);
if (!canMenubarCollapse) {
return;
}
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
is(menubar.getBoundingClientRect().height, 0, "menubar should be hidden by default");
setToolbarVisibility(menubar, true);
isnot(menubar.getBoundingClientRect().height, 0, "menubar should be visible now");
yield startCustomizing();
yield gCustomizeMode.reset();
is(menubar.getAttribute("autohide"), "true", "The menubar should have autohide=true after reset in customization mode");
is(menubar.getBoundingClientRect().height, 0, "The menubar should have height=0 after reset in customization mode");
yield endCustomizing();
is(menubar.getAttribute("autohide"), "true", "The menubar should have autohide=true after reset");
is(menubar.getBoundingClientRect().height, 0, "The menubar should have height=0 after reset");
});
// Customization reset should restore collapsed-state to default-collapsed toolbars.
add_task(function*() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
ok(bookmarksToolbar.collapsed, "bookmarksToolbar should be collapsed");
ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
setToolbarVisibility(bookmarksToolbar, true);
ok(!bookmarksToolbar.collapsed, "bookmarksToolbar should be visible now");
is(CustomizableUI.inDefaultState, false, "Should no longer be in default state");
yield startCustomizing();
ok(!bookmarksToolbar.collapsed, "The bookmarksToolbar should be visible before reset");
ok(!navbar.collapsed, "The navbar should be visible before reset");
ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
yield gCustomizeMode.reset();
ok(bookmarksToolbar.collapsed, "The bookmarksToolbar should be collapsed after reset");
ok(!tabsToolbar.collapsed, "TabsToolbar should not be collapsed");
ok(!navbar.collapsed, "The navbar should still be visible after reset");
ok(CustomizableUI.inDefaultState, "Everything should be back to default state");
yield endCustomizing();
});
// Check that the menubar will be collapsed by resetting, if the platform supports it.
add_task(function*() {
let menubar = document.getElementById("toolbar-menubar");
const canMenubarCollapse = CustomizableUI.isToolbarDefaultCollapsed(menubar.id);
if (!canMenubarCollapse) {
return;
}
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
yield startCustomizing();
let resetButton = document.getElementById("customization-reset-button");
is(resetButton.disabled, true, "The reset button should be disabled when in default state");
setToolbarVisibility(menubar, true);
is(resetButton.disabled, false, "The reset button should be enabled when not in default state")
ok(!CustomizableUI.inDefaultState, "No longer in default state when the menubar is shown");
yield gCustomizeMode.reset();
is(resetButton.disabled, true, "The reset button should be disabled when in default state");
ok(CustomizableUI.inDefaultState, "Everything should be in its default state");
yield endCustomizing();
});

View file

@ -1,25 +0,0 @@
/* 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 kWidgetId = "test-non-removable-widget";
// Adding non-removable items to a toolbar or the panel shouldn't change inDefaultState
add_task(function() {
ok(CustomizableUI.inDefaultState, "Should start in default state");
let button = createDummyXULButton(kWidgetId, "Test non-removable inDefaultState handling");
CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_NAVBAR);
button.setAttribute("removable", "false");
ok(CustomizableUI.inDefaultState, "Should still be in default state after navbar addition");
button.remove();
button = createDummyXULButton(kWidgetId, "Test non-removable inDefaultState handling");
CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_PANEL);
button.setAttribute("removable", "false");
ok(CustomizableUI.inDefaultState, "Should still be in default state after panel addition");
button.remove();
ok(CustomizableUI.inDefaultState, "Should be in default state after destroying both widgets");
});

View file

@ -1,70 +0,0 @@
/* 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 kToolbarId = "test-registerToolbarNode-toolbar";
const kButtonId = "test-registerToolbarNode-button";
registerCleanupFunction(cleanup);
// Registering a toolbar with defaultset attribute should work
add_task(function*() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
let btn = createDummyXULButton(kButtonId);
let toolbar = document.createElement("toolbar");
toolbar.id = kToolbarId;
toolbar.setAttribute("customizable", true);
toolbar.setAttribute("defaultset", kButtonId);
gNavToolbox.appendChild(toolbar);
ok(CustomizableUI.areas.indexOf(kToolbarId) != -1,
"Toolbar should have been registered automatically.");
is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR,
"Area should be registered as toolbar");
assertAreaPlacements(kToolbarId, [kButtonId]);
ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible.");
CustomizableUI.unregisterArea(kToolbarId, true);
toolbar.remove();
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
btn.remove();
});
// Registering a toolbar without a defaultset attribute should
// wait for the registerArea call
add_task(function*() {
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
let btn = createDummyXULButton(kButtonId);
let toolbar = document.createElement("toolbar");
toolbar.id = kToolbarId;
toolbar.setAttribute("customizable", true);
gNavToolbox.appendChild(toolbar);
ok(CustomizableUI.areas.indexOf(kToolbarId) == -1,
"Toolbar should not yet have been registered automatically.");
CustomizableUI.registerArea(kToolbarId, {defaultPlacements: [kButtonId]});
ok(CustomizableUI.areas.indexOf(kToolbarId) != -1,
"Toolbar should have been registered now.");
is(CustomizableUI.getAreaType(kToolbarId), CustomizableUI.TYPE_TOOLBAR,
"Area should be registered as toolbar");
assertAreaPlacements(kToolbarId, [kButtonId]);
ok(!CustomizableUI.inDefaultState, "No longer in default state after toolbar is registered and visible.");
CustomizableUI.unregisterArea(kToolbarId, true);
toolbar.remove();
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
btn.remove();
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});
function cleanup() {
let toolbar = document.getElementById(kToolbarId);
if (toolbar) {
toolbar.remove();
}
let btn = document.getElementById(kButtonId) ||
gNavToolbox.querySelector("#" + kButtonId);
if (btn) {
btn.remove();
}
}

View file

@ -1,136 +0,0 @@
/* 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";
var button, menuButton;
/* Clicking a button should close the panel */
add_task(function*() {
button = document.createElement("toolbarbutton");
button.id = "browser_940307_button";
button.setAttribute("label", "Button");
PanelUI.contents.appendChild(button);
yield PanelUI.show();
let hiddenAgain = promisePanelHidden(window);
EventUtils.synthesizeMouseAtCenter(button, {});
yield hiddenAgain;
button.remove();
});
/* Clicking a menu button should close the panel, opening the popup shouldn't. */
add_task(function*() {
menuButton = document.createElement("toolbarbutton");
menuButton.setAttribute("type", "menu-button");
menuButton.id = "browser_940307_menubutton";
menuButton.setAttribute("label", "Menu button");
let menuPopup = document.createElement("menupopup");
menuPopup.id = "browser_940307_menupopup";
let menuItem = document.createElement("menuitem");
menuItem.setAttribute("label", "Menu item");
menuItem.id = "browser_940307_menuitem";
menuPopup.appendChild(menuItem);
menuButton.appendChild(menuPopup);
PanelUI.contents.appendChild(menuButton);
yield PanelUI.show();
let hiddenAgain = promisePanelHidden(window);
let innerButton = document.getAnonymousElementByAttribute(menuButton, "anonid", "button");
EventUtils.synthesizeMouseAtCenter(innerButton, {});
yield hiddenAgain;
// Now click the dropmarker to show the menu
yield PanelUI.show();
hiddenAgain = promisePanelHidden(window);
let menuShown = promisePanelElementShown(window, menuPopup);
let dropmarker = document.getAnonymousElementByAttribute(menuButton, "type", "menu-button");
EventUtils.synthesizeMouseAtCenter(dropmarker, {});
yield menuShown;
// Panel should stay open:
ok(isPanelUIOpen(), "Panel should still be open");
let menuHidden = promisePanelElementHidden(window, menuPopup);
// Then click the menu item to close all the things
EventUtils.synthesizeMouseAtCenter(menuItem, {});
yield menuHidden;
yield hiddenAgain;
menuButton.remove();
});
add_task(function*() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
yield PanelUI.show();
yield waitForCondition(() => "value" in searchbar && searchbar.value === "");
// Focusing a non-empty searchbox will cause us to open the
// autocomplete panel and search for suggestions, which would
// trigger network requests. Temporarily disable suggestions.
yield SpecialPowers.pushPrefEnv({set: [["browser.search.suggest.enabled", false]]});
searchbar.value = "foo";
searchbar.focus();
// Reaching into this context menu is pretty evil, but hey... it's a test.
let textbox = document.getAnonymousElementByAttribute(searchbar.textbox, "anonid", "textbox-input-box");
let contextmenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu");
let contextMenuShown = promisePanelElementShown(window, contextmenu);
EventUtils.synthesizeMouseAtCenter(searchbar, {type: "contextmenu", button: 2});
yield contextMenuShown;
ok(isPanelUIOpen(), "Panel should still be open");
let selectAll = contextmenu.querySelector("[cmd='cmd_selectAll']");
let contextMenuHidden = promisePanelElementHidden(window, contextmenu);
EventUtils.synthesizeMouseAtCenter(selectAll, {});
yield contextMenuHidden;
// Hide the suggestion panel.
searchbar.textbox.popup.hidePopup();
ok(isPanelUIOpen(), "Panel should still be open");
let hiddenPanelPromise = promisePanelHidden(window);
EventUtils.synthesizeKey("VK_ESCAPE", {});
yield hiddenPanelPromise;
ok(!isPanelUIOpen(), "Panel should no longer be open");
// We focused the search bar earlier - ensure we don't keep doing that.
gURLBar.select();
CustomizableUI.reset();
});
add_task(function*() {
button = document.createElement("toolbarbutton");
button.id = "browser_946166_button_disabled";
button.setAttribute("disabled", "true");
button.setAttribute("label", "Button");
PanelUI.contents.appendChild(button);
yield PanelUI.show();
EventUtils.synthesizeMouseAtCenter(button, {});
is(PanelUI.panel.state, "open", "Popup stays open");
button.removeAttribute("disabled");
let hiddenAgain = promisePanelHidden(window);
EventUtils.synthesizeMouseAtCenter(button, {});
yield hiddenAgain;
button.remove();
});
registerCleanupFunction(function() {
if (button && button.parentNode) {
button.remove();
}
if (menuButton && menuButton.parentNode) {
menuButton.remove();
}
// Sadly this isn't task.jsm-enabled, so we can't wait for this to happen. But we should
// definitely close it here and hope it won't interfere with other tests.
// Of course, all the tests are meant to do this themselves, but if they fail...
if (isPanelUIOpen()) {
PanelUI.hide();
}
});

View file

@ -1,22 +0,0 @@
/* 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 kTestBtnId = "test-removable-navbar-customize-mode";
// Items without the removable attribute in the navbar should be considered non-removable
add_task(function*() {
let btn = createDummyXULButton(kTestBtnId, "Test removable in navbar in customize mode");
document.getElementById("nav-bar").customizationTarget.appendChild(btn);
yield startCustomizing();
ok(!CustomizableUI.isWidgetRemovable(kTestBtnId), "Widget should not be considered removable");
yield endCustomizing();
document.getElementById(kTestBtnId).remove();
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,31 +0,0 @@
/* 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";
// See https://bugzilla.mozilla.org/show_bug.cgi?id=941083
const kWidgetId = "test-invalidate-wrapper-cache";
// Check createWidget invalidates the widget cache
add_task(function() {
let groupWrapper = CustomizableUI.getWidget(kWidgetId);
ok(groupWrapper, "Should get group wrapper.");
let singleWrapper = groupWrapper.forWindow(window);
ok(singleWrapper, "Should get single wrapper.");
CustomizableUI.createWidget({id: kWidgetId, label: "Test invalidating widgets caching"});
let newGroupWrapper = CustomizableUI.getWidget(kWidgetId);
ok(newGroupWrapper, "Should get a group wrapper again.");
isnot(newGroupWrapper, groupWrapper, "Wrappers shouldn't be the same.");
isnot(newGroupWrapper.provider, groupWrapper.provider, "Wrapper providers shouldn't be the same.");
let newSingleWrapper = newGroupWrapper.forWindow(window);
isnot(newSingleWrapper, singleWrapper, "Single wrappers shouldn't be the same.");
isnot(newSingleWrapper.provider, singleWrapper.provider, "Single wrapper providers shouldn't be the same.");
CustomizableUI.destroyWidget(kWidgetId);
ok(!CustomizableUI.getWidget(kWidgetId), "Shouldn't get a wrapper after destroying the widget.");
});

View file

@ -1,106 +0,0 @@
/* 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 kToolbarName = "test-unregisterArea-placements-toolbar";
const kTestWidgetPfx = "test-widget-for-unregisterArea-placements-";
const kTestWidgetCount = 3;
registerCleanupFunction(removeCustomToolbars);
// unregisterArea should keep placements by default and restore them when re-adding the area
add_task(function*() {
let widgetIds = [];
for (let i = 0; i < kTestWidgetCount; i++) {
let id = kTestWidgetPfx + i;
widgetIds.push(id);
let spec = {id: id, type: 'button', removable: true, label: "unregisterArea test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
}
for (let i = kTestWidgetCount; i < kTestWidgetCount * 2; i++) {
let id = kTestWidgetPfx + i;
widgetIds.push(id);
createDummyXULButton(id, "unregisterArea XUL test " + i);
}
let toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
checkAbstractAndRealPlacements(toolbarNode, widgetIds);
// Now move one of them:
CustomizableUI.moveWidgetWithinArea(kTestWidgetPfx + kTestWidgetCount, 0);
// Clone the array so we know this is the modified one:
let modifiedWidgetIds = [...widgetIds];
let movedWidget = modifiedWidgetIds.splice(kTestWidgetCount, 1)[0];
modifiedWidgetIds.unshift(movedWidget);
// Check it:
checkAbstractAndRealPlacements(toolbarNode, modifiedWidgetIds);
// Then unregister
CustomizableUI.unregisterArea(kToolbarName);
// Check we tell the outside world no dangerous things:
checkWidgetFates(widgetIds);
// Only then remove the real node
toolbarNode.remove();
// Now move one of the items to the palette, and another to the navbar:
let lastWidget = modifiedWidgetIds.pop();
CustomizableUI.removeWidgetFromArea(lastWidget);
lastWidget = modifiedWidgetIds.pop();
CustomizableUI.addWidgetToArea(lastWidget, CustomizableUI.AREA_NAVBAR);
// Recreate ourselves with the default placements being the same:
toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
// Then check that after doing this, our actual placements match
// the modified list, not the default one.
checkAbstractAndRealPlacements(toolbarNode, modifiedWidgetIds);
// Now remove completely:
CustomizableUI.unregisterArea(kToolbarName, true);
checkWidgetFates(modifiedWidgetIds);
toolbarNode.remove();
// One more time:
// Recreate ourselves with the default placements being the same:
toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
// Should now be back to default:
checkAbstractAndRealPlacements(toolbarNode, widgetIds);
CustomizableUI.unregisterArea(kToolbarName, true);
checkWidgetFates(widgetIds);
toolbarNode.remove();
// XXXgijs: ensure cleanup function doesn't barf:
gAddedToolbars.delete(kToolbarName);
// Remove all the XUL widgets, destroy the others:
for (let widget of widgetIds) {
let widgetWrapper = CustomizableUI.getWidget(widget);
if (widgetWrapper.provider == CustomizableUI.PROVIDER_XUL) {
gNavToolbox.palette.querySelector("#" + widget).remove();
} else {
CustomizableUI.destroyWidget(widget);
}
}
});
function checkAbstractAndRealPlacements(aNode, aExpectedPlacements) {
assertAreaPlacements(kToolbarName, aExpectedPlacements);
let physicalWidgetIds = Array.from(aNode.childNodes, (node) => node.id);
placementArraysEqual(aNode.id, physicalWidgetIds, aExpectedPlacements);
}
function checkWidgetFates(aWidgetIds) {
for (let widget of aWidgetIds) {
ok(!CustomizableUI.getPlacementOfWidget(widget), "Widget should be in palette");
ok(!document.getElementById(widget), "Widget should not be in the DOM");
let widgetInPalette = !!gNavToolbox.palette.querySelector("#" + widget);
let widgetProvider = CustomizableUI.getWidget(widget).provider;
let widgetIsXULWidget = widgetProvider == CustomizableUI.PROVIDER_XUL;
is(widgetInPalette, widgetIsXULWidget, "Just XUL Widgets should be in the palette");
}
}
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,50 +0,0 @@
/* 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 kWidgetId = "test-addonbar-migration";
const kWidgetId2 = "test-addonbar-migration2";
var addonbar = document.getElementById(CustomizableUI.AREA_ADDONBAR);
var navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
var btn;
var btn2;
// Check we migrate normal stuff to the navbar
add_task(function*() {
btn = createDummyXULButton(kWidgetId, "Test");
btn2 = createDummyXULButton(kWidgetId2, "Test2");
addonbar.insertItem(btn.id);
ok(btn.parentNode == navbar.customizationTarget, "Button should end up in navbar");
let migrationArray = addonbar.getMigratedItems();
is(migrationArray.length, 1, "Should have migrated 1 item");
is(migrationArray[0], kWidgetId, "Should have migrated our 1 item");
addonbar.currentSet = addonbar.currentSet + "," + kWidgetId2;
ok(btn2.parentNode == navbar.customizationTarget, "Second button should end up in the navbar");
migrationArray = addonbar.getMigratedItems();
is(migrationArray.length, 2, "Should have migrated 2 items");
isnot(migrationArray.indexOf(kWidgetId2), -1, "Should have migrated our second item");
let otherWindow = yield openAndLoadWindow(undefined, true);
try {
let addonBar = otherWindow.document.getElementById("addon-bar");
let otherMigrationArray = addonBar.getMigratedItems();
is(migrationArray.length, otherMigrationArray.length,
"Other window should have the same number of migrated items.");
if (migrationArray.length == otherMigrationArray.length) {
for (let widget of migrationArray) {
isnot(otherMigrationArray.indexOf(widget), -1,
"Migrated widget " + widget + " should also be listed as migrated in the other window.");
}
}
} finally {
yield promiseWindowClosed(otherWindow);
}
btn.remove();
btn2.remove();
CustomizableUI.reset();
});

View file

@ -1,17 +0,0 @@
/* 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 kWidgetId = "test-destroy-in-palette";
// Check destroyWidget destroys the node if it's in the palette
add_task(function*() {
CustomizableUI.createWidget({id: kWidgetId, label: "Test destroying widgets in palette."});
yield startCustomizing();
yield endCustomizing();
ok(gNavToolbox.palette.querySelector("#" + kWidgetId), "Widget still exists in palette.");
CustomizableUI.destroyWidget(kWidgetId);
ok(!gNavToolbox.palette.querySelector("#" + kWidgetId), "Widget no longer exists in palette.");
});

View file

@ -1,35 +0,0 @@
/* 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 kWidgetId = "test-private-browsing-customize-mode-widget";
// Add a widget via the API with showInPrivateBrowsing set to false
// and ensure it does not appear in the list of unused widgets in private
// windows.
add_task(function* testPrivateBrowsingCustomizeModeWidget() {
CustomizableUI.createWidget({
id: kWidgetId,
showInPrivateBrowsing: false
});
let normalWidgetArray = CustomizableUI.getUnusedWidgets(gNavToolbox.palette);
normalWidgetArray = normalWidgetArray.map((w) => w.id);
ok(normalWidgetArray.indexOf(kWidgetId) > -1,
"Widget should appear as unused in non-private window");
let privateWindow = yield openAndLoadWindow({private: true});
let privateWidgetArray = CustomizableUI.getUnusedWidgets(privateWindow.gNavToolbox.palette);
privateWidgetArray = privateWidgetArray.map((w) => w.id);
is(privateWidgetArray.indexOf(kWidgetId), -1,
"Widget should not appear as unused in private window");
yield promiseWindowClosed(privateWindow);
CustomizableUI.destroyWidget(kWidgetId);
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,33 +0,0 @@
/* 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";
var initialLocation = gBrowser.currentURI.spec;
var newTab = null;
add_task(function*() {
info("Check addons button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
let addonsButton = document.getElementById("add-ons-button");
ok(addonsButton, "Add-ons button exists in Panel Menu");
addonsButton.click();
newTab = gBrowser.selectedTab;
yield waitForCondition(() => gBrowser.currentURI &&
gBrowser.currentURI.spec == "about:addons");
let addonsPage = gBrowser.selectedBrowser.contentWindow.document.
getElementById("addons-page");
ok(addonsPage, "Add-ons page was opened");
});
add_task(function* asyncCleanup() {
gBrowser.addTab(initialLocation);
gBrowser.removeTab(gBrowser.selectedTab);
info("Tabs were restored");
});

View file

@ -1,59 +0,0 @@
/* 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";
var initialLocation = gBrowser.currentURI.spec;
var globalClipboard;
add_task(function*() {
yield BrowserTestUtils.withNewTab({gBrowser, url: "about:blank"}, function*() {
info("Check copy button existence and functionality");
let testText = "copy text test";
gURLBar.focus();
info("The URL bar was focused");
yield PanelUI.show();
info("Menu panel was opened");
let copyButton = document.getElementById("copy-button");
ok(copyButton, "Copy button exists in Panel Menu");
ok(copyButton.getAttribute("disabled"), "Copy button is initially disabled");
// copy text from URL bar
gURLBar.value = testText;
gURLBar.focus();
gURLBar.select();
yield PanelUI.show();
info("Menu panel was opened");
ok(!copyButton.hasAttribute("disabled"), "Copy button is enabled when selecting");
copyButton.click();
is(gURLBar.value, testText, "Selected text is unaltered when clicking copy");
// check that the text was added to the clipboard
let clipboard = Services.clipboard;
let transferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
globalClipboard = clipboard.kGlobalClipboard;
transferable.init(null);
transferable.addDataFlavor("text/unicode");
clipboard.getData(transferable, globalClipboard);
let str = {}, strLength = {};
transferable.getTransferData("text/unicode", str, strLength);
let clipboardValue = "";
if (str.value) {
str.value.QueryInterface(Ci.nsISupportsString);
clipboardValue = str.value.data;
}
is(clipboardValue, testText, "Data was copied to the clipboard.");
});
});
registerCleanupFunction(function cleanup() {
Services.clipboard.emptyClipboard(globalClipboard);
});

View file

@ -1,57 +0,0 @@
/* 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";
var initialLocation = gBrowser.currentURI.spec;
var globalClipboard;
add_task(function*() {
yield BrowserTestUtils.withNewTab({gBrowser, url: "about:blank"}, function*() {
info("Check cut button existence and functionality");
let testText = "cut text test";
gURLBar.focus();
yield PanelUI.show();
info("Menu panel was opened");
let cutButton = document.getElementById("cut-button");
ok(cutButton, "Cut button exists in Panel Menu");
ok(cutButton.hasAttribute("disabled"), "Cut button is disabled");
// cut text from URL bar
gURLBar.value = testText;
gURLBar.focus();
gURLBar.select();
yield PanelUI.show();
info("Menu panel was opened");
ok(!cutButton.hasAttribute("disabled"), "Cut button is enabled when selecting");
cutButton.click();
is(gURLBar.value, "", "Selected text is removed from source when clicking on cut");
// check that the text was added to the clipboard
let clipboard = Services.clipboard;
let transferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
globalClipboard = clipboard.kGlobalClipboard;
transferable.init(null);
transferable.addDataFlavor("text/unicode");
clipboard.getData(transferable, globalClipboard);
let str = {}, strLength = {};
transferable.getTransferData("text/unicode", str, strLength);
let clipboardValue = "";
if (str.value) {
str.value.QueryInterface(Ci.nsISupportsString);
clipboardValue = str.value.data;
}
is(clipboardValue, testText, "Data was copied to the clipboard.");
});
});
registerCleanupFunction(function cleanup() {
Services.clipboard.emptyClipboard(globalClipboard);
});

View file

@ -1,22 +0,0 @@
/* 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";
add_task(function*() {
info("Check find button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
let findButton = document.getElementById("find-button");
ok(findButton, "Find button exists in Panel Menu");
findButton.click();
ok(!gFindBar.hasAttribute("hidden"), "Findbar opened successfully");
// close find bar
gFindBar.close();
info("Findbar was closed");
});

View file

@ -1,24 +0,0 @@
/* 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";
add_task(function*() {
info("Check history button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
let historyButton = document.getElementById("history-panelmenu");
ok(historyButton, "History button appears in Panel Menu");
historyButton.click();
let historyPanel = document.getElementById("PanelUI-history");
ok(historyPanel.getAttribute("current"), "History Panel is in view");
let panelHiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHiddenPromise
info("Menu panel was closed");
});

View file

@ -1,48 +0,0 @@
/* 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";
add_task(function*() {
info("Check private browsing button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
let windowWasHandled = false;
let privateWindow = null;
let observerWindowOpened = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
privateWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
privateWindow.addEventListener("load", function newWindowHandler() {
privateWindow.removeEventListener("load", newWindowHandler, false);
is(privateWindow.location.href, "chrome://browser/content/browser.xul",
"A new browser window was opened");
ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "Window is private");
windowWasHandled = true;
}, false);
}
}
}
Services.ww.registerNotification(observerWindowOpened);
let privateBrowsingButton = document.getElementById("privatebrowsing-button");
ok(privateBrowsingButton, "Private browsing button exists in Panel Menu");
privateBrowsingButton.click();
try {
yield waitForCondition(() => windowWasHandled);
yield promiseWindowClosed(privateWindow);
info("The new private window was closed");
}
catch (e) {
ok(false, "The new private browser window was not properly handled");
}
finally {
Services.ww.unregisterNotification(observerWindowOpened);
}
});

View file

@ -1,47 +0,0 @@
/* 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";
add_task(function*() {
info("Check new window button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
let windowWasHandled = false;
let newWindow = null;
let observerWindowOpened = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
newWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
newWindow.addEventListener("load", function newWindowHandler() {
newWindow.removeEventListener("load", newWindowHandler, false);
is(newWindow.location.href, "chrome://browser/content/browser.xul",
"A new browser window was opened");
ok(!PrivateBrowsingUtils.isWindowPrivate(newWindow), "Window is not private");
windowWasHandled = true;
}, false);
}
}
}
Services.ww.registerNotification(observerWindowOpened);
let newWindowButton = document.getElementById("new-window-button");
ok(newWindowButton, "New Window button exists in Panel Menu");
newWindowButton.click();
try {
yield waitForCondition(() => windowWasHandled);
yield promiseWindowClosed(newWindow);
info("The new window was closed");
}
catch (e) {
ok(false, "The new browser window was not properly handled");
}
finally {
Services.ww.unregisterNotification(observerWindowOpened);
}
});

View file

@ -1,41 +0,0 @@
/* 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";
var initialLocation = gBrowser.currentURI.spec;
var globalClipboard;
add_task(function*() {
yield BrowserTestUtils.withNewTab({gBrowser, url: "about:blank"}, function*() {
info("Check paste button existence and functionality");
let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
globalClipboard = Services.clipboard.kGlobalClipboard;
yield PanelUI.show();
info("Menu panel was opened");
let pasteButton = document.getElementById("paste-button");
ok(pasteButton, "Paste button exists in Panel Menu");
// add text to clipboard
let text = "Sample text for testing";
clipboard.copyString(text);
// test paste button by pasting text to URL bar
gURLBar.focus();
yield PanelUI.show();
info("Menu panel was opened");
ok(!pasteButton.hasAttribute("disabled"), "Paste button is enabled");
pasteButton.click();
is(gURLBar.value, text, "Text pasted successfully");
});
});
registerCleanupFunction(function cleanup() {
Services.clipboard.emptyClipboard(globalClipboard);
});

View file

@ -1,45 +0,0 @@
/* 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 isOSX = (Services.appinfo.OS === "Darwin");
add_task(function*() {
yield BrowserTestUtils.withNewTab({
gBrowser,
url: "http://example.com/",
}, function* () {
info("Check print button existence and functionality");
yield PanelUI.show();
info("Menu panel was opened");
yield waitForCondition(() => document.getElementById("print-button") != null);
let printButton = document.getElementById("print-button");
ok(printButton, "Print button exists in Panel Menu");
if (isOSX) {
let panelHiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHiddenPromise;
info("Menu panel was closed");
}
else {
printButton.click();
yield waitForCondition(() => gInPrintPreviewMode);
ok(gInPrintPreviewMode, "Entered print preview mode");
// close print preview
if (gInPrintPreviewMode) {
PrintUtils.exitPrintPreview();
yield waitForCondition(() => !window.gInPrintPreviewMode);
info("Exited print preview")
}
}
});
});

View file

@ -1,20 +0,0 @@
/* 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";
add_task(function*() {
info("Check save page button existence");
yield PanelUI.show();
info("Menu panel was opened");
let savePageButton = document.getElementById("save-page-button");
ok(savePageButton, "Save Page button exists in Panel Menu");
let panelHiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHiddenPromise;
info("Menu panel was closed");
});

View file

@ -1,37 +0,0 @@
/* 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";
var initialPageZoom = ZoomManager.zoom;
add_task(function*() {
info("Check zoom in button existence and functionality");
is(initialPageZoom, 1, "Initial zoom factor should be 1");
yield PanelUI.show();
info("Menu panel was opened");
let zoomInButton = document.getElementById("zoom-in-button");
ok(zoomInButton, "Zoom in button exists in Panel Menu");
zoomInButton.click();
let pageZoomLevel = parseInt(ZoomManager.zoom * 100);
let zoomResetButton = document.getElementById("zoom-reset-button");
let expectedZoomLevel = parseInt(zoomResetButton.getAttribute("label"), 10);
ok(pageZoomLevel > 100 && pageZoomLevel == expectedZoomLevel, "Page zoomed in correctly");
// close the Panel
let panelHiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHiddenPromise;
info("Menu panel was closed");
});
add_task(function* asyncCleanup() {
// reset zoom level
ZoomManager.zoom = initialPageZoom;
info("Zoom level was restored");
});

View file

@ -1,38 +0,0 @@
/* 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";
var initialPageZoom = ZoomManager.zoom;
add_task(function*() {
info("Check zoom out button existence and functionality");
is(initialPageZoom, 1, "Initial zoom factor should be 1");
yield PanelUI.show();
info("Menu panel was opened");
let zoomOutButton = document.getElementById("zoom-out-button");
ok(zoomOutButton, "Zoom out button exists in Panel Menu");
zoomOutButton.click();
let pageZoomLevel = Math.round(ZoomManager.zoom * 100);
let zoomResetButton = document.getElementById("zoom-reset-button");
let expectedZoomLevel = parseInt(zoomResetButton.getAttribute("label"), 10);
ok(pageZoomLevel < 100 && pageZoomLevel == expectedZoomLevel, "Page zoomed out correctly");
// close the panel
let panelHiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHiddenPromise;
info("Menu panel was closed");
});
add_task(function* asyncCleanup() {
// reset zoom level
ZoomManager.zoom = initialPageZoom;
info("Zoom level was restored");
});

View file

@ -1,40 +0,0 @@
/* 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";
var initialPageZoom = ZoomManager.zoom;
add_task(function*() {
info("Check zoom reset button existence and functionality");
is(initialPageZoom, 1, "Page zoom reset correctly");
ZoomManager.zoom = 0.5;
yield PanelUI.show();
info("Menu panel was opened");
let zoomResetButton = document.getElementById("zoom-reset-button");
ok(zoomResetButton, "Zoom reset button exists in Panel Menu");
zoomResetButton.click();
yield new Promise(SimpleTest.executeSoon);
let pageZoomLevel = Math.floor(ZoomManager.zoom * 100);
let expectedZoomLevel = 100;
let buttonZoomLevel = parseInt(zoomResetButton.getAttribute("label"), 10);
is(pageZoomLevel, expectedZoomLevel, "Page zoom reset correctly");
is(pageZoomLevel, buttonZoomLevel, "Button displays the correct zoom level");
// close the panel
let panelHiddenPromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHiddenPromise;
info("Menu panel was closed");
});
add_task(function* asyncCleanup() {
// reset zoom level
ZoomManager.zoom = initialPageZoom;
info("Zoom level was restored");
});

View file

@ -1,68 +0,0 @@
/* 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";
var kWidgetId = "test-removable-widget-default";
const kNavBar = CustomizableUI.AREA_NAVBAR;
var widgetCounter = 0;
registerCleanupFunction(removeCustomToolbars);
// Sanity checks
add_task(function() {
let brokenSpec = {id: kWidgetId + (widgetCounter++), removable: false};
SimpleTest.doesThrow(() => CustomizableUI.createWidget(brokenSpec),
"Creating non-removable widget without defaultArea should throw.");
// Widget without removable set should be removable:
let wrapper = CustomizableUI.createWidget({id: kWidgetId + (widgetCounter++)});
ok(CustomizableUI.isWidgetRemovable(wrapper.id), "Should be removable by default.");
CustomizableUI.destroyWidget(wrapper.id);
});
// Test non-removable widget with defaultArea
add_task(function*() {
// Non-removable widget with defaultArea should work:
let spec = {id: kWidgetId + (widgetCounter++), removable: false,
defaultArea: kNavBar};
let widgetWrapper;
try {
widgetWrapper = CustomizableUI.createWidget(spec);
} catch (ex) {
ok(false, "Creating a non-removable widget with a default area should not throw.");
return;
}
let placement = CustomizableUI.getPlacementOfWidget(spec.id);
ok(placement, "Widget should be placed.");
is(placement.area, kNavBar, "Widget should be in navbar");
let singleWrapper = widgetWrapper.forWindow(window);
ok(singleWrapper, "Widget should exist in window.");
ok(singleWrapper.node, "Widget node should exist in window.");
let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, window);
is(singleWrapper.node.parentNode, expectedParent, "Widget should be in navbar.");
let otherWin = yield openAndLoadWindow(true);
placement = CustomizableUI.getPlacementOfWidget(spec.id);
ok(placement, "Widget should be placed.");
is(placement && placement.area, kNavBar, "Widget should be in navbar");
singleWrapper = widgetWrapper.forWindow(otherWin);
ok(singleWrapper, "Widget should exist in other window.");
if (singleWrapper) {
ok(singleWrapper.node, "Widget node should exist in other window.");
if (singleWrapper.node) {
let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, otherWin);
is(singleWrapper.node.parentNode, expectedParent,
"Widget should be in navbar in other window.");
}
}
CustomizableUI.destroyWidget(spec.id);
yield promiseWindowClosed(otherWin);
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,32 +0,0 @@
/* 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/. */
const kWidgetId = "test-destroy-non-removable-defaultArea";
add_task(function() {
let spec = {id: kWidgetId, label: "Test non-removable defaultArea re-adding.",
removable: false, defaultArea: CustomizableUI.AREA_NAVBAR};
CustomizableUI.createWidget(spec);
let placement = CustomizableUI.getPlacementOfWidget(kWidgetId);
ok(placement, "Should have placed the widget.");
is(placement && placement.area, CustomizableUI.AREA_NAVBAR, "Widget should be in navbar");
CustomizableUI.destroyWidget(kWidgetId);
CustomizableUI.removeWidgetFromArea(kWidgetId);
CustomizableUI.createWidget(spec);
ok(placement, "Should have placed the widget.");
is(placement && placement.area, CustomizableUI.AREA_NAVBAR, "Widget should be in navbar");
CustomizableUI.destroyWidget(kWidgetId);
CustomizableUI.removeWidgetFromArea(kWidgetId);
const kPrefCustomizationAutoAdd = "browser.uiCustomization.autoAdd";
Services.prefs.setBoolPref(kPrefCustomizationAutoAdd, false);
CustomizableUI.createWidget(spec);
ok(placement, "Should have placed the widget.");
is(placement && placement.area, CustomizableUI.AREA_NAVBAR, "Widget should be in navbar");
CustomizableUI.destroyWidget(kWidgetId);
CustomizableUI.removeWidgetFromArea(kWidgetId);
Services.prefs.clearUserPref(kPrefCustomizationAutoAdd);
});

View file

@ -1,52 +0,0 @@
/* 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 kToolbarName = "test-unregisterArea-areaType";
const kUnregisterAreaTestWidget = "test-widget-for-unregisterArea-areaType";
const kTestWidget = "test-widget-no-area-areaType";
registerCleanupFunction(removeCustomToolbars);
function checkAreaType(widget) {
try {
is(widget.areaType, null, "areaType should be null");
} catch (ex) {
info("Fetching areaType threw: " + ex);
ok(false, "areaType getter shouldn't throw.");
}
}
// widget wrappers in unregisterArea'd areas and nowhere shouldn't throw when checking areaTypes.
add_task(function*() {
// Using the ID before it's been created will imply a XUL wrapper; we'll test
// an API-based wrapper below
let toolbarNode = createToolbarWithPlacements(kToolbarName, [kUnregisterAreaTestWidget]);
CustomizableUI.unregisterArea(kToolbarName);
toolbarNode.remove();
let w = CustomizableUI.getWidget(kUnregisterAreaTestWidget);
checkAreaType(w);
w = CustomizableUI.getWidget(kTestWidget);
checkAreaType(w);
let spec = {id: kUnregisterAreaTestWidget, type: 'button', removable: true,
label: "areaType test", tooltiptext: "areaType test"};
CustomizableUI.createWidget(spec);
toolbarNode = createToolbarWithPlacements(kToolbarName, [kUnregisterAreaTestWidget]);
CustomizableUI.unregisterArea(kToolbarName);
toolbarNode.remove();
w = CustomizableUI.getWidget(spec.id);
checkAreaType(w);
CustomizableUI.removeWidgetFromArea(kUnregisterAreaTestWidget);
checkAreaType(w);
// XXXgijs: ensure cleanup function doesn't barf:
gAddedToolbars.delete(kToolbarName);
});
add_task(function* asyncCleanup() {
yield resetCustomization();
});

View file

@ -1,31 +0,0 @@
/* 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";
// Adding a separator and then dragging it out of the navbar shouldn't throw
add_task(function*() {
try {
let navbar = document.getElementById("nav-bar");
let separatorSelector = "toolbarseparator[id^=customizableui-special-separator]";
ok(!navbar.querySelector(separatorSelector), "Shouldn't be a separator in the navbar");
CustomizableUI.addWidgetToArea('separator', 'nav-bar');
yield startCustomizing();
let separator = navbar.querySelector(separatorSelector);
ok(separator, "There should be a separator in the navbar now.");
let palette = document.getElementById("customization-palette");
simulateItemDrag(separator, palette);
ok(!palette.querySelector(separatorSelector), "No separator in the palette.");
} catch (ex) {
Cu.reportError(ex);
ok(false, "Shouldn't throw an exception moving an item to the navbar.");
} finally {
yield endCustomizing();
}
});
add_task(function* asyncCleanup() {
resetCustomization();
});

View file

@ -1,54 +0,0 @@
/* 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";
var originalWindowWidth;
// Drag to overflow chevron should open the overflow panel.
add_task(function*() {
originalWindowWidth = window.outerWidth;
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
let widgetOverflowPanel = document.getElementById("widget-overflow");
let panelShownPromise = promisePanelElementShown(window, widgetOverflowPanel);
let identityBox = document.getElementById("identity-box");
let overflowChevron = document.getElementById("nav-bar-overflow-button");
// Listen for hiding immediately so we don't miss the event because of the
// async-ness of the 'shown' yield...
let panelHiddenPromise = promisePanelElementHidden(window, widgetOverflowPanel);
var ds = Components.classes["@mozilla.org/widget/dragservice;1"].
getService(Components.interfaces.nsIDragService);
ds.startDragSession();
try {
var [result, dataTransfer] = EventUtils.synthesizeDragOver(identityBox, overflowChevron);
// Wait for showing panel before ending drag session.
yield panelShownPromise;
EventUtils.synthesizeDropAfterDragOver(result, dataTransfer, overflowChevron);
} finally {
ds.endDragSession(true);
}
info("Overflow panel is shown.");
widgetOverflowPanel.hidePopup();
yield panelHiddenPromise;
});
add_task(function*() {
window.resizeTo(originalWindowWidth, window.outerHeight);
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
});

View file

@ -1,67 +0,0 @@
/* 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";
add_task(function*() {
const kNormalLabel = "Character Encoding";
CustomizableUI.addWidgetToArea("characterencoding-button", CustomizableUI.AREA_NAVBAR);
let characterEncoding = document.getElementById("characterencoding-button");
const kOriginalLabel = characterEncoding.getAttribute("label");
characterEncoding.setAttribute("label", "\u00ad" + kNormalLabel);
CustomizableUI.addWidgetToArea("characterencoding-button", CustomizableUI.AREA_PANEL);
yield PanelUI.show();
is(characterEncoding.getAttribute("auto-hyphens"), "off",
"Hyphens should be disabled if the &shy; character is present in the label");
let multilineText = document.getAnonymousElementByAttribute(characterEncoding, "class", "toolbarbutton-multiline-text");
let multilineTextCS = getComputedStyle(multilineText);
is(multilineTextCS.MozHyphens, "manual", "-moz-hyphens should be set to manual when the &shy; character is present.")
let hiddenPanelPromise = promisePanelHidden(window);
PanelUI.toggle();
yield hiddenPanelPromise;
characterEncoding.setAttribute("label", kNormalLabel);
yield PanelUI.show();
isnot(characterEncoding.getAttribute("auto-hyphens"), "off",
"Hyphens should not be disabled if the &shy; character is not present in the label");
multilineText = document.getAnonymousElementByAttribute(characterEncoding, "class", "toolbarbutton-multiline-text");
multilineTextCS = getComputedStyle(multilineText);
is(multilineTextCS.MozHyphens, "auto", "-moz-hyphens should be set to auto by default.")
hiddenPanelPromise = promisePanelHidden(window);
PanelUI.toggle();
yield hiddenPanelPromise;
characterEncoding.setAttribute("label", "\u00ad" + kNormalLabel);
CustomizableUI.removeWidgetFromArea("characterencoding-button");
yield startCustomizing();
isnot(characterEncoding.getAttribute("auto-hyphens"), "off",
"Hyphens should not be disabled when the widget is in the palette");
gCustomizeMode.addToPanel(characterEncoding);
is(characterEncoding.getAttribute("auto-hyphens"), "off",
"Hyphens should be disabled if the &shy; character is present in the label in customization mode");
multilineText = document.getAnonymousElementByAttribute(characterEncoding, "class", "toolbarbutton-multiline-text");
multilineTextCS = getComputedStyle(multilineText);
is(multilineTextCS.MozHyphens, "manual", "-moz-hyphens should be set to manual when the &shy; character is present in customization mode.")
yield endCustomizing();
CustomizableUI.addWidgetToArea("characterencoding-button", CustomizableUI.AREA_NAVBAR);
ok(!characterEncoding.hasAttribute("auto-hyphens"),
"Removing the widget from the panel should remove the auto-hyphens attribute");
characterEncoding.setAttribute("label", kOriginalLabel);
});
add_task(function* asyncCleanup() {
yield endCustomizing();
yield resetCustomization();
});

View file

@ -1,34 +0,0 @@
/* 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 kToolbar = "test-toolbar-963639-non-customizable-customizing-attribute";
add_task(function*() {
info("Test for Bug 963639 - CustomizeMode _onToolbarVisibilityChange sets @customizing on non-customizable toolbars");
let toolbar = document.createElement("toolbar");
toolbar.id = kToolbar;
gNavToolbox.appendChild(toolbar);
let testToolbar = document.getElementById(kToolbar)
ok(testToolbar, "Toolbar was created.");
is(gNavToolbox.getElementsByAttribute("id", kToolbar).length, 1,
"Toolbar was added to the navigator toolbox");
toolbar.setAttribute("toolbarname", "NonCustomizableToolbarCustomizingAttribute");
toolbar.setAttribute("collapsed", "true");
yield startCustomizing();
window.setToolbarVisibility(toolbar, "true");
isnot(toolbar.getAttribute("customizing"), "true",
"Toolbar doesn't have the customizing attribute");
yield endCustomizing();
gNavToolbox.removeChild(toolbar);
is(gNavToolbox.getElementsByAttribute("id", kToolbar).length, 0,
"Toolbar was removed from the navigator toolbox");
});

View file

@ -1,62 +0,0 @@
/* 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 TEST_PAGE = "http://mochi.test:8888/browser/browser/components/customizableui/test/support/test_967000_charEncoding_page.html";
add_task(function*() {
info("Check Character Encoding button functionality");
// add the Character Encoding button to the panel
CustomizableUI.addWidgetToArea("characterencoding-button",
CustomizableUI.AREA_PANEL);
// check the button's functionality
yield PanelUI.show();
let charEncodingButton = document.getElementById("characterencoding-button");
ok(charEncodingButton, "The Character Encoding button was added to the Panel Menu");
is(charEncodingButton.getAttribute("disabled"), "true",
"The Character encoding button is initially disabled");
let panelHidePromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHidePromise;
let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE, true, true);
yield PanelUI.show();
ok(!charEncodingButton.hasAttribute("disabled"), "The Character encoding button gets enabled");
let characterEncodingView = document.getElementById("PanelUI-characterEncodingView");
let subviewShownPromise = subviewShown(characterEncodingView);
charEncodingButton.click();
yield subviewShownPromise;
ok(characterEncodingView.hasAttribute("current"), "The Character encoding panel is displayed");
let pinnedEncodings = document.getElementById("PanelUI-characterEncodingView-pinned");
let charsetsList = document.getElementById("PanelUI-characterEncodingView-charsets");
ok(pinnedEncodings, "Pinned charsets are available");
ok(charsetsList, "Charsets list is available");
let checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']");
is(checkedButtons.length, 2, "There should be 2 checked items (1 charset, 1 detector).");
is(checkedButtons[0].getAttribute("label"), "Unicode", "The unicode encoding is correctly selected");
is(characterEncodingView.querySelectorAll("#PanelUI-characterEncodingView-autodetect toolbarbutton[checked='true']").length,
1,
"There should be 1 checked detector.");
panelHidePromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHidePromise;
yield BrowserTestUtils.removeTab(newTab);
});
add_task(function* asyncCleanup() {
// reset the panel to the default state
yield resetCustomization();
ok(CustomizableUI.inDefaultState, "The UI is in default state again.");
});

View file

@ -1,60 +0,0 @@
/* 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 TEST_PAGE = "http://mochi.test:8888/browser/browser/components/customizableui/test/support/feeds_test_page.html";
const TEST_FEED = "http://mochi.test:8888/browser/browser/components/customizableui/test/support/test-feed.xml"
var newTab = null;
var initialLocation = gBrowser.currentURI.spec;
add_task(function*() {
info("Check Subscribe button functionality");
// add the Subscribe button to the panel
CustomizableUI.addWidgetToArea("feed-button",
CustomizableUI.AREA_PANEL);
// check the button's functionality
yield PanelUI.show();
let feedButton = document.getElementById("feed-button");
ok(feedButton, "The Subscribe button was added to the Panel Menu");
is(feedButton.getAttribute("disabled"), "true", "The Subscribe button is initially disabled");
let panelHidePromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHidePromise;
newTab = gBrowser.selectedTab;
yield promiseTabLoadEvent(newTab, TEST_PAGE);
yield PanelUI.show();
yield waitForCondition(() => !feedButton.hasAttribute("disabled"));
ok(!feedButton.hasAttribute("disabled"), "The Subscribe button gets enabled");
feedButton.click();
yield promiseTabLoadEvent(newTab, TEST_FEED);
is(gBrowser.currentURI.spec, TEST_FEED, "Subscribe page opened");
ok(!isPanelUIOpen(), "Panel is closed");
if (isPanelUIOpen()) {
panelHidePromise = promisePanelHidden(window);
PanelUI.hide();
yield panelHidePromise;
}
});
add_task(function* asyncCleanup() {
// reset the panel UI to the default state
yield resetCustomization();
ok(CustomizableUI.inDefaultState, "The UI is in default state again.");
// restore the initial location
gBrowser.addTab(initialLocation);
gBrowser.removeTab(newTab);
});

Some files were not shown because too many files have changed in this diff Show more