dom/devicestorage/ipc/test_ipc.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 OOP DeviceStorage</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     function iframeScriptFirst() {
    16       content.wrappedJSObject.RunSet.reloadAndRunAll({
    17           preventDefault: function() { },
    18           __exposedProps__: { preventDefault: 'r' }
    19       });
    20     }
    22     function iframeScriptSecond() {
    23       let TestRunner = content.wrappedJSObject.TestRunner;
    25       let oldComplete = TestRunner.onComplete;
    27       TestRunner.onComplete = function() {
    28         TestRunner.onComplete = oldComplete;
    30         sendAsyncMessage("test:DeviceStorage:ipcTestComplete", {
    31           result: JSON.stringify(TestRunner._failedTests)
    32         });
    34         if (oldComplete) {
    35           oldComplete();
    36         }
    37       };
    39       let oldLog = TestRunner.log;
    40       TestRunner.log = function(msg) {
    41         sendAsyncMessage("test:DeviceStorage:ipcTestMessage", { msg: msg });
    42       }
    43     }
    45     let regex = /^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL|TEST-DEBUG-INFO) \| ([^\|]+) \|(.*)/;
    47     function onTestMessage(data) {
    48       let message = SpecialPowers.wrap(data).json.msg;
    49       let match = regex.exec(message);
    50       if (match) {
    51         let state = match[1];
    52         let details = match[2] + " | " + match[3];
    54         switch (state) {
    55           case "TEST-PASS":
    56           case "TEST-KNOWN-FAIL":
    57             ok(true, details);
    58             break;
    60           case "TEST-UNEXPECTED-FAIL":
    61           case "TEST-UNEXPECTED-PASS":
    62             ok(false, details);
    63             break;
    65           case "TEST-DEBUG-INFO":
    66           default:
    67             info(details);
    68         }
    69       }
    70     }
    72     function onTestComplete() {
    73       let comp = SpecialPowers.wrap(SpecialPowers.Components);
    74       let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
    75       let spObserver = comp.classes["@mozilla.org/special-powers-observer;1"]
    76                             .getService(comp.interfaces.nsIMessageListener);
    78       mm.removeMessageListener("SPPrefService", spObserver);
    79       mm.removeMessageListener("SPProcessCrashService", spObserver);
    80       mm.removeMessageListener("SPPingService", spObserver);
    81       mm.removeMessageListener("SpecialPowers.Quit", spObserver);
    82       mm.removeMessageListener("SPPermissionManager", spObserver);
    84       mm.removeMessageListener("test:DeviceStorage:ipcTestMessage", onTestMessage);
    85       mm.removeMessageListener("test:DeviceStorage:ipcTestComplete", onTestComplete);
    87       SimpleTest.executeSoon(function () { SimpleTest.finish(); });
    88     }
    90     function runTests() {
    91       let iframe = document.createElement("iframe");
    92       SpecialPowers.wrap(iframe).mozbrowser = true;
    93       iframe.id = "iframe";
    94       iframe.style.width = "100%";
    95       iframe.style.height = "1000px";
    97       function iframeLoadSecond() {
    98         ok(true, "Got second iframe load event.");
    99         iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond);
   100         let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
   101         mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();",
   102                            false);
   103       }
   105       function iframeLoadFirst() {
   106         ok(true, "Got first iframe load event.");
   107         iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst);
   108         iframe.addEventListener("mozbrowserloadend", iframeLoadSecond);
   110         let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
   112         let comp = SpecialPowers.wrap(SpecialPowers.Components);
   114         let spObserver =
   115           comp.classes["@mozilla.org/special-powers-observer;1"]
   116               .getService(comp.interfaces.nsIMessageListener);
   118         mm.addMessageListener("SPPrefService", spObserver);
   119         mm.addMessageListener("SPProcessCrashService", spObserver);
   120         mm.addMessageListener("SPPingService", spObserver);
   121         mm.addMessageListener("SpecialPowers.Quit", spObserver);
   122         mm.addMessageListener("SPPermissionManager", spObserver);
   124         mm.addMessageListener("test:DeviceStorage:ipcTestMessage", onTestMessage);
   125         mm.addMessageListener("test:DeviceStorage:ipcTestComplete", onTestComplete);
   127         let specialPowersBase = "chrome://specialpowers/content/";
   128         mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false);
   129         mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false);
   130         mm.loadFrameScript(specialPowersBase + "specialpowers.js", false);
   132         mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", false);
   133       }
   135       iframe.addEventListener("mozbrowserloadend", iframeLoadFirst);
   137       // Strip this filename and one directory level and then add "/test".
   138       let href =  window.location.href;
   139       href = href.substring(0, href.lastIndexOf('/'));
   140       href = href.substring(0, href.lastIndexOf('/'));
   141       iframe.src = href + "/test?consoleLevel=INFO";
   143       document.body.appendChild(iframe);
   144     }
   146     addEventListener("load", function() {
   148       SpecialPowers.addPermission("browser", true, document);
   149       SpecialPowers.pushPrefEnv({
   150         "set": [
   152           ["device.storage.enabled", true],
   153           ["device.storage.testing", true],
   154           ["device.storage.prompt.testing", true],
   156           // TODO: remove this as part of bug 820712
   157           ["network.disable.ipc.security", true],
   159           ["dom.ipc.browser_frames.oop_by_default", true],
   160           ["dom.mozBrowserFramesEnabled", true],
   161           ["browser.pagethumbnails.capturing_disabled", true]
   162         ]
   163       }, runTests);
   164     });
   166   </script>
   167 </body>
   168 </html>

mercurial