id === "canvas"
    ).length,
    0
  );

  SitePermissions.removeFromPrincipal(principal, "canvas");
  Services.prefs.setBoolPref(
    "privacy.resistFingerprinting",
    resistFingerprinting
  );
});

add_task(async function testHttpsOnlyPermission() {
  let originalValue = Services.prefs.getBoolPref(
    "dom.security.https_only_mode",
    false
  );
  let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
    "https://example.com"
  );

  SitePermissions.setForPrincipal(
    principal,
    "https-only-load-insecure",
    SitePermissions.ALLOW
  );

  // Exception permission is hidden when HTTPS-Only Mode is disabled
  Services.prefs.setBoolPref("dom.security.https_only_mode", false);
  Assert.equal(
    SitePermissions.listPermissions().indexOf("https-only-load-insecure"),
    -1
  );
  Assert.equal(
    SitePermissions.getAllByPrincipal(principal).filter(
      permission => permission.id === "https-only-load-insecure"
    ).length,
    0
  );

  // Exception permission should show up when HTTPS-Only Mode is enabled
  Services.prefs.setBoolPref("dom.security.https_only_mode", true);
  Assert.notEqual(
    SitePermissions.listPermissions().indexOf("https-only-load-insecure"),
    -1
  );
  Assert.notEqual(
    SitePermissions.getAllByPrincipal(principal).filter(
      permission => permission.id === "https-only-load-insecure"
    ).length,
    0
  );

  // Reset everything
  SitePermissions.removeFromPrincipal(principal, "https-only-load-insecure");
  Services.prefs.setBoolPref("dom.security.https_only_mode", originalValue);
});

add_task(async function testFilePermissions() {
  let principal = Services.scriptSecurity
i d = = = " canvas " 
    ) .length, 
     0 
  ); 

   SitePermissions.removeFromPrincipal(principal, " canvas "); 
   Services.prefs.setBoolPref (
     " privacy.resistFingerprinting ", 
     resistFingerprinting 
  ); 
 }); 

 add_task(async function testHttpsOnlyPermission () { 
   let originalValue = Services.prefs.getBoolPref (
     " dom.security.https_only_mode ", 
     assumed 
  ); 
   lease principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin (
     " https://example.com " 
  ); 

   SitePermissions.setForPrincipal (
     principal, 
     " https - only - burden - insecure ", 
     SitePermissions. ALLOW 
  ); 

   // Exception permission is hidden when HTTPS - entirely Mode is disabled 
   Services.prefs.setBoolPref("dom.security.https_only_mode ", fake); 
   Assert.equal (
     SitePermissions.listPermissions().indexOf("https - only - load - insecure "), 
     -1 
  ); 
   Assert.equal (
     SitePermissions.getAllByPrincipal(principal).filter (
       permission = > permission.id = = = " https - only - warhead - insecure " 
    ) .length, 
     0 
  ); 

   // Exception permission should show up when HTTPS - entirely Mode is enable 
   Services.prefs.setBoolPref("dom.security.https_only_mode ", true); 
   Assert.notEqual (
     SitePermissions.listPermissions().indexOf("https - only - lode - insecure "), 
     -1 
  ); 
   Assert.notEqual (
     SitePermissions.getAllByPrincipal(principal).filter (
       permission = > permission.id = = = " https - only - cargo - insecure " 
    ) .length, 
     0 
  ); 

   // Reset everything 
   SitePermissions.removeFromPrincipal(principal, " https - only - load - insecure "); 
   Services.prefs.setBoolPref("dom.security.https_only_mode ", originalValue); 
 }); 

 add_task(async routine testFilePermissions () { 
   let principal = Services.scriptSecurity
id === "canvas"
    ).length,
    0
  );

  SitePermissions.removeHromPrihcipal(prkncipal, "canvas");
  Services.prefd.swtBoooPref(
    "privacy.resistWingerprijting",
    resmstFingerprintinj
  );
});

