Index: chrome/test/data/extensions/api_test/processes/api/test.js |
diff --git a/chrome/test/data/extensions/api_test/processes/api/test.js b/chrome/test/data/extensions/api_test/processes/api/test.js |
index de62d40fbaf18a4e28c375c341a421cf6485556f..d2d77a4376c553269bc70c54cabcb1247811ba25 100644 |
--- a/chrome/test/data/extensions/api_test/processes/api/test.js |
+++ b/chrome/test/data/extensions/api_test/processes/api/test.js |
@@ -9,9 +9,11 @@ var pass = chrome.test.callbackPass; |
var fail = chrome.test.callbackFail; |
var assertEq = chrome.test.assertEq; |
var assertTrue = chrome.test.assertTrue; |
+var assertFalse = chrome.test.assertFalse; |
var listenOnce = chrome.test.listenOnce; |
var tabs = []; |
+var hangingTabProcess = -1; |
function createTab(index, url) { |
chrome.tabs.create({"url": url}, pass(function(tab) { |
@@ -25,6 +27,33 @@ function pageUrl(letter) { |
return chrome.extension.getURL(letter + ".html"); |
} |
+function dumpProcess(process) { |
+ console.log("id " + process.id); |
+ console.log("osProcId " + process.osProcessId); |
+ console.log("type " + process.type); |
+ console.log("profile " + process.profile); |
+ console.log("tabs " + process.tabs); |
+ console.log("cpu " + process.cpu); |
+ console.log("privMem " + process.privateMemory); |
+ console.log("network " + process.network); |
+ console.log("jsMemAlloc " + process.jsMemoryAllocated); |
+ console.log("jsMemUsed " + process.jsMemoryUsed); |
+ console.log("sqliteMem " + process.sqliteMemory); |
+ console.log("fps " + process.fps); |
+ if ("imageCache" in process) { |
+ console.log("imageCache.size " + process.imageCache.size); |
+ console.log("imageCache.liveSize " + process.imageCache.liveSize); |
+ } |
+ if ("scriptCache" in process) { |
+ console.log("scriptCache.size " + process.scriptCache.size); |
+ console.log("scriptCache.liveSize " + process.scriptCache.liveSize); |
+ } |
+ if ("cssCache" in process) { |
+ console.log("cssCache.size " + process.cssCache.size); |
+ console.log("cssCache .liveSize " + process.cssCache.liveSize); |
+ } |
+} |
+ |
chrome.test.runTests([ |
function setupProcessTests() { |
// Open 4 tabs for test, then wait and create a 5th |
@@ -100,7 +129,7 @@ chrome.test.runTests([ |
var pids = Object.keys(processes); |
// There should be at least 5 processes: 1 browser, 1 extension, and 3 |
// renderers (for the 5 tabs). |
- assertTrue(pids.length >= 5); |
+ assertTrue(pids.length >= 5, "Unexpected size of pids"); |
// Should be able to look up process object by ID. |
assertTrue(processes[pids[0]].id == pids[0]); |
@@ -108,8 +137,8 @@ chrome.test.runTests([ |
getProcessId(tabs[0].id, pass(function(pidTab0) { |
// Process ID for tab 0 should be listed in pids. |
- assertTrue(processes[pidTab0] != undefined); |
- assertEq("renderer", processes[pidTab0].type); |
+ assertTrue(processes[pidTab0] != undefined, "Undefined Process"); |
+ assertEq("renderer", processes[pidTab0].type, "Tab0 is not renderer"); |
})); |
}); |
}, |
@@ -147,13 +176,119 @@ chrome.test.runTests([ |
for (pid in processes) { |
var process = processes[pid]; |
assertTrue("id" in process); |
+ assertTrue("osProcessId" in process); |
assertTrue("type" in process); |
- assertTrue("cpu" in process); |
- assertTrue("network" in process); |
- assertTrue("sharedMemory" in process); |
- assertTrue("privateMemory" in process); |
+ assertTrue("profile" in process); |
+ assertFalse("privateMemory" in process); |
} |
}); |
}, |
+ function propertiesOfProcessesWithMemory() { |
+ listenOnce(chrome.experimental.processes.onUpdatedWithMemory, |
+ function(processes) { |
+ for (pid in processes) { |
+ var process = processes[pid]; |
+ assertTrue("id" in process); |
+ assertTrue("osProcessId" in process); |
+ assertTrue("type" in process); |
+ assertTrue("profile" in process); |
+ assertTrue("privateMemory" in process); |
+ } |
+ }); |
+ }, |
+ |
+ function terminateProcess() { |
+ createTab(5, pageUrl("a")); |
+ listenOnce(chrome.experimental.processes.onExited, |
+ function(processId, type, code) { |
+ assertTrue(processId > 0); |
+ }); |
+ getProcessId(tabs[4].id, function(pid0) { |
+ chrome.experimental.processes.terminate(pid0, function(killed) { |
+ chrome.test.assertTrue(killed); |
+ }); |
+ }); |
+ }, |
+ |
+ function testOnCreated() { |
+ listenOnce(chrome.experimental.processes.onCreated, function(id, process) { |
+ assertTrue("id" in process, "process doesn't have id property"); |
+ assertTrue(id > 0, "id is not positive " + id); |
+ }); |
+ createTab(5, "chrome://newtab/"); |
+ }, |
+ |
+ function testOnExited() { |
+ createTab(5, "chrome://newtab/"); |
+ listenOnce(chrome.experimental.processes.onExited, |
+ function(processId, type, code) { |
+ assertTrue(type >= 0 && type < 5); |
+ }); |
+ chrome.tabs.create({"url": "http://google.com/"}, pass(function(tab) { |
+ chrome.tabs.remove(tab.id); |
+ })); |
+ }, |
+ |
+ function testGetProcessInfoList() { |
+ chrome.experimental.processes.getProcessInfo([0, 2], false, |
+ pass(function(processes) { |
+ assertTrue(Object.keys(processes).length == 2); |
+ })); |
+ }, |
+ |
+ function testGetProcessInfoSingle() { |
+ chrome.experimental.processes.getProcessInfo(0, false, |
+ pass(function(processes) { |
+ assertTrue(Object.keys(processes).length == 1); |
+ })); |
+ }, |
+ |
+ function testGetProcessInfoAll() { |
+ chrome.experimental.processes.getProcessInfo([], false, |
+ pass(function(processes) { |
+ assertTrue(Object.keys(processes).length >= 1); |
+ })); |
+ }, |
+ |
+ function testGetProcessInfo() { |
+ chrome.experimental.processes.getProcessInfo([], false, |
+ pass(function(processes) { |
+ for (pid in processes) { |
+ var process = processes[pid]; |
+ assertTrue("id" in process); |
+ assertTrue("osProcessId" in process); |
+ assertTrue("type" in process); |
+ assertTrue("profile" in process); |
+ assertFalse("privateMemory" in process); |
+ } |
+ })); |
+ }, |
+ |
+ function testGetProcessInfoWithMemory() { |
+ chrome.experimental.processes.getProcessInfo(0, true, |
+ pass(function(processes) { |
+ for (pid in processes) { |
+ var process = processes[pid]; |
+ assertTrue("privateMemory" in process); |
+ } |
+ })); |
+ }, |
+ |
+ function testOnUnresponsive() { |
+ listenOnce(chrome.experimental.processes.onUnresponsive, |
+ function(process) { |
+ assertTrue(process.id == hangingTabProcess); |
+ // actually kill the process, just to make sure it won't hang the test |
+ chrome.experimental.processes.terminate(process.id, function(killed) { |
+ chrome.test.assertTrue(killed); |
+ }); |
+ }); |
+ chrome.tabs.create({"url": "chrome://hang" }, function(tab) { |
+ getProcessId(tab.id, function(pid0) { |
+ hangingTabProcess = pid0; |
+ }); |
+ chrome.tabs.update(tab.id, { "url": "chrome://flags" }); |
+ }); |
+ } |
]); |