Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html lang="en"> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf8"> |
michael@0 | 5 | <title>Test for file activity tracking</title> |
michael@0 | 6 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <script type="text/javascript;version=1.8" src="common.js"></script> |
michael@0 | 8 | <!-- Any copyright is dedicated to the Public Domain. |
michael@0 | 9 | - http://creativecommons.org/publicdomain/zero/1.0/ --> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <p>Test for file activity tracking</p> |
michael@0 | 13 | |
michael@0 | 14 | <script class="testbody" type="text/javascript;version=1.8"> |
michael@0 | 15 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | Cu.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 18 | Cu.import("resource://gre/modules/FileUtils.jsm"); |
michael@0 | 19 | |
michael@0 | 20 | let gState; |
michael@0 | 21 | let gTmpFile; |
michael@0 | 22 | |
michael@0 | 23 | function doFileActivity() |
michael@0 | 24 | { |
michael@0 | 25 | info("doFileActivity"); |
michael@0 | 26 | let fileContent = "<p>hello world from bug 798764"; |
michael@0 | 27 | |
michael@0 | 28 | gTmpFile = FileUtils.getFile("TmpD", ["bug798764.html"]); |
michael@0 | 29 | gTmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); |
michael@0 | 30 | |
michael@0 | 31 | let fout = FileUtils.openSafeFileOutputStream(gTmpFile, |
michael@0 | 32 | FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE); |
michael@0 | 33 | |
michael@0 | 34 | let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. |
michael@0 | 35 | createInstance(Ci.nsIScriptableUnicodeConverter); |
michael@0 | 36 | converter.charset = "UTF-8"; |
michael@0 | 37 | let fileContentStream = converter.convertToInputStream(fileContent); |
michael@0 | 38 | |
michael@0 | 39 | NetUtil.asyncCopy(fileContentStream, fout, addIframe); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function addIframe(aStatus) |
michael@0 | 43 | { |
michael@0 | 44 | ok(Components.isSuccessCode(aStatus), |
michael@0 | 45 | "the temporary file was saved successfully"); |
michael@0 | 46 | |
michael@0 | 47 | let iframe = document.createElement("iframe"); |
michael@0 | 48 | iframe.src = NetUtil.newURI(gTmpFile).spec; |
michael@0 | 49 | document.body.appendChild(iframe); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function startTest() |
michael@0 | 53 | { |
michael@0 | 54 | removeEventListener("load", startTest); |
michael@0 | 55 | |
michael@0 | 56 | attachConsole(["FileActivity"], onAttach); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function onAttach(aState, aResponse) |
michael@0 | 60 | { |
michael@0 | 61 | gState = aState; |
michael@0 | 62 | gState.dbgClient.addListener("fileActivity", onFileActivity); |
michael@0 | 63 | doFileActivity(); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function onFileActivity(aType, aPacket) |
michael@0 | 67 | { |
michael@0 | 68 | is(aPacket.from, gState.actor, "fileActivity actor"); |
michael@0 | 69 | |
michael@0 | 70 | gState.dbgClient.removeListener("fileActivity", onFileActivity); |
michael@0 | 71 | |
michael@0 | 72 | info("aPacket.uri: " + aPacket.uri); |
michael@0 | 73 | ok(/\bbug798764\b.*\.html$/.test(aPacket.uri), "file URI match"); |
michael@0 | 74 | |
michael@0 | 75 | testEnd(); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function testEnd() |
michael@0 | 79 | { |
michael@0 | 80 | if (gTmpFile) { |
michael@0 | 81 | SimpleTest.executeSoon(function() { |
michael@0 | 82 | try { |
michael@0 | 83 | gTmpFile.remove(false); |
michael@0 | 84 | } |
michael@0 | 85 | catch (ex if (ex.name == "NS_ERROR_FILE_IS_LOCKED")) { |
michael@0 | 86 | // Sometimes remove() throws because the file is not unlocked soon |
michael@0 | 87 | // enough. |
michael@0 | 88 | } |
michael@0 | 89 | gTmpFile = null; |
michael@0 | 90 | }); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | if (gState) { |
michael@0 | 94 | closeDebugger(gState, function() { |
michael@0 | 95 | gState = null; |
michael@0 | 96 | SimpleTest.finish(); |
michael@0 | 97 | }); |
michael@0 | 98 | } else { |
michael@0 | 99 | SimpleTest.finish(); |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | addEventListener("load", startTest); |
michael@0 | 104 | </script> |
michael@0 | 105 | </body> |
michael@0 | 106 | </html> |