Chromium Code Reviews| 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..4dd92f3b8bcbda7cb48e3d74b8f25a62a5783cce 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,65 @@ 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); |
| + } |
| +} |
| + |
| +function validateProcessPropertiesOnUpdate(process) { |
| + assertTrue("id" in process); |
| + assertTrue("osProcessId" in process); |
| + assertTrue("type" in process); |
| + assertTrue("profile" in process); |
| + assertTrue("tabs" in process); |
| + assertTrue("cpu" in process); |
| + assertTrue("network" in process); |
|
Charlie Reis
2012/04/27 22:01:56
What about things like sqliteMemory? We should be
nasko
2012/04/30 18:05:19
Done.
|
| + assertFalse("privateMemory" in process); |
| +} |
| + |
| +function validateProcessPropertiesOnUpdateWithMemory(process) { |
| + assertTrue("id" in process); |
| + assertTrue("osProcessId" in process); |
| + assertTrue("type" in process); |
| + assertTrue("profile" in process); |
| + assertTrue("tabs" in process); |
| + assertTrue("cpu" in process); |
| + assertTrue("network" in process); |
|
Charlie Reis
2012/04/27 22:01:56
Could just call validateProcessPropertiesOnUpdate,
nasko
2012/04/30 18:05:19
I've rewritten the whole process validation.
|
| + assertTrue("privateMemory" in process); |
| +} |
| + |
| +function validateGetProcessInfo(process) { |
| + assertTrue("id" in process); |
| + assertTrue("osProcessId" in process); |
| + assertTrue("type" in process); |
| + assertTrue("profile" in process); |
| + assertTrue("tabs" in process) |
| + assertFalse("cpu" in process) |
| + assertFalse("network" in process) |
| +} |
| + |
| chrome.test.runTests([ |
| function setupProcessTests() { |
| // Open 4 tabs for test, then wait and create a 5th |
| @@ -75,6 +136,27 @@ chrome.test.runTests([ |
| })); |
| }, |
| + function extensionPagesMatchTabs() { |
| + getProcessId(tabs[1].id, pass(function(pid1) { |
| + getProcessId(tabs[2].id, pass(function(pid2) { |
| + // Pages from same extension should share a process |
| + assertEq(pid1, pid2); |
| + chrome.experimental.processes.getProcessInfo(pid1, false, |
| + function(pl1) { |
| + chrome.experimental.processes.getProcessInfo(pid2, false, |
| + function (pl2) { |
| + var proc1 = pl1[pid1]; |
| + var proc2 = pl2[pid2]; |
| + assertTrue(proc1.tabs.length == proc2.tabs.length); |
| + for (var i = 0; i < proc1.tabs.length; ++i) { |
| + assertEq(proc1.tabs[i], proc2.tabs[i]); |
| + } |
| + }); |
| + }); |
| + })); |
| + })); |
| + }, |
| + |
| function newTabPageInOwnProcess() { |
| getProcessId(tabs[0].id, pass(function(pid0) { |
| getProcessId(tabs[3].id, pass(function(pid3) { |
| @@ -100,7 +182,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 +190,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"); |
| })); |
| }); |
| }, |
| @@ -146,14 +228,113 @@ chrome.test.runTests([ |
| listenOnce(chrome.experimental.processes.onUpdated, function(processes) { |
| for (pid in processes) { |
| var process = processes[pid]; |
| - assertTrue("id" in process); |
| - assertTrue("type" in process); |
| - assertTrue("cpu" in process); |
| - assertTrue("network" in process); |
| - assertTrue("sharedMemory" in process); |
| - assertTrue("privateMemory" in process); |
| + validateProcessPropertiesOnUpdate(process); |
| } |
| }); |
| }, |
| + function propertiesOfProcessesWithMemory() { |
| + listenOnce(chrome.experimental.processes.onUpdatedWithMemory, |
| + function(processes) { |
| + for (pid in processes) { |
| + var process = processes[pid]; |
| + validateProcessPropertiesOnUpdateWithMemory(process); |
| + } |
| + }); |
| + }, |
| + |
| + function terminateProcess() { |
| + 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 terminateProcessNonExisting() { |
| + chrome.experimental.processes.terminate(31337, |
| + fail("Process not found: 31337.")); |
| + }, |
| + |
| + 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() { |
| + 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]; |
| + validateGetProcessInfo(process); |
| + assertFalse("privateMemory" in process); |
| + } |
| + })); |
| + }, |
| + |
| + function testGetProcessInfoWithMemory() { |
| + chrome.experimental.processes.getProcessInfo(0, true, |
| + pass(function(processes) { |
| + for (pid in processes) { |
| + var process = processes[pid]; |
| + validateGetProcessInfo(process); |
| + 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" }); |
| + }); |
| + } |
| ]); |