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