summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutwelcome/tests/browser/browser_aboutwelcome_screen_targeting.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/aboutwelcome/tests/browser/browser_aboutwelcome_screen_targeting.js')
-rw-r--r--browser/components/aboutwelcome/tests/browser/browser_aboutwelcome_screen_targeting.js274
1 files changed, 274 insertions, 0 deletions
diff --git a/browser/components/aboutwelcome/tests/browser/browser_aboutwelcome_screen_targeting.js b/browser/components/aboutwelcome/tests/browser/browser_aboutwelcome_screen_targeting.js
new file mode 100644
index 0000000000..1d91d4ca05
--- /dev/null
+++ b/browser/components/aboutwelcome/tests/browser/browser_aboutwelcome_screen_targeting.js
@@ -0,0 +1,274 @@
+"use strict";
+
+const TEST_DEFAULT_CONTENT = [
+ {
+ id: "AW_STEP1",
+ content: {
+ title: "Step 1",
+ primary_button: {
+ label: "Next",
+ action: {
+ navigate: true,
+ },
+ },
+ secondary_button: {
+ label: "Secondary",
+ },
+ },
+ },
+ {
+ id: "AW_STEP2",
+ targeting: "false",
+ content: {
+ title: "Step 2",
+ primary_button: {
+ label: "Next",
+ action: {
+ navigate: true,
+ },
+ },
+ secondary_button: {
+ label: "Secondary",
+ },
+ },
+ },
+ {
+ id: "AW_STEP3",
+ content: {
+ title: "Step 3",
+ primary_button: {
+ label: "Next",
+ action: {
+ navigate: true,
+ },
+ },
+ secondary_button: {
+ label: "Secondary",
+ },
+ },
+ },
+];
+
+const TEST_DEFAULT_JSON = JSON.stringify(TEST_DEFAULT_CONTENT);
+async function openAboutWelcome() {
+ await setAboutWelcomePref(true);
+ await setAboutWelcomeMultiStage(TEST_DEFAULT_JSON);
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ "about:welcome",
+ true
+ );
+ registerCleanupFunction(() => {
+ BrowserTestUtils.removeTab(tab);
+ });
+ return tab.linkedBrowser;
+}
+
+add_task(async function second_screen_filtered_by_targeting() {
+ const sandbox = sinon.createSandbox();
+ let browser = await openAboutWelcome();
+ let aboutWelcomeActor = await getAboutWelcomeParent(browser);
+ // Stub AboutWelcomeParent Content Message Handler
+ sandbox.spy(aboutWelcomeActor, "onContentMessage");
+
+ await test_screen_content(
+ browser,
+ "multistage step 1",
+ // Expected selectors:
+ ["main.AW_STEP1"],
+ // Unexpected selectors:
+ ["main.AW_STEP2", "main.AW_STEP3"]
+ );
+
+ await onButtonClick(browser, "button.primary");
+
+ await test_screen_content(
+ browser,
+ "multistage step 3",
+ // Expected selectors:
+ ["main.AW_STEP3"],
+ // Unexpected selectors:
+ ["main.AW_STEP2", "main.AW_STEP1"]
+ );
+
+ sandbox.restore();
+ await popPrefs();
+});
+
+/**
+ * Test MR template easy setup default content - Browser is not pinned
+ * and not set as default
+ */
+add_task(async function test_aboutwelcome_mr_template_easy_setup_default() {
+ const sandbox = sinon.createSandbox();
+ await pushPrefs(
+ ["browser.shell.checkDefaultBrowser", true],
+ ["messaging-system-action.showEmbeddedImport", false]
+ );
+ sandbox.stub(ShellService, "doesAppNeedPin").returns(true);
+ sandbox.stub(ShellService, "isDefaultBrowser").returns(false);
+
+ await clearHistoryAndBookmarks();
+
+ const { browser, cleanup } = await openMRAboutWelcome();
+
+ //should render easy setup with all checkboxes (default, pin, import)
+ await test_screen_content(
+ browser,
+ "doesn't render only pin, default, or import easy setup",
+ //Expected selectors:
+ ["main.AW_EASY_SETUP_NEEDS_DEFAULT_AND_PIN"],
+ //Unexpected selectors:
+ [
+ "main.AW_EASY_SETUP_NEEDS_DEFAULT",
+ "main.AW_EASY_SETUP_NEEDS_PIN",
+ "main.AW_ONLY_IMPORT",
+ ]
+ );
+
+ await onButtonClick(browser, ".action-buttons button.secondary");
+
+ await test_screen_content(
+ browser,
+ "renders mobile download screen",
+ //Expected selectors:
+ ["main.AW_MOBILE_DOWNLOAD"],
+ //Unexpected selectors:
+ ["main.AW_IMPORT_SETTINGS_EMBEDDED"]
+ );
+
+ await cleanup();
+ await popPrefs();
+ sandbox.restore();
+});
+
+/**
+ * Test MR template easy setup content - Browser is not pinned
+ * and set as default
+ */
+add_task(async function test_aboutwelcome_mr_template_easy_setup_needs_pin() {
+ const sandbox = sinon.createSandbox();
+ await pushPrefs(
+ ["browser.shell.checkDefaultBrowser", true],
+ ["messaging-system-action.showEmbeddedImport", false]
+ );
+ sandbox.stub(ShellService, "doesAppNeedPin").returns(true);
+ sandbox.stub(ShellService, "isDefaultBrowser").returns(true);
+
+ await clearHistoryAndBookmarks();
+
+ const { browser, cleanup } = await openMRAboutWelcome();
+
+ //should render easy setup needs pin
+ await test_screen_content(
+ browser,
+ "doesn't render default and pin, only default or import easy setup",
+ //Expected selectors:
+ ["main.AW_EASY_SETUP_NEEDS_PIN"],
+ //Unexpected selectors:
+ [
+ "main.AW_EASY_SETUP_NEEDS_DEFAULT",
+ "main.AW_EASY_SETUP_NEEDS_DEFAULT_AND_PIN",
+ "main.AW_ONLY_IMPORT",
+ ]
+ );
+
+ await cleanup();
+ await popPrefs();
+ sandbox.restore();
+});
+
+/**
+ * Test MR template easy setup content - Browser is pinned and
+ * not set as default
+ */
+add_task(
+ async function test_aboutwelcome_mr_template_easy_setup_needs_default() {
+ const sandbox = sinon.createSandbox();
+ await pushPrefs(
+ ["browser.shell.checkDefaultBrowser", true],
+ ["messaging-system-action.showEmbeddedImport", false]
+ );
+ sandbox.stub(ShellService, "doesAppNeedPin").returns(false);
+ sandbox.stub(ShellService, "isDefaultBrowser").returns(false);
+
+ await clearHistoryAndBookmarks();
+
+ const { browser, cleanup } = await openMRAboutWelcome();
+
+ //should render easy setup needs default
+ await test_screen_content(
+ browser,
+ "doesn't render pin, import and set to default",
+ //Expected selectors:
+ ["main.AW_EASY_SETUP_NEEDS_DEFAULT"],
+ //Unexpected selectors:
+ [
+ "main.AW_EASY_SETUP_NEEDS_PIN",
+ "main.AW_EASY_SETUP_NEEDS_DEFAULT_AND_PIN",
+ "main.AW_ONLY_IMPORT",
+ ]
+ );
+
+ await onButtonClick(browser, ".action-buttons button.secondary");
+ await test_screen_content(
+ browser,
+ "renders mobile download screen",
+ //Expected selectors:
+ ["main.AW_MOBILE_DOWNLOAD"],
+ //Unexpected selectors:
+ ["main.AW_IMPORT_SETTINGS_EMBEDDED"]
+ );
+
+ await cleanup();
+ await popPrefs();
+ sandbox.restore();
+ }
+);
+
+/**
+ * Test MR template easy setup content - Browser is pinned and
+ * set as default
+ */
+add_task(async function test_aboutwelcome_mr_template_easy_setup_only_import() {
+ const sandbox = sinon.createSandbox();
+ await pushPrefs(
+ ["browser.shell.checkDefaultBrowser", true],
+ ["messaging-system-action.showEmbeddedImport", false]
+ );
+ sandbox.stub(ShellService, "doesAppNeedPin").returns(false);
+ sandbox.stub(ShellService, "isDefaultBrowser").returns(true);
+
+ await clearHistoryAndBookmarks();
+
+ const { browser, cleanup } = await openMRAboutWelcome();
+
+ //should render easy setup - only import
+ await test_screen_content(
+ browser,
+ "doesn't render any combination of pin and default",
+ //Expected selectors:
+ ["main.AW_EASY_SETUP_ONLY_IMPORT"],
+ //Unexpected selectors:
+ [
+ "main.AW_EASY_SETUP_NEEDS_PIN",
+ "main.AW_EASY_SETUP_NEEDS_DEFAULT_AND_PIN",
+ "main.AW_EASY_SETUP_NEEDS_DEFAULT",
+ ]
+ );
+
+ await onButtonClick(browser, ".action-buttons button.secondary");
+ await test_screen_content(
+ browser,
+ "renders mobile download screen",
+ //Expected selectors:
+ ["main.AW_MOBILE_DOWNLOAD"],
+ //Unexpected selectors:
+ ["main.AW_IMPORT_SETTINGS_EMBEDDED"]
+ );
+
+ await cleanup();
+ await popPrefs();
+ sandbox.restore();
+});