Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf-8"> |
michael@0 | 5 | <title>Test Setting Screen Brightness with Power Management API</title> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 7 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <p id="display"></p> |
michael@0 | 11 | <div id="content" style="display: none"></div> |
michael@0 | 12 | <pre id="test"> |
michael@0 | 13 | <script type="application/javascript"> |
michael@0 | 14 | |
michael@0 | 15 | "use strict"; |
michael@0 | 16 | |
michael@0 | 17 | // Test setting brightness to a value < 0 |
michael@0 | 18 | function testInvalidBrightness1() { |
michael@0 | 19 | try { |
michael@0 | 20 | navigator.mozPower.screenBrightness = -1; |
michael@0 | 21 | } catch (e) { |
michael@0 | 22 | return ok(true, "Invalid brightness level results in exception."); |
michael@0 | 23 | } |
michael@0 | 24 | ok(false, "Exeception not thrown for invalid brightness level."); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | // Test setting brightness to a value > 1 |
michael@0 | 28 | function testInvalidBrightness2() { |
michael@0 | 29 | try { |
michael@0 | 30 | navigator.mozPower.screenBrightness = 2; |
michael@0 | 31 | } catch (e) { |
michael@0 | 32 | return ok(true, "Invalid brightness level results in exception."); |
michael@0 | 33 | } |
michael@0 | 34 | ok(false, "Exeception not thrown for invalid brightness level."); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function testSettingBrightness() { |
michael@0 | 38 | var newBright = 0.312; |
michael@0 | 39 | navigator.mozPower.screenBrightness = newBright; |
michael@0 | 40 | ok(fuzzyEq(newBright, navigator.mozPower.screenBrightness), |
michael@0 | 41 | "Set new brightness value."); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function startTests() { |
michael@0 | 45 | testInvalidBrightness1(); |
michael@0 | 46 | testInvalidBrightness2(); |
michael@0 | 47 | testSettingBrightness(); |
michael@0 | 48 | |
michael@0 | 49 | SimpleTest.finish(); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function fuzzyEq(a, b) { |
michael@0 | 53 | var epsilon = 0.002; |
michael@0 | 54 | return Math.abs(a - b) < epsilon; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | SimpleTest.expectAssertions(0, 9); |
michael@0 | 58 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 59 | if (SpecialPowers.hasPermission("power", document)) { |
michael@0 | 60 | // Currently only applicable on FxOS |
michael@0 | 61 | if (navigator.userAgent.indexOf("Mobile") != -1 && |
michael@0 | 62 | navigator.appVersion.indexOf("Android") == -1) { |
michael@0 | 63 | startTests(); |
michael@0 | 64 | } else { |
michael@0 | 65 | ok(true, "mozPower on Firefox OS only."); |
michael@0 | 66 | SimpleTest.finish(); |
michael@0 | 67 | } |
michael@0 | 68 | } else { |
michael@0 | 69 | // Add the permission and reload so it's propogated |
michael@0 | 70 | SpecialPowers.addPermission("power", true, document); |
michael@0 | 71 | window.location.reload(); |
michael@0 | 72 | } |
michael@0 | 73 | </script> |
michael@0 | 74 | </pre> |
michael@0 | 75 | </body> |
michael@0 | 76 | </html> |