testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersPushPermissions.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,146 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for SpecialPowers extension</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +</head>
    1.11 +<body onload="starttest();">
    1.12 +
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +const ALLOW_ACTION = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION;
    1.16 +const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION;
    1.17 +const UNKNOWN_ACTION = SpecialPowers.Ci.nsIPermissionManager.UNKNOWN_ACTION;
    1.18 +const PROMPT_ACTION = SpecialPowers.Ci.nsIPermissionManager.PROMPT_ACTION;
    1.19 +const ACCESS_SESSION = SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION;
    1.20 +const ACCESS_ALLOW_FIRST_PARTY_ONLY = SpecialPowers.Ci.nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY;
    1.21 +const ACCESS_LIMIT_THIRD_PARTY = SpecialPowers.Ci.nsICookiePermission.ACCESS_LIMIT_THIRD_PARTY;
    1.22 +
    1.23 +function starttest(){
    1.24 +  SpecialPowers.addPermission("pPROMPT", PROMPT_ACTION, document);
    1.25 +  SpecialPowers.addPermission("pALLOW", ALLOW_ACTION, document);
    1.26 +  SpecialPowers.addPermission("pDENY", DENY_ACTION, document);
    1.27 +  SpecialPowers.addPermission("pREMOVE", ALLOW_ACTION, document);
    1.28 +  SpecialPowers.addPermission("pSESSION", ACCESS_SESSION, document);
    1.29 +  SpecialPowers.addPermission("pFIRSTPARTY", ACCESS_ALLOW_FIRST_PARTY_ONLY, document);
    1.30 +  SpecialPowers.addPermission("pTHIRDPARTY", ACCESS_LIMIT_THIRD_PARTY, document);
    1.31 +
    1.32 +  setTimeout(test1, 0);
    1.33 +}
    1.34 +
    1.35 +SimpleTest.waitForExplicitFinish();
    1.36 +
    1.37 +function test1() {
    1.38 +  if (!SpecialPowers.testPermission('pALLOW', ALLOW_ACTION, document)) {
    1.39 +    dump('/**** allow not set ****/\n');
    1.40 +    setTimeout(test1, 0);
    1.41 +  } else if (!SpecialPowers.testPermission('pDENY', DENY_ACTION, document)) {
    1.42 +    dump('/**** deny not set ****/\n');
    1.43 +    setTimeout(test1, 0);
    1.44 +  } else if (!SpecialPowers.testPermission('pPROMPT', PROMPT_ACTION, document)) {
    1.45 +    dump('/**** prompt not set ****/\n');
    1.46 +    setTimeout(test1, 0);
    1.47 +  } else if (!SpecialPowers.testPermission('pREMOVE', ALLOW_ACTION, document)) {
    1.48 +    dump('/**** remove not set ****/\n');
    1.49 +    setTimeout(test1, 0);
    1.50 +  } else if (!SpecialPowers.testPermission('pSESSION', ACCESS_SESSION, document)) {
    1.51 +    dump('/**** ACCESS_SESSION not set ****/\n');
    1.52 +    setTimeout(test1, 0);
    1.53 +  } else if (!SpecialPowers.testPermission('pFIRSTPARTY', ACCESS_ALLOW_FIRST_PARTY_ONLY, document)) {
    1.54 +    dump('/**** ACCESS_ALLOW_FIRST_PARTY_ONLY not set ****/\n');
    1.55 +    setTimeout(test1, 0);
    1.56 +  } else if (!SpecialPowers.testPermission('pTHIRDPARTY', ACCESS_LIMIT_THIRD_PARTY, document)) {
    1.57 +    dump('/**** ACCESS_LIMIT_THIRD_PARTY not set ****/\n');
    1.58 +    setTimeout(test1, 0);
    1.59 +  } else {
    1.60 +    test2();
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +function test2() {
    1.65 +  ok(SpecialPowers.testPermission('pUNKNOWN', UNKNOWN_ACTION, document), 'pUNKNOWN value should have UNKOWN permission');
    1.66 +  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);
    1.67 +}
    1.68 +
    1.69 +function test3() {
    1.70 +  ok(SpecialPowers.testPermission('pUNKNOWN', ALLOW_ACTION, document), 'pUNKNOWN value should have ALLOW permission');
    1.71 +  ok(SpecialPowers.testPermission('pPROMPT', ALLOW_ACTION, document), 'pPROMPT value should have ALLOW permission');
    1.72 +  ok(SpecialPowers.testPermission('pALLOW', DENY_ACTION, document), 'pALLOW should have DENY permission');
    1.73 +  ok(SpecialPowers.testPermission('pDENY', ALLOW_ACTION, document), 'pDENY should have ALLOW permission');
    1.74 +  ok(SpecialPowers.testPermission('pREMOVE', UNKNOWN_ACTION, document), 'pREMOVE should have REMOVE permission');
    1.75 +  ok(SpecialPowers.testPermission('pSESSION', ALLOW_ACTION, document), 'pSESSION should have ALLOW permission');
    1.76 +  ok(SpecialPowers.testPermission('pFIRSTPARTY', ALLOW_ACTION, document), 'pFIRSTPARTY should have ALLOW permission');
    1.77 +  ok(SpecialPowers.testPermission('pTHIRDPARTY', ALLOW_ACTION, document), 'pTHIRDPARTY should have ALLOW permission');
    1.78 +
    1.79 +  // only pPROMPT (last one) is different, the other stuff is just to see if it doesn't cause test failures
    1.80 +  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);
    1.81 +}
    1.82 +
    1.83 +function test3b() {
    1.84 +  ok(SpecialPowers.testPermission('pPROMPT', DENY_ACTION, document), 'pPROMPT value should have DENY permission');
    1.85 +  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);
    1.86 +}
    1.87 +
    1.88 +function test4() {
    1.89 +  ok(SpecialPowers.testPermission('pUNKNOWN', DENY_ACTION, document), 'pUNKNOWN value should have DENY permission');
    1.90 +  ok(SpecialPowers.testPermission('pPROMPT', ALLOW_ACTION, document), 'pPROMPT value should have ALLOW permission');
    1.91 +  ok(SpecialPowers.testPermission('pALLOW', PROMPT_ACTION, document), 'pALLOW should have PROMPT permission');
    1.92 +  ok(SpecialPowers.testPermission('pDENY', PROMPT_ACTION, document), 'pDENY should have PROMPT permission');
    1.93 +  //this should reset all the permissions to before all the pushPermissions calls
    1.94 +  SpecialPowers.flushPermissions(test5);
    1.95 +}
    1.96 +
    1.97 +
    1.98 +function test5() {
    1.99 +  ok(SpecialPowers.testPermission('pUNKNOWN', UNKNOWN_ACTION, document), 'pUNKNOWN should have UNKNOWN permission');
   1.100 +  ok(SpecialPowers.testPermission('pALLOW', ALLOW_ACTION, document), 'pALLOW should have ALLOW permission');
   1.101 +  ok(SpecialPowers.testPermission('pDENY', DENY_ACTION, document), 'pDENY should have DENY permission');
   1.102 +  ok(SpecialPowers.testPermission('pPROMPT', PROMPT_ACTION, document), 'pPROMPT should have PROMPT permission');
   1.103 +  ok(SpecialPowers.testPermission('pREMOVE', ALLOW_ACTION, document), 'pREMOVE should have ALLOW permission');
   1.104 +  ok(SpecialPowers.testPermission('pSESSION', ACCESS_SESSION, document), 'pSESSION should have ACCESS_SESSION permission');
   1.105 +  ok(SpecialPowers.testPermission('pFIRSTPARTY', ACCESS_ALLOW_FIRST_PARTY_ONLY, document), 'pFIRSTPARTY should have ACCESS_ALLOW_FIRST_PARTY_ONLY permission');
   1.106 +  ok(SpecialPowers.testPermission('pTHIRDPARTY', ACCESS_LIMIT_THIRD_PARTY, document), 'pTHIRDPARTY should have ACCESS_LIMIT_THIRD_PARTY permission');
   1.107 +
   1.108 +  SpecialPowers.removePermission("pPROMPT", document);
   1.109 +  SpecialPowers.removePermission("pALLOW", document);
   1.110 +  SpecialPowers.removePermission("pDENY", document);
   1.111 +  SpecialPowers.removePermission("pREMOVE", document);
   1.112 +  SpecialPowers.removePermission("pSESSION", document);
   1.113 +  SpecialPowers.removePermission("pFIRSTPARTY", document);
   1.114 +  SpecialPowers.removePermission("pTHIRDPARTY", document);
   1.115 +
   1.116 +  setTimeout(test6, 0);
   1.117 +}
   1.118 +
   1.119 +function test6() {
   1.120 +  if (!SpecialPowers.testPermission('pALLOW', UNKNOWN_ACTION, document)) {
   1.121 +    dump('/**** allow still set ****/\n');
   1.122 +    setTimeout(test6, 0);
   1.123 +  } else if (!SpecialPowers.testPermission('pDENY', UNKNOWN_ACTION, document)) {
   1.124 +    dump('/**** deny still set ****/\n');
   1.125 +    setTimeout(test6, 0);
   1.126 +  } else if (!SpecialPowers.testPermission('pPROMPT', UNKNOWN_ACTION, document)) {
   1.127 +    dump('/**** prompt still set ****/\n');
   1.128 +    setTimeout(test6, 0);
   1.129 +  } else if (!SpecialPowers.testPermission('pREMOVE', UNKNOWN_ACTION, document)) {
   1.130 +    dump('/**** remove still set ****/\n');
   1.131 +    setTimeout(test6, 0);
   1.132 +  } else if (!SpecialPowers.testPermission('pSESSION', UNKNOWN_ACTION, document)) {
   1.133 +    dump('/**** pSESSION still set ****/\n');
   1.134 +    setTimeout(test6, 0);
   1.135 +  } else if (!SpecialPowers.testPermission('pFIRSTPARTY', UNKNOWN_ACTION, document)) {
   1.136 +    dump('/**** pFIRSTPARTY still set ****/\n');
   1.137 +    setTimeout(test6, 0);
   1.138 +  } else if (!SpecialPowers.testPermission('pTHIRDPARTY', UNKNOWN_ACTION, document)) {
   1.139 +    dump('/**** pTHIRDPARTY still set ****/\n');
   1.140 +    setTimeout(test6, 0);
   1.141 +  } else {
   1.142 +    SimpleTest.finish();
   1.143 +  }
   1.144 +}
   1.145 +</script>
   1.146 +</pre>
   1.147 +</body>
   1.148 +</html>
   1.149 +

mercurial