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