From 6cf549763ed9fadf7806cc413542ef5307260291 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Tue, 4 Aug 2015 22:55:21 -0700 Subject: [PATCH] Bug 1185579 - UITour: Make the "accountStatus" target use the FxA avatar when logged in. r=markh --HG-- extra : commitid : HoUXeCQssgu --- browser/components/uitour/UITour.jsm | 9 +++ browser/components/uitour/test/browser.ini | 2 + browser/components/uitour/test/browser_fxa.js | 68 +++++++++++++++++++ browser/components/uitour/test/head.js | 6 ++ 4 files changed, 85 insertions(+) create mode 100644 browser/components/uitour/test/browser_fxa.js diff --git a/browser/components/uitour/UITour.jsm b/browser/components/uitour/UITour.jsm index 19d804deb40c..9c143ff1a8a9 100644 --- a/browser/components/uitour/UITour.jsm +++ b/browser/components/uitour/UITour.jsm @@ -98,11 +98,20 @@ this.UITour = { targets: new Map([ ["accountStatus", { query: (aDocument) => { + // If the user is logged in, use the avatar element. + let fxAFooter = aDocument.getElementById("PanelUI-footer-fxa"); + if (fxAFooter.getAttribute("fxastatus")) { + return aDocument.getElementById("PanelUI-fxa-avatar"); + } + + // Otherwise use the sync setup icon. let statusButton = aDocument.getElementById("PanelUI-fxa-label"); return aDocument.getAnonymousElementByAttribute(statusButton, "class", "toolbarbutton-icon"); }, + // This is a fake widgetName starting with the "PanelUI-" prefix so we know + // to automatically open the appMenu when annotating this target. widgetName: "PanelUI-fxa-label", }], ["addons", {query: "#add-ons-button"}], diff --git a/browser/components/uitour/test/browser.ini b/browser/components/uitour/test/browser.ini index cb3d5fc4e27e..475bd2928e62 100644 --- a/browser/components/uitour/test/browser.ini +++ b/browser/components/uitour/test/browser.ini @@ -7,6 +7,8 @@ support-files = [browser_backgroundTab.js] skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly +[browser_fxa.js] +skip-if = e10s || debug || asan # Bug 1073247 - UITour tests not e10s friendly # updateAppMenuItem leaks [browser_no_tabs.js] [browser_openPreferences.js] skip-if = e10s # Bug 1073247 - UITour tests not e10s friendly diff --git a/browser/components/uitour/test/browser_fxa.js b/browser/components/uitour/test/browser_fxa.js new file mode 100644 index 000000000000..6659cd8a7859 --- /dev/null +++ b/browser/components/uitour/test/browser_fxa.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; + +XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts", + "resource://gre/modules/FxAccounts.jsm"); + +let gTestTab; +let gContentAPI; +let gContentWindow; + +function test() { + UITourTest(); +} + +registerCleanupFunction(function*() { + yield signOut(); + gFxAccounts.updateAppMenuItem(); +}); + +let tests = [ + taskify(function* test_highlight_accountStatus_loggedOut() { + let userData = yield fxAccounts.getSignedInUser(); + is(userData, null, "Not logged in initially"); + yield showMenuPromise("appMenu"); + yield showHighlightPromise("accountStatus"); + let highlight = document.getElementById("UITourHighlightContainer"); + is(highlight.getAttribute("targetName"), "accountStatus", "Correct highlight target"); + }), + + taskify(function* test_highlight_accountStatus_loggedIn() { + yield setSignedInUser(); + let userData = yield fxAccounts.getSignedInUser(); + isnot(userData, null, "Logged in now"); + // gFxAccounts.updateAppMenuItem(); // Causes a leak. + yield showMenuPromise("appMenu"); + yield showHighlightPromise("accountStatus"); + let highlight = document.getElementById("UITourHighlightContainer"); + todo_is(highlight.popupBoxObject.anchorNode.id, "PanelUI-fxa-avatar", "Anchored on avatar"); + is(highlight.getAttribute("targetName"), "accountStatus", "Correct highlight target"); + }), +]; + +// Helpers copied from browser_aboutAccounts.js +// watch out - these will fire observers which if you aren't careful, may +// interfere with the tests. +function setSignedInUser(data) { + if (!data) { + data = { + email: "foo@example.com", + uid: "1234@lcip.org", + assertion: "foobar", + sessionToken: "dead", + kA: "beef", + kB: "cafe", + verified: true + }; + } + return fxAccounts.setSignedInUser(data); +} + +function signOut() { + // we always want a "localOnly" signout here... + return fxAccounts.signOut(true); +} diff --git a/browser/components/uitour/test/head.js b/browser/components/uitour/test/head.js index 4ebe214beda2..81161a0343e3 100644 --- a/browser/components/uitour/test/head.js +++ b/browser/components/uitour/test/head.js @@ -139,6 +139,12 @@ function showInfoPromise(...args) { return promisePanelElementShown(window, popup); } +function showHighlightPromise(...args) { + let popup = document.getElementById("UITourHighlightContainer"); + gContentAPI.showHighlight.apply(gContentAPI, args); + return promisePanelElementShown(window, popup); +} + function showMenuPromise(name) { return new Promise(resolve => { gContentAPI.showMenu(name, () => resolve());