From c0f017826372f8ec86304cb9eac87090545e2d57 Mon Sep 17 00:00:00 2001 From: stoically Date: Tue, 8 May 2018 14:19:47 +0200 Subject: [PATCH] Add per Domain Isolation tests Part of #104 --- test/background.isolation.test.js | 88 +++++++++++++++++++++++++++---- test/setup.js | 2 +- 2 files changed, 80 insertions(+), 10 deletions(-) diff --git a/test/background.isolation.test.js b/test/background.isolation.test.js index b0d38a15..ea0d3044 100644 --- a/test/background.isolation.test.js +++ b/test/background.isolation.test.js @@ -1,19 +1,45 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify(preferences)}`, () => { let tab; + const defaultIsolationDomainPreferences = { + always: { + action: 'disabled', + allowedInPermanent: false + }, + navigation: { + action: 'global' + }, + mouseClick: { + middle: { + action: 'global' + }, + ctrlleft: { + action: 'global' + }, + left: { + action: 'global' + } + }, + excluded: {} + }; + [ - 'sametab', - 'newtab' + 'sametab.global', + 'sametab.perdomain', + 'newtab.global', + 'newtab.perdomain' ].map(navigatingIn => { describe(`navigatingIn: ${navigatingIn}`, () => { const navigateTo = async (url) => { switch (navigatingIn) { - case 'sametab': + case 'sametab.global': + case 'sametab.perdomain': return browser.tabs._update(tab.id, { url }); - case 'newtab': + case 'newtab.global': + case 'newtab.perdomain': return browser.tabs._create({ cookieStoreId: tab.cookieStoreId, openerTabId: tab.id, @@ -35,7 +61,18 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify( describe('navigating with preference "never"', () => { beforeEach(async () => { - background.storage.local.preferences.isolation.global.navigation.action = 'never'; + switch (navigatingIn) { + case 'sametab.global': + case 'newtab.global': + background.storage.local.preferences.isolation.global.navigation.action = 'never'; + break; + + case 'sametab.perdomain': + case 'newtab.perdomain': + background.storage.local.preferences.isolation.domain['example.com'] = defaultIsolationDomainPreferences; + background.storage.local.preferences.isolation.domain['example.com'].navigation.action = 'never'; + break; + } }); describe('if its the exact same domain', () => { @@ -71,7 +108,18 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify( describe('navigating with preference "always"', () => { beforeEach(async () => { - background.storage.local.preferences.isolation.global.navigation.action = 'always'; + switch (navigatingIn) { + case 'sametab.global': + case 'newtab.global': + background.storage.local.preferences.isolation.global.navigation.action = 'always'; + break; + + case 'sametab.perdomain': + case 'newtab.perdomain': + background.storage.local.preferences.isolation.domain['example.com'] = defaultIsolationDomainPreferences; + background.storage.local.preferences.isolation.domain['example.com'].navigation.action = 'always'; + break; + } }); describe('if its the exact same domain', () => { @@ -107,7 +155,18 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify( describe('navigating with preference "notsamedomain"', () => { beforeEach(() => { - background.storage.local.preferences.isolation.global.navigation.action = 'notsamedomain'; + switch (navigatingIn) { + case 'sametab.global': + case 'newtab.global': + background.storage.local.preferences.isolation.global.navigation.action = 'notsamedomain'; + break; + + case 'sametab.perdomain': + case 'newtab.perdomain': + background.storage.local.preferences.isolation.domain['example.com'] = defaultIsolationDomainPreferences; + background.storage.local.preferences.isolation.domain['example.com'].navigation.action = 'notsamedomain'; + break; + } }); describe('if its the exact same domain', () => { @@ -143,7 +202,18 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify( describe('navigating with preference "notsamedomainexact"', () => { beforeEach(() => { - background.storage.local.preferences.isolation.global.navigation.action = 'notsamedomainexact'; + switch (navigatingIn) { + case 'sametab.global': + case 'newtab.global': + background.storage.local.preferences.isolation.global.navigation.action = 'notsamedomainexact'; + break; + + case 'sametab.perdomain': + case 'newtab.perdomain': + background.storage.local.preferences.isolation.domain['example.com'] = defaultIsolationDomainPreferences; + background.storage.local.preferences.isolation.domain['example.com'].navigation.action = 'notsamedomainexact'; + break; + } }); describe('if its the exact same domain', () => { @@ -236,4 +306,4 @@ preferencesTestSet.map(preferences => { describe(`preferences: ${JSON.stringify( }); }); });}); -});}); \ No newline at end of file +});}); diff --git a/test/setup.js b/test/setup.js index cbfcb783..ca8f19b7 100644 --- a/test/setup.js +++ b/test/setup.js @@ -65,7 +65,7 @@ const buildWebExtension = async (build = {}) => { webExtension.background.browser.contextualIdentities.get.resolves({}); } webExtension.background.browser.cookies.getAll.resolves([]); - + if (process.argv[process.argv.length-1] === '--tmp-debug') { webExtension.background.window.log.DEBUG = true; }