toolkit/devtools/webconsole/test/test_file_uri.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/webconsole/test/test_file_uri.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html lang="en">
     1.6 +<head>
     1.7 +  <meta charset="utf8">
     1.8 +  <title>Test for file activity tracking</title>
     1.9 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <script type="text/javascript;version=1.8" src="common.js"></script>
    1.11 +  <!-- Any copyright is dedicated to the Public Domain.
    1.12 +     - http://creativecommons.org/publicdomain/zero/1.0/ -->
    1.13 +</head>
    1.14 +<body>
    1.15 +<p>Test for file activity tracking</p>
    1.16 +
    1.17 +<script class="testbody" type="text/javascript;version=1.8">
    1.18 +SimpleTest.waitForExplicitFinish();
    1.19 +
    1.20 +Cu.import("resource://gre/modules/NetUtil.jsm");
    1.21 +Cu.import("resource://gre/modules/FileUtils.jsm");
    1.22 +
    1.23 +let gState;
    1.24 +let gTmpFile;
    1.25 +
    1.26 +function doFileActivity()
    1.27 +{
    1.28 +  info("doFileActivity");
    1.29 +  let fileContent = "<p>hello world from bug 798764";
    1.30 +
    1.31 +  gTmpFile = FileUtils.getFile("TmpD", ["bug798764.html"]);
    1.32 +  gTmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
    1.33 +
    1.34 +  let fout = FileUtils.openSafeFileOutputStream(gTmpFile,
    1.35 +    FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE);
    1.36 +
    1.37 +  let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
    1.38 +                  createInstance(Ci.nsIScriptableUnicodeConverter);
    1.39 +  converter.charset = "UTF-8";
    1.40 +  let fileContentStream = converter.convertToInputStream(fileContent);
    1.41 +
    1.42 +  NetUtil.asyncCopy(fileContentStream, fout, addIframe);
    1.43 +}
    1.44 +
    1.45 +function addIframe(aStatus)
    1.46 +{
    1.47 +  ok(Components.isSuccessCode(aStatus),
    1.48 +     "the temporary file was saved successfully");
    1.49 +
    1.50 +  let iframe = document.createElement("iframe");
    1.51 +  iframe.src = NetUtil.newURI(gTmpFile).spec;
    1.52 +  document.body.appendChild(iframe);
    1.53 +}
    1.54 +
    1.55 +function startTest()
    1.56 +{
    1.57 +  removeEventListener("load", startTest);
    1.58 +
    1.59 +  attachConsole(["FileActivity"], onAttach);
    1.60 +}
    1.61 +
    1.62 +function onAttach(aState, aResponse)
    1.63 +{
    1.64 +  gState = aState;
    1.65 +  gState.dbgClient.addListener("fileActivity", onFileActivity);
    1.66 +  doFileActivity();
    1.67 +}
    1.68 +
    1.69 +function onFileActivity(aType, aPacket)
    1.70 +{
    1.71 +  is(aPacket.from, gState.actor, "fileActivity actor");
    1.72 +
    1.73 +  gState.dbgClient.removeListener("fileActivity", onFileActivity);
    1.74 +
    1.75 +  info("aPacket.uri: " + aPacket.uri);
    1.76 +  ok(/\bbug798764\b.*\.html$/.test(aPacket.uri), "file URI match");
    1.77 +
    1.78 +  testEnd();
    1.79 +}
    1.80 +
    1.81 +function testEnd()
    1.82 +{
    1.83 +  if (gTmpFile) {
    1.84 +    SimpleTest.executeSoon(function() {
    1.85 +      try {
    1.86 +        gTmpFile.remove(false);
    1.87 +      }
    1.88 +      catch (ex if (ex.name == "NS_ERROR_FILE_IS_LOCKED")) {
    1.89 +        // Sometimes remove() throws because the file is not unlocked soon
    1.90 +        // enough.
    1.91 +      }
    1.92 +      gTmpFile = null;
    1.93 +    });
    1.94 +  }
    1.95 +
    1.96 +  if (gState) {
    1.97 +    closeDebugger(gState, function() {
    1.98 +      gState = null;
    1.99 +      SimpleTest.finish();
   1.100 +    });
   1.101 +  } else {
   1.102 +    SimpleTest.finish();
   1.103 +  }
   1.104 +}
   1.105 +
   1.106 +addEventListener("load", startTest);
   1.107 +</script>
   1.108 +</body>
   1.109 +</html>

mercurial