summaryrefslogtreecommitdiffstats
path: root/toolkit/components/aboutmemory/tests/test_aboutmemory6.xul
blob: 365f990918dc09873921bb0f32f24ae32153e1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window title="about:memory"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

  <!-- This file tests the saving of GC and CC logs in both concise and
       verbose formats. -->

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml"></body>

  <iframe id="amFrame"  height="400" src="about:memory"></iframe>

  <script type="application/javascript">
  <![CDATA[
  "use strict";

  const Cc = Components.classes;
  const Ci = Components.interfaces;

  function onFocus() {
    let frame = document.getElementById("amFrame");
    frame.focus();

    // Checks that a file exists on the local file system and removes it if it
    // is present.
    function checkForFileAndRemove(aFilename) {
      let localFile = Cc["@mozilla.org/file/local;1"]
                        .createInstance(Ci.nsILocalFile);
      localFile.initWithPath(aFilename);

      let exists = localFile.exists();
      if (exists) {
        localFile.remove(/* recursive = */ false);
      }

      return exists;
    }

    // Given a save log button, triggers the action and checks if both CC & GC
    // logs were written to disk.
    function saveLogs(aLogButton, aCCLogType)
    {
      // trigger the log saving
      aLogButton.click();

      // mainDiv
      // |-> section
      //        | -> div gc log path
      //        | -> div cc log path
      let mainDiv = frame.contentWindow.document.getElementById("mainDiv");
      let logNodes = mainDiv.childNodes[0];

      // we expect 2 logs listed
      let numOfLogs = logNodes.childNodes.length;
      ok(numOfLogs == 2, "two log entries generated")

      // grab the path portion of the text
      let gcLogPath = logNodes.childNodes[0].textContent
                        .replace("Saved GC log to ", "");
      let ccLogPath = logNodes.childNodes[1].textContent
                        .replace("Saved " + aCCLogType + " CC log to ", "");

      // check that the files actually exist
      ok(checkForFileAndRemove(gcLogPath), "GC log file exists");
      ok(checkForFileAndRemove(ccLogPath), "CC log file exists");
    }

    // get the log buttons to test
    let saveConcise = frame.contentWindow.document
                        .getElementById("saveLogsConcise");
    let saveVerbose = frame.contentWindow.document
                        .getElementById("saveLogsVerbose");

    saveLogs(saveConcise, "concise");
    saveLogs(saveVerbose, "verbose");

    SimpleTest.finish();
  }

  SimpleTest.waitForFocus(onFocus);
  SimpleTest.waitForExplicitFinish();
  ]]>
  </script>
</window>