forked from mirrors/gecko-dev
		
	 5584301845
			
		
	
	
		5584301845
		
	
	
	
	
		
			
			This commit also moves the remaining trackingUI_* tests out of b/b/c/test/general, since I needed to touch them anyway Differential Revision: https://phabricator.services.mozilla.com/D2935 --HG-- rename : browser/base/content/test/general/benignPage.html => browser/base/content/test/trackingUI/benignPage.html rename : browser/base/content/test/general/browser_trackingUI_3.js => browser/base/content/test/trackingUI/browser_trackingUI_3.js rename : browser/base/content/test/general/browser_trackingUI_4.js => browser/base/content/test/trackingUI/browser_trackingUI_animation_2.js rename : browser/base/content/test/general/browser_trackingUI_6.js => browser/base/content/test/trackingUI/browser_trackingUI_fetch.js rename : browser/base/content/test/general/browser_trackingUI_5.js => browser/base/content/test/trackingUI/browser_trackingUI_pbmode_exceptions.js rename : browser/base/content/test/general/browser_trackingUI_telemetry.js => browser/base/content/test/trackingUI/browser_trackingUI_telemetry.js rename : browser/base/content/test/general/file_trackingUI_6.html => browser/base/content/test/trackingUI/file_trackingUI_fetch.html rename : browser/base/content/test/general/file_trackingUI_6.js => browser/base/content/test/trackingUI/file_trackingUI_fetch.js rename : browser/base/content/test/general/file_trackingUI_6.js^headers^ => browser/base/content/test/trackingUI/file_trackingUI_fetch.js^headers^ rename : browser/base/content/test/general/trackingPage.html => browser/base/content/test/trackingUI/trackingPage.html extra : rebase_source : 2a12463ab2ba39bdcf077580a2d6e565f80c879c
		
			
				
	
	
		
			113 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /*
 | |
|  * 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 CB_PREF = "browser.contentblocking.enabled";
 | |
| const TP_PREF = "privacy.trackingprotection.enabled";
 | |
| const TP_PB_PREF = "privacy.trackingprotection.enabled";
 | |
| 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";
 | |
| 
 | |
| registerCleanupFunction(function() {
 | |
|   UrlClassifierTestUtils.cleanupTestTrackers();
 | |
|   Services.prefs.clearUserPref(TP_PREF);
 | |
|   Services.prefs.clearUserPref(TP_PB_PREF);
 | |
|   Services.prefs.clearUserPref(CB_PREF);
 | |
| });
 | |
| 
 | |
| function waitForSecurityChange(tabbrowser, numChanges = 1) {
 | |
|   return new Promise(resolve => {
 | |
|     let n = 0;
 | |
|     let listener = {
 | |
|       onSecurityChange() {
 | |
|         n = n + 1;
 | |
|         info("Received onSecurityChange event " + n + " of " + numChanges);
 | |
|         if (n >= numChanges) {
 | |
|           tabbrowser.removeProgressListener(listener);
 | |
|           resolve();
 | |
|         }
 | |
|       }
 | |
|     };
 | |
|     tabbrowser.addProgressListener(listener);
 | |
|   });
 | |
| }
 | |
| 
 | |
| async function testTrackingProtectionAnimation(tabbrowser) {
 | |
|   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");
 | |
| 
 | |
|   info("Switch from tracking -> benign tab");
 | |
|   let securityChanged = waitForSecurityChange(tabbrowser);
 | |
|   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(tabbrowser);
 | |
|   tabbrowser.selectedTab = trackingTab;
 | |
|   await securityChanged;
 | |
| 
 | |
|   ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
 | |
|   ok(!ContentBlocking.iconBox.hasAttribute("animate"), "iconBox not animating");
 | |
| 
 | |
|   info("Reload tracking tab");
 | |
|   securityChanged = waitForSecurityChange(tabbrowser, 2);
 | |
|   tabbrowser.reload();
 | |
|   await securityChanged;
 | |
| 
 | |
|   ok(ContentBlocking.iconBox.hasAttribute("active"), "iconBox active");
 | |
|   ok(ContentBlocking.iconBox.hasAttribute("animate"), "iconBox 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");
 | |
| 
 | |
|   Services.prefs.setBoolPref(TP_PREF, true);
 | |
|   ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
 | |
|   Services.prefs.setBoolPref(CB_PREF, true);
 | |
|   ok(ContentBlocking.enabled, "CB 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");
 | |
| 
 | |
|   Services.prefs.setBoolPref(TP_PB_PREF, true);
 | |
|   ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
 | |
|   Services.prefs.setBoolPref(CB_PREF, true);
 | |
|   ok(TrackingProtection.enabled, "CB is enabled after setting the pref");
 | |
| 
 | |
|   await testTrackingProtectionAnimation(tabbrowser);
 | |
| 
 | |
|   privateWin.close();
 | |
| });
 |