toolkit/components/aboutmemory/tests/test_aboutmemory6.xul

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 4 <window title="about:memory"
michael@0 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 6 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 7 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 8
michael@0 9 <!-- This file tests the saving of GC and CC logs in both concise and
michael@0 10 verbose formats. -->
michael@0 11
michael@0 12 <!-- test results are displayed in the html:body -->
michael@0 13 <body xmlns="http://www.w3.org/1999/xhtml"></body>
michael@0 14
michael@0 15 <iframe id="amFrame" height="400" src="about:memory"></iframe>
michael@0 16
michael@0 17 <script type="application/javascript">
michael@0 18 <![CDATA[
michael@0 19 "use strict";
michael@0 20
michael@0 21 const Cc = Components.classes;
michael@0 22 const Ci = Components.interfaces;
michael@0 23
michael@0 24 function onFocus() {
michael@0 25 let frame = document.getElementById("amFrame");
michael@0 26 frame.focus();
michael@0 27
michael@0 28 // Checks that a file exists on the local file system and removes it if it
michael@0 29 // is present.
michael@0 30 function checkForFileAndRemove(aFilename) {
michael@0 31 let localFile = Cc["@mozilla.org/file/local;1"]
michael@0 32 .createInstance(Ci.nsILocalFile);
michael@0 33 localFile.initWithPath(aFilename);
michael@0 34
michael@0 35 let exists = localFile.exists();
michael@0 36 if (exists) {
michael@0 37 localFile.remove(/* recursive = */ false);
michael@0 38 }
michael@0 39
michael@0 40 return exists;
michael@0 41 }
michael@0 42
michael@0 43 // Given a save log button, triggers the action and checks if both CC & GC
michael@0 44 // logs were written to disk.
michael@0 45 function saveLogs(aLogButton, aCCLogType)
michael@0 46 {
michael@0 47 // trigger the log saving
michael@0 48 aLogButton.click();
michael@0 49
michael@0 50 // mainDiv
michael@0 51 // |-> section
michael@0 52 // | -> div gc log path
michael@0 53 // | -> div cc log path
michael@0 54 let mainDiv = frame.contentWindow.document.getElementById("mainDiv");
michael@0 55 let logNodes = mainDiv.childNodes[0];
michael@0 56
michael@0 57 // we expect 2 logs listed
michael@0 58 let numOfLogs = logNodes.childNodes.length;
michael@0 59 ok(numOfLogs == 2, "two log entries generated")
michael@0 60
michael@0 61 // grab the path portion of the text
michael@0 62 let gcLogPath = logNodes.childNodes[0].textContent
michael@0 63 .replace("Saved GC log to ", "");
michael@0 64 let ccLogPath = logNodes.childNodes[1].textContent
michael@0 65 .replace("Saved " + aCCLogType + " CC log to ", "");
michael@0 66
michael@0 67 // check that the files actually exist
michael@0 68 ok(checkForFileAndRemove(gcLogPath), "GC log file exists");
michael@0 69 ok(checkForFileAndRemove(ccLogPath), "CC log file exists");
michael@0 70 }
michael@0 71
michael@0 72 // get the log buttons to test
michael@0 73 let saveConcise = frame.contentWindow.document
michael@0 74 .getElementById("saveLogsConcise");
michael@0 75 let saveVerbose = frame.contentWindow.document
michael@0 76 .getElementById("saveLogsVerbose");
michael@0 77
michael@0 78 saveLogs(saveConcise, "concise");
michael@0 79 saveLogs(saveVerbose, "verbose");
michael@0 80
michael@0 81 SimpleTest.finish();
michael@0 82 }
michael@0 83
michael@0 84 SimpleTest.waitForFocus(onFocus);
michael@0 85 SimpleTest.waitForExplicitFinish();
michael@0 86 ]]>
michael@0 87 </script>
michael@0 88 </window>

mercurial