Fix Bug 1496428 - Turn on new simplified onboarding experience for everyone (#4465)

* Fix Bug 1496428 - Turn on new simplified onboarding experience for everyone

* Keep onboarding preff-ed off until legacy onboarding is deleted
This commit is contained in:
Ursula Sarracini 2018-10-05 10:50:46 -04:00 коммит произвёл GitHub
Родитель 115270b9ab
Коммит b44708b4f3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
26 изменённых файлов: 13 добавлений и 367 удалений

Просмотреть файл

@ -39,7 +39,6 @@ for (const type of [
"DELETE_HISTORY_URL",
"DIALOG_CANCEL",
"DIALOG_OPEN",
"DISABLE_ONBOARDING",
"DOWNLOAD_CHANGED",
"FILL_SEARCH_TERM",
"INIT",

Просмотреть файл

@ -18,7 +18,6 @@ const INITIAL_STATE = {
},
ASRouter: {
initialized: false,
allowLegacyOnboarding: null,
allowLegacySnippets: null,
},
Snippets: {initialized: false},

Просмотреть файл

@ -22,7 +22,7 @@
main {
margin: auto;
// Offset the snippets container so things at the bottom of the page are still
// visible when snippets / onboarding are visible. Adjust for other spacing.
// visible when snippets are visible. Adjust for other spacing.
padding-bottom: $snippets-container-height - $section-spacing - $base-gutter;
width: $wrapper-default-width;

Просмотреть файл

@ -1,6 +1,4 @@
export function enableASRouterContent(store, asrouterContent) {
let didHideOnboarding = false;
// Enable asrouter content
store.subscribe(() => {
const state = store.getState();
@ -11,16 +9,6 @@ export function enableASRouterContent(store, asrouterContent) {
if (!asrouterContent.initialized) {
asrouterContent.init();
}
// Until we can delete the existing onboarding tour, just hide the onboarding button when users are in
// the new simplified onboarding experiment. CSS hacks ftw
if (state.ASRouter.allowLegacyOnboarding === false && !didHideOnboarding) {
global.document.body.classList.add("hide-onboarding");
didHideOnboarding = true;
} else if (state.ASRouter.allowLegacyOnboarding === true && didHideOnboarding) {
global.document.body.classList.remove("hide-onboarding");
didHideOnboarding = false;
}
});
// Return this for testing purposes
return {asrouterContent};

Просмотреть файл

@ -62,9 +62,7 @@ export class SnippetsMap extends Map {
}
}
disableOnboarding() {
this._dispatch(ac.AlsoToMain({type: at.DISABLE_ONBOARDING}));
}
disableOnboarding() {}
showFirefoxAccounts() {
this._dispatch(ac.AlsoToMain({type: at.SHOW_FIREFOX_ACCOUNTS}));
@ -253,14 +251,6 @@ export class SnippetsProvider {
// TODO
}
_forceOnboardingVisibility(shouldBeVisible) {
const onboardingEl = document.getElementById("onboarding-notification-bar");
if (onboardingEl) {
onboardingEl.style.display = shouldBeVisible ? "" : "none";
}
}
_showRemoteSnippets() {
const snippetsEl = document.getElementById(this.elementId);
const payload = this.snippetsMap.get("snippets");
@ -352,13 +342,11 @@ export class SnippetsProvider {
window.dispatchEvent(new Event(SNIPPETS_ENABLED_EVENT));
this._forceOnboardingVisibility(true);
this.initialized = true;
}
uninit() {
window.dispatchEvent(new Event(SNIPPETS_DISABLED_EVENT));
this._forceOnboardingVisibility(false);
if (global.RPMRemoveMessageListener) {
global.RPMRemoveMessageListener("ActivityStream:MainToContent", this._onAction);
}

Просмотреть файл

@ -17,15 +17,6 @@ body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Ubuntu', 'Helvetica Neue', sans-serif;
font-size: 16px;
overflow-y: scroll;
&.hide-onboarding > #onboarding-overlay-button, // sass-lint:disable-line no-ids
&.hide-main > #onboarding-overlay-button { // sass-lint:disable-line no-ids
display: none !important; // sass-lint:disable-line no-important
}
&.hide-main > #onboarding-notification-bar { // sass-lint:disable-line no-ids
display: none;
}
}
h1,

Просмотреть файл

@ -36,7 +36,7 @@ a Promise that resolves when the blockList has been written to indexedDB.
`.showFirefoxAccounts()`: (func) A function that opens the Firefox Accounts signup page
(specifically `about:accounts?action=signup&entrypoint=snippets`)
`.disableOnboarding()`: (func) A function that disables onboarding for future new tabs (until Firefox restarts).
`.disableOnboarding()`: (func) DEPRECATED - A function that disables onboarding for future new tabs (until Firefox restarts).
You should ensure `gSnippetsMap.get("appData.onboardingFinished")` is false before calling this. Note that this
does not hide onboarding notifications on the **current** page, since that would be a disruptive user experience.
@ -90,7 +90,7 @@ to find out if a user has a Firefox account, you would check `gSnippetsMap.get("
`appData.telemetryEnabled`: (bool) Is telemetry enabled for the user?
`appData.onboardingFinished`: (bool) Has the onboarding tour been completed?
`appData.onboardingFinished`: (bool) DEPRECATED - Has the onboarding tour been completed?
`appData.fxaccount`: (bool) Does the user have a Firefox account?

Просмотреть файл

@ -145,6 +145,7 @@ module.exports = function(config) {
path.resolve("test"),
path.resolve("vendor"),
path.resolve("lib/ASRouterTargeting.jsm"),
path.resolve("content-src/lib/snippets.js"),
path.resolve("lib/ASRouterTriggerListeners.jsm"),
path.resolve("lib/OnboardingMessageProvider.jsm"),
path.resolve("lib/CFRMessageProvider.jsm"),

Просмотреть файл

@ -34,7 +34,6 @@ const DEFAULT_WHITELIST_HOSTS = {
"activity-stream-icons.services.mozilla.com": "production",
"snippets-admin.mozilla.org": "preview",
};
const ONBOARDING_FINISHED_PREF = "browser.onboarding.notification.finished";
const SNIPPETS_ENDPOINT_WHITELIST = "browser.newtab.activity-stream.asrouter.whitelistHosts";
// Max possible impressions cap for any message
const MAX_MESSAGE_LIFETIME_CAP = 100;
@ -249,17 +248,6 @@ const MessageLoaderUtils = {
this.MessageLoaderUtils = MessageLoaderUtils;
/**
* hasLegacyOnboardingConflict - Checks if we need to turn off snippets because of
* legacy onboarding using the same UI space
*
* @param {Provider} provider
* @returns {boolean} Is there a conflict with legacy onboarding?
*/
function hasLegacyOnboardingConflict(provider) {
return provider.id === "snippets" && !Services.prefs.getBoolPref(ONBOARDING_FINISHED_PREF, false);
}
/**
* @class _ASRouter - Keeps track of all messages, UI surfaces, and
* handles blocking, rotation, etc. Inspecting ASRouter.state will
@ -291,38 +279,9 @@ class _ASRouter {
this.onPrefChange = this.onPrefChange.bind(this);
}
/**
* Turns legacy onboarding off or on using the ONBOARDING_FINISHED_PREF.
* This is required since ASRouter also shows snippets and onboarding, which
* interferes with legacy onboarding.
*
* Note that when this pref is true, legacy onboarding does NOT show up;
* when it is false, iegacy onboarding may show up if the profile age etc.
* is appropriate for the user to see it.
*/
overrideOrEnableLegacyOnboarding() {
const {allowLegacyOnboarding} = ASRouterPreferences.specialConditions;
const onboardingFinished = Services.prefs.getBoolPref(ONBOARDING_FINISHED_PREF, true);
if (!allowLegacyOnboarding && onboardingFinished === false) {
Services.prefs.setBoolPref(ONBOARDING_FINISHED_PREF, true);
} else if (allowLegacyOnboarding && onboardingFinished === true) {
Services.prefs.setBoolPref(ONBOARDING_FINISHED_PREF, false);
}
}
// This will be removed when legacy onboarding is removed.
async observe(aSubject, aTopic, aPrefName) {
if (aPrefName === ONBOARDING_FINISHED_PREF) {
this._updateMessageProviders();
await this.loadMessagesFromAllProviders();
}
}
// Update message providers and fetch new messages on pref change
async onPrefChange() {
this._updateMessageProviders();
this.overrideOrEnableLegacyOnboarding();
await this.loadMessagesFromAllProviders();
this.dispatchToAS(ac.BroadcastToContent({type: at.AS_ROUTER_PREF_CHANGED, data: ASRouterPreferences.specialConditions}));
}
@ -348,9 +307,7 @@ class _ASRouter {
// The provider should be enabled and not have a user preference set to false
...ASRouterPreferences.providers.filter(p => (
p.enabled &&
ASRouterPreferences.getUserPreference(p.id) !== false) &&
// sorry this is crappy. will remove soon
!hasLegacyOnboardingConflict(p)
ASRouterPreferences.getUserPreference(p.id) !== false)
),
].map(_provider => {
// make a copy so we don't modify the source of the pref
@ -477,8 +434,6 @@ class _ASRouter {
this.dispatchToAS = dispatchToAS;
this.dispatch = this.dispatch.bind(this);
// For watching legacy onboarding. To be removed when legacy onboarding is gone.
Services.prefs.addObserver(ONBOARDING_FINISHED_PREF, this);
ASRouterPreferences.init();
ASRouterPreferences.addListener(this.onPrefChange);
@ -489,7 +444,6 @@ class _ASRouter {
const previousSessionEnd = await this._storage.get("previousSessionEnd") || 0;
await this.setState({messageBlockList, providerBlockList, messageImpressions, providerImpressions, previousSessionEnd});
this._updateMessageProviders();
this.overrideOrEnableLegacyOnboarding();
await this.loadMessagesFromAllProviders();
await MessageLoaderUtils.cleanupCache(this.state.providers, storage);
@ -508,10 +462,6 @@ class _ASRouter {
this.messageChannel = null;
this.dispatchToAS = null;
this.overrideOrEnableLegacyOnboarding();
// For watching legacy onboarding. To be removed when legacy onboarding is gone.
Services.prefs.removeObserver(ONBOARDING_FINISHED_PREF, this);
ASRouterPreferences.removeListener(this.onPrefChange);
ASRouterPreferences.uninit();

Просмотреть файл

@ -45,20 +45,13 @@ class _ASRouterPreferences {
}
get specialConditions() {
let allowLegacyOnboarding = true;
let allowLegacySnippets = true;
for (const provider of this.providers) {
if (provider.id === "onboarding" && provider.enabled && provider.cohort) {
allowLegacyOnboarding = false;
}
if (provider.id === "snippets" && provider.enabled) {
allowLegacySnippets = false;
}
}
return {
allowLegacyOnboarding,
allowLegacySnippets,
};
return {allowLegacySnippets};
}
observe(aSubject, aTopic, aPrefName) {

Просмотреть файл

@ -199,11 +199,6 @@ const TargetingGetters = {
}
)));
},
// Temporary targeting function for the purposes of running the simplified onboarding experience
get isInExperimentCohort() {
const {cohort} = ASRouterPreferences.providers.find(i => i.id === "onboarding") || {};
return (typeof cohort === "number" ? cohort : 0);
},
get providerCohorts() {
return ASRouterPreferences.providers.reduce((prev, current) => {
prev[current.id] = current.cohort || "";

Просмотреть файл

@ -210,7 +210,6 @@ const PREFS_CONFIG = new Map([
type: "local",
localProvider: "OnboardingMessageProvider",
enabled: false,
cohort: 0,
}, {
id: "snippets",
type: "remote",

Просмотреть файл

@ -55,7 +55,6 @@ const ONBOARDING_MESSAGES = () => ([
data: {page: "addons"},
},
},
targeting: "isInExperimentCohort == 1",
trigger: {id: "firstRun"},
},
{
@ -73,7 +72,7 @@ const ONBOARDING_MESSAGES = () => ([
data: {url: "https://addons.mozilla.org/en-US/firefox/addon/ghostery/"},
},
},
targeting: "isInExperimentCohort == 2",
targeting: "providerCohorts.onboarding == 'ghostery'",
trigger: {id: "firstRun"},
},
]);

Просмотреть файл

@ -13,7 +13,6 @@ ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
ChromeUtils.defineModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
const ONBOARDING_FINISHED_PREF = "browser.onboarding.notification.finished";
// List of prefs that require migration to indexedDB.
// Object key is the name of the pref in indexedDB, each will contain a
@ -46,30 +45,12 @@ this.PrefsFeed = class PrefsFeed {
}
}
_initOnboardingPref() {
const snippetsEnabled = this._prefs.get("feeds.snippets");
if (!snippetsEnabled) {
this.setOnboardingDisabledDefault(true);
}
}
setOnboardingDisabledDefault(value) {
const branch = Services.prefs.getDefaultBranch("");
branch.setBoolPref(ONBOARDING_FINISHED_PREF, value);
}
onPrefChanged(name, value) {
if (this._prefMap.has(name)) {
this.store.dispatch(ac.BroadcastToContent({type: at.PREF_CHANGED, data: {name, value}}));
}
this._checkPrerender(name);
if (name === "feeds.snippets") {
// If snippets are disabled, onboarding notifications should also be
// disabled because they look like snippets.
this.setOnboardingDisabledDefault(!value);
}
}
_migratePrefs() {
@ -117,7 +98,6 @@ this.PrefsFeed = class PrefsFeed {
this._migratePrefs();
this._setPrerenderPref();
this._initOnboardingPref();
}
removeListeners() {
@ -141,14 +121,10 @@ this.PrefsFeed = class PrefsFeed {
break;
case at.UNINIT:
this.removeListeners();
this.setOnboardingDisabledDefault(false);
break;
case at.SET_PREF:
this._prefs.set(action.data.name, action.data.value);
break;
case at.DISABLE_ONBOARDING:
this.setOnboardingDisabledDefault(true);
break;
case at.UPDATE_SECTION_PREFS:
this._setIndexedDBPref(action.data.id, action.data.value);
break;

Просмотреть файл

@ -21,7 +21,6 @@ ChromeUtils.defineModuleGetter(this, "NewTabUtils",
const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
const TELEMETRY_PREF = "datareporting.healthreport.uploadEnabled";
const FXA_USERNAME_PREF = "services.sync.username";
const ONBOARDING_FINISHED_PREF = "browser.onboarding.notification.finished";
// Prefix for any target matching a search engine.
const TARGET_SEARCHENGINE_PREFIX = "searchEngine-";
@ -148,7 +147,7 @@ this.SnippetsFeed = class SnippetsFeed {
snippetsURL: this.snippetsURL,
version: STARTPAGE_VERSION,
telemetryEnabled: Services.prefs.getBoolPref(TELEMETRY_PREF),
onboardingFinished: Services.prefs.getBoolPref(ONBOARDING_FINISHED_PREF),
onboardingFinished: true,
fxaccount: Services.prefs.prefHasUserValue(FXA_USERNAME_PREF),
selectedSearchEngine: await this.getSelectedSearchEngine(),
defaultBrowser: this.isDefaultBrowser(),
@ -171,7 +170,6 @@ this.SnippetsFeed = class SnippetsFeed {
Services.obs.addObserver(this, SEARCH_ENGINE_OBSERVER_TOPIC);
this._previousSessionEnd = await this._storage.get("previousSessionEnd");
await this._refresh();
Services.prefs.addObserver(ONBOARDING_FINISHED_PREF, this._refresh);
Services.prefs.addObserver(SNIPPETS_URL_PREF, this._refresh);
Services.prefs.addObserver(TELEMETRY_PREF, this._refresh);
Services.prefs.addObserver(FXA_USERNAME_PREF, this._refresh);
@ -179,7 +177,6 @@ this.SnippetsFeed = class SnippetsFeed {
uninit() {
this._storage.set("previousSessionEnd", Date.now());
Services.prefs.removeObserver(ONBOARDING_FINISHED_PREF, this._refresh);
Services.prefs.removeObserver(SNIPPETS_URL_PREF, this._refresh);
Services.prefs.removeObserver(TELEMETRY_PREF, this._refresh);
Services.prefs.removeObserver(FXA_USERNAME_PREF, this._refresh);

Просмотреть файл

@ -21,6 +21,5 @@ cd /mozilla-central && ./mach build \
browser/components/preferences/in-content/tests/browser_newtab_menu.js \
browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js \
browser/components/preferences/in-content/tests/browser_search_subdialogs_within_preferences_1.js \
browser/extensions/onboarding/test/browser \
&& ! grep -q TEST-UNEXPECTED test_run_log \
&& ! ./mach test all_files_referenced | grep activity-stream

Просмотреть файл

@ -357,15 +357,6 @@ add_task(async function check_sync() {
"should return correct mobileDevices info");
});
add_task(async function check_onboarding_cohort() {
await pushPrefs(["browser.newtabpage.activity-stream.asrouter.messageProviders", JSON.stringify([{id: "onboarding", messages: [], enabled: true, cohort: 1}])]);
is(await ASRouterTargeting.Environment.isInExperimentCohort, 1);
await pushPrefs(["browser.newtabpage.activity-stream.asrouter.messageProviders", JSON.stringify(17)]);
is(await ASRouterTargeting.Environment.isInExperimentCohort, 0);
await pushPrefs(["browser.newtabpage.activity-stream.asrouter.messageProviders", JSON.stringify([{id: "onboarding", messages: [], enabled: true, cohort: "hello"}])]);
is(await ASRouterTargeting.Environment.isInExperimentCohort, 0);
});
add_task(async function check_provider_cohorts() {
await pushPrefs(["browser.newtabpage.activity-stream.asrouter.messageProviders", JSON.stringify([{id: "onboarding", messages: [], enabled: true, cohort: "foo"}, {id: "cfr", messages: [], cohort: "bar"}])]);
is(await ASRouterTargeting.Environment.providerCohorts.onboarding, "foo");

Просмотреть файл

@ -37,26 +37,4 @@ describe("asrouter", () => {
store.dispatch({type: at.INIT});
assert.notCalled(addStub);
});
it("should hide onboarding if allowLegacyOnboarding is false", () => {
const addStub = sandbox.stub(global.document.body.classList, "add");
({asrouterContent} = enableASRouterContent(store, {
init: sandbox.stub(),
initialized: false,
}));
store.dispatch({type: at.AS_ROUTER_INITIALIZED, data: {allowLegacyOnboarding: false}});
assert.calledWith(addStub, "hide-onboarding");
});
it("should show onboarding if allowLegacyOnboarding is true and we previously hid it", () => {
sandbox.stub(global.document.body.classList, "add");
const removeStub = sandbox.stub(global.document.body.classList, "remove");
({asrouterContent} = enableASRouterContent(store, {
init: sandbox.stub(),
initialized: false,
}));
// first hide it
store.dispatch({type: at.AS_ROUTER_INITIALIZED, data: {allowLegacyOnboarding: false}});
// now, show it again
store.dispatch({type: at.AS_ROUTER_INITIALIZED, data: {allowLegacyOnboarding: true}});
assert.calledWith(removeStub, "hide-onboarding");
});
});

Просмотреть файл

@ -19,7 +19,6 @@ import ProviderResponseSchema from "content-src/asrouter/schemas/provider-respon
import {QueryCache} from "lib/ASRouterTargeting.jsm";
const MESSAGE_PROVIDER_PREF_NAME = "browser.newtabpage.activity-stream.asrouter.messageProviders";
const ONBOARDING_FINISHED_PREF = "browser.onboarding.notification.finished";
const FAKE_PROVIDERS = [FAKE_LOCAL_PROVIDER, FAKE_REMOTE_PROVIDER, FAKE_REMOTE_SETTINGS_PROVIDER];
const ALL_MESSAGE_IDS = [...FAKE_LOCAL_MESSAGES, ...FAKE_REMOTE_MESSAGES].map(message => message.id);
const FAKE_BUNDLE = [FAKE_LOCAL_MESSAGES[1], FAKE_LOCAL_MESSAGES[2]];
@ -202,18 +201,6 @@ describe("ASRouter", () => {
assert.lengthOf(Router.state.providers, length);
assert.isDefined(provider);
});
it("should update the list of providers and load messages on legacy onboarding pref change", async () => {
sandbox.spy(Router, "_updateMessageProviders");
sandbox.spy(Router, "loadMessagesFromAllProviders");
// we do NOT want to set the onboarding pref again and cause an infinite loop
sandbox.stub(global.Services.prefs, "setBoolPref");
await Router.observe(null, null, ONBOARDING_FINISHED_PREF);
assert.calledOnce(Router._updateMessageProviders);
assert.calledOnce(Router.loadMessagesFromAllProviders);
assert.notCalled(global.Services.prefs.setBoolPref);
});
});
describe("setState", () => {
@ -231,51 +218,6 @@ describe("ASRouter", () => {
});
});
describe("#overrideOrEnableLegacyOnboarding", () => {
it("should set the onboarding finished pref to true if legacy onboarding is NOT allowed", async () => {
sandbox.stub(global.Services.prefs, "getBoolPref").withArgs(ONBOARDING_FINISHED_PREF).returns(false);
sandbox.stub(ASRouterPreferences, "specialConditions").get(() => ({allowLegacyOnboarding: false}));
const setStub = sandbox.stub(global.Services.prefs, "setBoolPref");
Router.overrideOrEnableLegacyOnboarding();
assert.calledWith(setStub, ONBOARDING_FINISHED_PREF, true);
});
it("should set the onboarding finished pref to false if ASRPreferences.allowLegacyOnboarding is true and we previously override onboarding", async () => {
// First override the finished pref to be to true so we can reverse the overriding
const onboardingPrefStub = sandbox.stub(global.Services.prefs, "getBoolPref").withArgs(ONBOARDING_FINISHED_PREF).returns(false);
const specialConditionsStub = sandbox.stub(ASRouterPreferences, "specialConditions").get(() => ({allowLegacyOnboarding: false}));
Router.overrideOrEnableLegacyOnboarding();
// Now reverse it
onboardingPrefStub.withArgs(ONBOARDING_FINISHED_PREF).returns(true);
specialConditionsStub.get(() => ({allowLegacyOnboarding: true}));
const setStub = sandbox.stub(global.Services.prefs, "setBoolPref");
Router.overrideOrEnableLegacyOnboarding();
assert.calledWith(setStub, ONBOARDING_FINISHED_PREF, false);
});
it("should call .overrideOrEnableLegacyOnboarding on init", async () => {
Router = new _ASRouter();
sandbox.spy(Router, "overrideOrEnableLegacyOnboarding");
await Router.init(channel, createFakeStorage(), dispatchStub);
assert.calledOnce(Router.overrideOrEnableLegacyOnboarding);
});
it("should call .overrideOrEnableLegacyOnboarding on a preference change", async () => {
sandbox.spy(Router, "overrideOrEnableLegacyOnboarding");
await Router.onPrefChange();
assert.calledOnce(Router.overrideOrEnableLegacyOnboarding);
});
it("should call .overrideOrEnableLegacyOnboarding on uninit", async () => {
sandbox.spy(Router, "overrideOrEnableLegacyOnboarding");
Router.uninit();
assert.calledOnce(Router.overrideOrEnableLegacyOnboarding);
});
});
describe("#loadMessagesFromAllProviders", () => {
function assertRouterContainsMessages(messages) {
const messageIdsInRouter = Router.state.messages.map(m => m.id);
@ -384,15 +326,6 @@ describe("ASRouter", () => {
assert.equal(Router.state.providers.length, 1);
assert.equal(Router.state.providers[0].id, providers[1].id);
});
it("should not add snippets if legacy onboarding is not finished", () => {
sandbox.stub(global.Services.prefs, "getBoolPref").withArgs(ONBOARDING_FINISHED_PREF).returns(false);
const providers = [
{id: "snippets", enabled: true, type: "remote", url: "https://www.foo.com/"},
];
setMessageProviderPref(providers);
Router._updateMessageProviders();
assert.equal(Router.state.providers.length, 0);
});
});
describe("blocking", () => {

Просмотреть файл

@ -63,7 +63,7 @@ describe("ASRouterFeed", () => {
});
});
describe("#onAction: UNINIT", () => {
it("should uninitialize the ASRouter and restore onboarding", async () => {
it("should uninitialize the ASRouter", async () => {
await Router.init(new FakeRemotePageManager(), storage, () => {});
sinon.stub(Router, "uninit");

Просмотреть файл

@ -133,26 +133,6 @@ describe("ASRouterPreferences", () => {
});
});
describe(".specialConditions", () => {
it("should return .allowLegacyOnboarding=true if onboarding is not present, disabled, or doesn't have cohort", () => {
ASRouterPreferences.init();
let testProviders = [];
sandbox.stub(ASRouterPreferences, "providers").get(() => testProviders);
testProviders = [{id: "foo"}];
assert.isTrue(ASRouterPreferences.specialConditions.allowLegacyOnboarding);
testProviders = [{id: "onboarding", enabled: false, cohort: "test"}];
assert.isTrue(ASRouterPreferences.specialConditions.allowLegacyOnboarding);
testProviders = [{id: "onboarding", enabled: true}];
assert.isTrue(ASRouterPreferences.specialConditions.allowLegacyOnboarding);
});
it("should return .allowLegacyOnboarding=false if onboarding is enabled and has a cohort", () => {
ASRouterPreferences.init();
sandbox.stub(ASRouterPreferences, "providers").get(() => [{id: "onboarding", enabled: true, cohort: "test"}]);
assert.isFalse(ASRouterPreferences.specialConditions.allowLegacyOnboarding);
});
it("should return .allowLegacySnippets=true if snippets is not present or disabled", () => {
ASRouterPreferences.init();
let testProviders = [];

Просмотреть файл

@ -1,47 +1,8 @@
import {ASRouterTargeting, CachedTargetingGetter} from "lib/ASRouterTargeting.jsm";
import {ASRouterPreferences} from "lib/ASRouterPreferences.jsm";
import {CachedTargetingGetter} from "lib/ASRouterTargeting.jsm";
// Note that tests for the ASRouterTargeting environment can be found in
// test/functional/mochitest/browser_asrouter_targeting.js
describe("ASRouterTargeting#isInExperimentCohort", () => {
let sandbox;
let time;
beforeEach(() => {
sandbox = sinon.sandbox.create();
time = sinon.useFakeTimers();
});
afterEach(() => {
sandbox.restore();
time.restore();
ASRouterPreferences.uninit();
});
it("should return the correct if the onboardingCohort pref value", () => {
sandbox.stub(global.Services.prefs, "getStringPref").returns(JSON.stringify([{id: "onboarding", cohort: 1}]));
});
it("should return the correct cohort if the onboarding cohort pref value is defined", () => {
sandbox.stub(ASRouterPreferences, "providers").get(() => [{id: "onboarding", cohort: 1}]);
const result = ASRouterTargeting.Environment.isInExperimentCohort;
assert.equal(result, 1);
});
it("should return 0 if it cannot find the pref", () => {
sandbox.stub(ASRouterPreferences, "providers").get(() => [{id: "foo"}]);
const result = ASRouterTargeting.Environment.isInExperimentCohort;
assert.equal(result, 0);
});
it("should combine customContext and TargetingGetters", async () => {
sandbox.stub(global.FilterExpressions, "eval");
await ASRouterTargeting.isMatch("true == true", {foo: true});
assert.calledOnce(global.FilterExpressions.eval);
const [, context] = global.FilterExpressions.eval.firstCall.args;
// Assert direct properties instead of inherited
assert.equal(context.foo, true);
assert.match(context.currentDate, sinon.match.date);
});
});
describe("#CachedTargetingGetter", () => {
const sixHours = 6 * 60 * 60 * 1000;
let sandbox;

Просмотреть файл

@ -2,9 +2,7 @@ import {ASRouterTargeting} from "lib/ASRouterTargeting.jsm";
import docs from "content-src/asrouter/docs/targeting-attributes.md";
// The following targeting parameters are either deprecated or should not be included in the docs for some reason.
const SKIP_DOCS = [
"isInExperimentCohort",
];
const SKIP_DOCS = [];
// These are extra message context attributes via ASRouter.jsm
const MESSAGE_CONTEXT_ATTRIBUTES = [
"previousSessionEnd",

Просмотреть файл

@ -140,13 +140,6 @@ describe("SnippetsMap", () => {
assert.equal(dispatch.firstCall.args[0].type, at.SHOW_FIREFOX_ACCOUNTS);
});
});
describe("#disableOnboarding", () => {
it("should dispatch a DISABLE_ONBOARDING action", () => {
snippetsMap.disableOnboarding();
assert.calledOnce(dispatch);
assert.equal(dispatch.firstCall.args[0].type, at.DISABLE_ONBOARDING);
});
});
describe("#getTotalBookmarksCount", () => {
it("should dispatch a TOTAL_BOOKMARKS_REQUEST and resolve with the right data", async () => {
const bookmarksPromise = snippetsMap.getTotalBookmarksCount();
@ -264,15 +257,6 @@ describe("SnippetsProvider", () => {
assert.calledOnce(spy);
window.removeEventListener("Snippets:Enabled", spy);
});
it("should show the onboarding element if it exists", async () => {
const fakeEl = {style: {display: "none"}};
sandbox.stub(global.document, "getElementById").returns(fakeEl);
snippets = new SnippetsProvider(dispatch);
await snippets.init({connect: false});
assert.equal(fakeEl.style.display, "");
});
it("should add a message listener for incoming messages", async () => {
await snippets.init({connect: false});
assert.calledWith(global.RPMAddMessageListener, INCOMING_MESSAGE_NAME, snippets._onAction);
@ -298,11 +282,6 @@ describe("SnippetsProvider", () => {
assert.calledOnce(spy);
window.removeEventListener("Snippets:Disabled", spy);
});
it("should hide the onboarding element if it exists", () => {
snippets = new SnippetsProvider(dispatch);
snippets.uninit();
assert.equal(fakeEl.style.display, "none");
});
it("should remove the message listener for incoming messages", () => {
snippets = new SnippetsProvider(dispatch);
snippets.uninit();

Просмотреть файл

@ -5,7 +5,6 @@ import {PrerenderData} from "common/PrerenderData.jsm";
const {initialPrefs} = PrerenderData;
const PRERENDER_PREF_NAME = "prerender";
const ONBOARDING_FINISHED_PREF = "browser.onboarding.notification.finished";
let overrider = new GlobalOverrider();
@ -117,50 +116,6 @@ describe("PrefsFeed", () => {
assert.calledWith(feed._prefs.set, PRERENDER_PREF_NAME, false);
});
});
describe("Onboarding", () => {
let defaultBranch;
beforeEach(() => {
defaultBranch = {setBoolPref: sandbox.stub()};
sandbox.stub(global.Services.prefs, "getDefaultBranch").returns(defaultBranch);
});
it("should call feed.init on INIT action", () => {
sandbox.stub(feed, "init");
feed.onAction({type: at.INIT});
assert.calledOnce(feed.init);
});
it("should set ONBOARDING_FINISHED_PREF to true if prefs.feeds.snippets if false", async () => {
FAKE_PREFS.set("feeds.snippets", false);
await feed.init();
assert.calledWith(defaultBranch.setBoolPref, ONBOARDING_FINISHED_PREF, true);
});
it("should not set ONBOARDING_FINISHED_PREF if prefs.feeds.snippets is true", async () => {
FAKE_PREFS.set("feeds.snippets", true);
await feed.init();
assert.notCalled(defaultBranch.setBoolPref);
});
it("should set ONBOARDING_FINISHED_PREF to true if the feeds.snippets pref changes to false", () => {
feed.onPrefChanged("feeds.snippets", false);
assert.calledWith(defaultBranch.setBoolPref, ONBOARDING_FINISHED_PREF, true);
});
it("should set ONBOARDING_FINISHED_PREF to false if the feeds.snippets pref changes to true", () => {
feed.onPrefChanged("feeds.snippets", true);
assert.calledWith(defaultBranch.setBoolPref, ONBOARDING_FINISHED_PREF, false);
});
it("should not set ONBOARDING_FINISHED_PREF if an unrelated pref changes", () => {
feed.onPrefChanged("foo", true);
assert.notCalled(defaultBranch.setBoolPref);
});
it("should set ONBOARDING_FINISHED_PREF to true if a DISABLE_ONBOARDING action was received", () => {
feed.onAction({type: at.DISABLE_ONBOARDING});
assert.calledWith(defaultBranch.setBoolPref, ONBOARDING_FINISHED_PREF, true);
});
});
describe("indexedDB changes", () => {
it("should call _setIndexedDBPref on UPDATE_SECTION_PREFS", () => {
sandbox.stub(feed, "_setIndexedDBPref");

Просмотреть файл

@ -55,9 +55,7 @@ describe("SnippetsFeed", () => {
sandbox.stub(global.Services.prefs, "getStringPref").returns(url);
sandbox.stub(global.Services.prefs, "getBoolPref")
.withArgs("datareporting.healthreport.uploadEnabled")
.returns(true)
.withArgs("browser.onboarding.notification.finished")
.returns(false);
.returns(true);
sandbox.stub(global.Services.prefs, "prefHasUserValue")
.withArgs("services.sync.username")
.returns(true);
@ -90,7 +88,6 @@ describe("SnippetsFeed", () => {
assert.propertyVal(action.data, "profileCreatedWeeksAgo", 2);
assert.propertyVal(action.data, "profileResetWeeksAgo", 1);
assert.propertyVal(action.data, "telemetryEnabled", true);
assert.propertyVal(action.data, "onboardingFinished", false);
assert.propertyVal(action.data, "fxaccount", true);
assert.property(action.data, "selectedSearchEngine");
assert.deepEqual(action.data.selectedSearchEngine, searchData);