Dummy test page
+ + diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js index e0e8f19651..6e1f4168a1 100644 --- a/browser/base/content/test/static/browser_all_files_referenced.js +++ b/browser/base/content/test/static/browser_all_files_referenced.js @@ -60,7 +60,7 @@ var whitelist = [ { file: "chrome://pdf.js/locale/viewer.properties" }, // security/manager/pki/resources/content/device_manager.js - { file: "chrome://pippki/content/load_device.xul" }, + { file: "chrome://pippki/content/load_device.xhtml" }, // The l10n build system can't package string files only for some platforms. // See bug 1339424 for why this is hard to fix. @@ -162,9 +162,9 @@ var whitelist = [ // Bug 1356031 (only used by devtools) { file: "chrome://global/skin/icons/error-16.png" }, // Bug 1344267 - { file: "chrome://marionette/content/test_anonymous_content.xul" }, + { file: "chrome://marionette/content/test.xhtml" }, { file: "chrome://marionette/content/test_dialog.properties" }, - { file: "chrome://marionette/content/test_dialog.xul" }, + { file: "chrome://marionette/content/test_dialog.xhtml" }, // Bug 1348533 { file: "chrome://mozapps/skin/downloads/buttons.png", @@ -175,13 +175,11 @@ var whitelist = [ platforms: ["linux", "win"], }, // Bug 1348559 - { file: "chrome://pippki/content/resetpassword.xul" }, + { file: "chrome://pippki/content/resetpassword.xhtml" }, // Bug 1337345 { file: "resource://gre/modules/Manifest.jsm" }, - // Bug 1351097 - { file: "resource://gre/modules/accessibility/AccessFu.jsm" }, // Bug 1356045 - { file: "chrome://global/content/test-ipc.xul" }, + { file: "chrome://global/content/test-ipc.xhtml" }, // Bug 1378173 (warning: still used by devtools) { file: "resource://gre/modules/Promise.jsm" }, // Bug 1494170 @@ -828,7 +826,7 @@ add_task(async function checkAllTheFiles() { } if (isDevtools) { - // chrome://devtools/skin/devtools-browser.css is included from browser.xul + // chrome://devtools/skin/devtools-browser.css is included from browser.xhtml gReferencesFromCode.set(AppConstants.BROWSER_CHROME_URL, null); // devtools' css is currently included from browser.css, see bug 1204810. gReferencesFromCode.set("chrome://browser/skin/browser.css", null); diff --git a/browser/base/content/test/static/browser_misused_characters_in_strings.js b/browser/base/content/test/static/browser_misused_characters_in_strings.js index 6bbefe0c74..875d8e759a 100644 --- a/browser/base/content/test/static/browser_misused_characters_in_strings.js +++ b/browser/base/content/test/static/browser_misused_characters_in_strings.js @@ -89,11 +89,6 @@ let gWhitelist = [ key: "ImageMapPolyOddNumberOfCoords", type: "double-quote", }, - { - file: "xbl.properties", - key: "CommandNotInChrome", - type: "double-quote", - }, { file: "dom.properties", key: "PatternAttributeCompileFailure", diff --git a/browser/base/content/test/static/browser_parsable_css.js b/browser/base/content/test/static/browser_parsable_css.js index e893c1c32e..d55209736d 100644 --- a/browser/base/content/test/static/browser_parsable_css.js +++ b/browser/base/content/test/static/browser_parsable_css.js @@ -40,7 +40,7 @@ let whitelist = [ isFromDevTools: false, }, { - sourceName: /minimal-xul\.css$/i, + sourceName: /(minimal-xul|xul)\.css$/i, errorMessage: /Unknown pseudo-class.*-moz-/i, isFromDevTools: false, }, diff --git a/browser/base/content/test/sync/browser_sync.js b/browser/base/content/test/sync/browser_sync.js index 717ff20bea..1e5acd74c4 100644 --- a/browser/base/content/test/sync/browser_sync.js +++ b/browser/base/content/test/sync/browser_sync.js @@ -69,7 +69,7 @@ add_task(async function test_ui_state_syncing() { gSync.updateAllUI(state); - checkSyncNowButton("PanelUI-remotetabs-syncnow", true); + checkSyncNowButtons(true); // Be good citizens and remove the "syncing" state. gSync.updateAllUI({ @@ -208,7 +208,7 @@ function checkRemoteTabsPanel(expectedShownItemId, syncing, syncNowTooltip) { ); if (syncing != undefined && syncNowTooltip != undefined) { - checkSyncNowButton("PanelUI-remotetabs-syncnow", syncing, syncNowTooltip); + checkSyncNowButtons(syncing, syncNowTooltip); } } @@ -224,43 +224,41 @@ function checkMenuBarItem(expectedShownItemId) { ); } -function checkSyncNowButton(buttonId, syncing, tooltip = null) { - const remoteTabsButton = document.getElementById(buttonId); +function checkSyncNowButtons(syncing, tooltip = null) { + const syncButtons = document.querySelectorAll(".syncNowBtn"); - is( - remoteTabsButton.getAttribute("syncstatus"), - syncing ? "active" : "", - "button active has the right value" - ); - if (tooltip) { + for (const syncButton of syncButtons) { is( - remoteTabsButton.getAttribute("tooltiptext"), - tooltip, - "button tooltiptext is set to the right value" + syncButton.getAttribute("syncstatus"), + syncing ? "active" : "", + "button active has the right value" ); - } + if (tooltip) { + is( + syncButton.getAttribute("tooltiptext"), + tooltip, + "button tooltiptext is set to the right value" + ); + } - if (buttonId.endsWith("-fxa-icon")) { - return; - } - - is( - remoteTabsButton.hasAttribute("disabled"), - syncing, - "disabled has the right value" - ); - if (syncing) { is( - remoteTabsButton.getAttribute("label"), - gSync.syncStrings.GetStringFromName("syncingtabs.label"), - "label is set to the right value" - ); - } else { - is( - remoteTabsButton.getAttribute("label"), - gSync.syncStrings.GetStringFromName("syncnow.label"), - "label is set to the right value" + syncButton.hasAttribute("disabled"), + syncing, + "disabled has the right value" ); + if (syncing) { + is( + document.l10n.getAttributes(syncButton).id, + syncButton.getAttribute("syncinglabel"), + "label is set to the right value" + ); + } else { + is( + document.l10n.getAttributes(syncButton).id, + "fxa-toolbar-sync-now", + "label is set to the right value" + ); + } } } diff --git a/browser/base/content/test/tabs/browser.ini b/browser/base/content/test/tabs/browser.ini index 726eea06fc..9f6c14a431 100644 --- a/browser/base/content/test/tabs/browser.ini +++ b/browser/base/content/test/tabs/browser.ini @@ -72,6 +72,7 @@ skip-if = (verify && (os == 'win' || os == 'mac')) [browser_reload_deleted_file.js] skip-if = (debug && os == 'mac') || (debug && os == 'linux' && bits == 64) #Bug 1421183, disabled on Linux/OSX for leaked windows [browser_tabCloseSpacer.js] +[browser_tab_a11y_description.js] [browser_tab_label_during_reload.js] [browser_tabCloseProbes.js] [browser_tabContextMenu_keyboard.js] diff --git a/browser/base/content/test/tabs/browser_audioTabIcon.js b/browser/base/content/test/tabs/browser_audioTabIcon.js index 14857fa2f1..acea073f11 100644 --- a/browser/base/content/test/tabs/browser_audioTabIcon.js +++ b/browser/base/content/test/tabs/browser_audioTabIcon.js @@ -169,11 +169,7 @@ async function test_muting_using_menu(tab, expectMuted) { } async function test_playing_icon_on_tab(tab, browser, isPinned) { - let icon = document.getAnonymousElementByAttribute( - tab, - "anonid", - isPinned ? "overlay-icon" : "soundplaying-icon" - ); + let icon = isPinned ? tab.overlayIcon : tab.soundPlayingIcon; let isActiveTab = tab === gBrowser.selectedTab; await play(tab); @@ -248,13 +244,9 @@ async function test_playing_icon_on_hidden_tab(tab) { await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE, true, true), await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE, true, true), ]; - let tabContainer = tab.parentNode; + let tabContainer = tab.container; let alltabsButton = document.getElementById("alltabs-button"); - let alltabsBadge = document.getAnonymousElementByAttribute( - alltabsButton, - "class", - "toolbarbutton-badge" - ); + let alltabsBadge = alltabsButton.badgeLabel; function assertIconShowing() { is( @@ -366,12 +358,7 @@ async function test_swapped_browser_while_playing(oldTab, newBrowser) { "Expected the correct soundplaying attribute on the new tab" ); - let icon = document.getAnonymousElementByAttribute( - newTab, - "anonid", - "soundplaying-icon" - ); - await test_tooltip(icon, "Unmute tab", true); + await test_tooltip(newTab.soundPlayingIcon, "Unmute tab", true); } async function test_swapped_browser_while_not_playing(oldTab, newBrowser) { @@ -444,24 +431,14 @@ async function test_swapped_browser_while_not_playing(oldTab, newBrowser) { "Expected the correct soundplaying attribute on the new tab" ); - let icon = document.getAnonymousElementByAttribute( - newTab, - "anonid", - "soundplaying-icon" - ); - await test_tooltip(icon, "Unmute tab", true); + await test_tooltip(newTab.soundPlayingIcon, "Unmute tab", true); } async function test_browser_swapping(tab, browser) { // First, test swapping with a playing but muted tab. await play(tab); - let icon = document.getAnonymousElementByAttribute( - tab, - "anonid", - "soundplaying-icon" - ); - await test_mute_tab(tab, icon, true); + await test_mute_tab(tab, tab.soundPlayingIcon, true); await BrowserTestUtils.withNewTab( { @@ -507,11 +484,7 @@ async function test_click_on_pinned_tab_after_mute() { await play(tab); // Mute the tab. - let icon = document.getAnonymousElementByAttribute( - tab, - "anonid", - "overlay-icon" - ); + let icon = tab.overlayIcon; await test_mute_tab(tab, icon, true); // Pause playback and wait for it to finish. @@ -521,12 +494,7 @@ async function test_click_on_pinned_tab_after_mute() { await test_mute_tab(tab, icon, false); // Now click on the tab. - let image = document.getAnonymousElementByAttribute( - tab, - "anonid", - "tab-icon-image" - ); - EventUtils.synthesizeMouseAtCenter(image, { button: 0 }); + EventUtils.synthesizeMouseAtCenter(tab.iconImage, { button: 0 }); is(tab, gBrowser.selectedTab, "Tab switch should be successful"); diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_close.js b/browser/base/content/test/tabs/browser_multiselect_tabs_close.js index 8e5585a731..1a3bcd0eb0 100644 --- a/browser/base/content/test/tabs/browser_multiselect_tabs_close.js +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_close.js @@ -26,11 +26,7 @@ add_task(async function usingTabCloseButton() { is(gBrowser.selectedTab, tab1, "Tab1 is active"); // Closing a tab which is not multiselected - let tab4CloseBtn = document.getAnonymousElementByAttribute( - tab4, - "anonid", - "close-button" - ); + let tab4CloseBtn = tab4.closeButton; let tab4Closing = BrowserTestUtils.waitForTabClosing(tab4); tab4.mOverCloseButton = true; @@ -49,11 +45,7 @@ add_task(async function usingTabCloseButton() { is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs"); // Closing a selected tab - let tab2CloseBtn = document.getAnonymousElementByAttribute( - tab2, - "anonid", - "close-button" - ); + let tab2CloseBtn = tab2.closeButton; tab2.mOverCloseButton = true; let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1); let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2); diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_mute_unmute.js b/browser/base/content/test/tabs/browser_multiselect_tabs_mute_unmute.js index bf4fb5b5b2..be3642dbf2 100644 --- a/browser/base/content/test/tabs/browser_multiselect_tabs_mute_unmute.js +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_mute_unmute.js @@ -57,11 +57,7 @@ add_task(async function muteTabs_usingButton() { } // Mute tab0 which is not multiselected, thus other tabs muted state should not be affected - let tab0MuteAudioBtn = document.getAnonymousElementByAttribute( - tab0, - "anonid", - "soundplaying-icon" - ); + let tab0MuteAudioBtn = tab0.soundPlayingIcon; await test_mute_tab(tab0, tab0MuteAudioBtn, true); ok(muted(tab0), "Tab0 is muted"); @@ -97,11 +93,7 @@ add_task(async function muteTabs_usingButton() { // b) unmuted tabs (tab1, tab3) will become muted. // b) media-blocked tabs (tab2) will remain media-blocked. // However tab4 (unmuted) which is not multiselected should not be affected. - let tab1MuteAudioBtn = document.getAnonymousElementByAttribute( - tab1, - "anonid", - "soundplaying-icon" - ); + let tab1MuteAudioBtn = tab1.soundPlayingIcon; await test_mute_tab(tab1, tab1MuteAudioBtn, true); // Check mute state @@ -163,11 +155,7 @@ add_task(async function unmuteTabs_usingButton() { // b) unmuted tabs (tab0) will remain unmuted. // b) media-blocked tabs (tab1, tab2) will get playing. (media not blocked anymore) // However tab4 (muted) which is not multiselected should not be affected. - let tab3MuteAudioBtn = document.getAnonymousElementByAttribute( - tab3, - "anonid", - "soundplaying-icon" - ); + let tab3MuteAudioBtn = tab3.soundPlayingIcon; await test_mute_tab(tab3, tab3MuteAudioBtn, false); ok( @@ -290,11 +278,7 @@ add_task(async function playTabs_usingButton() { // b) unmuted tabs (tab3) will remain unmuted. // b) media-blocked tabs (tab1, tab2) will get playing. (media not blocked anymore) // However tab4 (muted) which is not multiselected should not be affected. - let tab2MuteAudioBtn = document.getAnonymousElementByAttribute( - tab2, - "anonid", - "soundplaying-icon" - ); + let tab2MuteAudioBtn = tab2.soundPlayingIcon; await test_mute_tab(tab2, tab2MuteAudioBtn, false); ok( diff --git a/browser/base/content/test/tabs/browser_multiselect_tabs_open_related.js b/browser/base/content/test/tabs/browser_multiselect_tabs_open_related.js index bc72fb8db6..413931c941 100644 --- a/browser/base/content/test/tabs/browser_multiselect_tabs_open_related.js +++ b/browser/base/content/test/tabs/browser_multiselect_tabs_open_related.js @@ -19,12 +19,7 @@ add_task(async function test() { let metaKeyEvent = AppConstants.platform == "macosx" ? { metaKey: true } : { ctrlKey: true }; - let tabs = document.getElementById("tabbrowser-tabs"); - let newTabButton = document.getAnonymousElementByAttribute( - tabs, - "anonid", - "tabs-newtab-button" - ); + let newTabButton = gBrowser.tabContainer.newTabButton; let promiseTabOpened = BrowserTestUtils.waitForEvent( gBrowser.tabContainer, "TabOpen" @@ -82,13 +77,15 @@ add_task(async function test() { EventUtils.synthesizeMouseAtCenter(newTabButton, metaKeyEvent); openEvent = await promiseTabOpened; newTab = openEvent.target; + let previous = gBrowser.tabContainer.findNextTab(newTab, { direction: -1 }); is( - newTab.previousElementSibling, + previous, tab3, "New tab should be opened after tab3 when tab1 and tab3 are selected" ); + let next = gBrowser.tabContainer.findNextTab(newTab, { direction: 1 }); is( - newTab.nextElementSibling, + next, null, "New tab should be opened at the end of the tabstrip when tab1 and tab3 are selected" ); @@ -106,14 +103,19 @@ add_task(async function test() { EventUtils.synthesizeMouseAtCenter(newTabButton, {}); openEvent = await promiseTabOpened; newTab = openEvent.target; + previous = gBrowser.tabContainer.findNextTab(newTab, { direction: -1 }); is( - newTab.previousElementSibling, + previous, tab3, "New tab should be opened after tab3 when ctrlKey is not used without multiselection" ); is( newTab.nextElementSibling, null, + next = gBrowser.tabContainer.findNextTab(newTab, { direction: 1 }); + is( + next, + null, "New tab should be opened at the end of the tabstrip when ctrlKey is not used without multiselection" ); BrowserTestUtils.removeTab(newTab); @@ -131,14 +133,19 @@ add_task(async function test() { EventUtils.synthesizeMouseAtCenter(newTabButton, {}); openEvent = await promiseTabOpened; newTab = openEvent.target; + previous = gBrowser.tabContainer.findNextTab(newTab, { direction: -1 }); is( - newTab.previousElementSibling, + previous, tab3, "New tab should be opened after tab3 when ctrlKey is not used with multiselection" ); is( newTab.nextElementSibling, null, + next = gBrowser.tabContainer.findNextTab(newTab, { direction: 1 }); + is( + next, + null, "New tab should be opened at the end of the tabstrip when ctrlKey is not used with multiselection" ); BrowserTestUtils.removeTab(newTab); diff --git a/browser/base/content/test/tabs/browser_overflowScroll.js b/browser/base/content/test/tabs/browser_overflowScroll.js index e6953684a9..a1c420d1e4 100644 --- a/browser/base/content/test/tabs/browser_overflowScroll.js +++ b/browser/base/content/test/tabs/browser_overflowScroll.js @@ -10,7 +10,6 @@ add_task(async function() { let arrowScrollbox = gBrowser.tabContainer.arrowScrollbox; let scrollbox = arrowScrollbox.scrollbox; let originalSmoothScroll = arrowScrollbox.smoothScroll; - let tabs = gBrowser.tabs; let tabMinWidth = parseInt( getComputedStyle(gBrowser.selectedTab, null).minWidth ); @@ -29,7 +28,7 @@ add_task(async function() { let elementFromPoint = x => arrowScrollbox._elementFromPoint(x); let nextLeftElement = () => elementFromPoint(left(scrollbox) - 1); let nextRightElement = () => elementFromPoint(right(scrollbox) + 1); - let firstScrollable = () => tabs[gBrowser._numPinnedTabs]; + let firstScrollable = () => gBrowser.tabs[gBrowser._numPinnedTabs]; let waitForNextFrame = async function() { await window.promiseDocumentFlushed(() => {}); await new Promise(resolve => Services.tm.dispatchToMainThread(resolve)); @@ -40,11 +39,11 @@ add_task(async function() { arrowScrollbox.smoothScroll = originalSmoothScroll; }); - while (tabs.length < tabCountForOverflow) { + while (gBrowser.tabs.length < tabCountForOverflow) { BrowserTestUtils.addTab(gBrowser, "about:blank", { skipAnimation: true }); } - gBrowser.pinTab(tabs[0]); + gBrowser.pinTab(gBrowser.tabs[0]); await BrowserTestUtils.waitForCondition(() => { return Array.from(gBrowser.tabs).every(tab => tab._fullyOpen); @@ -75,7 +74,7 @@ add_task(async function() { await waitForNextFrame(); isRight(element, "Scrolled one tab to the right with a single click"); - gBrowser.selectedTab = tabs[tabs.length - 1]; + gBrowser.selectedTab = gBrowser.tabs[gBrowser.tabs.length - 1]; await waitForNextFrame(); ok( right(gBrowser.selectedTab) <= right(scrollbox), @@ -116,7 +115,7 @@ add_task(async function() { ")" ); - while (tabs.length > 1) { + while (gBrowser.tabs.length > 1) { BrowserTestUtils.removeTab(gBrowser.tabs[0]); } }); diff --git a/browser/base/content/test/tabs/browser_tabCloseSpacer.js b/browser/base/content/test/tabs/browser_tabCloseSpacer.js index 80c351465d..4bb0092e16 100644 --- a/browser/base/content/test/tabs/browser_tabCloseSpacer.js +++ b/browser/base/content/test/tabs/browser_tabCloseSpacer.js @@ -80,11 +80,7 @@ async function overflowTabs() { function getLastCloseButton() { let lastTab = gBrowser.tabs[gBrowser.tabs.length - 1]; - return document.getAnonymousElementByAttribute( - lastTab, - "anonid", - "close-button" - ); + return lastTab.closeButton; } function getLastCloseButtonLocation() { diff --git a/browser/base/content/test/tabs/browser_tabReorder_overflow.js b/browser/base/content/test/tabs/browser_tabReorder_overflow.js index e37215fe85..59bff2026d 100644 --- a/browser/base/content/test/tabs/browser_tabReorder_overflow.js +++ b/browser/base/content/test/tabs/browser_tabReorder_overflow.js @@ -9,7 +9,6 @@ add_task(async function() { let initialTabsLength = gBrowser.tabs.length; let arrowScrollbox = gBrowser.tabContainer.arrowScrollbox; - let tabs = gBrowser.tabs; let tabMinWidth = parseInt( getComputedStyle(gBrowser.selectedTab, null).minWidth ); @@ -34,40 +33,26 @@ add_task(async function() { { skipAnimation: true } )); - while (tabs.length < tabCountForOverflow) { + while (gBrowser.tabs.length < tabCountForOverflow) { BrowserTestUtils.addTab(gBrowser, "about:blank", { skipAnimation: true }); } registerCleanupFunction(function() { - while (tabs.length > initialTabsLength) { - gBrowser.removeTab(gBrowser.tabs[initialTabsLength]); + while (gBrowser.tabs.length > initialTabsLength) { + gBrowser.removeTab(gBrowser.tabContainer.getItemAtIndex(initialTabsLength)); } }); - is(gBrowser.tabs.length, tabCountForOverflow, "new tabs are opened"); - is(gBrowser.tabs[initialTabsLength], newTab1, "newTab1 position is correct"); - is( - gBrowser.tabs[initialTabsLength + 1], - newTab2, - "newTab2 position is correct" - ); - is( - gBrowser.tabs[initialTabsLength + 2], - newTab3, - "newTab3 position is correct" - ); + let tabs = gBrowser.tabs; + is(tabs.length, tabCountForOverflow, "new tabs are opened"); + is(tabs[initialTabsLength], newTab1, "newTab1 position is correct"); + is(tabs[initialTabsLength + 1], newTab2, "newTab2 position is correct"); + is(tabs[initialTabsLength + 2], newTab3, "newTab3 position is correct"); await dragAndDrop(newTab1, newTab2, false); - is(gBrowser.tabs.length, tabCountForOverflow, "tabs are still there"); - is( - gBrowser.tabs[initialTabsLength], - newTab2, - "newTab2 and newTab1 are swapped" - ); - is( - gBrowser.tabs[initialTabsLength + 1], - newTab1, - "newTab1 and newTab2 are swapped" - ); - is(gBrowser.tabs[initialTabsLength + 2], newTab3, "newTab3 stays same place"); + tabs = gBrowser.tabs; + is(tabs.length, tabCountForOverflow, "tabs are still there"); + is(tabs[initialTabsLength], newTab2, "newTab2 and newTab1 are swapped"); + is(tabs[initialTabsLength + 1], newTab1, "newTab1 and newTab2 are swapped"); + is(tabs[initialTabsLength + 2], newTab3, "newTab3 stays same place"); }); diff --git a/browser/base/content/test/tabs/browser_tab_a11y_description.js b/browser/base/content/test/tabs/browser_tab_a11y_description.js new file mode 100644 index 0000000000..ca7a278f33 --- /dev/null +++ b/browser/base/content/test/tabs/browser_tab_a11y_description.js @@ -0,0 +1,82 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const PREF_MULTISELECT_TABS = "browser.tabs.multiselect"; + +async function waitForFocusAfterKey(ariaFocus, element, key, accel = false) { + let event = ariaFocus ? "AriaFocus" : "focus"; + let friendlyKey = key; + if (accel) { + friendlyKey = "Accel+" + key; + } + key = "KEY_" + key; + let focused = BrowserTestUtils.waitForEvent(element, event); + EventUtils.synthesizeKey(key, { accelKey: accel }); + await focused; + ok(true, element.label + " got " + event + " after " + friendlyKey); +} + +function getA11yDescription(element) { + let descId = element.getAttribute("aria-describedby"); + if (!descId) { + return null; + } + let descElem = document.getElementById(descId); + if (!descElem) { + return null; + } + return descElem.textContent; +} + +add_task(async function setup() { + await SpecialPowers.pushPrefEnv({ + set: [[PREF_MULTISELECT_TABS, true]], + }); +}); + +add_task(async function testTabA11yDescription() { + const tab1 = await addTab("http://mochi.test:8888/1", { userContextId: 1 }); + tab1.label = "tab1"; + const context1 = ContextualIdentityService.getUserContextLabel(1); + const tab2 = await addTab("http://mochi.test:8888/2", { userContextId: 2 }); + tab2.label = "tab2"; + const context2 = ContextualIdentityService.getUserContextLabel(2); + + await BrowserTestUtils.switchTab(gBrowser, tab1); + let focused = BrowserTestUtils.waitForEvent(tab1, "focus"); + tab1.focus(); + await focused; + ok(true, "tab1 initially focused"); + ok( + getA11yDescription(tab1).endsWith(context1), + "tab1 has correct a11y description" + ); + ok(!getA11yDescription(tab2), "tab2 has no a11y description"); + + info("Moving DOM focus to tab2"); + await waitForFocusAfterKey(false, tab2, "ArrowRight"); + ok( + getA11yDescription(tab2).endsWith(context2), + "tab2 has correct a11y description" + ); + ok(!getA11yDescription(tab1), "tab1 has no a11y description"); + + info("Moving ARIA focus to tab1"); + await waitForFocusAfterKey(true, tab1, "ArrowLeft", true); + ok( + getA11yDescription(tab1).endsWith(context1), + "tab1 has correct a11y description" + ); + ok(!getA11yDescription(tab2), "tab2 has no a11y description"); + + info("Removing ARIA focus (reverting to DOM focus)"); + await waitForFocusAfterKey(true, tab2, "ArrowRight"); + ok( + getA11yDescription(tab2).endsWith(context2), + "tab2 has correct a11y description" + ); + ok(!getA11yDescription(tab1), "tab1 has no a11y description"); + + BrowserTestUtils.removeTab(tab1); + BrowserTestUtils.removeTab(tab2); +}); diff --git a/browser/base/content/test/trackingUI/benignPage.html b/browser/base/content/test/trackingUI/benignPage.html deleted file mode 100644 index 0be1cbc1c7..0000000000 --- a/browser/base/content/test/trackingUI/benignPage.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/browser/base/content/test/trackingUI/browser.ini b/browser/base/content/test/trackingUI/browser.ini deleted file mode 100644 index 42a92ed4df..0000000000 --- a/browser/base/content/test/trackingUI/browser.ini +++ /dev/null @@ -1,37 +0,0 @@ -[DEFAULT] -tags = trackingprotection -support-files = - head.js - benignPage.html - containerPage.html - cookiePage.html - cookieSetterPage.html - cookieServer.sjs - embeddedPage.html - trackingAPI.js - trackingPage.html - -[browser_trackingUI_3.js] -[browser_trackingUI_animation.js] -[browser_trackingUI_animation_2.js] -[browser_trackingUI_appMenu.js] -[browser_trackingUI_background_tabs.js] -[browser_trackingUI_categories.js] -[browser_trackingUI_cookies_subview.js] -[browser_trackingUI_cryptominers.js] -[browser_trackingUI_fetch.js] -support-files = - file_trackingUI_fetch.html - file_trackingUI_fetch.js - file_trackingUI_fetch.js^headers^ -[browser_trackingUI_fingerprinters.js] -[browser_trackingUI_open_preferences.js] -[browser_trackingUI_pbmode_exceptions.js] -[browser_trackingUI_report_breakage.js] -skip-if = os == 'linux' && (debug || asan) # Bug 1546797 -[browser_trackingUI_state.js] -skip-if = serviceworker_e10s # see https://bugzilla.mozilla.org/show_bug.cgi?id=1511303#c1 -[browser_trackingUI_state_all_disabled.js] -[browser_trackingUI_state_reset.js] -[browser_trackingUI_telemetry.js] -[browser_trackingUI_trackers_subview.js] diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_3.js b/browser/base/content/test/trackingUI/browser_trackingUI_3.js deleted file mode 100644 index 7621a0c6be..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_3.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Test that the Tracking Protection is correctly enabled / disabled - * in both normal and private windows given all possible states of the prefs: - * privacy.trackingprotection.enabled - * privacy.trackingprotection.pbmode.enabled - * See also Bug 1178985. - */ - -const PREF = "privacy.trackingprotection.enabled"; -const PB_PREF = "privacy.trackingprotection.pbmode.enabled"; - -registerCleanupFunction(function() { - Services.prefs.clearUserPref(PREF); - Services.prefs.clearUserPref(PB_PREF); -}); - -add_task(async function testNormalBrowsing() { - let TrackingProtection = gBrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the browser window"); - - Services.prefs.setBoolPref(PREF, true); - Services.prefs.setBoolPref(PB_PREF, false); - ok(TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=false)"); - Services.prefs.setBoolPref(PB_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=true)"); - - Services.prefs.setBoolPref(PREF, false); - Services.prefs.setBoolPref(PB_PREF, false); - ok(!TrackingProtection.enabled, "TP is disabled (ENABLED=false,PB=false)"); - Services.prefs.setBoolPref(PB_PREF, true); - ok(!TrackingProtection.enabled, "TP is disabled (ENABLED=false,PB=true)"); -}); - -add_task(async function testPrivateBrowsing() { - let privateWin = await BrowserTestUtils.openNewBrowserWindow({ - private: true, - }); - let TrackingProtection = privateWin.gBrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the browser window"); - - Services.prefs.setBoolPref(PREF, true); - Services.prefs.setBoolPref(PB_PREF, false); - ok(TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=false)"); - Services.prefs.setBoolPref(PB_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled (ENABLED=true,PB=true)"); - - Services.prefs.setBoolPref(PREF, false); - Services.prefs.setBoolPref(PB_PREF, false); - ok(!TrackingProtection.enabled, "TP is disabled (ENABLED=false,PB=false)"); - Services.prefs.setBoolPref(PB_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled (ENABLED=false,PB=true)"); - - privateWin.close(); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_animation.js b/browser/base/content/test/trackingUI/browser_trackingUI_animation.js deleted file mode 100644 index 6fbc4ac25f..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_animation.js +++ /dev/null @@ -1,65 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const TP_PREF = "privacy.trackingprotection.enabled"; -const ANIMATIONS_PREF = "toolkit.cosmeticAnimations.enabled"; -const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications"; - -// Test that the shield icon animation can be controlled by the cosmetic -// animations pref and that one of the icons is visible in each case. -add_task(async function testShieldAnimation() { - await UrlClassifierTestUtils.addTestTrackers(); - Services.prefs.setBoolPref(TP_PREF, true); - Services.prefs.setBoolPref(DTSCBN_PREF, true); - - let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser)); - - let animationIcon = document.getElementById( - "tracking-protection-icon-animatable-image" - ); - let noAnimationIcon = document.getElementById("tracking-protection-icon"); - - Services.prefs.setBoolPref(ANIMATIONS_PREF, true); - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2, tab.linkedBrowser.ownerGlobal), - ]); - ok( - BrowserTestUtils.is_hidden(noAnimationIcon), - "the default icon is hidden when animations are enabled" - ); - ok( - BrowserTestUtils.is_visible(animationIcon), - "the animated icon is shown when animations are enabled" - ); - - await promiseTabLoadEvent(tab, BENIGN_PAGE); - ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden"); - ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden"); - - Services.prefs.setBoolPref(ANIMATIONS_PREF, false); - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2, tab.linkedBrowser.ownerGlobal), - ]); - ok( - BrowserTestUtils.is_visible(noAnimationIcon), - "the default icon is shown when animations are disabled" - ); - ok( - BrowserTestUtils.is_hidden(animationIcon), - "the animated icon is hidden when animations are disabled" - ); - - gBrowser.removeCurrentTab(); - Services.prefs.clearUserPref(ANIMATIONS_PREF); - Services.prefs.clearUserPref(TP_PREF); - Services.prefs.clearUserPref(DTSCBN_PREF); - UrlClassifierTestUtils.cleanupTestTrackers(); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_animation_2.js b/browser/base/content/test/trackingUI/browser_trackingUI_animation_2.js deleted file mode 100644 index a0c37042c3..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_animation_2.js +++ /dev/null @@ -1,228 +0,0 @@ -/* eslint-disable mozilla/no-arbitrary-setTimeout */ -/* - * Test that the Content Blocking icon is properly animated in the identity - * block when loading tabs and switching between tabs. - * See also Bug 1175858. - */ - -const TP_PREF = "privacy.trackingprotection.enabled"; -const TP_PB_PREF = "privacy.trackingprotection.enabled"; -const NCB_PREF = "network.cookie.cookieBehavior"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const COOKIE_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/cookiePage.html"; -const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications"; - -requestLongerTimeout(2); - -registerCleanupFunction(function() { - UrlClassifierTestUtils.cleanupTestTrackers(); - Services.prefs.clearUserPref(TP_PREF); - Services.prefs.clearUserPref(TP_PB_PREF); - Services.prefs.clearUserPref(NCB_PREF); - Services.prefs.clearUserPref(DTSCBN_PREF); -}); - -async function testTrackingProtectionAnimation(tabbrowser) { - Services.prefs.setBoolPref(DTSCBN_PREF, true); - - info("Load a test page not containing tracking elements"); - let benignTab = await BrowserTestUtils.openNewForegroundTab( - tabbrowser, - BENIGN_PAGE - ); - let ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking; - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "iconBox not active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - info("Load a test page containing tracking elements"); - let trackingTab = await BrowserTestUtils.openNewForegroundTab( - tabbrowser, - TRACKING_PAGE - ); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating"); - await BrowserTestUtils.waitForEvent( - ContentBlocking.animatedIcon, - "animationend" - ); - - info("Load a test page containing tracking cookies"); - let trackingCookiesTab = await BrowserTestUtils.openNewForegroundTab( - tabbrowser, - COOKIE_PAGE - ); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating"); - await BrowserTestUtils.waitForEvent( - ContentBlocking.animatedIcon, - "animationend" - ); - - info("Switch from tracking cookie -> benign tab"); - let securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - tabbrowser.selectedTab = benignTab; - await securityChanged; - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "iconBox not active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - info("Switch from benign -> tracking tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - tabbrowser.selectedTab = trackingTab; - await securityChanged; - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - info("Switch from tracking -> tracking cookies tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - tabbrowser.selectedTab = trackingCookiesTab; - await securityChanged; - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - info("Reload tracking cookies tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - let contentBlockingEvent = waitForContentBlockingEvent( - 2, - tabbrowser.ownerGlobal - ); - tabbrowser.reload(); - await Promise.all([securityChanged, contentBlockingEvent]); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating"); - await BrowserTestUtils.waitForEvent( - ContentBlocking.animatedIcon, - "animationend" - ); - - info("Reload tracking tab"); - securityChanged = waitForSecurityChange(2, tabbrowser.ownerGlobal); - contentBlockingEvent = waitForContentBlockingEvent(3, tabbrowser.ownerGlobal); - tabbrowser.selectedTab = trackingTab; - tabbrowser.reload(); - await Promise.all([securityChanged, contentBlockingEvent]); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox animating"); - await BrowserTestUtils.waitForEvent( - ContentBlocking.animatedIcon, - "animationend" - ); - - info("Inject tracking cookie inside tracking tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - let timeoutPromise = new Promise(resolve => setTimeout(resolve, 500)); - await ContentTask.spawn(tabbrowser.selectedBrowser, {}, function() { - content.postMessage("cookie", "*"); - }); - let result = await Promise.race([securityChanged, timeoutPromise]); - is(result, undefined, "No securityChange events should be received"); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - info("Inject tracking element inside tracking tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - timeoutPromise = new Promise(resolve => setTimeout(resolve, 500)); - await ContentTask.spawn(tabbrowser.selectedBrowser, {}, function() { - content.postMessage("tracking", "*"); - }); - result = await Promise.race([securityChanged, timeoutPromise]); - is(result, undefined, "No securityChange events should be received"); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - tabbrowser.selectedTab = trackingCookiesTab; - - info("Inject tracking cookie inside tracking cookies tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - timeoutPromise = new Promise(resolve => setTimeout(resolve, 500)); - await ContentTask.spawn(tabbrowser.selectedBrowser, {}, function() { - content.postMessage("cookie", "*"); - }); - result = await Promise.race([securityChanged, timeoutPromise]); - is(result, undefined, "No securityChange events should be received"); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - info("Inject tracking element inside tracking cookies tab"); - securityChanged = waitForSecurityChange(1, tabbrowser.ownerGlobal); - timeoutPromise = new Promise(resolve => setTimeout(resolve, 500)); - await ContentTask.spawn(tabbrowser.selectedBrowser, {}, function() { - content.postMessage("tracking", "*"); - }); - result = await Promise.race([securityChanged, timeoutPromise]); - is(result, undefined, "No securityChange events should be received"); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active"); - ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating"); - - while (tabbrowser.tabs.length > 1) { - tabbrowser.removeCurrentTab(); - } -} - -add_task(async function testNormalBrowsing() { - await UrlClassifierTestUtils.addTestTrackers(); - - let ContentBlocking = gBrowser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the browser window"); - let TrackingProtection = gBrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the browser window"); - let ThirdPartyCookies = gBrowser.ownerGlobal.ThirdPartyCookies; - ok(ThirdPartyCookies, "TPC is attached to the browser window"); - - Services.prefs.setBoolPref(TP_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled after setting the pref"); - Services.prefs.setIntPref( - NCB_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - ok( - ThirdPartyCookies.enabled, - "ThirdPartyCookies is enabled after setting the pref" - ); - - await testTrackingProtectionAnimation(gBrowser); -}); - -add_task(async function testPrivateBrowsing() { - let privateWin = await BrowserTestUtils.openNewBrowserWindow({ - private: true, - }); - let tabbrowser = privateWin.gBrowser; - - let ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the private window"); - let TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the private window"); - let ThirdPartyCookies = tabbrowser.ownerGlobal.ThirdPartyCookies; - ok(ThirdPartyCookies, "TPC is attached to the browser window"); - - Services.prefs.setBoolPref(TP_PB_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled after setting the pref"); - Services.prefs.setIntPref( - NCB_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - ok( - ThirdPartyCookies.enabled, - "ThirdPartyCookies is enabled after setting the pref" - ); - - await testTrackingProtectionAnimation(tabbrowser); - - privateWin.close(); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_appMenu.js b/browser/base/content/test/trackingUI/browser_trackingUI_appMenu.js deleted file mode 100644 index ba34f7c63d..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_appMenu.js +++ /dev/null @@ -1,38 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -ChromeUtils.import( - "resource://testing-common/CustomizableUITestUtils.jsm", - this -); - -// Test that the "Tracking Protection" button in the app menu loads about:preferences -add_task(async function testPreferencesButton() { - let cuiTestUtils = new CustomizableUITestUtils(window); - - await BrowserTestUtils.withNewTab(gBrowser, async function(browser) { - await cuiTestUtils.openMainMenu(); - - let loaded = TestUtils.waitForCondition( - () => gBrowser.currentURI.spec == "about:preferences#privacy", - "Should open about:preferences." - ); - document.getElementById("appMenu-tp-label").click(); - await loaded; - - await ContentTask.spawn(browser, {}, async function() { - let doc = content.document; - let section = await ContentTaskUtils.waitForCondition( - () => doc.querySelector(".spotlight"), - "The spotlight should appear." - ); - is( - section.getAttribute("data-subcategory"), - "trackingprotection", - "The trackingprotection section is spotlighted." - ); - }); - }); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js b/browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js deleted file mode 100644 index d6fc1f1a26..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js +++ /dev/null @@ -1,69 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; - -const TP_PREF = "privacy.trackingprotection.enabled"; - -add_task(async function testBackgroundTabs() { - info( - "Testing receiving and storing content blocking events in non-selected tabs." - ); - - await SpecialPowers.pushPrefEnv({ - set: [[TP_PREF, true]], - }); - await UrlClassifierTestUtils.addTestTrackers(); - - registerCleanupFunction(() => { - UrlClassifierTestUtils.cleanupTestTrackers(); - }); - - let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE); - - let backgroundTab = BrowserTestUtils.addTab(gBrowser); - let browser = backgroundTab.linkedBrowser; - let hasContentBlockingEvent = TestUtils.waitForCondition( - () => browser.securityUI.contentBlockingEvent != 0 - ); - await promiseTabLoadEvent(backgroundTab, TRACKING_PAGE); - await hasContentBlockingEvent; - - is( - browser.securityUI.contentBlockingEvent, - Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, - "Background tab has the correct content blocking event." - ); - - is( - tab.linkedBrowser.securityUI.contentBlockingEvent, - 0, - "Foreground tab has the correct content blocking event." - ); - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - await BrowserTestUtils.switchTab(gBrowser, backgroundTab); - - is( - browser.securityUI.contentBlockingEvent, - Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, - "Background tab still has the correct content blocking event." - ); - - is( - tab.linkedBrowser.securityUI.contentBlockingEvent, - 0, - "Foreground tab still has the correct content blocking event." - ); - - ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - - gBrowser.removeTab(backgroundTab); - gBrowser.removeTab(tab); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_categories.js b/browser/base/content/test/trackingUI/browser_trackingUI_categories.js deleted file mode 100644 index 32cdcb5f07..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_categories.js +++ /dev/null @@ -1,303 +0,0 @@ -const CAT_PREF = "browser.contentblocking.category"; -const TP_PREF = "privacy.trackingprotection.enabled"; -const TP_PB_PREF = "privacy.trackingprotection.pbmode.enabled"; -const TPC_PREF = "network.cookie.cookieBehavior"; -const CM_PREF = "privacy.trackingprotection.cryptomining.enabled"; -const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled"; - -ChromeUtils.import( - "resource://testing-common/CustomizableUITestUtils.jsm", - this -); - -registerCleanupFunction(function() { - Services.prefs.clearUserPref(TP_PREF); - Services.prefs.clearUserPref(TP_PB_PREF); - Services.prefs.clearUserPref(TPC_PREF); - Services.prefs.clearUserPref(CAT_PREF); - Services.prefs.clearUserPref(CM_PREF); - Services.prefs.clearUserPref(FP_PREF); -}); - -add_task(async function testCategoryLabelsInControlPanel() { - await BrowserTestUtils.withNewTab("http://www.example.com", async function() { - await openIdentityPopup(); - - let preferencesButton = document.getElementById( - "tracking-protection-preferences-button" - ); - ok(preferencesButton.label, "The preferencesButton label exists"); - - Services.prefs.setStringPref(CAT_PREF, "strict"); - await TestUtils.waitForCondition( - () => - preferencesButton.label == - gNavigatorBundle.getString("contentBlocking.category.strict") - ); - is( - preferencesButton.label, - gNavigatorBundle.getString("contentBlocking.category.strict"), - "The preferencesButton label has been changed to strict" - ); - - Services.prefs.setStringPref(CAT_PREF, "standard"); - await TestUtils.waitForCondition( - () => - preferencesButton.label == - gNavigatorBundle.getString("contentBlocking.category.standard") - ); - is( - preferencesButton.label, - gNavigatorBundle.getString("contentBlocking.category.standard"), - "The preferencesButton label has been changed to standard" - ); - - Services.prefs.setStringPref(CAT_PREF, "custom"); - await TestUtils.waitForCondition( - () => - preferencesButton.label == - gNavigatorBundle.getString("contentBlocking.category.custom") - ); - is( - preferencesButton.label, - gNavigatorBundle.getString("contentBlocking.category.custom"), - "The preferencesButton label has been changed to custom" - ); - }); -}); - -add_task(async function testCategoryLabelsInAppMenu() { - await BrowserTestUtils.withNewTab("http://www.example.com", async function() { - let cuiTestUtils = new CustomizableUITestUtils(window); - await cuiTestUtils.openMainMenu(); - - let appMenuCategoryLabel = document.getElementById("appMenu-tp-category"); - ok(appMenuCategoryLabel.value, "The appMenuCategory label exists"); - - Services.prefs.setStringPref(CAT_PREF, "strict"); - await TestUtils.waitForCondition( - () => - appMenuCategoryLabel.value == - gNavigatorBundle.getString("contentBlocking.category.strict") - ); - is( - appMenuCategoryLabel.value, - gNavigatorBundle.getString("contentBlocking.category.strict"), - "The appMenuCategory label has been changed to strict" - ); - - Services.prefs.setStringPref(CAT_PREF, "standard"); - await TestUtils.waitForCondition( - () => - appMenuCategoryLabel.value == - gNavigatorBundle.getString("contentBlocking.category.standard") - ); - is( - appMenuCategoryLabel.value, - gNavigatorBundle.getString("contentBlocking.category.standard"), - "The appMenuCategory label has been changed to standard" - ); - - Services.prefs.setStringPref(CAT_PREF, "custom"); - await TestUtils.waitForCondition( - () => - appMenuCategoryLabel.value == - gNavigatorBundle.getString("contentBlocking.category.custom") - ); - is( - appMenuCategoryLabel.value, - gNavigatorBundle.getString("contentBlocking.category.custom"), - "The appMenuCategory label has been changed to custom" - ); - }); -}); - -add_task(async function testSubcategoryLabels() { - SpecialPowers.pushPrefEnv({ - set: [ - ["browser.contentblocking.control-center.ui.showAllowedLabels", true], - ["browser.contentblocking.control-center.ui.showBlockedLabels", true], - ], - }); - - await BrowserTestUtils.withNewTab("http://www.example.com", async function() { - let categoryLabel = document.getElementById( - "identity-popup-content-blocking-tracking-protection-state-label" - ); - - Services.prefs.setBoolPref(TP_PREF, true); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString("contentBlocking.trackers.blocking.label"), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.trackers.blocking.label") - ); - - Services.prefs.setBoolPref(TP_PREF, false); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString("contentBlocking.trackers.allowed.label"), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.trackers.allowed.label") - ); - - categoryLabel = document.getElementById( - "identity-popup-content-blocking-cookies-state-label" - ); - - Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString("contentBlocking.cookies.allowed.label"), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.cookies.allowed.label") - ); - - Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString("contentBlocking.cookies.blockingAll.label"), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.cookies.blockingAll.label") - ); - - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN - ); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.cookies.blocking3rdParty.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString( - "contentBlocking.cookies.blocking3rdParty.label" - ) - ); - - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.cookies.blockingTrackers.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString( - "contentBlocking.cookies.blockingTrackers.label" - ) - ); - - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN - ); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.cookies.blockingUnvisited.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString( - "contentBlocking.cookies.blockingUnvisited.label" - ) - ); - - categoryLabel = document.getElementById( - "identity-popup-content-blocking-fingerprinters-state-label" - ); - - Services.prefs.setBoolPref(FP_PREF, true); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.fingerprinters.blocking.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString( - "contentBlocking.fingerprinters.blocking.label" - ) - ); - - Services.prefs.setBoolPref(FP_PREF, false); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.fingerprinters.allowed.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.fingerprinters.allowed.label") - ); - - categoryLabel = document.getElementById( - "identity-popup-content-blocking-cryptominers-state-label" - ); - - Services.prefs.setBoolPref(CM_PREF, true); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.cryptominers.blocking.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.cryptominers.blocking.label") - ); - - Services.prefs.setBoolPref(CM_PREF, false); - await TestUtils.waitForCondition( - () => - categoryLabel.textContent == - gNavigatorBundle.getString( - "contentBlocking.cryptominers.allowed.label" - ), - "The category label has updated correctly" - ); - is( - categoryLabel.textContent, - gNavigatorBundle.getString("contentBlocking.cryptominers.allowed.label") - ); - }); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js b/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js deleted file mode 100644 index 6f102b9905..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js +++ /dev/null @@ -1,538 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -/* eslint-disable mozilla/no-arbitrary-setTimeout */ - -"use strict"; - -const COOKIE_PAGE = - "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookiePage.html"; -const CONTAINER_PAGE = - "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/containerPage.html"; - -const TPC_PREF = "network.cookie.cookieBehavior"; - -add_task(async function setup() { - await UrlClassifierTestUtils.addTestTrackers(); - - registerCleanupFunction(() => { - UrlClassifierTestUtils.cleanupTestTrackers(); - }); -}); - -async function assertSitesListed( - trackersBlocked, - thirdPartyBlocked, - firstPartyBlocked -) { - let promise = BrowserTestUtils.openNewForegroundTab({ - url: COOKIE_PAGE, - gBrowser, - }); - let specialCase = - firstPartyBlocked || - (trackersBlocked && thirdPartyBlocked && !firstPartyBlocked) || - (!trackersBlocked && !thirdPartyBlocked && !firstPartyBlocked); - let count = 4; - if (firstPartyBlocked) { - count = 6; - } else if (trackersBlocked && thirdPartyBlocked && !firstPartyBlocked) { - count = 5; - } else if (!trackersBlocked && !thirdPartyBlocked && !firstPartyBlocked) { - count = 3; - } - let [tab] = await Promise.all([promise, waitForContentBlockingEvent(count)]); - let browser = tab.linkedBrowser; - - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-cookies" - ); - ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); - let cookiesView = document.getElementById("identity-popup-cookiesView"); - let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - let listHeaders = cookiesView.querySelectorAll( - ".identity-popup-cookiesView-list-header" - ); - is(listHeaders.length, 3, "We have 3 list headers"); - - let emptyLabels = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-empty-label" - ); - if (specialCase) { - count = 1; - } else { - count = 2; - } - is(emptyLabels.length, count, `We have ${count} empty labels`); - - let listItems = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - if (specialCase) { - count = 2; - } else { - count = 1; - } - is(listItems.length, count, `We have ${count} cookie in the list`); - - let listItem = listItems[specialCase ? 1 : 0]; - let label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is(label.value, "http://trackertest.org", "Has an item for trackertest.org"); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !trackersBlocked, - "Indicates whether the cookie was blocked or allowed" - ); - - if (specialCase) { - listItem = listItems[0]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "http://not-tracking.example.com", - "Has an item for not-tracking.example.com" - ); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !firstPartyBlocked, - "Indicates whether the cookie was blocked" - ); - } - - let mainView = document.getElementById("identity-popup-mainView"); - viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - let backButton = cookiesView.querySelector(".subviewbutton-back"); - backButton.click(); - await viewShown; - - ok(true, "Main view was shown"); - - let change = waitForContentBlockingEvent(); - let timeoutPromise = new Promise(resolve => setTimeout(resolve, 1000)); - - await ContentTask.spawn(browser, {}, function() { - content.postMessage("third-party-cookie", "*"); - }); - - let result = await Promise.race([change, timeoutPromise]); - is(result, undefined, "No contentBlockingEvent events should be received"); - - viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - emptyLabels = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-empty-label" - ); - if (specialCase) { - count = 0; - } else { - count = 1; - } - is(emptyLabels.length, count, `We have ${count} empty label`); - - listItems = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - if (specialCase) { - count = 3; - } else { - count = 2; - } - is(listItems.length, count, `We have ${count} cookies in the list`); - - listItem = listItems[specialCase ? 2 : 1]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "https://test1.example.org", - "Has an item for test1.example.org" - ); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !thirdPartyBlocked, - "Indicates whether the cookie was blocked or allowed" - ); - - if (specialCase) { - listItem = listItems[1]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "http://trackertest.org", - "Has an item for trackertest.org" - ); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !trackersBlocked && !thirdPartyBlocked && !firstPartyBlocked, - "Indicates whether the cookie was blocked" - ); - } - - viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - backButton.click(); - await viewShown; - - ok(true, "Main view was shown"); - - change = waitForSecurityChange(); - timeoutPromise = new Promise(resolve => setTimeout(resolve, 1000)); - - await ContentTask.spawn(browser, {}, function() { - content.postMessage("first-party-cookie", "*"); - }); - - result = await Promise.race([change, timeoutPromise]); - is(result, undefined, "No securityChange events should be received"); - - viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - emptyLabels = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-empty-label" - ); - is(emptyLabels.length, 0, "We have 0 empty label"); - - listItems = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 3, "We have 2 cookies in the list"); - - listItem = listItems[0]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "http://not-tracking.example.com", - "Has an item for the first party" - ); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !firstPartyBlocked, - "Indicates whether the cookie was blocked or allowed" - ); - - BrowserTestUtils.removeTab(tab); -} - -add_task(async function testCookiesSubView() { - info("Testing cookies subview with reject tracking cookies."); - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - await assertSitesListed(true, false, false); - info("Testing cookies subview with reject third party cookies."); - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN - ); - await assertSitesListed(true, true, false); - info("Testing cookies subview with reject all cookies."); - Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT); - await assertSitesListed(true, true, true); - info("Testing cookies subview with accept all cookies."); - Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); - await assertSitesListed(false, false, false); - - Services.prefs.clearUserPref(TPC_PREF); -}); - -add_task(async function testCookiesSubViewAllowed() { - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin( - "http://trackertest.org/" - ); - Services.perms.addFromPrincipal( - principal, - "cookie", - Services.perms.ALLOW_ACTION - ); - - let promise = BrowserTestUtils.openNewForegroundTab({ - url: COOKIE_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent(3)]); - - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-cookies" - ); - ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); - let cookiesView = document.getElementById("identity-popup-cookiesView"); - let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - let listItems = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 2, "We have 1 cookie in the list"); - - let listItem = listItems[0]; - let label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "http://not-tracking.example.com", - "has an item for not-tracking.example.com" - ); - ok(BrowserTestUtils.is_visible(listItem), "list item is visible"); - ok( - listItem.classList.contains("allowed"), - "indicates whether the cookie was blocked or allowed" - ); - - listItem = listItems[1]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is(label.value, "http://trackertest.org", "has an item for trackertest.org"); - ok(BrowserTestUtils.is_visible(listItem), "list item is visible"); - ok( - listItem.classList.contains("allowed"), - "indicates whether the cookie was blocked or allowed" - ); - - let button = listItem.querySelector( - ".identity-popup-permission-remove-button" - ); - ok( - BrowserTestUtils.is_visible(button), - "Permission remove button is visible" - ); - button.click(); - is( - Services.perms.testExactPermissionFromPrincipal(principal, "cookie"), - Services.perms.UNKNOWN_ACTION, - "Button click should remove cookie pref." - ); - ok(!listItem.classList.contains("allowed"), "Has removed the allowed class"); - - BrowserTestUtils.removeTab(tab); - - Services.prefs.clearUserPref(TPC_PREF); -}); - -add_task(async function testCookiesSubViewAllowedHeuristic() { - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - let principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin( - "http://not-tracking.example.com/" - ); - - // Pretend that the tracker has already been interacted with - let trackerPrincipal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin( - "http://trackertest.org/" - ); - Services.perms.addFromPrincipal( - trackerPrincipal, - "storageAccessAPI", - Services.perms.ALLOW_ACTION - ); - - let promise = BrowserTestUtils.openNewForegroundTab({ - url: COOKIE_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent(5)]); - let browser = tab.linkedBrowser; - - let popup; - let windowCreated = TestUtils.topicObserved( - "chrome-document-global-created", - (subject, data) => { - popup = subject; - return true; - } - ); - let permChanged = TestUtils.topicObserved("perm-changed", (subject, data) => { - return ( - subject && - subject.QueryInterface(Ci.nsIPermission).type == - "3rdPartyStorage^http://trackertest.org" && - subject.principal.origin == principal.origin && - data == "added" - ); - }); - - await ContentTask.spawn(browser, {}, function() { - content.postMessage("window-open", "*"); - }); - await Promise.all([windowCreated, permChanged]); - - await new Promise(resolve => waitForFocus(resolve, popup)); - await new Promise(resolve => waitForFocus(resolve, window)); - - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-cookies" - ); - ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); - let cookiesView = document.getElementById("identity-popup-cookiesView"); - let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - let listItems = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 2, "We have 2 cookie in the list"); - - let listItem = listItems[0]; - let label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "http://not-tracking.example.com", - "has an item for not-tracking.example.com" - ); - ok(BrowserTestUtils.is_visible(listItem), "list item is visible"); - ok( - listItem.classList.contains("allowed"), - "indicates whether the cookie was blocked or allowed" - ); - - listItem = listItems[1]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is(label.value, "http://trackertest.org", "has an item for trackertest.org"); - ok(BrowserTestUtils.is_visible(listItem), "list item is visible"); - ok( - listItem.classList.contains("allowed"), - "indicates whether the cookie was blocked or allowed" - ); - - let button = listItem.querySelector( - ".identity-popup-permission-remove-button" - ); - ok( - BrowserTestUtils.is_visible(button), - "Permission remove button is visible" - ); - button.click(); - is( - Services.perms.testExactPermissionFromPrincipal( - principal, - "3rdPartyStorage^http://trackertest.org" - ), - Services.perms.UNKNOWN_ACTION, - "Button click should remove the storage pref." - ); - ok(!listItem.classList.contains("allowed"), "Has removed the allowed class"); - - await ContentTask.spawn(browser, {}, function() { - content.postMessage("window-close", "*"); - }); - - BrowserTestUtils.removeTab(tab); - - Services.prefs.clearUserPref(TPC_PREF); -}); - -add_task(async function testCookiesSubViewBlockedDoublyNested() { - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - - let promise = BrowserTestUtils.openNewForegroundTab({ - url: CONTAINER_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent(3)]); - - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-cookies" - ); - ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); - let cookiesView = document.getElementById("identity-popup-cookiesView"); - let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - let listItems = cookiesView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 2, "We have 2 cookie in the list"); - - let listItem = listItems[0]; - let label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is( - label.value, - "http://not-tracking.example.com", - "has an item for not-tracking.example.com" - ); - ok(BrowserTestUtils.is_visible(listItem), "list item is visible"); - ok( - listItem.classList.contains("allowed"), - "indicates whether the cookie was blocked or allowed" - ); - - listItem = listItems[1]; - label = listItem.querySelector( - ".identity-popup-content-blocking-list-host-label" - ); - is(label.value, "http://trackertest.org", "has an item for trackertest.org"); - ok(BrowserTestUtils.is_visible(listItem), "list item is visible"); - ok( - !listItem.classList.contains("allowed"), - "indicates whether the cookie was blocked or allowed" - ); - - let button = listItem.querySelector( - ".identity-popup-permission-remove-button" - ); - ok(!button, "Permission remove button doesn't exist"); - - BrowserTestUtils.removeTab(tab); - - Services.prefs.clearUserPref(TPC_PREF); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js b/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js deleted file mode 100644 index ebea135b80..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js +++ /dev/null @@ -1,204 +0,0 @@ -/* eslint-disable mozilla/no-arbitrary-setTimeout */ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TRACKING_PAGE = - "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const CM_PROTECTION_PREF = "privacy.trackingprotection.cryptomining.enabled"; -const CM_ANNOTATION_PREF = - "privacy.trackingprotection.cryptomining.annotate.enabled"; -let cmHistogram; - -add_task(async function setup() { - await SpecialPowers.pushPrefEnv({ - set: [ - [ - "urlclassifier.features.cryptomining.blacklistHosts", - "cryptomining.example.com", - ], - [ - "urlclassifier.features.cryptomining.annotate.blacklistHosts", - "cryptomining.example.com", - ], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.annotate_channels", false], - ["privacy.trackingprotection.fingerprinting.enabled", false], - ["privacy.trackingprotection.fingerprinting.annotate.enabled", false], - ], - }); - cmHistogram = Services.telemetry.getHistogramById( - "CRYPTOMINERS_BLOCKED_COUNT" - ); - registerCleanupFunction(() => { - cmHistogram.clear(); - }); -}); - -async function testIdentityState(hasException) { - cmHistogram.clear(); - let promise = BrowserTestUtils.openNewForegroundTab({ - url: TRACKING_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.disableForCurrentPage(); - await loaded; - } - - ok( - !ContentBlocking.content.hasAttribute("detected"), - "cryptominers are not detected" - ); - ok( - BrowserTestUtils.is_hidden(ContentBlocking.iconBox), - "icon box is not visible" - ); - - promise = waitForContentBlockingEvent(); - - await ContentTask.spawn(tab.linkedBrowser, {}, function() { - content.postMessage("cryptomining", "*"); - }); - - await promise; - - ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); - ok( - BrowserTestUtils.is_visible(ContentBlocking.iconBox), - "icon box is visible" - ); - is( - ContentBlocking.iconBox.hasAttribute("hasException"), - hasException, - "Shows an exception when appropriate" - ); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.enableForCurrentPage(); - await loaded; - } - - let loads = hasException ? 3 : 1; - testTelemetry(loads, 1, hasException); - - BrowserTestUtils.removeTab(tab); -} - -async function testSubview(hasException) { - cmHistogram.clear(); - let promise = BrowserTestUtils.openNewForegroundTab({ - url: TRACKING_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.disableForCurrentPage(); - await loaded; - } - - promise = waitForContentBlockingEvent(); - await ContentTask.spawn(tab.linkedBrowser, {}, function() { - content.postMessage("cryptomining", "*"); - }); - await promise; - - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-cryptominers" - ); - ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); - let subview = document.getElementById("identity-popup-cryptominersView"); - let viewShown = BrowserTestUtils.waitForEvent(subview, "ViewShown"); - categoryItem.click(); - await viewShown; - - let listItems = subview.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 1, "We have 1 item in the list"); - let listItem = listItems[0]; - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.querySelector("label").value, - "cryptomining.example.com", - "Has the correct host" - ); - is( - listItem.classList.contains("allowed"), - hasException, - "Indicates the miner was blocked or allowed" - ); - - let mainView = document.getElementById("identity-popup-mainView"); - viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - let backButton = subview.querySelector(".subviewbutton-back"); - backButton.click(); - await viewShown; - - ok(true, "Main view was shown"); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.enableForCurrentPage(); - await loaded; - } - - let loads = hasException ? 3 : 1; - testTelemetry(loads, 1, hasException); - - BrowserTestUtils.removeTab(tab); -} - -function testTelemetry(pagesVisited, pagesWithBlockableContent, hasException) { - let results = cmHistogram.snapshot(); - Assert.equal( - results.values[0], - pagesVisited, - "The correct number of page loads have been recorded" - ); - let expectedValue = hasException ? 2 : 1; - Assert.equal( - results.values[expectedValue], - pagesWithBlockableContent, - "The correct number of cryptominers have been recorded as blocked or allowed." - ); -} - -add_task(async function test() { - Services.prefs.setBoolPref(CM_PROTECTION_PREF, true); - Services.prefs.setBoolPref(CM_ANNOTATION_PREF, true); - - await testIdentityState(false); - await testIdentityState(true); - - await testSubview(false); - await testSubview(true); - - Services.prefs.clearUserPref(CM_PROTECTION_PREF); - Services.prefs.clearUserPref(CM_ANNOTATION_PREF); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js b/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js deleted file mode 100644 index 2c94546e5e..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_fetch.js +++ /dev/null @@ -1,35 +0,0 @@ -const URL = - "http://mochi.test:8888/browser/browser/base/content/test/trackingUI/file_trackingUI_fetch.html"; - -add_task(async function test_fetch() { - await SpecialPowers.pushPrefEnv({ - set: [["privacy.trackingprotection.enabled", true]], - }); - - await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function( - newTabBrowser - ) { - let contentBlockingEvent = waitForContentBlockingEvent(); - await ContentTask.spawn(newTabBrowser, null, async function() { - await content.wrappedJSObject - .test_fetch() - .then(response => Assert.ok(false, "should have denied the request")) - .catch(e => Assert.ok(true, `Caught exception: ${e}`)); - }); - await contentBlockingEvent; - - let ContentBlocking = newTabBrowser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "got CB object"); - - ok( - ContentBlocking.content.hasAttribute("detected"), - "has detected content blocking" - ); - ok(ContentBlocking.iconBox.hasAttribute("active"), "icon box is active"); - is( - ContentBlocking.iconBox.getAttribute("tooltiptext"), - gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), - "correct tooltip" - ); - }); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js b/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js deleted file mode 100644 index d976b56a6e..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js +++ /dev/null @@ -1,204 +0,0 @@ -/* eslint-disable mozilla/no-arbitrary-setTimeout */ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TRACKING_PAGE = - "http://example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const FP_PROTECTION_PREF = "privacy.trackingprotection.fingerprinting.enabled"; -const FP_ANNOTATION_PREF = - "privacy.trackingprotection.fingerprinting.annotate.enabled"; -let fpHistogram; - -add_task(async function setup() { - await SpecialPowers.pushPrefEnv({ - set: [ - [ - "urlclassifier.features.fingerprinting.blacklistHosts", - "fingerprinting.example.com", - ], - [ - "urlclassifier.features.fingerprinting.annotate.blacklistHosts", - "fingerprinting.example.com", - ], - ["privacy.trackingprotection.enabled", false], - ["privacy.trackingprotection.annotate_channels", false], - ["privacy.trackingprotection.cryptomining.enabled", false], - ["privacy.trackingprotection.cryptomining.annotate.enabled", false], - ], - }); - fpHistogram = Services.telemetry.getHistogramById( - "FINGERPRINTERS_BLOCKED_COUNT" - ); - registerCleanupFunction(() => { - fpHistogram.clear(); - }); -}); - -async function testIdentityState(hasException) { - fpHistogram.clear(); - let promise = BrowserTestUtils.openNewForegroundTab({ - url: TRACKING_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.disableForCurrentPage(); - await loaded; - } - - ok( - !ContentBlocking.content.hasAttribute("detected"), - "fingerprinters are not detected" - ); - ok( - BrowserTestUtils.is_hidden(ContentBlocking.iconBox), - "icon box is not visible" - ); - - promise = waitForContentBlockingEvent(); - - await ContentTask.spawn(tab.linkedBrowser, {}, function() { - content.postMessage("fingerprinting", "*"); - }); - - await promise; - - ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); - ok( - BrowserTestUtils.is_visible(ContentBlocking.iconBox), - "icon box is visible" - ); - is( - ContentBlocking.iconBox.hasAttribute("hasException"), - hasException, - "Shows an exception when appropriate" - ); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.enableForCurrentPage(); - await loaded; - } - - let loads = hasException ? 3 : 1; - testTelemetry(loads, 1, hasException); - - BrowserTestUtils.removeTab(tab); -} - -async function testSubview(hasException) { - fpHistogram.clear(); - let promise = BrowserTestUtils.openNewForegroundTab({ - url: TRACKING_PAGE, - gBrowser, - }); - let [tab] = await Promise.all([promise, waitForContentBlockingEvent()]); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.disableForCurrentPage(); - await loaded; - } - - promise = waitForContentBlockingEvent(); - await ContentTask.spawn(tab.linkedBrowser, {}, function() { - content.postMessage("fingerprinting", "*"); - }); - await promise; - - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-fingerprinters" - ); - ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible"); - let subview = document.getElementById("identity-popup-fingerprintersView"); - let viewShown = BrowserTestUtils.waitForEvent(subview, "ViewShown"); - categoryItem.click(); - await viewShown; - - let listItems = subview.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 1, "We have 1 item in the list"); - let listItem = listItems[0]; - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.querySelector("label").value, - "fingerprinting.example.com", - "Has the correct host" - ); - is( - listItem.classList.contains("allowed"), - hasException, - "Indicates the fingerprinter was blocked or allowed" - ); - - let mainView = document.getElementById("identity-popup-mainView"); - viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - let backButton = subview.querySelector(".subviewbutton-back"); - backButton.click(); - await viewShown; - - ok(true, "Main view was shown"); - - if (hasException) { - let loaded = BrowserTestUtils.browserLoaded( - tab.linkedBrowser, - false, - TRACKING_PAGE - ); - ContentBlocking.enableForCurrentPage(); - await loaded; - } - - let loads = hasException ? 3 : 1; - testTelemetry(loads, 1, hasException); - - BrowserTestUtils.removeTab(tab); -} - -function testTelemetry(pagesVisited, pagesWithBlockableContent, hasException) { - let results = fpHistogram.snapshot(); - Assert.equal( - results.values[0], - pagesVisited, - "The correct number of page loads have been recorded" - ); - let expectedValue = hasException ? 2 : 1; - Assert.equal( - results.values[expectedValue], - pagesWithBlockableContent, - "The correct number of fingerprinters have been recorded as blocked or allowed." - ); -} - -add_task(async function test() { - Services.prefs.setBoolPref(FP_PROTECTION_PREF, true); - Services.prefs.setBoolPref(FP_ANNOTATION_PREF, true); - - await testIdentityState(false); - await testIdentityState(true); - - await testSubview(false); - await testSubview(true); - - Services.prefs.clearUserPref(FP_PROTECTION_PREF); - Services.prefs.clearUserPref(FP_ANNOTATION_PREF); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js b/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js deleted file mode 100644 index e363bb6eab..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js +++ /dev/null @@ -1,207 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TP_PREF = "privacy.trackingprotection.enabled"; -const TPC_PREF = "network.cookie.cookieBehavior"; -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; - -async function waitAndAssertPreferencesShown(_spotlight) { - await BrowserTestUtils.waitForEvent( - gIdentityHandler._identityPopup, - "popuphidden" - ); - await TestUtils.waitForCondition( - () => gBrowser.currentURI.spec == "about:preferences#privacy", - "Should open about:preferences." - ); - - await ContentTask.spawn( - gBrowser.selectedBrowser, - { spotlight: _spotlight }, - async function({ spotlight }) { - let doc = content.document; - let section = await ContentTaskUtils.waitForCondition( - () => doc.querySelector(".spotlight"), - "The spotlight should appear." - ); - is( - section.getAttribute("data-subcategory"), - spotlight, - "The correct section is spotlighted." - ); - } - ); - - BrowserTestUtils.removeTab(gBrowser.selectedTab); -} - -add_task(async function setup() { - await UrlClassifierTestUtils.addTestTrackers(); - let oldCanRecord = Services.telemetry.canRecordExtended; - Services.telemetry.canRecordExtended = true; - - registerCleanupFunction(() => { - Services.telemetry.canRecordExtended = oldCanRecord; - UrlClassifierTestUtils.cleanupTestTrackers(); - }); -}); - -// Tests that pressing the content blocking preferences icon in the identity popup -// links to about:preferences -add_task(async function testOpenPreferencesFromCBPrefsButton() { - await BrowserTestUtils.withNewTab("https://example.com", async function() { - let promisePanelOpen = BrowserTestUtils.waitForEvent( - gIdentityHandler._identityPopup, - "popupshown" - ); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; - - let preferencesButton = document.getElementById( - "tracking-protection-preferences-button" - ); - - ok( - BrowserTestUtils.is_visible(preferencesButton), - "The preferences button is shown." - ); - - let shown = waitAndAssertPreferencesShown("trackingprotection"); - preferencesButton.click(); - await shown; - }); -}); - -// Tests that pressing the permissions preferences icon in the identity popup -// links to about:preferences -add_task(async function testOpenPreferencesFromPermissionsPrefsButton() { - await BrowserTestUtils.withNewTab("https://example.com", async function() { - let promisePanelOpen = BrowserTestUtils.waitForEvent( - gIdentityHandler._identityPopup, - "popupshown" - ); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; - - let preferencesButton = document.getElementById( - "identity-popup-permission-preferences-button" - ); - - ok( - BrowserTestUtils.is_visible(preferencesButton), - "The preferences button is shown." - ); - - Services.telemetry.clearEvents(); - - let shown = waitAndAssertPreferencesShown("permissions"); - preferencesButton.click(); - await shown; - - let events = Services.telemetry.snapshotEvents( - Ci.nsITelemetry.DATASET_PRERELEASE_CHANNELS, - true - ).parent; - let clickEvents = events.filter( - e => - e[1] == "security.ui.identitypopup" && - e[2] == "click" && - e[3] == "permission_prefs_btn" - ); - is(clickEvents.length, 1, "recorded telemetry for the click"); - }); -}); - -// Tests that pressing the preferences button in the trackers subview -// links to about:preferences -add_task(async function testOpenPreferencesFromTrackersSubview() { - Services.prefs.setBoolPref(TP_PREF, true); - - await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() { - let promisePanelOpen = BrowserTestUtils.waitForEvent( - gIdentityHandler._identityPopup, - "popupshown" - ); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-tracking-protection" - ); - ok( - BrowserTestUtils.is_visible(categoryItem), - "TP category item is visible" - ); - let trackersView = document.getElementById("identity-popup-trackersView"); - let viewShown = BrowserTestUtils.waitForEvent(trackersView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Trackers view was shown"); - - let preferencesButton = document.getElementById( - "identity-popup-trackersView-settings-button" - ); - - ok( - BrowserTestUtils.is_visible(preferencesButton), - "The preferences button is shown." - ); - - let shown = waitAndAssertPreferencesShown("trackingprotection"); - preferencesButton.click(); - await shown; - }); - - Services.prefs.clearUserPref(TP_PREF); -}); - -// Tests that pressing the preferences button in the cookies subview -// links to about:preferences -add_task(async function testOpenPreferencesFromCookiesSubview() { - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - - await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() { - let promisePanelOpen = BrowserTestUtils.waitForEvent( - gIdentityHandler._identityPopup, - "popupshown" - ); - gIdentityHandler._identityBox.click(); - await promisePanelOpen; - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-cookies" - ); - ok( - BrowserTestUtils.is_visible(categoryItem), - "TP category item is visible" - ); - let cookiesView = document.getElementById("identity-popup-cookiesView"); - let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Cookies view was shown"); - - let preferencesButton = document.getElementById( - "identity-popup-cookiesView-settings-button" - ); - - ok( - BrowserTestUtils.is_visible(preferencesButton), - "The preferences button is shown." - ); - - let shown = waitAndAssertPreferencesShown("trackingprotection"); - preferencesButton.click(); - await shown; - }); - - Services.prefs.clearUserPref(TPC_PREF); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js b/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js deleted file mode 100644 index fc7cb2f068..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js +++ /dev/null @@ -1,213 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// Test that sites added to the Tracking Protection whitelist in private -// browsing mode don't persist once the private browsing window closes. - -const TP_PB_PREF = "privacy.trackingprotection.enabled"; -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications"; -var TrackingProtection = null; -var ContentBlocking = null; -var browser = null; - -registerCleanupFunction(function() { - Services.prefs.clearUserPref(TP_PB_PREF); - Services.prefs.clearUserPref(DTSCBN_PREF); - ContentBlocking = TrackingProtection = browser = null; - UrlClassifierTestUtils.cleanupTestTrackers(); -}); - -function hidden(sel) { - let win = browser.ownerGlobal; - let el = win.document.querySelector(sel); - let display = win.getComputedStyle(el).getPropertyValue("display", null); - return display === "none"; -} - -function identityPopupState() { - let win = browser.ownerGlobal; - return win.document.getElementById("identity-popup").state; -} - -function clickButton(sel) { - let win = browser.ownerGlobal; - let el = win.document.querySelector(sel); - el.doCommand(); -} - -function testTrackingPage(window) { - info("Tracking content must be blocked"); - ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); - ok( - !ContentBlocking.content.hasAttribute("hasException"), - "content shows no exception" - ); - - ok( - BrowserTestUtils.is_visible(ContentBlocking.iconBox), - "icon box is visible" - ); - ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - ok( - !ContentBlocking.iconBox.hasAttribute("hasException"), - "icon box shows no exception" - ); - is( - ContentBlocking.iconBox.getAttribute("tooltiptext"), - gNavigatorBundle.getString("trackingProtection.icon.activeTooltip"), - "correct tooltip" - ); - - ok(hidden("#tracking-action-block"), "blockButton is hidden"); - - if (PrivateBrowsingUtils.isWindowPrivate(window)) { - ok(hidden("#tracking-action-unblock"), "unblockButton is hidden"); - ok( - !hidden("#tracking-action-unblock-private"), - "unblockButtonPrivate is visible" - ); - } else { - ok(!hidden("#tracking-action-unblock"), "unblockButton is visible"); - ok( - hidden("#tracking-action-unblock-private"), - "unblockButtonPrivate is hidden" - ); - } - - ok( - hidden("#identity-popup-content-blocking-not-detected"), - "blocking not detected label is hidden" - ); - ok( - !hidden("#identity-popup-content-blocking-detected"), - "blocking detected label is visible" - ); -} - -function testTrackingPageUnblocked() { - info("Tracking content must be white-listed and not blocked"); - ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); - ok( - ContentBlocking.content.hasAttribute("hasException"), - "content shows exception" - ); - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - ok( - ContentBlocking.iconBox.hasAttribute("hasException"), - "shield shows exception" - ); - is( - ContentBlocking.iconBox.getAttribute("tooltiptext"), - gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), - "correct tooltip" - ); - - ok( - BrowserTestUtils.is_visible(ContentBlocking.iconBox), - "icon box is visible" - ); - ok(!hidden("#tracking-action-block"), "blockButton is visible"); - ok(hidden("#tracking-action-unblock"), "unblockButton is hidden"); - - ok( - hidden("#identity-popup-content-blocking-not-detected"), - "blocking not detected label is hidden" - ); - ok( - !hidden("#identity-popup-content-blocking-detected"), - "blocking detected label is visible" - ); -} - -add_task(async function testExceptionAddition() { - await UrlClassifierTestUtils.addTestTrackers(); - Services.prefs.setBoolPref(DTSCBN_PREF, true); - let privateWin = await BrowserTestUtils.openNewBrowserWindow({ - private: true, - }); - browser = privateWin.gBrowser; - let tab = await BrowserTestUtils.openNewForegroundTab({ - gBrowser: browser, - waitForLoad: true, - waitForStateStop: true, - }); - - ContentBlocking = browser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the private window"); - TrackingProtection = browser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the private window"); - - Services.prefs.setBoolPref(TP_PB_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled after setting the pref"); - - info("Load a test page containing tracking elements"); - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2, tab.ownerGlobal), - ]); - - testTrackingPage(tab.ownerGlobal); - - info("Disable TP for the page (which reloads the page)"); - let tabReloadPromise = promiseTabLoadEvent(tab); - clickButton("#tracking-action-unblock"); - is(identityPopupState(), "closed", "Identity popup is closed"); - - await tabReloadPromise; - testTrackingPageUnblocked(); - - info( - "Test that the exception is remembered across tabs in the same private window" - ); - tab = browser.selectedTab = BrowserTestUtils.addTab(browser); - - info("Load a test page containing tracking elements"); - await promiseTabLoadEvent(tab, TRACKING_PAGE); - testTrackingPageUnblocked(); - - privateWin.close(); -}); - -add_task(async function testExceptionPersistence() { - info("Open another private browsing window"); - let privateWin = await BrowserTestUtils.openNewBrowserWindow({ - private: true, - }); - browser = privateWin.gBrowser; - let tab = await BrowserTestUtils.openNewForegroundTab({ - gBrowser: browser, - waitForLoad: true, - waitForStateStop: true, - }); - - ContentBlocking = browser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the private window"); - TrackingProtection = browser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the private window"); - - ok(TrackingProtection.enabled, "TP is still enabled"); - - info("Load a test page containing tracking elements"); - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2, tab.ownerGlobal), - ]); - - testTrackingPage(tab.ownerGlobal); - - info("Disable TP for the page (which reloads the page)"); - let tabReloadPromise = promiseTabLoadEvent(tab); - clickButton("#tracking-action-unblock"); - is(identityPopupState(), "closed", "Identity popup is closed"); - - await Promise.all([ - tabReloadPromise, - waitForContentBlockingEvent(2, tab.ownerGlobal), - ]); - testTrackingPageUnblocked(); - - privateWin.close(); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js b/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js deleted file mode 100644 index e2bd8de490..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js +++ /dev/null @@ -1,385 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const COOKIE_PAGE = - "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookiePage.html"; - -const CM_PREF = "privacy.trackingprotection.cryptomining.enabled"; -const FP_PREF = "privacy.trackingprotection.fingerprinting.enabled"; -const TP_PREF = "privacy.trackingprotection.enabled"; -const CB_PREF = "network.cookie.cookieBehavior"; - -const PREF_REPORT_BREAKAGE_ENABLED = - "browser.contentblocking.reportBreakage.enabled"; -const PREF_REPORT_BREAKAGE_URL = "browser.contentblocking.reportBreakage.url"; - -let { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); -let { CommonUtils } = ChromeUtils.import("resource://services-common/utils.js"); -let { Preferences } = ChromeUtils.import( - "resource://gre/modules/Preferences.jsm" -); - -add_task(async function setup() { - await UrlClassifierTestUtils.addTestTrackers(); - - let oldCanRecord = Services.telemetry.canRecordExtended; - Services.telemetry.canRecordExtended = true; - - registerCleanupFunction(() => { - Services.telemetry.canRecordExtended = oldCanRecord; - - // Clear prefs that are touched in this test again for sanity. - Services.prefs.clearUserPref(TP_PREF); - Services.prefs.clearUserPref(CB_PREF); - Services.prefs.clearUserPref(FP_PREF); - Services.prefs.clearUserPref(CM_PREF); - Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED); - Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL); - - UrlClassifierTestUtils.cleanupTestTrackers(); - }); - - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.trackingprotection.fingerprinting.annotate.enabled", true], - [ - "urlclassifier.features.fingerprinting.blacklistHosts", - "fingerprinting.example.com", - ], - [ - "urlclassifier.features.fingerprinting.annotate.blacklistHosts", - "fingerprinting.example.com", - ], - ["privacy.trackingprotection.cryptomining.enabled", true], - [ - "urlclassifier.features.cryptomining.blacklistHosts", - "cryptomining.example.com", - ], - [ - "urlclassifier.features.cryptomining.annotate.blacklistHosts", - "cryptomining.example.com", - ], - ], - }); -}); - -add_task(async function testReportBreakageVisibility() { - let scenarios = [ - { - url: TRACKING_PAGE, - prefs: { - "privacy.trackingprotection.enabled": true, - "browser.contentblocking.reportBreakage.enabled": true, - }, - buttonVisible: true, - }, - { - url: TRACKING_PAGE, - hasException: true, - prefs: { - "privacy.trackingprotection.enabled": true, - "browser.contentblocking.reportBreakage.enabled": true, - }, - buttonVisible: true, - }, - { - url: TRACKING_PAGE, - prefs: { - "privacy.trackingprotection.enabled": true, - "browser.contentblocking.reportBreakage.enabled": false, - }, - buttonVisible: false, - }, - { - url: BENIGN_PAGE, - prefs: { - "privacy.trackingprotection.enabled": true, - "browser.contentblocking.reportBreakage.enabled": true, - }, - buttonVisible: false, - }, - { - url: COOKIE_PAGE, - prefs: { - "privacy.trackingprotection.enabled": false, - "network.cookie.cookieBehavior": - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER, - "browser.contentblocking.reportBreakage.enabled": false, - "browser.contentblocking.rejecttrackers.reportBreakage.enabled": true, - }, - buttonVisible: true, - }, - ]; - - for (let scenario of scenarios) { - for (let pref in scenario.prefs) { - Preferences.set(pref, scenario.prefs[pref]); - } - - let uri = Services.io.newURI(scenario.url); - if (scenario.hasException) { - Services.perms.add( - uri, - "trackingprotection", - Services.perms.ALLOW_ACTION - ); - } - - await BrowserTestUtils.withNewTab(scenario.url, async function() { - await openIdentityPopup(); - - let reportBreakageButton = document.getElementById( - "identity-popup-content-blocking-report-breakage" - ); - await TestUtils.waitForCondition( - () => - BrowserTestUtils.is_visible(reportBreakageButton) == - scenario.buttonVisible, - "waiting for correct visibility" - ); - ok(true, "report breakage button has the correct visibility"); - }); - - Services.perms.remove(uri, "trackingprotection"); - for (let pref in scenario.prefs) { - Services.prefs.clearUserPref(pref); - } - } -}); - -add_task(async function testReportBreakageCancel() { - Services.prefs.setBoolPref(TP_PREF, true); - Services.prefs.setBoolPref(PREF_REPORT_BREAKAGE_ENABLED, true); - - await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() { - await openIdentityPopup(); - - Services.telemetry.clearEvents(); - - let reportBreakageButton = document.getElementById( - "identity-popup-content-blocking-report-breakage" - ); - ok( - BrowserTestUtils.is_visible(reportBreakageButton), - "report breakage button is visible" - ); - let reportBreakageView = document.getElementById( - "identity-popup-breakageReportView" - ); - let viewShown = BrowserTestUtils.waitForEvent( - reportBreakageView, - "ViewShown" - ); - reportBreakageButton.click(); - await viewShown; - - let events = Services.telemetry.snapshotEvents( - Ci.nsITelemetry.DATASET_PRERELEASE_CHANNELS - ).parent; - let clickEvents = events.filter( - e => - e[1] == "security.ui.identitypopup" && - e[2] == "click" && - e[3] == "report_breakage" - ); - is(clickEvents.length, 1, "recorded telemetry for the click"); - - ok(true, "Report breakage view was shown"); - - let mainView = document.getElementById("identity-popup-mainView"); - viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - let cancelButton = document.getElementById( - "identity-popup-breakageReportView-cancel" - ); - cancelButton.click(); - await viewShown; - - ok(true, "Main view was shown"); - }); - - Services.prefs.clearUserPref(TP_PREF); - Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED); -}); - -add_task(async function testTP() { - Services.prefs.setBoolPref(TP_PREF, true); - // Make sure that we correctly strip the query. - let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊"; - await BrowserTestUtils.withNewTab(url, async function() { - await testReportBreakage(TRACKING_PAGE, "trackingprotection"); - }); - - Services.prefs.clearUserPref(TP_PREF); -}); - -add_task(async function testCR() { - Services.prefs.setIntPref( - CB_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - // Make sure that we correctly strip the query. - let url = COOKIE_PAGE + "?a=b&1=abc&unicode=🦊"; - await BrowserTestUtils.withNewTab(url, async function() { - await testReportBreakage(COOKIE_PAGE, "cookierestrictions"); - }); - - Services.prefs.clearUserPref(CB_PREF); -}); - -add_task(async function testFP() { - Services.prefs.setIntPref(CB_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); - Services.prefs.setBoolPref(FP_PREF, true); - // Make sure that we correctly strip the query. - let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊"; - await BrowserTestUtils.withNewTab(url, async function(browser) { - await ContentTask.spawn(browser, {}, function() { - content.postMessage("fingerprinting", "*"); - }); - - await testReportBreakage(TRACKING_PAGE, "fingerprinting"); - }); - - Services.prefs.clearUserPref(FP_PREF); - Services.prefs.clearUserPref(CB_PREF); -}); - -add_task(async function testCM() { - Services.prefs.setIntPref(CB_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); - Services.prefs.setBoolPref(CM_PREF, true); - // Make sure that we correctly strip the query. - let url = TRACKING_PAGE + "?a=b&1=abc&unicode=🦊"; - await BrowserTestUtils.withNewTab(url, async function(browser) { - await ContentTask.spawn(browser, {}, function() { - content.postMessage("cryptomining", "*"); - }); - - await testReportBreakage(TRACKING_PAGE, "cryptomining"); - }); - - Services.prefs.clearUserPref(CM_PREF); - Services.prefs.clearUserPref(CB_PREF); -}); - -async function testReportBreakage(url, tags) { - // Setup a mock server for receiving breakage reports. - let server = new HttpServer(); - server.start(-1); - let i = server.identity; - let path = - i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/"; - - Services.prefs.setBoolPref(PREF_REPORT_BREAKAGE_ENABLED, true); - Services.prefs.setStringPref(PREF_REPORT_BREAKAGE_URL, path); - - await openIdentityPopup(); - - let comments = document.getElementById( - "identity-popup-breakageReportView-collection-comments" - ); - is(comments.value, "", "Comments textarea should initially be empty"); - - let reportBreakageButton = document.getElementById( - "identity-popup-content-blocking-report-breakage" - ); - await TestUtils.waitForCondition( - () => BrowserTestUtils.is_visible(reportBreakageButton), - "report breakage button is visible" - ); - let reportBreakageView = document.getElementById( - "identity-popup-breakageReportView" - ); - let viewShown = BrowserTestUtils.waitForEvent( - reportBreakageView, - "ViewShown" - ); - reportBreakageButton.click(); - await viewShown; - - let submitButton = document.getElementById( - "identity-popup-breakageReportView-submit" - ); - let reportURL = document.getElementById( - "identity-popup-breakageReportView-collection-url" - ).value; - - is(reportURL, url, "Shows the correct URL in the report UI."); - - // Make sure that sending the report closes the identity popup. - let popuphidden = BrowserTestUtils.waitForEvent( - gIdentityHandler._identityPopup, - "popuphidden" - ); - - // Check that we're receiving a good report. - await new Promise(resolve => { - server.registerPathHandler("/", async (request, response) => { - is(request.method, "POST", "request was a post"); - - // Extract and "parse" the form data in the request body. - let body = CommonUtils.readBytesFromInputStream(request.bodyInputStream); - let boundary = request - .getHeader("Content-Type") - .match(/boundary=-+([^-]*)/i)[1]; - let regex = new RegExp("-+" + boundary + "-*\\s+"); - let sections = body.split(regex); - - let prefs = [ - "privacy.trackingprotection.enabled", - "privacy.trackingprotection.pbmode.enabled", - "urlclassifier.trackingTable", - "network.http.referer.defaultPolicy", - "network.http.referer.defaultPolicy.pbmode", - "network.cookie.cookieBehavior", - "network.cookie.lifetimePolicy", - "privacy.restrict3rdpartystorage.expiration", - "privacy.trackingprotection.fingerprinting.enabled", - "privacy.trackingprotection.cryptomining.enabled", - ]; - let prefsBody = ""; - - for (let pref of prefs) { - prefsBody += `${pref}: ${Preferences.get(pref)}\r\n`; - } - - Assert.deepEqual( - sections, - [ - "", - `Content-Disposition: form-data; name=\"title\"\r\n\r\n${ - Services.io.newURI(reportURL).host - }\r\n`, - 'Content-Disposition: form-data; name="body"\r\n\r\n' + - `Full URL: ${reportURL + "?"}\r\n` + - `userAgent: ${navigator.userAgent}\r\n\r\n` + - "**Preferences**\r\n" + - `${prefsBody}\r\n` + - "**Comments**\r\n" + - "This is a comment\r\n", - 'Content-Disposition: form-data; name="labels"\r\n\r\n' + - `${tags}\r\n`, - "", - ], - "Should send the correct form data" - ); - - resolve(); - }); - - comments.value = "This is a comment"; - submitButton.click(); - }); - - await popuphidden; - - // Stop the server. - await new Promise(r => server.stop(r)); - - Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_ENABLED); - Services.prefs.clearUserPref(PREF_REPORT_BREAKAGE_URL); -} diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_state.js b/browser/base/content/test/trackingUI/browser_trackingUI_state.js deleted file mode 100644 index 0caa9cf655..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_state.js +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Test that the Tracking Protection section is visible in the Control Center - * and has the correct state for the cases when: - * - * In a normal window as well as a private window, - * With TP enabled - * 1) A page with no tracking elements is loaded. - * 2) A page with tracking elements is loaded and they are blocked. - * 3) A page with tracking elements is loaded and they are not blocked. - * With TP disabled - * 1) A page with no tracking elements is loaded. - * 2) A page with tracking elements is loaded. - * - * See also Bugs 1175327, 1043801, 1178985 - */ - -const TP_PREF = "privacy.trackingprotection.enabled"; -const TP_PB_PREF = "privacy.trackingprotection.pbmode.enabled"; -const TPC_PREF = "network.cookie.cookieBehavior"; -const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const COOKIE_PAGE = - "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookiePage.html"; -var ContentBlocking = null; -var TrackingProtection = null; -var ThirdPartyCookies = null; -var tabbrowser = null; -var gTrackingPageURL = TRACKING_PAGE; - -registerCleanupFunction(function() { - TrackingProtection = ContentBlocking = ThirdPartyCookies = tabbrowser = null; - UrlClassifierTestUtils.cleanupTestTrackers(); - Services.prefs.clearUserPref(TP_PREF); - Services.prefs.clearUserPref(TP_PB_PREF); - Services.prefs.clearUserPref(TPC_PREF); - Services.prefs.clearUserPref(DTSCBN_PREF); -}); - -// This is a special version of "hidden" that doesn't check for item -// visibility and just asserts the display and opacity attributes. -// That way we can test elements even when their panel is hidden... -function hidden(sel) { - let win = tabbrowser.ownerGlobal; - let el = win.document.querySelector(sel); - let display = win.getComputedStyle(el).getPropertyValue("display", null); - let opacity = win.getComputedStyle(el).getPropertyValue("opacity", null); - return display === "none" || opacity === "0"; -} - -function clickButton(sel) { - let win = tabbrowser.ownerGlobal; - let el = win.document.querySelector(sel); - el.doCommand(); -} - -function testBenignPage() { - info("Non-tracking content must not be blocked"); - ok( - !ContentBlocking.content.hasAttribute("detected"), - "no trackers are detected" - ); - ok( - !ContentBlocking.content.hasAttribute("hasException"), - "content shows no exception" - ); - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - ok( - !ContentBlocking.iconBox.hasAttribute("hasException"), - "icon box shows no exception" - ); - ok( - !ContentBlocking.iconBox.hasAttribute("tooltiptext"), - "icon box has no tooltip" - ); - - ok(BrowserTestUtils.is_hidden(ContentBlocking.iconBox), "icon box is hidden"); - ok(hidden("#tracking-action-block"), "blockButton is hidden"); - ok(hidden("#tracking-action-unblock"), "unblockButton is hidden"); - - ok( - !hidden("#identity-popup-content-blocking-not-detected"), - "blocking not detected label is visible" - ); - ok( - hidden("#identity-popup-content-blocking-detected"), - "blocking detected label is hidden" - ); - ok( - hidden("#identity-popup-content-blocking-category-cookies"), - "Not showing cookie restrictions category" - ); - ok( - hidden("#identity-popup-content-blocking-category-tracking-protection"), - "Not showing trackers category" - ); -} - -function testBenignPageWithException() { - info("Non-tracking content must not be blocked"); - ok( - !ContentBlocking.content.hasAttribute("detected"), - "no trackers are detected" - ); - ok( - ContentBlocking.content.hasAttribute("hasException"), - "content shows exception" - ); - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - ok( - ContentBlocking.iconBox.hasAttribute("hasException"), - "shield shows exception" - ); - is( - ContentBlocking.iconBox.getAttribute("tooltiptext"), - gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), - "correct tooltip" - ); - - ok( - !BrowserTestUtils.is_hidden(ContentBlocking.iconBox), - "icon box is not hidden" - ); - ok(!hidden("#tracking-action-block"), "blockButton is visible"); - ok(hidden("#tracking-action-unblock"), "unblockButton is hidden"); - - ok( - !hidden("#identity-popup-content-blocking-not-detected"), - "blocking not detected label is visible" - ); - ok( - hidden("#identity-popup-content-blocking-detected"), - "blocking detected label is hidden" - ); - ok( - hidden("#identity-popup-content-blocking-category-cookies"), - "Not showing cookie restrictions category" - ); - ok( - hidden("#identity-popup-content-blocking-category-tracking-protection"), - "Not showing trackers category" - ); -} - -function areTrackersBlocked(isPrivateBrowsing) { - let blockedByTP = Services.prefs.getBoolPref( - isPrivateBrowsing ? TP_PB_PREF : TP_PREF - ); - let blockedByTPC = - Services.prefs.getIntPref(TPC_PREF) == - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER; - return blockedByTP || blockedByTPC; -} - -function testTrackingPage(window) { - info("Tracking content must be blocked"); - ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); - ok( - !ContentBlocking.content.hasAttribute("hasException"), - "content shows no exception" - ); - - let isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window); - let blockedByTP = areTrackersBlocked(isWindowPrivate); - is( - BrowserTestUtils.is_visible(ContentBlocking.iconBox), - blockedByTP, - "icon box is" + (blockedByTP ? "" : " not") + " visible" - ); - is( - ContentBlocking.iconBox.hasAttribute("active"), - blockedByTP, - "shield is" + (blockedByTP ? "" : " not") + " active" - ); - ok( - !ContentBlocking.iconBox.hasAttribute("hasException"), - "icon box shows no exception" - ); - is( - ContentBlocking.iconBox.getAttribute("tooltiptext"), - blockedByTP - ? gNavigatorBundle.getString("trackingProtection.icon.activeTooltip") - : "", - "correct tooltip" - ); - - ok(hidden("#tracking-action-block"), "blockButton is hidden"); - - if (isWindowPrivate) { - ok(hidden("#tracking-action-unblock"), "unblockButton is hidden"); - is( - !hidden("#tracking-action-unblock-private"), - blockedByTP, - "unblockButtonPrivate is" + (blockedByTP ? "" : " not") + " visible" - ); - } else { - ok( - hidden("#tracking-action-unblock-private"), - "unblockButtonPrivate is hidden" - ); - is( - !hidden("#tracking-action-unblock"), - blockedByTP, - "unblockButton is" + (blockedByTP ? "" : " not") + " visible" - ); - } - - ok( - hidden("#identity-popup-content-blocking-not-detected"), - "blocking not detected label is hidden" - ); - ok( - !hidden("#identity-popup-content-blocking-detected"), - "blocking detected label is visible" - ); - - ok( - !hidden("#identity-popup-content-blocking-category-tracking-protection"), - "Showing trackers category" - ); - if (gTrackingPageURL == COOKIE_PAGE) { - ok( - !hidden("#identity-popup-content-blocking-category-cookies"), - "Showing cookie restrictions category" - ); - } else { - ok( - hidden("#identity-popup-content-blocking-category-cookies"), - "Not showing cookie restrictions category" - ); - } -} - -function testTrackingPageUnblocked(blockedByTP, window) { - info("Tracking content must be white-listed and not blocked"); - ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected"); - ok( - ContentBlocking.content.hasAttribute("hasException"), - "content shows exception" - ); - - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - ok( - ContentBlocking.iconBox.hasAttribute("hasException"), - "shield shows exception" - ); - is( - ContentBlocking.iconBox.getAttribute("tooltiptext"), - gNavigatorBundle.getString("trackingProtection.icon.disabledTooltip"), - "correct tooltip" - ); - - ok( - BrowserTestUtils.is_visible(ContentBlocking.iconBox), - "icon box is visible" - ); - ok(!hidden("#tracking-action-block"), "blockButton is visible"); - ok(hidden("#tracking-action-unblock"), "unblockButton is hidden"); - - ok( - hidden("#identity-popup-content-blocking-not-detected"), - "blocking not detected label is hidden" - ); - ok( - !hidden("#identity-popup-content-blocking-detected"), - "blocking detected label is visible" - ); - - ok( - !hidden("#identity-popup-content-blocking-category-tracking-protection"), - "Showing trackers category" - ); - if (gTrackingPageURL == COOKIE_PAGE) { - ok( - !hidden("#identity-popup-content-blocking-category-cookies"), - "Showing cookie restrictions category" - ); - } else { - ok( - hidden("#identity-popup-content-blocking-category-cookies"), - "Not showing cookie restrictions category" - ); - } -} - -async function testContentBlocking(tab) { - info("Testing with Tracking Protection ENABLED."); - - info("Load a test page not containing tracking elements"); - await promiseTabLoadEvent(tab, BENIGN_PAGE); - testBenignPage(); - - info( - "Load a test page not containing tracking elements which has an exception." - ); - let isPrivateBrowsing = PrivateBrowsingUtils.isWindowPrivate(tab.ownerGlobal); - let uri = Services.io.newURI("https://example.org/"); - if (isPrivateBrowsing) { - PrivateBrowsingUtils.addToTrackingAllowlist(uri); - } else { - Services.perms.add(uri, "trackingprotection", Services.perms.ALLOW_ACTION); - } - - await promiseTabLoadEvent(tab, uri.spec); - testBenignPageWithException(); - - if (isPrivateBrowsing) { - PrivateBrowsingUtils.removeFromTrackingAllowlist(uri); - } else { - Services.perms.remove(uri, "trackingprotection"); - } - - info("Load a test page containing tracking elements"); - await promiseTabLoadEvent(tab, gTrackingPageURL); - testTrackingPage(tab.ownerGlobal); - - info("Disable CB for the page (which reloads the page)"); - let tabReloadPromise = promiseTabLoadEvent(tab); - clickButton("#tracking-action-unblock"); - await tabReloadPromise; - let blockedByTP = areTrackersBlocked(isPrivateBrowsing); - testTrackingPageUnblocked(blockedByTP, tab.ownerGlobal); - - info("Re-enable TP for the page (which reloads the page)"); - tabReloadPromise = promiseTabLoadEvent(tab); - clickButton("#tracking-action-block"); - await tabReloadPromise; - testTrackingPage(tab.ownerGlobal); -} - -add_task(async function testNormalBrowsing() { - await UrlClassifierTestUtils.addTestTrackers(); - - Services.prefs.setBoolPref(DTSCBN_PREF, true); - - tabbrowser = gBrowser; - let tab = (tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser)); - - ContentBlocking = gBrowser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the browser window"); - TrackingProtection = gBrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the browser window"); - is( - TrackingProtection.enabled, - Services.prefs.getBoolPref(TP_PREF), - "TP.enabled is based on the original pref value" - ); - - Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); - - await testContentBlocking(tab); - - Services.prefs.setBoolPref(TP_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled after setting the pref"); - - await testContentBlocking(tab); - - gBrowser.removeCurrentTab(); - - Services.prefs.clearUserPref(TPC_PREF); -}); - -add_task(async function testPrivateBrowsing() { - let privateWin = await BrowserTestUtils.openNewBrowserWindow({ - private: true, - }); - tabbrowser = privateWin.gBrowser; - let tab = (tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser)); - - // Set the normal mode pref to false to check the pbmode pref. - Services.prefs.setBoolPref(TP_PREF, false); - - Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT); - - ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the private window"); - TrackingProtection = tabbrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the private window"); - is( - TrackingProtection.enabled, - Services.prefs.getBoolPref(TP_PB_PREF), - "TP.enabled is based on the pb pref value" - ); - - await testContentBlocking(tab); - - Services.prefs.setBoolPref(TP_PB_PREF, true); - ok(TrackingProtection.enabled, "TP is enabled after setting the pref"); - - await testContentBlocking(tab); - - privateWin.close(); - - Services.prefs.clearUserPref(TPC_PREF); -}); - -add_task(async function testThirdPartyCookies() { - await UrlClassifierTestUtils.addTestTrackers(); - gTrackingPageURL = COOKIE_PAGE; - - tabbrowser = gBrowser; - let tab = (tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser)); - - ContentBlocking = gBrowser.ownerGlobal.ContentBlocking; - ok(ContentBlocking, "CB is attached to the browser window"); - ThirdPartyCookies = gBrowser.ownerGlobal.ThirdPartyCookies; - ok(ThirdPartyCookies, "TP is attached to the browser window"); - is( - ThirdPartyCookies.enabled, - Services.prefs.getIntPref(TPC_PREF) == - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER, - "TPC.enabled is based on the original pref value" - ); - - await testContentBlocking(tab); - - Services.prefs.setIntPref( - TPC_PREF, - Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER - ); - ok(ThirdPartyCookies.enabled, "TPC is enabled after setting the pref"); - - await testContentBlocking(tab); - - Services.prefs.clearUserPref(TPC_PREF); - gBrowser.removeCurrentTab(); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_state_all_disabled.js b/browser/base/content/test/trackingUI/browser_trackingUI_state_all_disabled.js deleted file mode 100644 index fceb4fafc0..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_state_all_disabled.js +++ /dev/null @@ -1,64 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const TP_PREF = "privacy.trackingprotection.enabled"; -const COOKIE_PREF = "network.cookie.cookieBehavior"; -const ANIMATIONS_PREF = "toolkit.cosmeticAnimations.enabled"; -const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications"; - -// Check that the shield icon is always hidden when all content blocking -// categories are turned off, even when content blocking is on. -add_task(async function testContentBlockingAllDisabled() { - await SpecialPowers.pushPrefEnv({ - set: [ - [TP_PREF, false], - [COOKIE_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT], - [DTSCBN_PREF, true], - ], - }); - await UrlClassifierTestUtils.addTestTrackers(); - - let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser)); - Services.prefs.setBoolPref(ANIMATIONS_PREF, true); - - registerCleanupFunction(function() { - gBrowser.removeCurrentTab(); - Services.prefs.clearUserPref(ANIMATIONS_PREF); - UrlClassifierTestUtils.cleanupTestTrackers(); - }); - - let animationIcon = document.getElementById( - "tracking-protection-icon-animatable-image" - ); - let noAnimationIcon = document.getElementById("tracking-protection-icon"); - - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2, tab.ownerGlobal), - ]); - ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden"); - ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden"); - - await promiseTabLoadEvent(tab, BENIGN_PAGE); - ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden"); - ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden"); - - Services.prefs.setBoolPref(ANIMATIONS_PREF, false); - await promiseTabLoadEvent(tab, TRACKING_PAGE); - ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden"); - ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden"); - - // Sanitity check that the shield is showing when at least one blocker is enabled. - await SpecialPowers.pushPrefEnv({ set: [[TP_PREF, true]] }); - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2, tab.ownerGlobal), - ]); - ok(BrowserTestUtils.is_visible(noAnimationIcon), "the default icon is shown"); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js b/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js deleted file mode 100644 index 99fbbd90ee..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js +++ /dev/null @@ -1,109 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -const TP_PREF = "privacy.trackingprotection.enabled"; -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const ABOUT_PAGE = "about:preferences"; - -/* This asserts that the content blocking event state is correctly reset - * when navigating to a new location, and that the user is correctly - * reset when switching between tabs. */ - -add_task(async function testResetOnLocationChange() { - Services.prefs.setBoolPref(TP_PREF, true); - - let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE); - let browser = tab.linkedBrowser; - - is( - browser.securityUI.contentBlockingEvent, - 0, - "Benign page has no content blocking event" - ); - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(2), - ]); - - is( - browser.securityUI.contentBlockingEvent, - Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, - "Tracking page has a content blocking event" - ); - ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - - await promiseTabLoadEvent(tab, BENIGN_PAGE); - - is( - browser.securityUI.contentBlockingEvent, - 0, - "Benign page has no content blocking event" - ); - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - let contentBlockingEvent = waitForContentBlockingEvent(3); - let trackingTab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - TRACKING_PAGE - ); - await contentBlockingEvent; - - is( - trackingTab.linkedBrowser.securityUI.contentBlockingEvent, - Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT, - "Tracking page has a content blocking event" - ); - ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - - gBrowser.selectedTab = tab; - is( - browser.securityUI.contentBlockingEvent, - 0, - "Benign page has no content blocking event" - ); - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - gBrowser.removeTab(trackingTab); - gBrowser.removeTab(tab); - - Services.prefs.clearUserPref(TP_PREF); -}); - -/* Test that the content blocking icon is correctly reset - * when changing tabs or navigating to an about: page */ -add_task(async function testResetOnTabChange() { - Services.prefs.setBoolPref(TP_PREF, true); - - let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, ABOUT_PAGE); - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - await Promise.all([ - promiseTabLoadEvent(tab, TRACKING_PAGE), - waitForContentBlockingEvent(3), - ]); - ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - - await promiseTabLoadEvent(tab, ABOUT_PAGE); - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - let contentBlockingEvent = waitForContentBlockingEvent(3); - let trackingTab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - TRACKING_PAGE - ); - await contentBlockingEvent; - ok(ContentBlocking.iconBox.hasAttribute("active"), "shield is active"); - - gBrowser.selectedTab = tab; - ok(!ContentBlocking.iconBox.hasAttribute("active"), "shield is not active"); - - gBrowser.removeTab(trackingTab); - gBrowser.removeTab(tab); - - Services.prefs.clearUserPref(TP_PREF); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js b/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js deleted file mode 100644 index 5a29eebb83..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Test telemetry for Tracking Protection - */ - -const PREF = "privacy.trackingprotection.enabled"; -const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications"; -const BENIGN_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html"; -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; - -/** - * Enable local telemetry recording for the duration of the tests. - */ -var oldCanRecord = Services.telemetry.canRecordExtended; -Services.telemetry.canRecordExtended = true; -registerCleanupFunction(function() { - UrlClassifierTestUtils.cleanupTestTrackers(); - Services.telemetry.canRecordExtended = oldCanRecord; - Services.prefs.clearUserPref(PREF); - Services.prefs.clearUserPref(DTSCBN_PREF); -}); - -function getShieldHistogram() { - return Services.telemetry.getHistogramById("TRACKING_PROTECTION_SHIELD"); -} - -function getShieldCounts() { - return getShieldHistogram().snapshot().values; -} - -add_task(async function setup() { - await UrlClassifierTestUtils.addTestTrackers(); - Services.prefs.setBoolPref(DTSCBN_PREF, true); - - let TrackingProtection = gBrowser.ownerGlobal.TrackingProtection; - ok(TrackingProtection, "TP is attached to the browser window"); - ok(!TrackingProtection.enabled, "TP is not enabled"); - - let enabledCounts = Services.telemetry - .getHistogramById("TRACKING_PROTECTION_ENABLED") - .snapshot().values; - is(enabledCounts[0], 1, "TP was not enabled on start up"); - - let scalars = Services.telemetry.getSnapshotForScalars("main", false).parent; - - is(scalars["contentblocking.exceptions"], 0, "no CB exceptions at startup"); -}); - -add_task(async function testShieldHistogram() { - Services.prefs.setBoolPref(PREF, true); - let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); - - // Reset these to make counting easier - getShieldHistogram().clear(); - - await promiseTabLoadEvent(tab, BENIGN_PAGE); - is(getShieldCounts()[0], 1, "Page loads without tracking"); - - await promiseTabLoadEvent(tab, TRACKING_PAGE); - is(getShieldCounts()[0], 2, "Adds one more page load"); - is(getShieldCounts()[2], 1, "Counts one instance of the shield being shown"); - - info("Disable TP for the page (which reloads the page)"); - let tabReloadPromise = promiseTabLoadEvent(tab); - document.querySelector("#tracking-action-unblock").doCommand(); - await tabReloadPromise; - is(getShieldCounts()[0], 3, "Adds one more page load"); - is( - getShieldCounts()[1], - 1, - "Counts one instance of the shield being crossed out" - ); - - info("Re-enable TP for the page (which reloads the page)"); - tabReloadPromise = promiseTabLoadEvent(tab); - document.querySelector("#tracking-action-block").doCommand(); - await tabReloadPromise; - is(getShieldCounts()[0], 4, "Adds one more page load"); - is( - getShieldCounts()[2], - 2, - "Adds one more instance of the shield being shown" - ); - - gBrowser.removeCurrentTab(); - - // Reset these to make counting easier for the next test - getShieldHistogram().clear(); -}); diff --git a/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js b/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js deleted file mode 100644 index 161e677dba..0000000000 --- a/browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js +++ /dev/null @@ -1,131 +0,0 @@ -/* eslint-disable mozilla/no-arbitrary-setTimeout */ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const { PermissionTestUtils } = ChromeUtils.import( - "resource://testing-common/PermissionTestUtils.jsm" -); - -const TRACKING_PAGE = - "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html"; - -const TP_PREF = "privacy.trackingprotection.enabled"; - -add_task(async function setup() { - await UrlClassifierTestUtils.addTestTrackers(); - - registerCleanupFunction(() => { - UrlClassifierTestUtils.cleanupTestTrackers(); - }); -}); - -async function assertSitesListed(blocked) { - await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function(browser) { - await openIdentityPopup(); - - let categoryItem = document.getElementById( - "identity-popup-content-blocking-category-tracking-protection" - ); - ok( - BrowserTestUtils.is_visible(categoryItem), - "TP category item is visible" - ); - let trackersView = document.getElementById("identity-popup-trackersView"); - let viewShown = BrowserTestUtils.waitForEvent(trackersView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Trackers view was shown"); - - let listItems = trackersView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ); - is(listItems.length, 1, "We have 1 tracker in the list"); - - let strictInfo = document.getElementById( - "identity-popup-trackersView-strict-info" - ); - is( - BrowserTestUtils.is_hidden(strictInfo), - Services.prefs.getBoolPref(TP_PREF), - "Strict info is hidden if TP is enabled." - ); - - let mainView = document.getElementById("identity-popup-mainView"); - viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - let backButton = trackersView.querySelector(".subviewbutton-back"); - backButton.click(); - await viewShown; - - ok(true, "Main view was shown"); - - let change = waitForSecurityChange(1); - let timeoutPromise = new Promise(resolve => setTimeout(resolve, 1000)); - - await ContentTask.spawn(browser, {}, function() { - content.postMessage("more-tracking", "*"); - }); - - let result = await Promise.race([change, timeoutPromise]); - is(result, undefined, "No securityChange events should be received"); - - viewShown = BrowserTestUtils.waitForEvent(trackersView, "ViewShown"); - categoryItem.click(); - await viewShown; - - ok(true, "Trackers view was shown"); - - listItems = Array.from( - trackersView.querySelectorAll( - ".identity-popup-content-blocking-list-item" - ) - ); - is(listItems.length, 2, "We have 2 trackers in the list"); - - let listItem = listItems.find( - item => item.querySelector("label").value == "trackertest.org" - ); - ok(listItem, "Has an item for trackertest.org"); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !blocked, - "Indicates whether the tracker was blocked or allowed" - ); - - listItem = listItems.find( - item => item.querySelector("label").value == "itisatracker.org" - ); - ok(listItem, "Has an item for itisatracker.org"); - ok(BrowserTestUtils.is_visible(listItem), "List item is visible"); - is( - listItem.classList.contains("allowed"), - !blocked, - "Indicates whether the tracker was blocked or allowed" - ); - }); -} - -add_task(async function testTrackersSubView() { - info("Testing trackers subview with TP disabled."); - Services.prefs.setBoolPref(TP_PREF, false); - await assertSitesListed(false); - info("Testing trackers subview with TP enabled."); - Services.prefs.setBoolPref(TP_PREF, true); - await assertSitesListed(true); - info("Testing trackers subview with TP enabled and a CB exception."); - let uri = Services.io.newURI("https://tracking.example.org"); - PermissionTestUtils.add( - uri, - "trackingprotection", - Services.perms.ALLOW_ACTION - ); - await assertSitesListed(false); - info("Testing trackers subview with TP enabled and a CB exception removed."); - PermissionTestUtils.remove(uri, "trackingprotection"); - await assertSitesListed(true); - - Services.prefs.clearUserPref(TP_PREF); -}); diff --git a/browser/base/content/test/trackingUI/containerPage.html b/browser/base/content/test/trackingUI/containerPage.html deleted file mode 100644 index b4b12c9892..0000000000 --- a/browser/base/content/test/trackingUI/containerPage.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/browser/base/content/test/trackingUI/cookiePage.html b/browser/base/content/test/trackingUI/cookiePage.html deleted file mode 100644 index 9d8ffb4ebe..0000000000 --- a/browser/base/content/test/trackingUI/cookiePage.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/browser/base/content/test/trackingUI/cookieServer.sjs b/browser/base/content/test/trackingUI/cookieServer.sjs deleted file mode 100644 index 4c84df3922..0000000000 --- a/browser/base/content/test/trackingUI/cookieServer.sjs +++ /dev/null @@ -1,9 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -function handleRequest(request, response) { - response.setStatusLine(request.httpVersion, 200); - response.setHeader("Set-Cookie", "foopy=1"); - response.write("cookie served"); -} diff --git a/browser/base/content/test/trackingUI/cookieSetterPage.html b/browser/base/content/test/trackingUI/cookieSetterPage.html deleted file mode 100644 index aab18e0aff..0000000000 --- a/browser/base/content/test/trackingUI/cookieSetterPage.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/browser/base/content/test/trackingUI/embeddedPage.html b/browser/base/content/test/trackingUI/embeddedPage.html deleted file mode 100644 index 013abe194b..0000000000 --- a/browser/base/content/test/trackingUI/embeddedPage.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/browser/base/content/test/trackingUI/file_trackingUI_fetch.html b/browser/base/content/test/trackingUI/file_trackingUI_fetch.html deleted file mode 100644 index 48d2b5d37a..0000000000 --- a/browser/base/content/test/trackingUI/file_trackingUI_fetch.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - -Hello there!
- - - diff --git a/browser/base/content/test/trackingUI/file_trackingUI_fetch.js b/browser/base/content/test/trackingUI/file_trackingUI_fetch.js deleted file mode 100644 index f7ac687cfc..0000000000 --- a/browser/base/content/test/trackingUI/file_trackingUI_fetch.js +++ /dev/null @@ -1,2 +0,0 @@ -/* Some code goes here! */ -void 0; diff --git a/browser/base/content/test/trackingUI/file_trackingUI_fetch.js^headers^ b/browser/base/content/test/trackingUI/file_trackingUI_fetch.js^headers^ deleted file mode 100644 index cb762eff80..0000000000 --- a/browser/base/content/test/trackingUI/file_trackingUI_fetch.js^headers^ +++ /dev/null @@ -1 +0,0 @@ -Access-Control-Allow-Origin: * diff --git a/browser/base/content/test/trackingUI/head.js b/browser/base/content/test/trackingUI/head.js deleted file mode 100644 index 1aead5f03e..0000000000 --- a/browser/base/content/test/trackingUI/head.js +++ /dev/null @@ -1,86 +0,0 @@ -var { UrlClassifierTestUtils } = ChromeUtils.import( - "resource://testing-common/UrlClassifierTestUtils.jsm" -); - -/** - * Waits for a load (or custom) event to finish in a given tab. If provided - * load an uri into the tab. - * - * @param tab - * The tab to load into. - * @param [optional] url - * The url to load, or the current url. - * @return {Promise} resolved when the event is handled. - * @resolves to the received event - * @rejects if a valid load event is not received within a meaningful interval - */ -function promiseTabLoadEvent(tab, url) { - info("Wait tab event: load"); - - function handle(loadedUrl) { - if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) { - info(`Skipping spurious load event for ${loadedUrl}`); - return false; - } - - info("Tab event received: load"); - return true; - } - - let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle); - - if (url) { - BrowserTestUtils.loadURI(tab.linkedBrowser, url); - } - - return loaded; -} - -function openIdentityPopup() { - let mainView = document.getElementById("identity-popup-mainView"); - let viewShown = BrowserTestUtils.waitForEvent(mainView, "ViewShown"); - gIdentityHandler._identityBox.click(); - return viewShown; -} - -function waitForSecurityChange(numChanges = 1, win = null) { - if (!win) { - win = window; - } - return new Promise(resolve => { - let n = 0; - let listener = { - onSecurityChange() { - n = n + 1; - info("Received onSecurityChange event " + n + " of " + numChanges); - if (n >= numChanges) { - win.gBrowser.removeProgressListener(listener); - resolve(n); - } - }, - }; - win.gBrowser.addProgressListener(listener); - }); -} - -function waitForContentBlockingEvent(numChanges = 1, win = null) { - if (!win) { - win = window; - } - return new Promise(resolve => { - let n = 0; - let listener = { - onContentBlockingEvent() { - n = n + 1; - info( - "Received onContentBlockingEvent event " + n + " of " + numChanges - ); - if (n >= numChanges) { - win.gBrowser.removeProgressListener(listener); - resolve(n); - } - }, - }; - win.gBrowser.addProgressListener(listener); - }); -} diff --git a/browser/base/content/test/trackingUI/trackingAPI.js b/browser/base/content/test/trackingUI/trackingAPI.js deleted file mode 100644 index 8f2e458c0d..0000000000 --- a/browser/base/content/test/trackingUI/trackingAPI.js +++ /dev/null @@ -1,51 +0,0 @@ -function createIframe(src) { - let ifr = document.createElement("iframe"); - ifr.src = src; - document.body.appendChild(ifr); -} - -onmessage = event => { - switch (event.data) { - case "tracking": - createIframe("https://trackertest.org/"); - break; - case "cryptomining": - createIframe("http://cryptomining.example.com/"); - break; - case "fingerprinting": - createIframe("https://fingerprinting.example.com/"); - break; - case "more-tracking": - createIframe("https://itisatracker.org/"); - break; - case "cookie": - createIframe( - "https://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs" - ); - break; - case "first-party-cookie": - // Since the content blocking log doesn't seem to get updated for - // top-level cookies right now, we just create an iframe with the - // first party domain... - createIframe( - "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookieServer.sjs" - ); - break; - case "third-party-cookie": - createIframe( - "https://test1.example.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs" - ); - break; - case "window-open": - window.win = window.open( - "http://trackertest.org/browser/browser/base/content/test/trackingUI/cookieServer.sjs", - "_blank", - "width=100,height=100" - ); - break; - case "window-close": - window.win.close(); - window.win = null; - break; - } -}; diff --git a/browser/base/content/test/trackingUI/trackingPage.html b/browser/base/content/test/trackingUI/trackingPage.html deleted file mode 100644 index 60ee20203b..0000000000 --- a/browser/base/content/test/trackingUI/trackingPage.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/browser/base/content/test/webextensions/browser.ini b/browser/base/content/test/webextensions/browser.ini index dff68c569b..2bc856e461 100644 --- a/browser/base/content/test/webextensions/browser.ini +++ b/browser/base/content/test/webextensions/browser.ini @@ -28,5 +28,4 @@ skip-if = !e10s [browser_permissions_pointerevent.js] [browser_permissions_unsigned.js] [browser_update_checkForUpdates.js] -[browser_update_findUpdates.js] [browser_update_interactive_noprompt.js] diff --git a/browser/base/content/test/webextensions/browser_extension_sideloading.js b/browser/base/content/test/webextensions/browser_extension_sideloading.js index 1d88ac00f5..1684936712 100644 --- a/browser/base/content/test/webextensions/browser_extension_sideloading.js +++ b/browser/base/content/test/webextensions/browser_extension_sideloading.js @@ -35,72 +35,37 @@ function promiseEvent(eventEmitter, event) { }); } -async function getAddonElement(managerWindow, addonId) { - if (managerWindow.useHtmlViews) { - // about:addons is using the new HTML page. - const { contentDocument: doc } = managerWindow.document.getElementById( - "html-view-browser" - ); - const card = await BrowserTestUtils.waitForCondition( - () => doc.querySelector(`addon-card[addon-id="${addonId}"]`), - `Found entry for sideload extension addon "${addonId}" in HTML about:addons` - ); - - return card; - } - - // about:addons is using the XUL-based views. - let list = managerWindow.document.getElementById("addon-list"); - // Make sure XBL bindings are applied - list.clientHeight; - const item = Array.from(list.children).find(_item => _item.value == addonId); - ok(item, "Found entry for sideloaded extension in about:addons"); - - return item; +function getAddonElement(managerWindow, addonId) { + const { contentDocument: doc } = managerWindow.document.getElementById( + "html-view-browser" + ); + return BrowserTestUtils.waitForCondition( + () => doc.querySelector(`addon-card[addon-id="${addonId}"]`), + `Found entry for sideload extension addon "${addonId}" in HTML about:addons` + ); } -function assertDisabledSideloadedAddonElement(managerWindow, addonElement) { - if (managerWindow.useHtmlViews) { - // about:addons is using the new HTML page. - const doc = addonElement.ownerDocument; - const enableBtn = addonElement.querySelector('[action="toggle-disabled"]'); - is( - doc.l10n.getAttributes(enableBtn).id, - "enable-addon-button", - "The button has the enable label" - ); - } else { - addonElement.scrollIntoView({ behavior: "instant" }); - ok( - BrowserTestUtils.is_visible(addonElement._enableBtn), - "Enable button is visible for sideloaded extension" - ); - ok( - BrowserTestUtils.is_hidden(addonElement._disableBtn), - "Disable button is not visible for sideloaded extension" - ); - } +function assertSideloadedAddonElementState(addonElement, checked) { + const enableBtn = addonElement.querySelector('[action="toggle-disabled"]'); + is( + enableBtn.checked, + checked, + `The enable button is ${!checked ? " not " : ""} checked` + ); + is(enableBtn.localName, "input", "The enable button is an input"); + is(enableBtn.type, "checkbox", "It's a checkbox"); } function clickEnableExtension(managerWindow, addonElement) { - if (managerWindow.useHtmlViews) { - addonElement.querySelector('[action="toggle-disabled"]').click(); - } else { - BrowserTestUtils.synthesizeMouseAtCenter( - addonElement._enableBtn, - {}, - gBrowser.selectedBrowser - ); - } + addonElement.querySelector('[action="toggle-disabled"]').click(); } -async function test_sideloading({ useHtmlViews }) { +add_task(async function test_sideloading() { const DEFAULT_ICON_URL = "chrome://mozapps/skin/extensions/extensionGeneric.svg"; await SpecialPowers.pushPrefEnv({ set: [ - ["extensions.htmlaboutaddons.enabled", useHtmlViews], ["extensions.autoDisableScopes", 15], ["extensions.ui.ignoreUnsigned", true], ["extensions.allowPrivateBrowsingByDefault", false], @@ -252,7 +217,7 @@ async function test_sideloading({ useHtmlViews }) { // XUL or HTML about:addons addon entry element. const addonElement = await getAddonElement(win, ID2); - assertDisabledSideloadedAddonElement(win, addonElement); + assertSideloadedAddonElementState(addonElement, false); info("Test enabling sideloaded addon 2 from about:addons enable button"); @@ -299,6 +264,7 @@ async function test_sideloading({ useHtmlViews }) { addon2 = await AddonManager.getAddonByID(ID2); is(addon2.userDisabled, false, "Addon 2 should be enabled"); + assertSideloadedAddonElementState(addonElement, true); // Test post install notification on addon 2. await testPostInstallIncognitoCheckbox(addon2); @@ -389,12 +355,4 @@ async function test_sideloading({ useHtmlViews }) { { ...baseEventAddon2, method: "enable" }, { ...baseEventAddon2, method: "uninstall" }, ]; -} - -add_task(async function test_xul_aboutaddons_sideloading() { - await test_sideloading({ useHtmlViews: false }); -}); - -add_task(async function test_html_aboutaddons_sideloading() { - await test_sideloading({ useHtmlViews: true }); }); diff --git a/browser/base/content/test/webextensions/browser_permissions_local_file.js b/browser/base/content/test/webextensions/browser_permissions_local_file.js index 689438f3c6..94188923a3 100644 --- a/browser/base/content/test/webextensions/browser_permissions_local_file.js +++ b/browser/base/content/test/webextensions/browser_permissions_local_file.js @@ -14,11 +14,14 @@ async function installFile(filename) { MockFilePicker.setFiles([file]); MockFilePicker.afterOpenCallback = MockFilePicker.cleanup; - await BrowserOpenAddonsMgr("addons://list/extension"); - let contentWin = gBrowser.selectedTab.linkedBrowser.contentWindow; + let managerWin = await BrowserOpenAddonsMgr("addons://list/extension"); // Do the install... - contentWin.gViewController.doCommand("cmd_installFromFile"); + await BrowserTestUtils.waitForEvent(managerWin.document, "ViewChanged"); + let installButton = managerWin + .getHtmlBrowser() + .contentDocument.querySelector('[action="install-from-file"]'); + installButton.click(); } add_task(async function test_install_extension_from_local_file() { diff --git a/browser/base/content/test/webextensions/browser_update_checkForUpdates.js b/browser/base/content/test/webextensions/browser_update_checkForUpdates.js index aaa1dc6a05..b902527cae 100644 --- a/browser/base/content/test/webextensions/browser_update_checkForUpdates.js +++ b/browser/base/content/test/webextensions/browser_update_checkForUpdates.js @@ -1,6 +1,6 @@ // Invoke the "Check for Updates" menu item function checkAll(win) { - win.gViewController.doCommand("cmd_findAllUpdates"); + triggerPageOptionsAction(win, "check-for-updates"); return new Promise(resolve => { let observer = { observe(subject, topic, data) { @@ -13,29 +13,5 @@ function checkAll(win) { } // Test "Check for Updates" with both auto-update settings -async function test_check_for_updates() { - info("Test 'Check for Updates' with auto-update true"); - await interactiveUpdateTest(true, checkAll); - info("Test 'Check for Updates' with auto-update false"); - await interactiveUpdateTest(false, checkAll); -} - -add_task(async function test_xul_aboutaddons() { - await SpecialPowers.pushPrefEnv({ - set: [["extensions.htmlaboutaddons.enabled", false]], - }); - - await test_check_for_updates(); - - await SpecialPowers.popPrefEnv(); -}); - -add_task(async function test_html_aboutaddons() { - await SpecialPowers.pushPrefEnv({ - set: [["extensions.htmlaboutaddons.enabled", true]], - }); - - await test_check_for_updates(); - - await SpecialPowers.popPrefEnv(); -}); +add_task(() => interactiveUpdateTest(true, checkAll)); +add_task(() => interactiveUpdateTest(false, checkAll)); diff --git a/browser/base/content/test/webextensions/browser_update_findUpdates.js b/browser/base/content/test/webextensions/browser_update_findUpdates.js deleted file mode 100644 index 553da5041b..0000000000 --- a/browser/base/content/test/webextensions/browser_update_findUpdates.js +++ /dev/null @@ -1,32 +0,0 @@ -// Invoke an invidual extension's "Find Updates" menu item -function checkOne(win, addon) { - win.gViewController.doCommand("cmd_findItemUpdates", addon); -} - -// Test "Find Updates" with both auto-update settings -async function test_find_updates() { - info("Test 'Find Updates' with auto-update true"); - await interactiveUpdateTest(true, checkOne); - info("Test 'Find Updates' with auto-update false"); - await interactiveUpdateTest(false, checkOne); -} - -add_task(async function test_xul_aboutaddons() { - await SpecialPowers.pushPrefEnv({ - set: [["extensions.htmlaboutaddons.enabled", false]], - }); - - await test_find_updates(); - - await SpecialPowers.popPrefEnv(); -}); - -add_task(async function test_html_aboutaddons() { - await SpecialPowers.pushPrefEnv({ - set: [["extensions.htmlaboutaddons.enabled", true]], - }); - - await test_find_updates(); - - await SpecialPowers.popPrefEnv(); -}); diff --git a/browser/base/content/test/webextensions/browser_update_interactive_noprompt.js b/browser/base/content/test/webextensions/browser_update_interactive_noprompt.js index 3f55305003..edc1d733d7 100644 --- a/browser/base/content/test/webextensions/browser_update_interactive_noprompt.js +++ b/browser/base/content/test/webextensions/browser_update_interactive_noprompt.js @@ -32,6 +32,8 @@ async function testUpdateNoPrompt( // Go to Extensions in about:addons let win = await BrowserOpenAddonsMgr("addons://list/extension"); + await BrowserTestUtils.waitForEvent(win.document, "ViewChanged"); + let sawPopup = false; function popupListener() { sawPopup = true; @@ -40,7 +42,7 @@ async function testUpdateNoPrompt( // Trigger an update check, we should see the update get applied let updatePromise = waitForUpdate(addon); - win.gViewController.doCommand("cmd_findAllUpdates"); + triggerPageOptionsAction(win, "check-for-updates"); await updatePromise; addon = await AddonManager.getAddonByID(id); diff --git a/browser/base/content/test/webextensions/head.js b/browser/base/content/test/webextensions/head.js index 8960ff426c..c656874fa4 100644 --- a/browser/base/content/test/webextensions/head.js +++ b/browser/base/content/test/webextensions/head.js @@ -175,6 +175,16 @@ async function waitForUpdate(addon) { return newAddon; } +/** + * Trigger an action from the page options menu. + */ +function triggerPageOptionsAction(win, action) { + win + .getHtmlBrowser() + .contentDocument.querySelector(`#page-options [action="${action}"]`) + .click(); +} + function isDefaultIcon(icon) { // These are basically the same icon, but code within webextensions // generates references to the former and generic add-ons manager code @@ -472,29 +482,25 @@ async function interactiveUpdateTest(autoUpdate, checkFn) { if (manualUpdatePromise) { await manualUpdatePromise; - if (win.useHtmlViews) { - // about:addons is using the new HTML views. - const availableUpdates = win.document.getElementById( - "updates-manualUpdatesFound-btn" + let doc = win.getHtmlBrowser().contentDocument; + if (win.gViewController.currentViewId !== "addons://updates/available") { + let showUpdatesBtn = doc.querySelector("addon-updates-message").button; + await TestUtils.waitForCondition(() => { + return !showUpdatesBtn.hidden; + }, "Wait for show updates button"); + let viewChanged = BrowserTestUtils.waitForEvent( + win.document, + "ViewChanged" ); - availableUpdates.click(); - let doc = win.getHtmlBrowser().contentDocument; - let card = await BrowserTestUtils.waitForCondition(() => { - return doc.querySelector(`addon-card[addon-id="${ID}"]`); - }, `Wait addon card for "${ID}"`); - let updateBtn = card.querySelector( - 'panel-item[action="install-update"]' - ); - ok(updateBtn, `Found update button for "${ID}"`); - updateBtn.click(); - } else { - // about:addons is still using the legacy XUL views. - let list = win.document.getElementById("addon-list"); - // Make sure we have XBL bindings - list.clientHeight; - let item = list.itemChildren.find(_item => _item.value == ID); - EventUtils.synthesizeMouseAtCenter(item._updateBtn, {}, win); + showUpdatesBtn.click(); + await viewChanged; } + let card = await TestUtils.waitForCondition(() => { + return doc.querySelector(`addon-card[addon-id="${ID}"]`); + }, `Wait addon card for "${ID}"`); + let updateBtn = card.querySelector('panel-item[action="install-update"]'); + ok(updateBtn, `Found update button for "${ID}"`); + updateBtn.click(); } return { promise }; @@ -514,6 +520,8 @@ async function interactiveUpdateTest(autoUpdate, checkFn) { let win = await BrowserOpenAddonsMgr("addons://list/extension"); + await BrowserTestUtils.waitForEvent(win.document, "ViewChanged"); + // Trigger an update check let popupPromise = promisePopupNotificationShown("addon-webext-permissions"); let { promise: checkPromise } = await triggerUpdate(win, addon); diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js index 254c703e0a..a7d3ce99cd 100644 --- a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js @@ -38,11 +38,7 @@ var gTests = [ aSharing, "the tab has the attribute to show the " + aSharing + " icon" ); - let icon = document.getAnonymousElementByAttribute( - tab, - "anonid", - "sharing-icon" - ); + let icon = tab.sharingIcon; is( window.getComputedStyle(icon).display, "none", diff --git a/browser/base/content/test/webrtc/head.js b/browser/base/content/test/webrtc/head.js index c08c7a6c6c..0e9d3bc877 100644 --- a/browser/base/content/test/webrtc/head.js +++ b/browser/base/content/test/webrtc/head.js @@ -92,7 +92,7 @@ function promiseIndicatorWindow() { return Promise.resolve(); } - return promiseWindow("chrome://browser/content/webrtcIndicator.xul"); + return promiseWindow("chrome://browser/content/webrtcIndicator.xhtml"); } async function assertWebRTCIndicatorStatus(expected) { diff --git a/browser/base/content/titlebar-items.inc.xul b/browser/base/content/titlebar-items.inc.xhtml similarity index 100% rename from browser/base/content/titlebar-items.inc.xul rename to browser/base/content/titlebar-items.inc.xhtml diff --git a/browser/base/content/urlbarBindings.xml b/browser/base/content/urlbarBindings.xml deleted file mode 100644 index 2ef3d0c992..0000000000 --- a/browser/base/content/urlbarBindings.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - -%browserDTD; -]> - -browser.urlbar
API to experiment with new features in the URLBar. Restricted to Mozilla privileged WebExtensions.",
+ "permissions": [
+ "urlbar"
+ ],
+ "types": [
+ {
+ "id": "SourceType",
+ "type": "string",
+ "description": "The source of a result.",
+ "enum": ["bookmarks", "history", "search", "tabs", "local", "network"]
+ },
+ {
+ "id": "QueryContext",
+ "type": "object",
+ "description": "Context of the current query request.",
+ "properties": {
+ "isPrivate": {
+ "type": "boolean",
+ "description": "Whether the browser context is private."
+ },
+ "maxResults": {
+ "type": "integer",
+ "description": "The maximum number of results shown to the user."
+ },
+ "searchString": {
+ "type": "string",
+ "description": "The current search string."
+ },
+ "acceptableSources": {
+ "type": "array",
+ "description": "List of acceptable SourceType to return.",
+ "items": {
+ "$ref": "SourceType"
+ }
+ }
+ }
+ }
+ ],
+ "properties": {
+ "openViewOnFocus": {
+ "$ref": "types.Setting",
+ "description": "Enables or disables the open-view-on-focus mode."
+ }
+ },
+ "events": [
+ {
+ "name": "onQueryReady",
+ "type": "function",
+ "description": "Fired before starting a search to get the provider's behavior.",
+ "parameters": [
+ {
+ "name": "context",
+ "$ref": "QueryContext"
+ }
+ ],
+ "extraParameters": [
+ {
+ "name": "name",
+ "type": "string",
+ "description": "Name of the provider.",
+ "pattern": "^[a-zA-Z0-9_-]+$"
+ }
+ ],
+ "returns": {
+ "type": "string",
+ "description": "Whether this provider should be queried, and if it wants to restrict results",
+ "enum": ["active", "inactive", "restricting"]
+ }
+ }
+ ]
+ }
+]
diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
index 9c5fb258b4..54fc488c2d 100644
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
@@ -166,11 +166,7 @@ async function runTests(options) {
);
if (details.badge) {
- let badge = button.ownerDocument.getAnonymousElementByAttribute(
- button,
- "class",
- "toolbarbutton-badge"
- );
+ let badge = button.badgeLabel;
let style = window.getComputedStyle(badge);
let expected = {
backgroundColor: serializeColor(details.badgeBackgroundColor),
@@ -508,11 +504,7 @@ add_task(async function testBadgeColorPersistence() {
function getBadgeForWindow(win) {
const widget = getBrowserActionWidget(extension).forWindow(win).node;
- return document.getAnonymousElementByAttribute(
- widget,
- "class",
- "toolbarbutton-badge"
- );
+ return widget.badgeLabel;
}
let badge = getBadgeForWindow(window);
@@ -526,7 +518,7 @@ add_task(async function testBadgeColorPersistence() {
await badgeChanged;
- is(badge.value, "hi", "badge text is set in first window");
+ is(badge.textContent, "hi", "badge text is set in first window");
is(
badge.style.backgroundColor,
"rgb(0, 255, 0)",
@@ -538,7 +530,7 @@ add_task(async function testBadgeColorPersistence() {
await windowOpenedPromise;
badge = getBadgeForWindow(win);
- is(badge.value, "hi", "badge text is set in new window");
+ is(badge.textContent, "hi", "badge text is set in new window");
is(
badge.style.backgroundColor,
"rgb(0, 255, 0)",
diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js b/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js
index 4109e6fd18..8d522ab795 100644
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js
@@ -1,11 +1,5 @@
"use strict";
-XPCOMUtils.defineLazyPreferenceGetter(
- this,
- "HTML_ABOUTADDONS_ENABLED",
- "extensions.htmlaboutaddons.enabled",
- false
-);
let extData = {
manifest: {
@@ -240,21 +234,16 @@ add_task(async function browseraction_contextmenu_manage_extension() {
);
await closeChromeContextMenu(menuId, manageExtension, win);
let managerWindow = (await addonManagerPromise).linkedBrowser.contentWindow;
- if (managerWindow.useHtmlViews) {
- // Check the UI to make sure that the correct view is loaded.
- is(
- managerWindow.gViewController.currentViewId,
- `addons://detail/${encodeURIComponent(id)}`,
- "Expected extension details view in about:addons"
- );
- // In HTML about:addons, the default view does not show the inline
- // options browser, so we should not receive an "options-loaded" event.
- // (if we do, the test will fail due to the unexpected message).
- } else {
- info("Waiting for inline options page in XUL about:addons");
- // In XUL about:addons, the inline options page is shown by default.
- await extension.awaitMessage("options-loaded");
- }
+
+ // Check the UI to make sure that the correct view is loaded.
+ is(
+ managerWindow.gViewController.currentViewId,
+ `addons://detail/${encodeURIComponent(id)}`,
+ "Expected extension details view in about:addons"
+ );
+ // In HTML about:addons, the default view does not show the inline
+ // options browser, so we should not receive an "options-loaded" event.
+ // (if we do, the test will fail due to the unexpected message).
info(
`Remove the opened tab, and await customize mode to be restored if necessary`
@@ -315,11 +304,7 @@ add_task(async function browseraction_contextmenu_manage_extension() {
info("Wait until the overflow menu is ready");
let overflowButton = win.document.getElementById("nav-bar-overflow-button");
- let icon = win.document.getAnonymousElementByAttribute(
- overflowButton,
- "class",
- "toolbarbutton-icon"
- );
+ let icon = overflowButton.icon;
await waitForElementShown(icon);
if (!customizing) {
@@ -421,11 +406,7 @@ async function runTestContextMenu({
info("Wait until the overflow menu is ready");
let overflowButton = win.document.getElementById("nav-bar-overflow-button");
- let icon = win.document.getAnonymousElementByAttribute(
- overflowButton,
- "class",
- "toolbarbutton-icon"
- );
+ let icon = overflowButton.icon;
await waitForElementShown(icon);
if (!customizing) {
diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon_permissions.js b/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon_permissions.js
index 21f761a52c..33b174ae52 100644
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon_permissions.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon_permissions.js
@@ -154,7 +154,10 @@ add_task(async function testSecureURLsDenied() {
browser.tabs.query({ active: true, currentWindow: true }, tabs => {
let tabId = tabs[0].id;
- let urls = ["chrome://browser/content/browser.xul", "javascript:true"];
+ let urls = [
+ "chrome://browser/content/browser.xhtml",
+ "javascript:true",
+ ];
let promises = [];
for (let url of urls) {
@@ -185,7 +188,7 @@ add_task(async function testSecureURLsDenied() {
add_task(async function testSecureManifestURLsDenied() {
// Test URLs included in the manifest.
- let urls = ["chrome://browser/content/browser.xul", "javascript:true"];
+ let urls = ["chrome://browser/content/browser.xhtml", "javascript:true"];
let apis = ["browser_action", "page_action"];
diff --git a/browser/components/extensions/test/browser/browser_ext_identity_indication.js b/browser/components/extensions/test/browser/browser_ext_identity_indication.js
index dd341e5d02..c95c29f06e 100644
--- a/browser/components/extensions/test/browser/browser_ext_identity_indication.js
+++ b/browser/components/extensions/test/browser/browser_ext_identity_indication.js
@@ -20,8 +20,11 @@ function confirmDefaults() {
).listStyleImage;
is(extensionIconURL, "none", "Extension icon should not be displayed");
- let label = document.getElementById("identity-icon-label").value;
- is(label, "", "No label should be used before the extension is started");
+ let label = document.getElementById("identity-icon-label");
+ ok(
+ BrowserTestUtils.is_hidden(label),
+ "No label should be used before the extension is started"
+ );
}
function confirmExtensionPage() {
@@ -52,8 +55,13 @@ function confirmExtensionPage() {
"The correct tooltip should be used"
);
- let label = document.getElementById("identity-icon-label").value;
- is(label, "Extension (Test Extension)", "The correct label should be used");
+ let label = document.getElementById("identity-icon-label");
+ is(
+ label.value,
+ "Extension (Test Extension)",
+ "The correct label should be used"
+ );
+ ok(BrowserTestUtils.is_visible(label), "No label should be visible");
}
add_task(async function testIdentityIndication() {
diff --git a/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js b/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
index b24a8e17f7..bcc02f61ba 100644
--- a/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
@@ -237,7 +237,7 @@ add_task(async function testPageActionPopup() {
});
add_task(async function testPageActionSecurity() {
- const URL = "chrome://browser/content/browser.xul";
+ const URL = "chrome://browser/content/browser.xhtml";
let apis = ["browser_action", "page_action"];
diff --git a/browser/components/extensions/test/browser/browser_ext_popup_background.js b/browser/components/extensions/test/browser/browser_ext_popup_background.js
index 826ae0b118..d85e794aa7 100644
--- a/browser/components/extensions/test/browser/browser_ext_popup_background.js
+++ b/browser/components/extensions/test/browser/browser_ext_popup_background.js
@@ -3,12 +3,8 @@
async function testPanel(browser, standAlone, initial_background) {
let panel = getPanelForNode(browser);
- let arrowContent = document.getAnonymousElementByAttribute(
- panel,
- "class",
- "panel-arrowcontent"
- );
- let arrow = document.getAnonymousElementByAttribute(panel, "anonid", "arrow");
+ let arrowContent = panel.shadowRoot.querySelector(".panel-arrowcontent");
+ let arrow = panel.shadowRoot.querySelector(".panel-arrow");
let checkArrow = (background = null) => {
if (background == null || !standAlone) {
diff --git a/browser/components/extensions/test/browser/browser_ext_popup_corners.js b/browser/components/extensions/test/browser/browser_ext_popup_corners.js
index 231d833b58..805e86c5b4 100644
--- a/browser/components/extensions/test/browser/browser_ext_popup_corners.js
+++ b/browser/components/extensions/test/browser/browser_ext_popup_corners.js
@@ -33,13 +33,14 @@ add_task(async function testPopupBorderRadius() {
async function testPanel(browser, standAlone = true) {
let panel = getPanelForNode(browser);
- let arrowContent = document.getAnonymousElementByAttribute(
- panel,
- "class",
- "panel-arrowcontent"
- );
+ let arrowContent = panel.shadowRoot.querySelector(".panel-arrowcontent");
let panelStyle = getComputedStyle(arrowContent);
+ is(
+ panelStyle.overflow,
+ "hidden",
+ "overflow is not hidden, thus it doesn't clip"
+ );
let stack = browser.parentNode;
let viewNode = stack.parentNode === panel ? browser : stack.parentNode;
diff --git a/browser/components/extensions/test/browser/browser_ext_popup_select.js b/browser/components/extensions/test/browser/browser_ext_popup_select.js
index e4cf28f5e3..f7dd32dbc4 100644
--- a/browser/components/extensions/test/browser/browser_ext_popup_select.js
+++ b/browser/components/extensions/test/browser/browser_ext_popup_select.js
@@ -5,6 +5,11 @@ add_task(async function testSetup() {
});
add_task(async function testPopupSelectPopup() {
+ let tab = await BrowserTestUtils.openNewForegroundTab({
+ gBrowser,
+ url: "https://example.com",
+ });
+
let extension = ExtensionTestUtils.loadExtension({
background() {
browser.tabs.query({ active: true, currentWindow: true }, tabs => {
@@ -108,6 +113,7 @@ add_task(async function testPopupSelectPopup() {
await closePageAction(extension);
}
+ BrowserTestUtils.removeTab(tab);
await extension.unload();
});
diff --git a/browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js b/browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js
index c547789742..1c0a1d9280 100644
--- a/browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js
+++ b/browser/components/extensions/test/browser/browser_ext_runtime_openOptionsPage.js
@@ -60,7 +60,7 @@ async function loadExtension(options) {
return extension;
}
-async function run_test_inline_options() {
+add_task(async function run_test_inline_options() {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"http://example.com/"
@@ -254,19 +254,6 @@ async function run_test_inline_options() {
await extension.unload();
BrowserTestUtils.removeTab(tab);
-}
-
-add_task(async function test_inline_options() {
- for (let htmlEnabled of [false, true]) {
- info(
- `Test options opened inline ${htmlEnabled ? "HTML" : "XUL"} about:addons`
- );
- await SpecialPowers.pushPrefEnv({
- set: [["extensions.htmlaboutaddons.enabled", htmlEnabled]],
- });
- await run_test_inline_options();
- await SpecialPowers.popPrefEnv();
- }
});
add_task(async function test_tab_options() {
diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js b/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
index e198bb1829..81448fcd4d 100644
--- a/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_create_url.js
@@ -82,7 +82,7 @@ add_task(async function test_urlbar_focus() {
info(`After opening an empty tab, gURLBar.focused: ${gURLBar.focused}`);
is(active.tagName, "html:input", "Input element focused");
- ok(active.classList.contains("urlbar-input"), "Urlbar focused");
+ is(active.id, "urlbar-input", "Urlbar focused");
extension.sendMessage("remove", tab2.id);
await extension.awaitMessage("result");
diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js b/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
index 815a03584f..f2182b1359 100644
--- a/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
@@ -1,44 +1,39 @@
"use strict";
add_task(async function() {
- await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.net/");
- let window1 = await BrowserTestUtils.openNewBrowserWindow();
- await BrowserTestUtils.openNewForegroundTab(
- window1.gBrowser,
- "http://example.com/"
- );
- let window2 = await BrowserTestUtils.openNewBrowserWindow({ private: true });
- await BrowserTestUtils.openNewForegroundTab(
- window2.gBrowser,
- "http://example.com/"
- );
-
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["tabs"],
},
incognitoOverride: "spanning",
async background() {
- let tabs = await browser.tabs.query({ url: "