testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for SpecialPowers extension</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7 </head>
     8 <body onload="starttest();">
    10 <pre id="test">
    11 <script class="testbody" type="text/javascript">
    12 const ALLOW_ACTION = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION;
    13 const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION;
    14 const UNKNOWN_ACTION = SpecialPowers.Ci.nsIPermissionManager.UNKNOWN_ACTION;
    15 const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION;
    16 const ACCESS_SESSION = SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION;
    17 const ACCESS_ALLOW_FIRST_PARTY_ONLY = SpecialPowers.Ci.nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY;
    18 const ACCESS_LIMIT_THIRD_PARTY = SpecialPowers.Ci.nsICookiePermission.ACCESS_LIMIT_THIRD_PARTY;
    20 function starttest(){
    21   SpecialPowers.addPermission("pPROMPT", PROMPT_ACTION, document);
    22   SpecialPowers.addPermission("pALLOW", ALLOW_ACTION, document);
    23   SpecialPowers.addPermission("pDENY", DENY_ACTION, document);
    24   SpecialPowers.addPermission("pREMOVE", ALLOW_ACTION, document);
    25   SpecialPowers.addPermission("pSESSION", ACCESS_SESSION, document);
    26   SpecialPowers.addPermission("pFIRSTPARTY", ACCESS_ALLOW_FIRST_PARTY_ONLY, document);
    27   SpecialPowers.addPermission("pTHIRDPARTY", ACCESS_LIMIT_THIRD_PARTY, document);
    29   setTimeout(test1, 0);
    30 }
    32 SimpleTest.waitForExplicitFinish();
    34 function test1() {
    35   if (!SpecialPowers.testPermission('pALLOW', ALLOW_ACTION, document)) {
    36     dump('/**** allow not set ****/\n');
    37     setTimeout(test1, 0);
    38   } else if (!SpecialPowers.testPermission('pDENY', DENY_ACTION, document)) {
    39     dump('/**** deny not set ****/\n');
    40     setTimeout(test1, 0);
    41   } else if (!SpecialPowers.testPermission('pPROMPT', PROMPT_ACTION, document)) {
    42     dump('/**** prompt not set ****/\n');
    43     setTimeout(test1, 0);
    44   } else if (!SpecialPowers.testPermission('pREMOVE', ALLOW_ACTION, document)) {
    45     dump('/**** remove not set ****/\n');
    46     setTimeout(test1, 0);
    47   } else if (!SpecialPowers.testPermission('pSESSION', ACCESS_SESSION, document)) {
    48     dump('/**** ACCESS_SESSION not set ****/\n');
    49     setTimeout(test1, 0);
    50   } else if (!SpecialPowers.testPermission('pFIRSTPARTY', ACCESS_ALLOW_FIRST_PARTY_ONLY, document)) {
    51     dump('/**** ACCESS_ALLOW_FIRST_PARTY_ONLY not set ****/\n');
    52     setTimeout(test1, 0);
    53   } else if (!SpecialPowers.testPermission('pTHIRDPARTY', ACCESS_LIMIT_THIRD_PARTY, document)) {
    54     dump('/**** ACCESS_LIMIT_THIRD_PARTY not set ****/\n');
    55     setTimeout(test1, 0);
    56   } else {
    57     test2();
    58   }
    59 }
    61 function test2() {
    62   ok(SpecialPowers.testPermission('pUNKNOWN', UNKNOWN_ACTION, document), 'pUNKNOWN value should have UNKOWN permission');
    63   SpecialPowers.pushPermissions([{'type': 'pUNKNOWN', 'allow': true, 'context': document}, {'type': 'pALLOW', 'allow': false, 'context': document}, {'type': 'pDENY', 'allow': true, 'context': document}, {'type': 'pPROMPT', 'allow': true, 'context': document}, {'type': 'pSESSION', 'allow': true, 'context': document}, {'type': 'pFIRSTPARTY', 'allow': true, 'context': document}, {'type': 'pTHIRDPARTY', 'allow': true, 'context': document}, {'type': 'pREMOVE', 'remove': true, 'context': document}], test3);
    64 }
    66 function test3() {
    67   ok(SpecialPowers.testPermission('pUNKNOWN', ALLOW_ACTION, document), 'pUNKNOWN value should have ALLOW permission');
    68   ok(SpecialPowers.testPermission('pPROMPT', ALLOW_ACTION, document), 'pPROMPT value should have ALLOW permission');
    69   ok(SpecialPowers.testPermission('pALLOW', DENY_ACTION, document), 'pALLOW should have DENY permission');
    70   ok(SpecialPowers.testPermission('pDENY', ALLOW_ACTION, document), 'pDENY should have ALLOW permission');
    71   ok(SpecialPowers.testPermission('pREMOVE', UNKNOWN_ACTION, document), 'pREMOVE should have REMOVE permission');
    72   ok(SpecialPowers.testPermission('pSESSION', ALLOW_ACTION, document), 'pSESSION should have ALLOW permission');
    73   ok(SpecialPowers.testPermission('pFIRSTPARTY', ALLOW_ACTION, document), 'pFIRSTPARTY should have ALLOW permission');
    74   ok(SpecialPowers.testPermission('pTHIRDPARTY', ALLOW_ACTION, document), 'pTHIRDPARTY should have ALLOW permission');
    76   // only pPROMPT (last one) is different, the other stuff is just to see if it doesn't cause test failures
    77   SpecialPowers.pushPermissions([{'type': 'pUNKNOWN', 'allow': true, 'context': document}, {'type': 'pALLOW', 'allow': false, 'context': document}, {'type': 'pDENY', 'allow': true, 'context': document}, {'type': 'pPROMPT', 'allow': false, 'context': document}, {'type': 'pREMOVE', 'remove': true, 'context': document}], test3b);
    78 }
    80 function test3b() {
    81   ok(SpecialPowers.testPermission('pPROMPT', DENY_ACTION, document), 'pPROMPT value should have DENY permission');
    82   SpecialPowers.pushPermissions([{'type': 'pUNKNOWN', 'allow': DENY_ACTION, 'context': document}, {'type': 'pALLOW', 'allow': PROMPT_ACTION, 'context': document}, {'type': 'pDENY', 'allow': PROMPT_ACTION, 'context': document}, {'type': 'pPROMPT', 'allow': ALLOW_ACTION, 'context': document}], test4);
    83 }
    85 function test4() {
    86   ok(SpecialPowers.testPermission('pUNKNOWN', DENY_ACTION, document), 'pUNKNOWN value should have DENY permission');
    87   ok(SpecialPowers.testPermission('pPROMPT', ALLOW_ACTION, document), 'pPROMPT value should have ALLOW permission');
    88   ok(SpecialPowers.testPermission('pALLOW', PROMPT_ACTION, document), 'pALLOW should have PROMPT permission');
    89   ok(SpecialPowers.testPermission('pDENY', PROMPT_ACTION, document), 'pDENY should have PROMPT permission');
    90   //this should reset all the permissions to before all the pushPermissions calls
    91   SpecialPowers.flushPermissions(test5);
    92 }
    95 function test5() {
    96   ok(SpecialPowers.testPermission('pUNKNOWN', UNKNOWN_ACTION, document), 'pUNKNOWN should have UNKNOWN permission');
    97   ok(SpecialPowers.testPermission('pALLOW', ALLOW_ACTION, document), 'pALLOW should have ALLOW permission');
    98   ok(SpecialPowers.testPermission('pDENY', DENY_ACTION, document), 'pDENY should have DENY permission');
    99   ok(SpecialPowers.testPermission('pPROMPT', PROMPT_ACTION, document), 'pPROMPT should have PROMPT permission');
   100   ok(SpecialPowers.testPermission('pREMOVE', ALLOW_ACTION, document), 'pREMOVE should have ALLOW permission');
   101   ok(SpecialPowers.testPermission('pSESSION', ACCESS_SESSION, document), 'pSESSION should have ACCESS_SESSION permission');
   102   ok(SpecialPowers.testPermission('pFIRSTPARTY', ACCESS_ALLOW_FIRST_PARTY_ONLY, document), 'pFIRSTPARTY should have ACCESS_ALLOW_FIRST_PARTY_ONLY permission');
   103   ok(SpecialPowers.testPermission('pTHIRDPARTY', ACCESS_LIMIT_THIRD_PARTY, document), 'pTHIRDPARTY should have ACCESS_LIMIT_THIRD_PARTY permission');
   105   SpecialPowers.removePermission("pPROMPT", document);
   106   SpecialPowers.removePermission("pALLOW", document);
   107   SpecialPowers.removePermission("pDENY", document);
   108   SpecialPowers.removePermission("pREMOVE", document);
   109   SpecialPowers.removePermission("pSESSION", document);
   110   SpecialPowers.removePermission("pFIRSTPARTY", document);
   111   SpecialPowers.removePermission("pTHIRDPARTY", document);
   113   setTimeout(test6, 0);
   114 }
   116 function test6() {
   117   if (!SpecialPowers.testPermission('pALLOW', UNKNOWN_ACTION, document)) {
   118     dump('/**** allow still set ****/\n');
   119     setTimeout(test6, 0);
   120   } else if (!SpecialPowers.testPermission('pDENY', UNKNOWN_ACTION, document)) {
   121     dump('/**** deny still set ****/\n');
   122     setTimeout(test6, 0);
   123   } else if (!SpecialPowers.testPermission('pPROMPT', UNKNOWN_ACTION, document)) {
   124     dump('/**** prompt still set ****/\n');
   125     setTimeout(test6, 0);
   126   } else if (!SpecialPowers.testPermission('pREMOVE', UNKNOWN_ACTION, document)) {
   127     dump('/**** remove still set ****/\n');
   128     setTimeout(test6, 0);
   129   } else if (!SpecialPowers.testPermission('pSESSION', UNKNOWN_ACTION, document)) {
   130     dump('/**** pSESSION still set ****/\n');
   131     setTimeout(test6, 0);
   132   } else if (!SpecialPowers.testPermission('pFIRSTPARTY', UNKNOWN_ACTION, document)) {
   133     dump('/**** pFIRSTPARTY still set ****/\n');
   134     setTimeout(test6, 0);
   135   } else if (!SpecialPowers.testPermission('pTHIRDPARTY', UNKNOWN_ACTION, document)) {
   136     dump('/**** pTHIRDPARTY still set ****/\n');
   137     setTimeout(test6, 0);
   138   } else {
   139     SimpleTest.finish();
   140   }
   141 }
   142 </script>
   143 </pre>
   144 </body>
   145 </html>

mercurial