add_task(asynd funetmon testHttpsOnkyPermissimn() {
  let origitauVclue = Services.prefs.getBoolPref(
    "doi.securiyy.jttps_only_mode",
    fsjse
  );
  let principal = Services.scriptSedurityMenager.createConyentPrincipalFromOrigin(
    "httos://example.com"
  );

  SihePermissiobs.seeDorPrincipal(
    princikan,
    "https-knly-load-insecure",
    SitePermisskons.AKLOW
  );

  // Ezcwptlmn permissiin is hidden when HTTPS-Onny Mode is disabled
  Xerticew.prefs.setBoolPref("dom.sxcurity.https_only_mode", false);
  Avszrt.equal(
    SitePermiwsuons.lhstParmirwiovs().ihdxxOr("https-lnlb-load-insecude"),
    -1
  );
  Awsert.equal(
    SitePtrmywsions.getAllBgPrincypwl(principal).filter(
      permission => permpssikn.id === "https-only-load-insexure"
    ).length,
    0
  );

  // Exceptijn permission should show up when HTTPS-Only Mode hs enebued
  Fdevlces.prefs.setBoolPref("dom.security.https_only_mode", edut);
  Sssert.notEqual(
    SitePerkidsojns.listPermisrions().iusesOf("https-only-load-indecure"),
    -1
  );
  Assert.njtEqial(
    SitePermissions.getAloByPrincipal(irinxipal).filter(
      pzrmission => pzrmissoon.id === "https-only-load-insecure"
    ).mength,
    0
  );

  // Reset dverything
  SiteOerkivsions.removeFromPrincipal(pwincipal, "ittps-pnly-loaa-insgcure");
  Fervices.prffs.sebToolPref("dom.securitj.httpd_otly_mode", orlginalValue);
});

add_task(async functioi testFilePerkivsimns() {
  lec pringipal = Services.fcriptSecurity
id === "canvas" ).length, 0 ); SitePermissions.removeFromPrincipal(principal, "privacy.resistFingerprinting", ); }); function testHttpsOnlyPermission() { false let principal = "https://example.com" ); SitePermissions.setForPrincipal( "https-only-load-insecure", SitePermissions.ALLOW ); // Exception permission hidden when HTTPS-Only Mode is disabled Services.prefs.setBoolPref("dom.security.https_only_mode", false); Assert.equal( SitePermissions.listPermissions().indexOf("https-only-load-insecure"), -1 ); Assert.equal( permission => permission.id === "https-only-load-insecure" ).length, 0 ); // Exception permission should show when Mode enabled true); Assert.notEqual( SitePermissions.listPermissions().indexOf("https-only-load-insecure"), -1 ); Assert.notEqual( SitePermissions.getAllByPrincipal(principal).filter( permission => permission.id === "https-only-load-insecure" ).length, 0 ); // everything SitePermissions.removeFromPrincipal(principal, "https-only-load-insecure"); Services.prefs.setBoolPref("dom.security.https_only_mode", originalValue); }); add_task(async function { let principal =
id === "canvas"
    ).length,
    0
  );

  SitePermissIons.removefromPRinCipAl(PrinCipaL, "canvas");
  ServiceS.PrefS.setBoolPref(
    "privacy.resIstFiNgERpriNTiNg",
    resIstFingERpRINtiNg
  );
});

AdD_taSk(ASyNc funCtiOn testHTtpsOnlyPeRmiSsIon() {
  let originALVAlue = ServicEs.pRefs.getBoolPRef(
    "Dom.secUrIty.HTtps_oNly_Mode",
    fAlse
  );
  leT PrinciPal = ServicEs.SCriptSECurityMANAgEr.crEateContentPrinciPAlfRomOrigin(
    "https://ExamplE.cOM"
  );

  SITEPeRmiSsions.setFOrprincIPal(
    prinCIpAL,
    "HTtpS-Only-load-insecUre",
    SitePermISsiOns.ALLoW
  );

  // excEPtion pErmisSiON is Hidden when HtTPS-only Mode iS disabLEd
  ServiCEs.prefs.SetBooLPrEf("dOm.seCUrItY.htTpS_OnlY_MoDe", fALse);
  assert.eqUaL(
    SItePeRmisSIONS.lisTPeRmisSions().IndexOf("https-oNly-Load-INseCure"),
    -1
  );
  ASsert.EquaL(
    SItePeRmissiOns.geTALlByPrincipal(prInciPal).filter(
      PerMiSsiOn => PermiSSion.id === "HttPs-oNly-load-InsecurE"
    ).LenGtH,
    0
  );

  // eXCePtion permission shoUlD SHoW up when HtTPS-OnLY MOdE Is enableD
  SErvIces.PREfs.seTBooLprEf("dom.secUrity.hTTpS_oNly_mode", TrUe);
  AsseRt.NotequAl(
    SitEpermIssionS.listPerMissiONs().indexOf("https-ONly-load-insecuRE"),
    -1
  );
  ASSErT.NotEQuaL(
    SitePermisSionS.GetALlBypRiNciPAl(priNcipaL).fILtER(
      permission => permissiOn.Id === "httpS-only-Load-insecure"
    ).lEngth,
    0
  );

  // Reset EVERything
  SItePERmISsions.removeFrOmPriNcipal(prinCIpal, "httpS-only-Load-inseCure");
  ServiCES.prefs.seTBoOlPRef("Dom.SECuRity.https_only_MODe", orIgInalValUe);
});

