1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory6.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<window title="about:memory" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.9 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.10 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.11 + 1.12 + <!-- This file tests the saving of GC and CC logs in both concise and 1.13 + verbose formats. --> 1.14 + 1.15 + <!-- test results are displayed in the html:body --> 1.16 + <body xmlns="http://www.w3.org/1999/xhtml"></body> 1.17 + 1.18 + <iframe id="amFrame" height="400" src="about:memory"></iframe> 1.19 + 1.20 + <script type="application/javascript"> 1.21 + <![CDATA[ 1.22 + "use strict"; 1.23 + 1.24 + const Cc = Components.classes; 1.25 + const Ci = Components.interfaces; 1.26 + 1.27 + function onFocus() { 1.28 + let frame = document.getElementById("amFrame"); 1.29 + frame.focus(); 1.30 + 1.31 + // Checks that a file exists on the local file system and removes it if it 1.32 + // is present. 1.33 + function checkForFileAndRemove(aFilename) { 1.34 + let localFile = Cc["@mozilla.org/file/local;1"] 1.35 + .createInstance(Ci.nsILocalFile); 1.36 + localFile.initWithPath(aFilename); 1.37 + 1.38 + let exists = localFile.exists(); 1.39 + if (exists) { 1.40 + localFile.remove(/* recursive = */ false); 1.41 + } 1.42 + 1.43 + return exists; 1.44 + } 1.45 + 1.46 + // Given a save log button, triggers the action and checks if both CC & GC 1.47 + // logs were written to disk. 1.48 + function saveLogs(aLogButton, aCCLogType) 1.49 + { 1.50 + // trigger the log saving 1.51 + aLogButton.click(); 1.52 + 1.53 + // mainDiv 1.54 + // |-> section 1.55 + // | -> div gc log path 1.56 + // | -> div cc log path 1.57 + let mainDiv = frame.contentWindow.document.getElementById("mainDiv"); 1.58 + let logNodes = mainDiv.childNodes[0]; 1.59 + 1.60 + // we expect 2 logs listed 1.61 + let numOfLogs = logNodes.childNodes.length; 1.62 + ok(numOfLogs == 2, "two log entries generated") 1.63 + 1.64 + // grab the path portion of the text 1.65 + let gcLogPath = logNodes.childNodes[0].textContent 1.66 + .replace("Saved GC log to ", ""); 1.67 + let ccLogPath = logNodes.childNodes[1].textContent 1.68 + .replace("Saved " + aCCLogType + " CC log to ", ""); 1.69 + 1.70 + // check that the files actually exist 1.71 + ok(checkForFileAndRemove(gcLogPath), "GC log file exists"); 1.72 + ok(checkForFileAndRemove(ccLogPath), "CC log file exists"); 1.73 + } 1.74 + 1.75 + // get the log buttons to test 1.76 + let saveConcise = frame.contentWindow.document 1.77 + .getElementById("saveLogsConcise"); 1.78 + let saveVerbose = frame.contentWindow.document 1.79 + .getElementById("saveLogsVerbose"); 1.80 + 1.81 + saveLogs(saveConcise, "concise"); 1.82 + saveLogs(saveVerbose, "verbose"); 1.83 + 1.84 + SimpleTest.finish(); 1.85 + } 1.86 + 1.87 + SimpleTest.waitForFocus(onFocus); 1.88 + SimpleTest.waitForExplicitFinish(); 1.89 + ]]> 1.90 + </script> 1.91 +</window>