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 (31ec81b5d7bb)

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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for OOP DeviceStorage</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
  <body>

  <script type="application/javascript;version=1.7">
    "use strict";

    SimpleTest.waitForExplicitFinish();

    function iframeScriptFirst() {
      content.wrappedJSObject.RunSet.reloadAndRunAll({
          preventDefault: function() { },
          __exposedProps__: { preventDefault: 'r' }
      });
    }

    function iframeScriptSecond() {
      let TestRunner = content.wrappedJSObject.TestRunner;

      let oldComplete = TestRunner.onComplete;

      TestRunner.onComplete = function() {
        TestRunner.onComplete = oldComplete;

        sendAsyncMessage("test:DeviceStorage:ipcTestComplete", {
          result: JSON.stringify(TestRunner._failedTests)
        });

        if (oldComplete) {
          oldComplete();
        }
      };

      let oldLog = TestRunner.log;
      TestRunner.log = function(msg) {
        sendAsyncMessage("test:DeviceStorage:ipcTestMessage", { msg: msg });
      }
    }

    let regex = /^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL|TEST-DEBUG-INFO) \| ([^\|]+) \|(.*)/;

    function onTestMessage(data) {
      let message = SpecialPowers.wrap(data).json.msg;
      let match = regex.exec(message);
      if (match) {
        let state = match[1];
        let details = match[2] + " | " + match[3];

        switch (state) {
          case "TEST-PASS":
          case "TEST-KNOWN-FAIL":
            ok(true, details);
            break;

          case "TEST-UNEXPECTED-FAIL":
          case "TEST-UNEXPECTED-PASS":
            ok(false, details);
            break;

          case "TEST-DEBUG-INFO":
          default:
            info(details);
        }
      }
    }

    function onTestComplete() {
      let comp = SpecialPowers.wrap(SpecialPowers.Components);
      let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
      let spObserver = comp.classes["@mozilla.org/special-powers-observer;1"]
                            .getService(comp.interfaces.nsIMessageListener);

      mm.removeMessageListener("SPPrefService", spObserver);
      mm.removeMessageListener("SPProcessCrashService", spObserver);
      mm.removeMessageListener("SPPingService", spObserver);
      mm.removeMessageListener("SpecialPowers.Quit", spObserver);
      mm.removeMessageListener("SPPermissionManager", spObserver);

      mm.removeMessageListener("test:DeviceStorage:ipcTestMessage", onTestMessage);
      mm.removeMessageListener("test:DeviceStorage:ipcTestComplete", onTestComplete);

      SimpleTest.executeSoon(function () { SimpleTest.finish(); });
    }

    function runTests() {
      let iframe = document.createElement("iframe");
      SpecialPowers.wrap(iframe).mozbrowser = true;
      iframe.id = "iframe";
      iframe.style.width = "100%";
      iframe.style.height = "1000px";

      function iframeLoadSecond() {
        ok(true, "Got second iframe load event.");
        iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond);
        let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
        mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();",
                           false);
      }

      function iframeLoadFirst() {
        ok(true, "Got first iframe load event.");
        iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst);
        iframe.addEventListener("mozbrowserloadend", iframeLoadSecond);

        let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);

        let comp = SpecialPowers.wrap(SpecialPowers.Components);

        let spObserver =
          comp.classes["@mozilla.org/special-powers-observer;1"]
              .getService(comp.interfaces.nsIMessageListener);

        mm.addMessageListener("SPPrefService", spObserver);
        mm.addMessageListener("SPProcessCrashService", spObserver);
        mm.addMessageListener("SPPingService", spObserver);
        mm.addMessageListener("SpecialPowers.Quit", spObserver);
        mm.addMessageListener("SPPermissionManager", spObserver);

        mm.addMessageListener("test:DeviceStorage:ipcTestMessage", onTestMessage);
        mm.addMessageListener("test:DeviceStorage:ipcTestComplete", onTestComplete);

        let specialPowersBase = "chrome://specialpowers/content/";
        mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false);
        mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false);
        mm.loadFrameScript(specialPowersBase + "specialpowers.js", false);

        mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", false);
      }

      iframe.addEventListener("mozbrowserloadend", iframeLoadFirst);

      // Strip this filename and one directory level and then add "/test".
      let href =  window.location.href;
      href = href.substring(0, href.lastIndexOf('/'));
      href = href.substring(0, href.lastIndexOf('/'));
      iframe.src = href + "/test?consoleLevel=INFO";

      document.body.appendChild(iframe);
    }

    addEventListener("load", function() {

      SpecialPowers.addPermission("browser", true, document);
      SpecialPowers.pushPrefEnv({
        "set": [

          ["device.storage.enabled", true],
          ["device.storage.testing", true],
          ["device.storage.prompt.testing", true],

          // TODO: remove this as part of bug 820712
          ["network.disable.ipc.security", true],

          ["dom.ipc.browser_frames.oop_by_default", true],
          ["dom.mozBrowserFramesEnabled", true],
          ["browser.pagethumbnails.capturing_disabled", true]
        ]
      }, runTests);
    });

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