dom/mobilemessage/tests/test_sms_basics.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for WebSMS</title>
     5   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     7 </head>
     8 <body>
     9 <p id="display"></p>
    10 <div id="content" style="display: none">
    11 <iframe></iframe>
    12 </div>
    13 <pre id="test">
    14 <script type="application/javascript">
    15 var defaultEnabled = ('mozMobileMessage' in frames[0].navigator);
    17 /** Test for WebSMS **/
    19 function checkSmsDisabled() {
    20   ok(!('mozMobileMessage' in frames[0].navigator), "navigator.mozMobileMessage should not exist");
    21   ok(frames[0].navigator.mozMobileMessage === undefined,
    22      "navigator.mozMobileMessage should return undefined");
    23 }
    25 function checkSmsEnabled() {
    26   // Bug 784617: WebSms is disabled on all platforms except Android for the moment.
    27   if (navigator.appVersion.indexOf("Android") == -1 && SpecialPowers.Services.appinfo.name != "B2G") {
    28     checkSmsDisabled();
    29     return;
    30   }
    32   ok('mozMobileMessage' in frames[0].navigator, "navigator.mozMobileMessage should exist");
    33   ok(frames[0].navigator.mozMobileMessage, "navigator.mozMobileMessage returns an object");
    34   ok(frames[0].navigator.mozMobileMessage instanceof MozMobileMessageManager,
    35      "navigator.mozMobileMessage is an MobileMessageManager object");
    36 }
    38 function checkSmsDisabledOrEnabled() {
    39   if (!defaultEnabled)
    40     checkSmsDisabled();
    41   else
    42     checkSmsEnabled();
    43 }
    45 function checkInterface(aInterface) {
    46   ok(!(aInterface in window), aInterface + " should be prefixed");
    47   ok(("Moz" + aInterface) in window, aInterface + " should be prefixed");
    48 }
    50 function test() {
    51   checkInterface("SmsMessage");
    52   checkInterface("SmsEvent");
    53   checkInterface("SmsFilter");
    55   // If sms is disabled and permission is removed, sms is disabled.
    56   SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, function() {
    57     SpecialPowers.pushPermissions([{'type': 'sms', 'remove': true, 'context': document}], test2);
    58   });
    59 }
    61 function test2() {
    62   checkSmsDisabledOrEnabled();
    64   // If sms is enabled and permission is removed, sms is disabled.
    65   SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", true]]}, function() {
    66     SpecialPowers.pushPermissions([{'type': 'sms', 'remove': true, 'context': document}], test3);
    67   });
    68 }
    70 function test3() {
    71   checkSmsDisabledOrEnabled();
    73   // If sms is disabled and permission is granted, sms is disabled.
    74   SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, function() {
    75     SpecialPowers.pushPermissions([{'type': 'sms', 'allow': true, 'context': document}], test4);
    76   });
    77 }
    79 function test4() {
    80   checkSmsDisabledOrEnabled();
    82   // If sms is enabled and permission is granted, sms is enabled.
    83   SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", true]]}, function() {
    84     SpecialPowers.pushPermissions([{'type': 'sms', 'allow': true, 'context': document}], test5);
    85   });
    86 }
    88 function test5() {
    89    checkSmsDisabledOrEnabled();
    91   // Now, if sms are disabled with the pref, they will still be enabled.
    92   // The page has to be reloaded.
    93   SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, test6);
    94 }
    96 function test6() {
    97   checkSmsDisabledOrEnabled();
    99   var iframeElt = document.getElementsByTagName('iframe')[0];
   100   iframeElt.addEventListener("load", function() {
   101     iframeElt.removeEventListener("load", arguments.callee);
   102     checkSmsEnabled();
   104     iframeElt.addEventListener("load", function() {
   105       iframeElt.removeEventListener("load", arguments.callee);
   107       checkSmsDisabled();
   109       SimpleTest.finish();
   110     });
   112     // Disabling sms takes effect on reload.
   113     SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", false]]}, function() {
   114       frames[0].location.reload();
   115     });
   116   });
   118   SpecialPowers.pushPrefEnv({"set": [["dom.sms.enabled", true]]}, function() {
   119     frames[0].location.reload();
   120   });
   121 }
   123 SimpleTest.waitForExplicitFinish();
   124 addLoadEvent(test);
   126 </script>
   127 </pre>
   128 </body>
   129 </html>

mercurial