dom/indexedDB/ipc/test_ipc.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for OOP IndexedDB</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>
    10   <script type="application/javascript;version=1.7">
    11     "use strict";
    13     SimpleTest.waitForExplicitFinish();
    15     // This isn't a single test, really... It runs the entirety of the IndexedDB
    16     // tests. Each of those has a normal timeout handler, so there's no point in
    17     // having a timeout here. I'm setting this really high just to avoid getting
    18     // killed.
    19     SimpleTest.requestLongerTimeout(100);
    21     // Disable crash observers as it breaks later tests.
    22     function iframeScriptFirst() {
    23       SpecialPowers.prototype.registerProcessCrashObservers = function() { };
    24       SpecialPowers.prototype.unregisterProcessCrashObservers = function() { };
    26       content.wrappedJSObject.RunSet.reloadAndRunAll({
    27         preventDefault: function() { },
    28         __exposedProps__: { preventDefault: 'r' }
    29       });
    30     }
    32     function iframeScriptSecond() {
    33       let isMainProcess = content.wrappedJSObject.SpecialPowers.isMainProcess();
    35       sendAsyncMessage("test:indexedDB:ipcProcessType",
    36                        { isMainProcess: isMainProcess });
    38       let TestRunner = content.wrappedJSObject.TestRunner;
    40       let oldComplete = TestRunner.onComplete;
    42       TestRunner.onComplete = function() {
    43         TestRunner.onComplete = oldComplete;
    45         sendAsyncMessage("test:indexedDB:ipcTestComplete");
    47         if (oldComplete) {
    48           oldComplete();
    49         }
    50       };
    52       function sendTestMessage(msg) {
    53         sendAsyncMessage("test:indexedDB:ipcTestMessage", { msg: msg });
    54       }
    56       TestRunner.log = sendTestMessage;
    57       TestRunner.error = sendTestMessage;
    58     }
    60     let regexString =
    61       "^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL" +
    62       "|TEST-DEBUG-INFO|TEST-INFO) \\| ([^\\|]+) \\|(.*)";
    64     let regex = new RegExp(regexString);
    66     let seenTestMessage = false;
    68     function onTestMessage(data) {
    69       seenTestMessage = true;
    70       let message = SpecialPowers.wrap(data).data.msg;
    71       let match = regex.exec(message);
    72       if (match) {
    73         let state = match[1];
    74         let details = match[2] + " | " + match[3];
    76         switch (state) {
    77           case "TEST-PASS":
    78           case "TEST-KNOWN-FAIL":
    79             ok(true, details);
    80             break;
    82           case "TEST-UNEXPECTED-FAIL":
    83           case "TEST-UNEXPECTED-PASS":
    84             ok(false, details);
    85             break;
    87           case "TEST-INFO":
    88           case "TEST-DEBUG-INFO":
    89           default:
    90             info(details);
    91         }
    92       }
    93     }
    95     let usingChildProcess = false;
    97     function onProcessType(data) {
    98       let isMainProcess = SpecialPowers.wrap(data).data.isMainProcess;
    99       usingChildProcess = !isMainProcess;
   100     }
   102     function onTestComplete() {
   103       is(usingChildProcess, true, "Expecting to run in child process");
   104       is(seenTestMessage, true, "Expecting to receive messages from child");
   105       SpecialPowers.removePermission("browser", window.location.href);
   106       SimpleTest.executeSoon(function () { SimpleTest.finish(); });
   107     }
   109     function runTests() {
   110       let iframe = document.createElement("iframe");
   111       SpecialPowers.wrap(iframe).mozbrowser = true;
   112       iframe.id = "iframe";
   113       iframe.style.width = "100%";
   114       iframe.style.height = "1000px";
   116       function iframeLoadSecond() {
   117         ok(true, "Got second iframe load event.");
   118         iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond);
   119         let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
   120         mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();",
   121                            false);
   122       }
   124       function iframeLoadFirst() {
   125         ok(true, "Got first iframe load event.");
   126         iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst);
   127         iframe.addEventListener("mozbrowserloadend", iframeLoadSecond);
   129         let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
   131         let comp = SpecialPowers.wrap(SpecialPowers.Components);
   133         let spObserver =
   134           comp.classes["@mozilla.org/special-powers-observer;1"]
   135               .getService(comp.interfaces.nsIMessageListener);
   137         mm.addMessageListener("SPPrefService", spObserver);
   138         mm.addMessageListener("SPProcessCrashService", spObserver);
   139         mm.addMessageListener("SPPingService", spObserver);
   140         mm.addMessageListener("SpecialPowers.Quit", spObserver);
   141         mm.addMessageListener("SPPermissionManager", spObserver);
   142         mm.addMessageListener("SPObserverService", spObserver);
   144         mm.addMessageListener("test:indexedDB:ipcTestMessage", onTestMessage);
   145         mm.addMessageListener("test:indexedDB:ipcProcessType", onProcessType);
   146         mm.addMessageListener("test:indexedDB:ipcTestComplete", onTestComplete);
   148         let specialPowersBase = "chrome://specialpowers/content/";
   149         mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false);
   150         mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false);
   151         mm.loadFrameScript(specialPowersBase + "specialpowers.js", false);
   153         mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();",
   154                            false);
   155       }
   157       iframe.addEventListener("mozbrowserloadend", iframeLoadFirst);
   159       // Strip this filename and one directory level and then add "/test".
   160       let href =  window.location.href;
   161       href = href.substring(0, href.lastIndexOf('/'));
   162       href = href.substring(0, href.lastIndexOf('/'));
   163       iframe.src = href + "/test?consoleLevel=INFO";
   165       document.body.appendChild(iframe);
   166     }
   168     addEventListener("load", function() {
   169       SpecialPowers.addPermission("browser", true, document);
   170       SpecialPowers.pushPrefEnv({
   171         "set": [
   172           // TODO: remove this as part of bug 820712
   173           ["network.disable.ipc.security", true],
   175           ["dom.ipc.browser_frames.oop_by_default", true],
   176           ["dom.mozBrowserFramesEnabled", true]
   177         ]
   178       }, runTests);
   179     });
   180   </script>
   181 </body>
   182 </html>

mercurial