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