Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: chrome/test/data/extensions/api_test/processes/api/test.js

Issue 10175008: Improving the process model extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Syncing to the latest tree after a week away. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/samples.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..474ee318fe8471c99338c4854fa1280db6f79858 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,62 @@ 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 validateProcessProperties(process, updating, memory_included) {
+ // Always present.
+ assertTrue("id" in process);
+ assertTrue("osProcessId" in process);
+ assertTrue("type" in process);
+ assertTrue("profile" in process);
+ assertTrue("tabs" in process);
+
+ // Present if onUpdate(WithMemory) listener is registered.
+ assertEq(("cpu" in process), updating);
+ assertEq(("network" in process), updating);
+ assertEq(("fps" in process), updating);
+
+ // Present if memory details are requested.
+ assertEq(("privateMemory" in process), memory_included);
+
+ // sqliteMemory is only reported for the browser process
+ if (process.type == "browser") {
+ assertEq(("sqliteMemory" in process), updating);
+ } else {
+ // The rest are not present in the browser process
+ assertEq(("jsMemoryAllocated" in process), updating);
+ assertEq(("jsMemoryUsed" in process), updating);
+ assertEq(("imageCache" in process), updating);
+ assertEq(("scriptCache" in process), updating);
+ assertEq(("cssCache" in process), updating);
+ }
+}
+
chrome.test.runTests([
function setupProcessTests() {
// Open 4 tabs for test, then wait and create a 5th
@@ -75,6 +133,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 +179,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 +187,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 +225,111 @@ 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);
+ validateProcessProperties(process, true, false);
}
});
},
+ function propertiesOfProcessesWithMemory() {
+ listenOnce(chrome.experimental.processes.onUpdatedWithMemory,
+ function(processes) {
+ for (pid in processes) {
+ var process = processes[pid];
+ validateProcessProperties(process, true, true);
+ }
+ });
+ },
+
+ 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(process) {
+ assertTrue("id" in process, "process doesn't have id property");
+ assertTrue(process.id > 0, "id is not positive " + process.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() {
+ getProcessId(tabs[0].id, pass(function(pidTab0) {
+ getProcessId(tabs[1].id, pass(function(pidTab1) {
+ chrome.experimental.processes.getProcessInfo([pidTab0, pidTab1], 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 testGetProcessInfo() {
+ chrome.experimental.processes.getProcessInfo([], false,
+ pass(function(processes) {
+ assertTrue(Object.keys(processes).length >= 1);
+ for (pid in processes) {
+ var process = processes[pid];
+ validateProcessProperties(process, false, false);
+ assertFalse("privateMemory" in process);
+ }
+ }));
+ },
+
+ function testGetProcessInfoWithMemory() {
+ chrome.experimental.processes.getProcessInfo(0, true,
+ pass(function(processes) {
+ for (pid in processes) {
+ var process = processes[pid];
+ validateProcessProperties(process, false, true);
+ 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" });
+ });
+ }
]);
« no previous file with comments | « chrome/common/extensions/docs/samples.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698