forked from mirrors/gecko-dev
		
	Differential Revision: https://phabricator.services.mozilla.com/D68073 --HG-- rename : browser/base/content/test/siteProtections/.eslintrc.js => browser/base/content/test/protectionsUI/.eslintrc.js rename : browser/base/content/test/trackingUI/benignPage.html => browser/base/content/test/protectionsUI/benignPage.html rename : browser/base/content/test/siteProtections/browser.ini => browser/base/content/test/protectionsUI/browser.ini rename : browser/base/content/test/siteProtections/browser_protections_UI.js => browser/base/content/test/protectionsUI/browser_protectionsUI.js rename : browser/base/content/test/trackingUI/browser_trackingUI_3.js => browser/base/content/test/protectionsUI/browser_protectionsUI_3.js rename : browser/base/content/test/trackingUI/browser_trackingUI_animation.js => browser/base/content/test/protectionsUI/browser_protectionsUI_animation.js rename : browser/base/content/test/trackingUI/browser_trackingUI_animation_2.js => browser/base/content/test/protectionsUI/browser_protectionsUI_animation_2.js rename : browser/base/content/test/trackingUI/browser_trackingUI_background_tabs.js => browser/base/content/test/protectionsUI/browser_protectionsUI_background_tabs.js rename : browser/base/content/test/trackingUI/browser_trackingUI_categories.js => browser/base/content/test/protectionsUI/browser_protectionsUI_categories.js rename : browser/base/content/test/trackingUI/browser_trackingUI_cookies_subview.js => browser/base/content/test/protectionsUI/browser_protectionsUI_cookies_subview.js rename : browser/base/content/test/trackingUI/browser_trackingUI_cryptominers.js => browser/base/content/test/protectionsUI/browser_protectionsUI_cryptominers.js rename : browser/base/content/test/trackingUI/browser_trackingUI_fetch.js => browser/base/content/test/protectionsUI/browser_protectionsUI_fetch.js rename : browser/base/content/test/trackingUI/browser_trackingUI_fingerprinters.js => browser/base/content/test/protectionsUI/browser_protectionsUI_fingerprinters.js rename : browser/base/content/test/siteProtections/browser_protections_UI_milestones.js => browser/base/content/test/protectionsUI/browser_protectionsUI_milestones.js rename : browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js => browser/base/content/test/protectionsUI/browser_protectionsUI_open_preferences.js rename : browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js => browser/base/content/test/protectionsUI/browser_protectionsUI_pbmode_exceptions.js rename : browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js => browser/base/content/test/protectionsUI/browser_protectionsUI_report_breakage.js rename : browser/base/content/test/trackingUI/browser_trackingUI_shield_visibility.js => browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js rename : browser/base/content/test/trackingUI/browser_trackingUI_socialtracking.js => browser/base/content/test/protectionsUI/browser_protectionsUI_socialtracking.js rename : browser/base/content/test/trackingUI/browser_trackingUI_state.js => browser/base/content/test/protectionsUI/browser_protectionsUI_state.js rename : browser/base/content/test/trackingUI/browser_trackingUI_state_reset.js => browser/base/content/test/protectionsUI/browser_protectionsUI_state_reset.js rename : browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js => browser/base/content/test/protectionsUI/browser_protectionsUI_telemetry.js rename : browser/base/content/test/trackingUI/browser_trackingUI_trackers_subview.js => browser/base/content/test/protectionsUI/browser_protectionsUI_trackers_subview.js rename : browser/base/content/test/trackingUI/containerPage.html => browser/base/content/test/protectionsUI/containerPage.html rename : browser/base/content/test/trackingUI/cookiePage.html => browser/base/content/test/protectionsUI/cookiePage.html rename : browser/base/content/test/trackingUI/cookieServer.sjs => browser/base/content/test/protectionsUI/cookieServer.sjs rename : browser/base/content/test/trackingUI/cookieSetterPage.html => browser/base/content/test/protectionsUI/cookieSetterPage.html rename : browser/base/content/test/trackingUI/embeddedPage.html => browser/base/content/test/protectionsUI/embeddedPage.html rename : browser/base/content/test/trackingUI/file_trackingUI_fetch.html => browser/base/content/test/protectionsUI/file_protectionsUI_fetch.html rename : browser/base/content/test/trackingUI/file_trackingUI_fetch.js => browser/base/content/test/protectionsUI/file_protectionsUI_fetch.js rename : browser/base/content/test/trackingUI/file_trackingUI_fetch.js^headers^ => browser/base/content/test/protectionsUI/file_protectionsUI_fetch.js^headers^ rename : browser/base/content/test/siteProtections/head.js => browser/base/content/test/protectionsUI/head.js rename : browser/base/content/test/trackingUI/trackingAPI.js => browser/base/content/test/protectionsUI/trackingAPI.js rename : browser/base/content/test/trackingUI/trackingPage.html => browser/base/content/test/protectionsUI/trackingPage.html extra : moz-landing-system : lando
		
			
				
	
	
		
			127 lines
		
	
	
	
		
			3.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			127 lines
		
	
	
	
		
			3.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/* 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/protectionsUI/trackingPage.html";
 | 
						|
const BENIGN_PAGE =
 | 
						|
  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/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.getContentBlockingEvents(),
 | 
						|
    0,
 | 
						|
    "Benign page has no content blocking event"
 | 
						|
  );
 | 
						|
  ok(
 | 
						|
    !gProtectionsHandler.iconBox.hasAttribute("active"),
 | 
						|
    "shield is not active"
 | 
						|
  );
 | 
						|
 | 
						|
  await Promise.all([
 | 
						|
    promiseTabLoadEvent(tab, TRACKING_PAGE),
 | 
						|
    waitForContentBlockingEvent(2),
 | 
						|
  ]);
 | 
						|
 | 
						|
  is(
 | 
						|
    browser.getContentBlockingEvents(),
 | 
						|
    Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
 | 
						|
    "Tracking page has a content blocking event"
 | 
						|
  );
 | 
						|
  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 | 
						|
 | 
						|
  await promiseTabLoadEvent(tab, BENIGN_PAGE);
 | 
						|
 | 
						|
  is(
 | 
						|
    browser.getContentBlockingEvents(),
 | 
						|
    0,
 | 
						|
    "Benign page has no content blocking event"
 | 
						|
  );
 | 
						|
  ok(
 | 
						|
    !gProtectionsHandler.iconBox.hasAttribute("active"),
 | 
						|
    "shield is not active"
 | 
						|
  );
 | 
						|
 | 
						|
  let contentBlockingEvent = waitForContentBlockingEvent(3);
 | 
						|
  let trackingTab = await BrowserTestUtils.openNewForegroundTab(
 | 
						|
    gBrowser,
 | 
						|
    TRACKING_PAGE
 | 
						|
  );
 | 
						|
  await contentBlockingEvent;
 | 
						|
 | 
						|
  is(
 | 
						|
    trackingTab.linkedBrowser.getContentBlockingEvents(),
 | 
						|
    Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
 | 
						|
    "Tracking page has a content blocking event"
 | 
						|
  );
 | 
						|
  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 | 
						|
 | 
						|
  gBrowser.selectedTab = tab;
 | 
						|
  is(
 | 
						|
    browser.getContentBlockingEvents(),
 | 
						|
    0,
 | 
						|
    "Benign page has no content blocking event"
 | 
						|
  );
 | 
						|
  ok(
 | 
						|
    !gProtectionsHandler.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(
 | 
						|
    !gProtectionsHandler.iconBox.hasAttribute("active"),
 | 
						|
    "shield is not active"
 | 
						|
  );
 | 
						|
 | 
						|
  await Promise.all([
 | 
						|
    promiseTabLoadEvent(tab, TRACKING_PAGE),
 | 
						|
    waitForContentBlockingEvent(3),
 | 
						|
  ]);
 | 
						|
  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 | 
						|
 | 
						|
  await promiseTabLoadEvent(tab, ABOUT_PAGE);
 | 
						|
  ok(
 | 
						|
    !gProtectionsHandler.iconBox.hasAttribute("active"),
 | 
						|
    "shield is not active"
 | 
						|
  );
 | 
						|
 | 
						|
  let contentBlockingEvent = waitForContentBlockingEvent(3);
 | 
						|
  let trackingTab = await BrowserTestUtils.openNewForegroundTab(
 | 
						|
    gBrowser,
 | 
						|
    TRACKING_PAGE
 | 
						|
  );
 | 
						|
  await contentBlockingEvent;
 | 
						|
  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
 | 
						|
 | 
						|
  gBrowser.selectedTab = tab;
 | 
						|
  ok(
 | 
						|
    !gProtectionsHandler.iconBox.hasAttribute("active"),
 | 
						|
    "shield is not active"
 | 
						|
  );
 | 
						|
 | 
						|
  gBrowser.removeTab(trackingTab);
 | 
						|
  gBrowser.removeTab(tab);
 | 
						|
 | 
						|
  Services.prefs.clearUserPref(TP_PREF);
 | 
						|
});
 |