Backed out 2 changesets (bug 1196105, bug 1196104) for frequent OSX browser_UITour_heartbeat.js failures.

Backed out changeset e2ac20d24cb2 (bug 1196105)
Backed out changeset 52b8ae99625a (bug 1196104)
This commit is contained in:
Ryan VanderMeulen 2015-08-26 14:02:52 -04:00
parent 2c9e1e684f
commit 91fa73bab5
3 changed files with 26 additions and 164 deletions

View File

@ -12,7 +12,6 @@ Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource:///modules/RecentWindow.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/TelemetryController.jsm");
@ -400,6 +399,7 @@ this.UITour = {
window = Services.wm.getMostRecentWindow("navigator:browser");
}
let tab = window.gBrowser.getTabForBrowser(browser);
let messageManager = browser.messageManager;
log.debug("onPageEvent:", aEvent.detail, aMessage);
@ -479,17 +479,8 @@ this.UITour = {
return false;
}
let heartbeatWindow = window;
if (data.privateWindowsOnly && !PrivateBrowsingUtils.isWindowPrivate(heartbeatWindow)) {
heartbeatWindow = RecentWindow.getMostRecentBrowserWindow({ private: true });
if (!heartbeatWindow) {
log.debug("showHeartbeat: No private window found");
return false;
}
}
// Finally show the Heartbeat UI.
this.showHeartbeat(heartbeatWindow, data);
this.showHeartbeat(window, data);
break;
}
@ -1145,18 +1136,8 @@ this.UITour = {
* @param {String} [aOptions.learnMoreURL=null]
* The learn more URL to open when clicking on the learn more link. No learn more
* will be shown if this is an invalid URL.
* @param {String} [aOptions.privateWindowsOnly=false]
* Whether the heartbeat UI should only be targeted at a private window (if one exists).
* No notifications should be fired when this is true.
*/
showHeartbeat(aChromeWindow, aOptions) {
let maybeNotifyHeartbeat = (...aParams) => {
if (aOptions.privateWindowsOnly) {
return;
}
this.notify(...aParams);
};
let nb = aChromeWindow.document.getElementById("high-priority-global-notificationbox");
let buttons = null;
@ -1165,7 +1146,7 @@ this.UITour = {
label: aOptions.engagementButtonLabel,
callback: () => {
// Let the consumer know user engaged.
maybeNotifyHeartbeat("Heartbeat:Engaged", { flowId: aOptions.flowId, timestamp: Date.now() });
this.notify("Heartbeat:Engaged", { flowId: aOptions.flowId, timestamp: Date.now() });
userEngaged(new Map([
["type", "button"],
@ -1179,7 +1160,7 @@ this.UITour = {
"chrome://browser/skin/heartbeat-icon.svg", nb.PRIORITY_INFO_HIGH, buttons, function() {
// Let the consumer know the notification bar was closed. This also happens
// after voting.
maybeNotifyHeartbeat("Heartbeat:NotificationClosed", { flowId: aOptions.flowId, timestamp: Date.now() });
this.notify("Heartbeat:NotificationClosed", { flowId: aOptions.flowId, timestamp: Date.now() });
}.bind(this));
// Get the elements we need to style.
@ -1251,11 +1232,7 @@ this.UITour = {
let rating = Number(evt.target.getAttribute("data-score"), 10);
// Let the consumer know user voted.
maybeNotifyHeartbeat("Heartbeat:Voted", {
flowId: aOptions.flowId,
score: rating,
timestamp: Date.now(),
});
this.notify("Heartbeat:Voted", { flowId: aOptions.flowId, score: rating, timestamp: Date.now() });
// Append the score data to the engagement URL.
userEngaged(new Map([
@ -1294,7 +1271,7 @@ this.UITour = {
learnMore.className = "text-link";
learnMore.href = learnMoreURL.toString();
learnMore.setAttribute("value", aOptions.learnMoreLabel);
learnMore.addEventListener("click", () => maybeNotifyHeartbeat("Heartbeat:LearnMore",
learnMore.addEventListener("click", () => this.notify("Heartbeat:LearnMore",
{ flowId: aOptions.flowId, timestamp: Date.now() }));
frag.appendChild(learnMore);
}
@ -1306,10 +1283,7 @@ this.UITour = {
messageText.classList.add("heartbeat");
// Let the consumer know the notification was shown.
maybeNotifyHeartbeat("Heartbeat:NotificationOffered", {
flowId: aOptions.flowId,
timestamp: Date.now(),
});
this.notify("Heartbeat:NotificationOffered", { flowId: aOptions.flowId, timestamp: Date.now() });
},
/**

View File

@ -6,13 +6,13 @@
let gTestTab;
let gContentAPI;
let gContentWindow;
let notificationBox = document.getElementById("high-priority-global-notificationbox");
function test() {
UITourTest();
}
function getHeartbeatNotification(aId, aChromeWindow = window) {
let notificationBox = aChromeWindow.document.getElementById("high-priority-global-notificationbox");
function getHeartbeatNotification(aId) {
// UITour.jsm prefixes the notification box ID with "heartbeat-" to prevent collisions.
return notificationBox.getNotificationWithValue("heartbeat-" + aId);
}
@ -57,12 +57,10 @@ function clickLearnMore(aId) {
*
* @param aId
* The id of the notification box to remove.
* @param [aChromeWindow=window]
* The chrome window the notification box is in.
*/
function cleanUpNotification(aId, aChromeWindow = window) {
let notification = getHeartbeatNotification(aId, aChromeWindow);
notification.close();
function cleanUpNotification(aId) {
let notification = notificationBox.getNotificationWithValue("heartbeat-" + aId);
notificationBox.removeNotification(notification);
}
let tests = [
@ -344,114 +342,21 @@ let tests = [
"What is this?", dummyURL);
},
taskify(function test_invalidEngagementButtonLabel(done) {
function test_invalidEngagementButtonLabel(done) {
let engagementURL = "http://example.com";
let flowId = "ui-engagewithfirefox-" + Math.random();
let eventPromise = promisePageEvent();
gContentAPI.showHeartbeat("Do you want to engage with us?", "Thank you!", flowId, engagementURL,
null, null, {
engagementButtonLabel: 42,
});
yield eventPromise;
ok(!isTourBrowser(gBrowser.selectedBrowser),
"Invalid engagementButtonLabel should prevent init");
}),
taskify(function test_privateWindowsOnly_noneOpen(done) {
let engagementURL = "http://example.com";
let flowId = "ui-engagewithfirefox-" + Math.random();
let eventPromise = promisePageEvent();
gContentAPI.showHeartbeat("Do you want to engage with us?", "Thank you!", flowId, engagementURL,
null, null, {
engagementButtonLabel: "Yes!",
privateWindowsOnly: true,
});
yield eventPromise;
ok(!isTourBrowser(gBrowser.selectedBrowser),
"If there are no private windows opened, tour init should be prevented");
}),
taskify(function test_privateWindowsOnly_notMostRecent(done) {
let engagementURL = "http://example.com";
let flowId = "ui-engagewithfirefox-" + Math.random();
let privateWin = yield BrowserTestUtils.openNewBrowserWindow({ private: true });
let mostRecentWin = yield BrowserTestUtils.openNewBrowserWindow();
let eventPromise = promisePageEvent();
gContentAPI.showHeartbeat("Do you want to engage with us?", "Thank you!", flowId, engagementURL,
null, null, {
engagementButtonLabel: "Yes!",
privateWindowsOnly: true,
});
yield eventPromise;
is(getHeartbeatNotification(flowId, window), null,
"Heartbeat shouldn't appear in the default window");
is(!!getHeartbeatNotification(flowId, privateWin), true,
"Heartbeat should appear in the most recent private window");
is(getHeartbeatNotification(flowId, mostRecentWin), null,
"Heartbeat shouldn't appear in the most recent non-private window");
yield BrowserTestUtils.closeWindow(mostRecentWin);
yield BrowserTestUtils.closeWindow(privateWin);
}),
taskify(function test_privateWindowsOnly() {
let engagementURL = "http://example.com";
let learnMoreURL = "http://example.org/learnmore/";
let flowId = "ui-engagewithfirefox-" + Math.random();
let privateWin = yield BrowserTestUtils.openNewBrowserWindow({ private: true });
yield new Promise((resolve) => {
gContentAPI.observe(function(aEventName, aData) {
ok(false, "No heartbeat notifications should arrive for privateWindowsOnly");
}, resolve);
Services.mm.addMessageListener("UITour:onPageEvent", function onPageEvent(aMessage) {
Services.mm.removeMessageListener("UITour:onPageEvent", onPageEvent);
SimpleTest.executeSoon(() => {
ok(!(UITour.tourBrowsersByWindow.get(window) &&
UITour.tourBrowsersByWindow.get(window).has(gBrowser.selectedBrowser)),
"Invalid engagementButtonLabel should prevent init");
});
done();
});
gContentAPI.showHeartbeat("Do you want to engage with us?", "Thank you!", flowId, engagementURL,
"Learn More", learnMoreURL, {
engagementButtonLabel: "Yes!",
privateWindowsOnly: true,
});
yield promisePageEvent();
ok(isTourBrowser(gBrowser.selectedBrowser), "UITour should have been init for the browser");
let notification = getHeartbeatNotification(flowId, privateWin);
is(notification.querySelectorAll(".star-x").length, 0, "No stars should be present");
info("Test the learn more link.");
let learnMoreLink = notification.querySelector(".text-link");
is(learnMoreLink.value, "Learn More", "Check learn more label");
let learnMoreTabPromise = BrowserTestUtils.waitForNewTab(privateWin.gBrowser, null);
learnMoreLink.click();
let learnMoreTab = yield learnMoreTabPromise;
is(learnMoreTab.linkedBrowser.currentURI.host, "example.org", "Check learn more site opened");
ok(PrivateBrowsingUtils.isBrowserPrivate(learnMoreTab.linkedBrowser), "Ensure the learn more tab is private");
yield BrowserTestUtils.removeTab(learnMoreTab);
info("Test the engagement button's new tab.");
let engagementButton = notification.querySelector(".notification-button");
is(engagementButton.label, "Yes!", "Check engagement button text");
let engagementTabPromise = BrowserTestUtils.waitForNewTab(privateWin.gBrowser, null);
engagementButton.doCommand();
let engagementTab = yield engagementTabPromise;
is(engagementTab.linkedBrowser.currentURI.host, "example.com", "Check enagement site opened");
ok(PrivateBrowsingUtils.isBrowserPrivate(engagementTab.linkedBrowser), "Ensure the engagement tab is private");
yield BrowserTestUtils.removeTab(engagementTab);
yield BrowserTestUtils.closeWindow(privateWin);
}),
gContentAPI.showHeartbeat("Do you want to engage with us?", "Thank you!", flowId, engagementURL, null, null, {
engagementButtonLabel: 42,
});
},
];

View File

@ -41,13 +41,11 @@ function waitForCondition(condition, nextTest, errorMsg) {
*/
function taskify(fun) {
return (done) => {
// Output the inner function name otherwise no name will be output.
info("\t" + fun.name);
return Task.spawn(fun).then(done, (reason) => {
ok(false, reason);
done();
});
};
}
}
function is_hidden(element) {
@ -191,21 +189,6 @@ function is_element_hidden(element, msg) {
ok(is_hidden(element), msg);
}
function isTourBrowser(aBrowser) {
let chromeWindow = aBrowser.ownerDocument.defaultView;
return UITour.tourBrowsersByWindow.has(chromeWindow) &&
UITour.tourBrowsersByWindow.get(chromeWindow).has(aBrowser);
}
function promisePageEvent() {
return new Promise((resolve) => {
Services.mm.addMessageListener("UITour:onPageEvent", function onPageEvent(aMessage) {
Services.mm.removeMessageListener("UITour:onPageEvent", onPageEvent);
SimpleTest.executeSoon(resolve);
});
});
}
function loadUITourTestPage(callback, host = "https://example.org/") {
if (gTestTab)
gBrowser.removeTab(gTestTab);