toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.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 the URI Classifier</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7 </head>
     9 <p id="display"></p>
    10 <div id="content" style="display: none">
    11 </div>
    12 <pre id="test">
    14 <script class="testbody" type="text/javascript">
    16 var Cc = SpecialPowers.Cc;
    17 var Ci = SpecialPowers.Ci;
    19 // Add some URLs to the malware database.
    20 var testData = "example.com/tests/toolkit/components/url-classifier/tests/mochitest/evilWorker.js";
    21 var testUpdate =
    22   "n:1000\ni:test-malware-simple\nad:550\n" +
    23   "a:550:32:" + testData.length + "\n" +
    24   testData;
    26 var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
    27                 .getService(Ci.nsIUrlClassifierDBService);
    29 function doUpdate(update) {
    30   var listener = {
    31     QueryInterface: function(iid)
    32     {
    33       if (iid.equals(Ci.nsISupports) ||
    34           iid.equals(Ci.nsIUrlClassifierUpdateObserver))
    35         return this;
    37       throw Cr.NS_ERROR_NO_INTERFACE;
    38     },
    39     updateUrlRequested: function(url) { },
    40     streamFinished: function(status) { },
    41     updateError: function(errorCode) {
    42       ok(false, "Couldn't update classifier.");
    43       // Abort test.
    44       SimpleTest.finish();
    45     },
    46     updateSuccess: function(requestedTimeout) {
    47       SpecialPowers.pushPrefEnv(
    48         {"set" : [["browser.safebrowsing.malware.enabled", true]]},
    49         function loadTestFrame() {
    50           document.getElementById("testFrame").src =
    51             "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/workerFrame.html";
    52         }
    53       );
    54     }
    55   };
    57   dbService.beginUpdate(listener, "test-malware-simple", "");
    58   dbService.beginStream("", "");
    59   dbService.updateStream(update);
    60   dbService.finishStream();
    61   dbService.finishUpdate();
    62 }
    64 function onmessage(event)
    65 {
    66   var pieces = event.data.split(':');
    67   if (pieces[0] == "finish") {
    68     SimpleTest.finish();
    69     return;
    70   }
    72   is(pieces[0], "success", pieces[1]);
    73 }
    75 SpecialPowers.pushPrefEnv(
    76   {"set" : [["urlclassifier.malware_table", "test-malware-simple"],
    77             ["urlclassifier.phish_table", "test-phish-simple"]]},
    78   function() { doUpdate(testUpdate); });
    80 window.addEventListener("message", onmessage, false);
    82 SimpleTest.waitForExplicitFinish();
    84 </script>
    86 </pre>
    87 <iframe id="testFrame" onload=""></iframe>
    88 </body>
    89 </html>

mercurial