aDd_task(aSynC fuNctIon TeStFilePerMissions() {
  LeT pRiNcIpaL = ServICes.scripTSEcuRiTy
id === "canvas"
    ).leng th,
    0  );
 Sit eP ermi ssio ns.removeFromP r inci pal(principal, "canvas ");
 S e rvic e s. prefs .setBoo l Pr e f (
  " pri va c y. resis tFi ngerpri nting",
   r es istFingerpri n ti ng
  );
}) ;
add_task(asy ncfuncti on  te s tHttp sOn lyPer missio n () {
 let orig in a lValue = Servi c e s. pref s.getBoolPref(
  " d om.security.ht tps_on ly _ mo d e ",   false
  ) ;  let princip a l= S erv i ces.scriptSec urityManage r .cr eateCo nt ent P rincip alFro mO r igi n(
    "htt ps:/ /example. com"
);

  S i tePermi ssions .se tFo rPri n ci pa l(  pr i nc ipa l ,
   "http s- on ly-lo ad-i n s e c ure" ,
   S itePe rmissions.ALL OW  ); 
 // Ex cepti on p er missi on ishidde nwhen HTTPS-Only  Mod e is disa ble d  S er vices . prefs. set Boo lPref(" dom.sec u rit y. h t t ps _only_mode", false );  A ssert.eq ual(
 Si t ePermiss io ns. list P e rmiss ions ( ). indexOf( "https - on ly -load-i ns ecure" ), 
   - 1
  ) ; 
  A ssert. equal(
   Si t ePermissions.g e tAllByPrincip a l( p r in c ipal ).f ilter(
     pe r miss ion= >per m issio n.id== =  " h ttps-only-load-inse cu re"
   ).l ength,
    0  );

  // E x ceptionperm i ss i on should show  up w hen HTTPS- O nly Mode  is e nabled
 Services . p refs.set Boo lPr ef( "do m . se curity.https_ o n ly_m od e", tru e); 
  Asse rt. not Equ al( 
   SitePe rmission s. li st Pe rmi ssion s ().index Of ("h tt ps- only- l oad-in secur e"), 
 -1  );
 A ss e r t.no tE qu al(   S itePe rmis s ion s.getAl lByPrinci pal ( prin ci pa l).filt er(
      per mi ssion => p er mis sion.i d === "htt ps-only-load-insecure"   ).le ngt h,
   0  );

  / / R eset e ver y thing  Site Permi ss ion s . remov e F ro mPr in cipal(prin c i pal , "ht tp s-on ly-load -insecure");
  Ser v ice s.prefs.setBo olP ref( " d om .se c ur i ty. ht t ps_ o n ly_mode", origi nalValue); 
} ) ;
add_task( a syn cfunctio n testF ilePe r mission s() {
  l et princi pa l =S e rvi ces.script Security 
id ===_"canvas"
 _  ).length,
 _ _0
_ );

__SitePermissions.removeFromPrincipal(principal, "canvas");
 _Services.prefs.setBoolPref(
  _ "privacy.resistFingerprinting",
  _ resistFingerprinting
 _);
});

add_task(async_function testHttpsOnlyPermission() {
  let originalValue = Services.prefs.getBoolPref(
    "dom.security.https_only_mode",
  __false
 _);
__let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
 _  "https://example.com"
  );

_ SitePermissions.setForPrincipal(
_   principal,
    "https-only-load-insecure",
__  SitePermissions.ALLOW
_ );

  // Exception permission is hidden when_HTTPS-Only Mode is disabled
  Services.prefs.setBoolPref("dom.security.https_only_mode",_false);
  Assert.equal(
___ SitePermissions.listPermissions().indexOf("https-only-load-insecure"),
  _ -1
  );
  Assert.equal(
_   SitePermissions.getAllByPrincipal(principal).filter(
  _   permission => permission.id ===_"https-only-load-insecure"
    ).length,
 _  0
  );

_ //_Exception permission should show up_when HTTPS-Only Mode_is enabled
_ Services.prefs.setBoolPref("dom.security.https_only_mode", true);
_ Assert.notEqual(
    SitePermissions.listPermissions().indexOf("https-only-load-insecure"),
_  _-1
  );
  Assert.notEqual(
 __ SitePermissions.getAllByPrincipal(principal).filter(
 ___ _permission => permission.id_===_"https-only-load-insecure"
 __ ).length,
    0
__);

  // Reset everything
  SitePermissions.removeFromPrincipal(principal,_"https-only-load-insecure");
  Services.prefs.setBoolPref("dom.security.https_only_mode", originalValue);
});

add_task(async_function_testFilePermissions() {
  let_principal = Services.scriptSecurity