2010-04-09 10:45:25 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is browser popup notification test code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Gavin Sharp <gavin@gavinsharp.com>
|
2010-09-13 03:44:27 -07:00
|
|
|
* Sylvain Pasche <sylvain.pasche@gmail.com>
|
2011-01-03 15:02:23 -08:00
|
|
|
* Drew Willcoxon <adw@mozilla.com>
|
2011-01-18 14:57:40 -08:00
|
|
|
* Margaret Leibovic <margaret.leibovic@gmail.com>
|
2010-04-09 10:45:25 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
ok(PopupNotifications, "PopupNotifications object exists");
|
|
|
|
ok(PopupNotifications.panel, "PopupNotifications panel exists");
|
|
|
|
|
|
|
|
registerCleanupFunction(cleanUp);
|
|
|
|
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanUp() {
|
|
|
|
for (var topic in gActiveObservers)
|
|
|
|
Services.obs.removeObserver(gActiveObservers[topic], topic);
|
|
|
|
for (var eventName in gActiveListeners)
|
|
|
|
PopupNotifications.panel.removeEventListener(eventName, gActiveListeners[eventName], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
var gActiveListeners = {};
|
|
|
|
var gActiveObservers = {};
|
|
|
|
|
|
|
|
function runNextTest() {
|
|
|
|
let nextTest = tests[gTestIndex];
|
|
|
|
|
|
|
|
function goNext() {
|
|
|
|
if (++gTestIndex == tests.length)
|
|
|
|
executeSoon(finish);
|
|
|
|
else
|
|
|
|
executeSoon(runNextTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addObserver(topic) {
|
|
|
|
function observer() {
|
|
|
|
Services.obs.removeObserver(observer, "PopupNotifications-" + topic);
|
|
|
|
delete gActiveObservers["PopupNotifications-" + topic];
|
|
|
|
|
|
|
|
info("[Test #" + gTestIndex + "] observer for " + topic + " called");
|
|
|
|
nextTest[topic]();
|
|
|
|
goNext();
|
|
|
|
}
|
|
|
|
Services.obs.addObserver(observer, "PopupNotifications-" + topic, false);
|
|
|
|
gActiveObservers["PopupNotifications-" + topic] = observer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextTest.backgroundShow) {
|
|
|
|
addObserver("backgroundShow");
|
|
|
|
} else if (nextTest.updateNotShowing) {
|
|
|
|
addObserver("updateNotShowing");
|
|
|
|
} else {
|
|
|
|
doOnPopupEvent("popupshowing", function () {
|
|
|
|
info("[Test #" + gTestIndex + "] popup showing");
|
|
|
|
});
|
|
|
|
doOnPopupEvent("popupshown", function () {
|
|
|
|
info("[Test #" + gTestIndex + "] popup shown");
|
|
|
|
nextTest.onShown(this);
|
|
|
|
});
|
2011-01-03 15:02:23 -08:00
|
|
|
|
|
|
|
// We allow multiple onHidden functions to be defined in an array. They're
|
|
|
|
// called in the order they appear.
|
|
|
|
let onHiddenArray = nextTest.onHidden instanceof Array ?
|
|
|
|
nextTest.onHidden :
|
|
|
|
[nextTest.onHidden];
|
2010-04-09 10:45:25 -07:00
|
|
|
doOnPopupEvent("popuphidden", function () {
|
2011-01-03 15:02:23 -08:00
|
|
|
let onHidden = onHiddenArray.shift();
|
|
|
|
info("[Test #" + gTestIndex + "] popup hidden (" + onHiddenArray.length + " hides remaining)");
|
|
|
|
onHidden.call(nextTest, this);
|
|
|
|
if (!onHiddenArray.length)
|
|
|
|
goNext();
|
|
|
|
}, onHiddenArray.length);
|
2010-04-09 10:45:25 -07:00
|
|
|
info("[Test #" + gTestIndex + "] added listeners; panel state: " + PopupNotifications.isPanelOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
info("[Test #" + gTestIndex + "] running test");
|
|
|
|
nextTest.run();
|
|
|
|
}
|
|
|
|
|
2011-01-03 15:02:23 -08:00
|
|
|
function doOnPopupEvent(eventName, callback, numExpected) {
|
2010-04-09 10:45:25 -07:00
|
|
|
gActiveListeners[eventName] = function (event) {
|
|
|
|
if (event.target != PopupNotifications.panel)
|
|
|
|
return;
|
2011-01-03 15:02:23 -08:00
|
|
|
if (typeof(numExpected) === "number")
|
|
|
|
numExpected--;
|
|
|
|
if (!numExpected) {
|
|
|
|
PopupNotifications.panel.removeEventListener(eventName, gActiveListeners[eventName], false);
|
|
|
|
delete gActiveListeners[eventName];
|
|
|
|
}
|
2010-04-09 10:45:25 -07:00
|
|
|
|
|
|
|
callback.call(PopupNotifications.panel);
|
|
|
|
}
|
|
|
|
PopupNotifications.panel.addEventListener(eventName, gActiveListeners[eventName], false);
|
|
|
|
}
|
|
|
|
|
|
|
|
var gTestIndex = 0;
|
|
|
|
var gNewTab;
|
|
|
|
|
|
|
|
function basicNotification() {
|
|
|
|
var self = this;
|
|
|
|
this.browser = gBrowser.selectedBrowser;
|
2010-12-14 17:50:44 -08:00
|
|
|
this.id = "test-notification-" + gTestIndex;
|
2010-04-09 10:45:25 -07:00
|
|
|
this.message = "This is popup notification " + this.id + " from test " + gTestIndex;
|
|
|
|
this.anchorID = null;
|
|
|
|
this.mainAction = {
|
|
|
|
label: "Main Action",
|
|
|
|
accessKey: "M",
|
|
|
|
callback: function () {
|
|
|
|
self.mainActionClicked = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.secondaryActions = [
|
|
|
|
{
|
|
|
|
label: "Secondary Action",
|
|
|
|
accessKey: "S",
|
|
|
|
callback: function () {
|
|
|
|
self.secondaryActionClicked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2010-09-13 03:44:27 -07:00
|
|
|
this.options = {
|
2010-09-16 16:10:04 -07:00
|
|
|
eventCallback: function (eventName) {
|
|
|
|
switch (eventName) {
|
|
|
|
case "dismissed":
|
|
|
|
self.dismissalCallbackTriggered = true;
|
|
|
|
break;
|
|
|
|
case "shown":
|
|
|
|
self.shownCallbackTriggered = true;
|
|
|
|
break;
|
|
|
|
case "removed":
|
|
|
|
self.removedCallbackTriggered = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-09-13 03:44:27 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this.addOptions = function(options) {
|
|
|
|
for (let [name, value] in Iterator(options))
|
|
|
|
self.options[name] = value;
|
|
|
|
}
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var wrongBrowserNotificationObject = new basicNotification();
|
|
|
|
var wrongBrowserNotification;
|
|
|
|
|
|
|
|
var tests = [
|
|
|
|
{ // Test #0
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
triggerMainCommand(popup);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.notifyObj.mainActionClicked, "mainAction was clicked");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ // Test #1
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
triggerSecondaryCommand(popup, 0);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.notifyObj.secondaryActionClicked, "secondaryAction was clicked");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ // Test #2
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
this.notification = showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
2010-04-09 10:45:25 -07:00
|
|
|
this.notification.remove();
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// test opening a notification for a background browser
|
|
|
|
{ // Test #3
|
|
|
|
run: function () {
|
|
|
|
gNewTab = gBrowser.addTab("about:blank");
|
|
|
|
isnot(gBrowser.selectedTab, gNewTab, "new tab isn't selected");
|
|
|
|
wrongBrowserNotificationObject.browser = gBrowser.getBrowserForTab(gNewTab);
|
|
|
|
wrongBrowserNotification = showNotification(wrongBrowserNotificationObject);
|
|
|
|
},
|
|
|
|
backgroundShow: function () {
|
|
|
|
is(PopupNotifications.isPanelOpen, false, "panel isn't open");
|
|
|
|
ok(!wrongBrowserNotificationObject.mainActionClicked, "main action wasn't clicked");
|
|
|
|
ok(!wrongBrowserNotificationObject.secondaryActionClicked, "secondary action wasn't clicked");
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal callback wasn't called");
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// now select that browser and test to see that the notification appeared
|
|
|
|
{ // Test #4
|
|
|
|
run: function () {
|
|
|
|
this.oldSelectedTab = gBrowser.selectedTab;
|
|
|
|
gBrowser.selectedTab = gNewTab;
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, wrongBrowserNotificationObject);
|
|
|
|
is(PopupNotifications.isPanelOpen, true, "isPanelOpen getter doesn't lie");
|
|
|
|
|
|
|
|
// switch back to the old browser
|
|
|
|
gBrowser.selectedTab = this.oldSelectedTab;
|
|
|
|
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
// actually remove the notification to prevent it from reappearing
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal callback wasn't called");
|
2010-04-09 10:45:25 -07:00
|
|
|
wrongBrowserNotification.remove();
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal callback wasn't called after remove()");
|
|
|
|
ok(wrongBrowserNotificationObject.removedCallbackTriggered, "removed callback triggered");
|
2010-04-09 10:45:25 -07:00
|
|
|
wrongBrowserNotification = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// test that the removed notification isn't shown on browser re-select
|
|
|
|
{ // Test #5
|
|
|
|
run: function () {
|
|
|
|
gBrowser.selectedTab = gNewTab;
|
|
|
|
},
|
|
|
|
updateNotShowing: function () {
|
|
|
|
is(PopupNotifications.isPanelOpen, false, "panel isn't open");
|
|
|
|
gBrowser.removeTab(gNewTab);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test that two notifications with the same ID result in a single displayed
|
|
|
|
// notification.
|
|
|
|
{ // Test #6
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
// Show the same notification twice
|
|
|
|
this.notification1 = showNotification(this.notifyObj);
|
|
|
|
this.notification2 = showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
2010-12-14 17:50:44 -08:00
|
|
|
this.notification2.remove();
|
2010-04-09 10:45:25 -07:00
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test that two notifications with different IDs are displayed
|
|
|
|
{ // Test #7
|
|
|
|
run: function () {
|
|
|
|
this.testNotif1 = new basicNotification();
|
|
|
|
this.testNotif1.message += " 1";
|
|
|
|
showNotification(this.testNotif1);
|
|
|
|
this.testNotif2 = new basicNotification();
|
|
|
|
this.testNotif2.message += " 2";
|
2010-12-14 17:50:44 -08:00
|
|
|
this.testNotif2.id += "-2";
|
2010-04-09 10:45:25 -07:00
|
|
|
showNotification(this.testNotif2);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
is(popup.childNodes.length, 2, "two notifications are shown");
|
|
|
|
// Trigger the main command for the first notification, and the secondary
|
|
|
|
// for the second. Need to do mainCommand first since the secondaryCommand
|
|
|
|
// triggering is async.
|
|
|
|
triggerMainCommand(popup);
|
|
|
|
is(popup.childNodes.length, 1, "only one notification left");
|
|
|
|
triggerSecondaryCommand(popup, 0);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.testNotif1.mainActionClicked, "main action #1 was clicked");
|
|
|
|
ok(!this.testNotif1.secondaryActionClicked, "secondary action #1 wasn't clicked");
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(!this.testNotif1.dismissalCallbackTriggered, "dismissal callback #1 wasn't called");
|
2010-04-09 10:45:25 -07:00
|
|
|
|
|
|
|
ok(!this.testNotif2.mainActionClicked, "main action #2 wasn't clicked");
|
|
|
|
ok(this.testNotif2.secondaryActionClicked, "secondary action #2 was clicked");
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(!this.testNotif2.dismissalCallbackTriggered, "dismissal callback #2 wasn't called");
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test notification without mainAction
|
|
|
|
{ // Test #8
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
this.notifyObj.mainAction = null;
|
2010-12-14 17:50:44 -08:00
|
|
|
this.notification = showNotification(this.notifyObj);
|
2010-04-09 10:45:25 -07:00
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
2010-12-14 17:50:44 -08:00
|
|
|
this.notification.remove();
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test two notifications with different anchors
|
|
|
|
{ // Test #9
|
|
|
|
run: function () {
|
2010-06-23 21:54:44 -07:00
|
|
|
this.notifyObj = new basicNotification();
|
2010-04-09 10:45:25 -07:00
|
|
|
this.firstNotification = showNotification(this.notifyObj);
|
|
|
|
this.notifyObj2 = new basicNotification();
|
|
|
|
this.notifyObj2.id += "-2";
|
2010-06-23 09:53:09 -07:00
|
|
|
this.notifyObj2.anchorID = "addons-notification-icon";
|
2010-04-09 10:45:25 -07:00
|
|
|
// Second showNotification() overrides the first
|
|
|
|
this.secondNotification = showNotification(this.notifyObj2);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
// This also checks that only one element is shown.
|
|
|
|
checkPopup(popup, this.notifyObj2);
|
2010-06-25 09:05:45 -07:00
|
|
|
is(document.getElementById("geo-notification-icon").boxObject.width, 0,
|
|
|
|
"geo anchor shouldn't be visible");
|
2010-04-09 10:45:25 -07:00
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
2011-01-03 15:02:23 -08:00
|
|
|
onHidden: [
|
2010-12-14 17:50:44 -08:00
|
|
|
// The second showing triggers a popuphidden event that we should ignore.
|
|
|
|
function (popup) {},
|
2011-01-03 15:02:23 -08:00
|
|
|
function (popup) {
|
2010-12-14 17:50:44 -08:00
|
|
|
// Remove the notifications
|
2011-01-03 15:02:23 -08:00
|
|
|
this.firstNotification.remove();
|
2010-12-14 17:50:44 -08:00
|
|
|
this.secondNotification.remove();
|
2011-01-03 15:02:23 -08:00
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
2010-12-14 17:50:44 -08:00
|
|
|
ok(this.notifyObj2.removedCallbackTriggered, "removed callback triggered");
|
|
|
|
}
|
2010-09-24 14:04:04 -07:00
|
|
|
]
|
2010-04-09 10:45:25 -07:00
|
|
|
},
|
2010-06-23 21:54:44 -07:00
|
|
|
// Test optional params
|
|
|
|
{ // Test #10
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification();
|
|
|
|
this.notifyObj.secondaryActions = undefined;
|
|
|
|
this.notification = showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
2010-06-23 21:54:44 -07:00
|
|
|
this.notification.remove();
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
2010-06-23 21:54:44 -07:00
|
|
|
}
|
|
|
|
},
|
2010-08-27 13:39:34 -07:00
|
|
|
// Test that icons appear
|
2010-06-25 09:05:45 -07:00
|
|
|
{ // Test #11
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification();
|
2010-08-27 13:39:34 -07:00
|
|
|
this.notifyObj.id = "geolocation";
|
2010-06-25 09:05:45 -07:00
|
|
|
this.notifyObj.anchorID = "geo-notification-icon";
|
|
|
|
this.notification = showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
isnot(document.getElementById("geo-notification-icon").boxObject.width, 0,
|
|
|
|
"geo anchor should be visible");
|
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
2010-12-14 17:50:44 -08:00
|
|
|
let icon = document.getElementById("geo-notification-icon");
|
|
|
|
isnot(icon.boxObject.width, 0,
|
|
|
|
"geo anchor should be visible after dismissal");
|
2010-06-25 09:05:45 -07:00
|
|
|
this.notification.remove();
|
2010-12-14 17:50:44 -08:00
|
|
|
is(icon.boxObject.width, 0,
|
|
|
|
"geo anchor should not be visible after removal");
|
2010-06-25 09:05:45 -07:00
|
|
|
}
|
|
|
|
},
|
2010-07-29 15:59:55 -07:00
|
|
|
// Test that persistence allows the notification to persist across reloads
|
|
|
|
{ // Test #12
|
|
|
|
run: function () {
|
|
|
|
this.oldSelectedTab = gBrowser.selectedTab;
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("http://example.com/", function() {
|
|
|
|
self.notifyObj = new basicNotification();
|
2010-09-13 03:44:27 -07:00
|
|
|
self.notifyObj.addOptions({
|
2010-07-29 15:59:55 -07:00
|
|
|
persistence: 2
|
2010-09-13 03:44:27 -07:00
|
|
|
});
|
2010-07-29 15:59:55 -07:00
|
|
|
self.notification = showNotification(self.notifyObj);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
this.complete = false;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("http://example.org/", function() {
|
|
|
|
loadURI("http://example.com/", function() {
|
|
|
|
|
2010-09-24 14:04:04 -07:00
|
|
|
// Next load will remove the notification
|
2010-07-29 15:59:55 -07:00
|
|
|
self.complete = true;
|
|
|
|
|
|
|
|
loadURI("http://example.org/");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.complete, "Should only have hidden the notification after 3 page loads");
|
2010-09-24 14:04:04 -07:00
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removal callback triggered");
|
2010-07-29 15:59:55 -07:00
|
|
|
gBrowser.removeTab(gBrowser.selectedTab);
|
|
|
|
gBrowser.selectedTab = this.oldSelectedTab;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test that a timeout allows the notification to persist across reloads
|
|
|
|
{ // Test #13
|
|
|
|
run: function () {
|
|
|
|
this.oldSelectedTab = gBrowser.selectedTab;
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("http://example.com/", function() {
|
|
|
|
self.notifyObj = new basicNotification();
|
|
|
|
// Set a timeout of 10 minutes that should never be hit
|
2010-09-13 03:44:27 -07:00
|
|
|
self.notifyObj.addOptions({
|
2010-07-29 15:59:55 -07:00
|
|
|
timeout: Date.now() + 600000
|
2010-09-13 03:44:27 -07:00
|
|
|
});
|
2010-07-29 15:59:55 -07:00
|
|
|
self.notification = showNotification(self.notifyObj);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
this.complete = false;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("http://example.org/", function() {
|
|
|
|
loadURI("http://example.com/", function() {
|
|
|
|
|
|
|
|
// Next load will hide the notification
|
|
|
|
self.notification.options.timeout = Date.now() - 1;
|
|
|
|
self.complete = true;
|
|
|
|
|
|
|
|
loadURI("http://example.org/");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.complete, "Should only have hidden the notification after the timeout was passed");
|
|
|
|
this.notification.remove();
|
|
|
|
gBrowser.removeTab(gBrowser.selectedTab);
|
|
|
|
gBrowser.selectedTab = this.oldSelectedTab;
|
|
|
|
}
|
|
|
|
},
|
2010-10-11 20:32:59 -07:00
|
|
|
// Test that setting persistWhileVisible allows a visible notification to
|
|
|
|
// persist across location changes
|
2010-08-22 19:49:16 -07:00
|
|
|
{ // Test #14
|
2010-10-11 20:32:59 -07:00
|
|
|
run: function () {
|
|
|
|
this.oldSelectedTab = gBrowser.selectedTab;
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("http://example.com/", function() {
|
|
|
|
self.notifyObj = new basicNotification();
|
|
|
|
self.notifyObj.addOptions({
|
|
|
|
persistWhileVisible: true
|
|
|
|
});
|
|
|
|
self.notification = showNotification(self.notifyObj);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
this.complete = false;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("http://example.org/", function() {
|
|
|
|
loadURI("http://example.com/", function() {
|
|
|
|
|
|
|
|
// Notification should persist across location changes
|
|
|
|
self.complete = true;
|
|
|
|
dismissNotification(popup);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.complete, "Should only have hidden the notification after it was dismissed");
|
|
|
|
this.notification.remove();
|
|
|
|
gBrowser.removeTab(gBrowser.selectedTab);
|
|
|
|
gBrowser.selectedTab = this.oldSelectedTab;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test that nested icon nodes correctly activate popups
|
|
|
|
{ // Test #15
|
2010-08-22 19:49:16 -07:00
|
|
|
run: function() {
|
|
|
|
// Add a temporary box as the anchor with a button
|
|
|
|
this.box = document.createElement("box");
|
|
|
|
PopupNotifications.iconBox.appendChild(this.box);
|
|
|
|
|
|
|
|
let button = document.createElement("button");
|
|
|
|
button.setAttribute("label", "Please click me!");
|
|
|
|
this.box.appendChild(button);
|
|
|
|
|
|
|
|
// The notification should open up on the box
|
|
|
|
this.notifyObj = new basicNotification();
|
|
|
|
this.notifyObj.anchorID = this.box.id = "nested-box";
|
2010-09-13 03:44:27 -07:00
|
|
|
this.notifyObj.addOptions({dismissed: true});
|
2010-08-22 19:49:16 -07:00
|
|
|
this.notification = showNotification(this.notifyObj);
|
|
|
|
|
|
|
|
EventUtils.synthesizeMouse(button, 1, 1, {});
|
|
|
|
},
|
|
|
|
onShown: function(popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
|
|
|
onHidden: function(popup) {
|
|
|
|
this.notification.remove();
|
|
|
|
this.box.parentNode.removeChild(this.box);
|
|
|
|
}
|
|
|
|
},
|
2010-08-18 02:49:34 -07:00
|
|
|
// Test that popupnotifications without popups have anchor icons shown
|
2010-10-11 20:32:59 -07:00
|
|
|
{ // Test #16
|
2010-08-18 02:49:34 -07:00
|
|
|
run: function() {
|
|
|
|
let notifyObj = new basicNotification();
|
|
|
|
notifyObj.anchorID = "geo-notification-icon";
|
2010-09-13 03:44:27 -07:00
|
|
|
notifyObj.addOptions({neverShow: true});
|
2010-08-18 02:49:34 -07:00
|
|
|
showNotification(notifyObj);
|
|
|
|
},
|
|
|
|
updateNotShowing: function() {
|
|
|
|
isnot(document.getElementById("geo-notification-icon").boxObject.width, 0,
|
|
|
|
"geo anchor should be visible");
|
|
|
|
}
|
|
|
|
},
|
2010-12-16 09:53:24 -08:00
|
|
|
// Test notification "Not Now" menu item
|
|
|
|
{ // Test #17
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
this.notification = showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
triggerSecondaryCommand(popup, 1);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
2011-01-13 16:07:44 -08:00
|
|
|
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
|
|
|
this.notification.remove();
|
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Test notification close button
|
|
|
|
{ // Test #18
|
|
|
|
run: function () {
|
|
|
|
this.notifyObj = new basicNotification(),
|
|
|
|
this.notification = showNotification(this.notifyObj);
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
let notification = popup.childNodes[0];
|
|
|
|
EventUtils.synthesizeMouseAtCenter(notification.closebutton, {});
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
2010-12-16 09:53:24 -08:00
|
|
|
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
|
|
|
this.notification.remove();
|
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
|
|
|
}
|
|
|
|
},
|
2011-01-18 14:57:40 -08:00
|
|
|
// Test notification when chrome is hidden
|
|
|
|
{ // Test #18
|
|
|
|
run: function () {
|
|
|
|
this.oldSelectedTab = gBrowser.selectedTab;
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
loadURI("about:addons", function() {
|
|
|
|
self.notifyObj = new basicNotification();
|
|
|
|
self.notification = showNotification(self.notifyObj);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onShown: function (popup) {
|
|
|
|
checkPopup(popup, this.notifyObj);
|
|
|
|
is(popup.anchorNode.className, "tabbrowser-tab", "notification anchored to tab");
|
|
|
|
dismissNotification(popup);
|
|
|
|
},
|
|
|
|
onHidden: function (popup) {
|
|
|
|
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
|
|
|
this.notification.remove();
|
|
|
|
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
|
|
|
|
|
|
|
gBrowser.removeTab(gBrowser.selectedTab);
|
|
|
|
gBrowser.selectedTab = this.oldSelectedTab;
|
|
|
|
}
|
|
|
|
},
|
2010-04-09 10:45:25 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
function showNotification(notifyObj) {
|
|
|
|
return PopupNotifications.show(notifyObj.browser,
|
|
|
|
notifyObj.id,
|
|
|
|
notifyObj.message,
|
|
|
|
notifyObj.anchorID,
|
|
|
|
notifyObj.mainAction,
|
2010-07-29 15:59:55 -07:00
|
|
|
notifyObj.secondaryActions,
|
|
|
|
notifyObj.options);
|
2010-04-09 10:45:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkPopup(popup, notificationObj) {
|
|
|
|
info("[Test #" + gTestIndex + "] checking popup");
|
|
|
|
|
2010-09-16 16:10:04 -07:00
|
|
|
ok(notificationObj.shownCallbackTriggered, "shown callback was triggered");
|
|
|
|
|
|
|
|
let notifications = popup.childNodes;
|
2010-04-09 10:45:25 -07:00
|
|
|
is(notifications.length, 1, "only one notification displayed");
|
|
|
|
let notification = notifications[0];
|
2010-08-27 13:39:34 -07:00
|
|
|
let icon = document.getAnonymousElementByAttribute(notification, "class", "popup-notification-icon");
|
2011-01-18 14:57:40 -08:00
|
|
|
if (notificationObj.id == "geolocation") {
|
2010-08-27 13:39:34 -07:00
|
|
|
isnot(icon.boxObject.width, 0, "icon for geo displayed");
|
2011-01-18 14:57:40 -08:00
|
|
|
is(popup.anchorNode.className, "notification-anchor-icon", "notification anchored to icon");
|
|
|
|
}
|
2010-04-09 10:45:25 -07:00
|
|
|
is(notification.getAttribute("label"), notificationObj.message, "message matches");
|
2010-08-27 13:39:34 -07:00
|
|
|
is(notification.id, notificationObj.id + "-notification", "id matches");
|
2010-04-09 10:45:25 -07:00
|
|
|
if (notificationObj.mainAction) {
|
|
|
|
is(notification.getAttribute("buttonlabel"), notificationObj.mainAction.label, "main action label matches");
|
|
|
|
is(notification.getAttribute("buttonaccesskey"), notificationObj.mainAction.accessKey, "main action accesskey matches");
|
|
|
|
}
|
|
|
|
let actualSecondaryActions = notification.childNodes;
|
|
|
|
let secondaryActions = notificationObj.secondaryActions || [];
|
2010-12-16 09:53:24 -08:00
|
|
|
let actualSecondaryActionsCount = actualSecondaryActions.length;
|
|
|
|
if (secondaryActions.length) {
|
|
|
|
let lastChild = actualSecondaryActions.item(actualSecondaryActions.length - 1);
|
|
|
|
is(lastChild.tagName, "menuseparator", "menuseparator exists");
|
|
|
|
actualSecondaryActionsCount--;
|
|
|
|
}
|
|
|
|
is(actualSecondaryActionsCount, secondaryActions.length, actualSecondaryActions.length + " secondary actions");
|
2010-04-09 10:45:25 -07:00
|
|
|
secondaryActions.forEach(function (a, i) {
|
|
|
|
is(actualSecondaryActions[i].getAttribute("label"), a.label, "label for secondary action " + i + " matches");
|
|
|
|
is(actualSecondaryActions[i].getAttribute("accesskey"), a.accessKey, "accessKey for secondary action " + i + " matches");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerMainCommand(popup) {
|
|
|
|
info("[Test #" + gTestIndex + "] triggering main command");
|
|
|
|
let notifications = popup.childNodes;
|
|
|
|
ok(notifications.length > 0, "at least one notification displayed");
|
|
|
|
let notification = notifications[0];
|
|
|
|
|
|
|
|
// 20, 10 so that the inner button is hit
|
|
|
|
EventUtils.synthesizeMouse(notification.button, 20, 10, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerSecondaryCommand(popup, index) {
|
|
|
|
info("[Test #" + gTestIndex + "] triggering secondary command");
|
|
|
|
let notifications = popup.childNodes;
|
|
|
|
ok(notifications.length > 0, "at least one notification displayed");
|
|
|
|
let notification = notifications[0];
|
|
|
|
|
|
|
|
notification.button.focus();
|
|
|
|
|
|
|
|
popup.addEventListener("popupshown", function () {
|
|
|
|
popup.removeEventListener("popupshown", arguments.callee, false);
|
|
|
|
|
|
|
|
// Press down until the desired command is selected
|
|
|
|
for (let i = 0; i <= index; i++)
|
|
|
|
EventUtils.synthesizeKey("VK_DOWN", {});
|
|
|
|
|
|
|
|
// Activate
|
|
|
|
EventUtils.synthesizeKey("VK_ENTER", {});
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
// One down event to open the popup
|
|
|
|
EventUtils.synthesizeKey("VK_DOWN", { altKey: (navigator.platform.indexOf("Mac") == -1) });
|
|
|
|
}
|
|
|
|
|
2010-07-29 15:59:55 -07:00
|
|
|
function loadURI(uri, callback) {
|
2010-06-23 09:53:09 -07:00
|
|
|
if (callback) {
|
|
|
|
gBrowser.addEventListener("load", function() {
|
|
|
|
// Ignore the about:blank load
|
|
|
|
if (gBrowser.currentURI.spec != uri)
|
|
|
|
return;
|
2010-07-29 15:59:55 -07:00
|
|
|
|
2010-06-23 09:53:09 -07:00
|
|
|
gBrowser.removeEventListener("load", arguments.callee, true);
|
2010-07-29 15:59:55 -07:00
|
|
|
|
2010-06-23 09:53:09 -07:00
|
|
|
callback();
|
|
|
|
}, true);
|
|
|
|
}
|
2010-07-29 15:59:55 -07:00
|
|
|
gBrowser.loadURI(uri);
|
|
|
|
}
|
|
|
|
|
2010-04-09 10:45:25 -07:00
|
|
|
function dismissNotification(popup) {
|
|
|
|
info("[Test #" + gTestIndex + "] dismissing notification");
|
|
|
|
executeSoon(function () {
|
|
|
|
EventUtils.synthesizeKey("VK_ESCAPE", {});
|
|
|
|
});
|
2010-06-23 09:53:09 -07:00
|
|
|
}
|