DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for WebSMS</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<iframe></iframe>
</div>
<pre id="test">
<script type="application/javascript">

/** Test for WebSMS **/

function checkSmsDisabled() {
  ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist");
  is(frames[0].navigator.mozSms, null, "navigator.mozSms should return null");
}

function checkSmsEnabled() {
  // Bug 784617: WebSms is disabled on all platforms except Android for the moment.
  if (navigator.appVersion.indexOf("Android") == -1) {
    checkSmsDisabled();
    return;
  }

  ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist");
  ok(frames[0].navigator.mozSms, "navigator.mozSms returns an object");
  ok(frames[0].navigator.mozSms instanceof MozSmsManager, "navigator.mozSms is an SmsManager object");
}

function checkInterface(aInterface) {
  ok(!(aInterface in window), aInterface + " should be prefixed");
  ok(("Moz" + aInterface) in window, aInterface + " should be prefixed");
}

function test() {
  var gSmsEnabled = SpecialPowers.getBoolPref("dom.sms.enabled");

  checkInterface("SmsManager");
  checkInterface("NavigatorSms");
  checkInterface("SmsMessage");
  checkInterface("SmsEvent");
  checkInterface("SmsFilter");

  // If sms is disabled and permission is removed, sms is disabled.
  SpecialPowers.setBoolPref("dom.sms.enabled", false);
  SpecialPowers.removePermission("sms", document);
  checkSmsDisabled();

  // If sms is enabled and permission is removed, sms is disabled.
  SpecialPowers.setBoolPref("dom.sms.enabled", true);
  SpecialPowers.removePermission("sms", document);
  checkSmsDisabled();

  // If sms is disabled and permission is granted, sms is disabled.
  SpecialPowers.setBoolPref("dom.sms.enabled", false);
  SpecialPowers.addPermission("sms", true, document);
  checkSmsDisabled();

  // If sms is enabled and permission is granted, sms is enabled.
  SpecialPowers.setBoolPref("dom.sms.enabled", true);
  SpecialPowers.addPermission("sms", true, document);
  checkSmsEnabled();

  // Now, if sms are disabled with the pref, they will still be enabled.
  // The page has to be reloaded.
  SpecialPowers.setBoolPref("dom.sms.enabled", false);
  checkSmsEnabled();

  var iframeElt = document.getElementsByTagName('iframe')[0];
  iframeElt.addEventListener("load", function() {
    iframeElt.removeEventListener("load", arguments.callee);
    checkSmsEnabled();

    // Disabling sms takes effect on reload.
    SpecialPowers.setBoolPref("dom.sms.enabled", false);
    iframeElt.addEventListener("load", function() {
      iframeElt.removeEventListener("load", arguments.callee);

      checkSmsDisabled();

      // Cleanup and quit.
      SpecialPowers.setBoolPref("dom.sms.enabled", gSmsEnabled);
      SpecialPowers.removePermission("sms", document);
      SimpleTest.finish();
    });
    frames[0].location.reload();
  });

  SpecialPowers.setBoolPref("dom.sms.enabled", true);
  frames[0].location.reload();
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(test);

</script>
</pre>
</body>
</html>