From 69dd530e1ba925ad8423dce93a8e1b1b46bb6739 Mon Sep 17 00:00:00 2001 From: gasolin Date: Thu, 22 Jun 2017 16:25:53 +0800 Subject: [PATCH] Bug 1367696 - PART II add xpcshell structure for onboarding;r=mossop,rexboy MozReview-Commit-ID: LA3LD8qx35d --HG-- extra : rebase_source : 839385a2817eb857db265d0d7516b61aed8e5d52 --- .../extensions/formautofill/test/unit/head.js | 2 +- browser/extensions/onboarding/moz.build | 2 + .../onboarding/test/unit/.eslintrc.js | 7 ++++ .../extensions/onboarding/test/unit/head.js | 39 +++++++++++++++++++ .../test/unit/test-onboarding-tour-type.js | 13 +++++++ .../onboarding/test/unit/xpcshell.ini | 5 +++ .../test/unit/head_xpc.js | 2 +- 7 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 browser/extensions/onboarding/test/unit/.eslintrc.js create mode 100644 browser/extensions/onboarding/test/unit/head.js create mode 100644 browser/extensions/onboarding/test/unit/test-onboarding-tour-type.js create mode 100644 browser/extensions/onboarding/test/unit/xpcshell.ini diff --git a/browser/extensions/formautofill/test/unit/head.js b/browser/extensions/formautofill/test/unit/head.js index 6bad37928b4f..452e2683df38 100644 --- a/browser/extensions/formautofill/test/unit/head.js +++ b/browser/extensions/formautofill/test/unit/head.js @@ -53,7 +53,7 @@ extensionDir.append(EXTENSION_ID); // If the unpacked extension doesn't exist, use the packed version. if (!extensionDir.exists()) { extensionDir = extensionDir.parent; - extensionDir.append(EXTENSION_ID + ".xpi"); + extensionDir.leafName += ".xpi"; } Components.manager.addBootstrappedManifestLocation(extensionDir); diff --git a/browser/extensions/onboarding/moz.build b/browser/extensions/onboarding/moz.build index a2fdc5f83f2d..a7df40c9e71b 100644 --- a/browser/extensions/onboarding/moz.build +++ b/browser/extensions/onboarding/moz.build @@ -19,4 +19,6 @@ FINAL_TARGET_FILES.features['onboarding@mozilla.org'] += [ BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini'] +XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini'] + JAR_MANIFESTS += ['jar.mn'] diff --git a/browser/extensions/onboarding/test/unit/.eslintrc.js b/browser/extensions/onboarding/test/unit/.eslintrc.js new file mode 100644 index 000000000000..58f8bd73ee48 --- /dev/null +++ b/browser/extensions/onboarding/test/unit/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "plugin:mozilla/xpcshell-test", + ], +}; diff --git a/browser/extensions/onboarding/test/unit/head.js b/browser/extensions/onboarding/test/unit/head.js new file mode 100644 index 000000000000..1d91bec0c062 --- /dev/null +++ b/browser/extensions/onboarding/test/unit/head.js @@ -0,0 +1,39 @@ +/** + * Provides infrastructure for automated onboarding components tests. + */ + +"use strict"; + +/* global Cc, Ci, Cu */ +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; +Cu.import("resource://gre/modules/Preferences.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +// Load our bootstrap extension manifest so we can access our chrome/resource URIs. +// Cargo culted from formautofill system add-on +const EXTENSION_ID = "onboarding@mozilla.org"; +let extensionDir = Services.dirsvc.get("GreD", Ci.nsIFile); +extensionDir.append("browser"); +extensionDir.append("features"); +extensionDir.append(EXTENSION_ID); +// If the unpacked extension doesn't exist, use the packed version. +if (!extensionDir.exists()) { + extensionDir = extensionDir.parent; + extensionDir.leafName += ".xpi"; +} +Components.manager.addBootstrappedManifestLocation(extensionDir); + +const TOURSET_VERSION = 1; +const PREF_TOUR_TYPE = "browser.onboarding.tour-type"; +const PREF_TOURSET_VERSION = "browser.onboarding.tourset-version"; +const PREF_SEEN_TOURSET_VERSION = "browser.onboarding.seen-tourset-version"; +const PREF_ONBOARDING_HIDDEN = "browser.onboarding.hidden"; + +function resetOnboardingDefaultState() { + // All the prefs should be reset to what prefs should looks like in a new user profile + Services.prefs.setBoolPref(PREF_ONBOARDING_HIDDEN, false); + Services.prefs.setIntPref(PREF_TOURSET_VERSION, TOURSET_VERSION); + Services.prefs.clearUserPref(PREF_SEEN_TOURSET_VERSION); + Services.prefs.clearUserPref(PREF_TOUR_TYPE); +} diff --git a/browser/extensions/onboarding/test/unit/test-onboarding-tour-type.js b/browser/extensions/onboarding/test/unit/test-onboarding-tour-type.js new file mode 100644 index 000000000000..a248f61654b9 --- /dev/null +++ b/browser/extensions/onboarding/test/unit/test-onboarding-tour-type.js @@ -0,0 +1,13 @@ +/* + * Test for onboarding tour type check. + */ + +"use strict"; + +add_task(async function() { + do_print("Starting testcase: New user state"); + resetOnboardingDefaultState(); + + do_check_eq(Preferences.get(PREF_TOURSET_VERSION), TOURSET_VERSION); + do_check_eq(Preferences.get(PREF_ONBOARDING_HIDDEN), false); +}); diff --git a/browser/extensions/onboarding/test/unit/xpcshell.ini b/browser/extensions/onboarding/test/unit/xpcshell.ini new file mode 100644 index 000000000000..ed484d0f200f --- /dev/null +++ b/browser/extensions/onboarding/test/unit/xpcshell.ini @@ -0,0 +1,5 @@ +[DEFAULT] +firefox-appdir = browser +head = head.js + +[test-onboarding-tour-type.js] diff --git a/browser/extensions/shield-recipe-client/test/unit/head_xpc.js b/browser/extensions/shield-recipe-client/test/unit/head_xpc.js index 6b620e44caac..55beb83b668e 100644 --- a/browser/extensions/shield-recipe-client/test/unit/head_xpc.js +++ b/browser/extensions/shield-recipe-client/test/unit/head_xpc.js @@ -16,7 +16,7 @@ extensionDir.append(EXTENSION_ID); // If the unpacked extension doesn't exist, use the packed version. if (!extensionDir.exists()) { extensionDir = extensionDir.parent; - extensionDir.append(EXTENSION_ID + ".xpi"); + extensionDir.leafName += ".xpi"; } Components.manager.addBootstrappedManifestLocation(extensionDir);