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

Side by Side 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: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Processes API test for Chrome. 5 // Processes API test for Chrome.
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Processes 6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Processes
7 7
8 var pass = chrome.test.callbackPass; 8 var pass = chrome.test.callbackPass;
9 var fail = chrome.test.callbackFail; 9 var fail = chrome.test.callbackFail;
10 var assertEq = chrome.test.assertEq; 10 var assertEq = chrome.test.assertEq;
11 var assertTrue = chrome.test.assertTrue; 11 var assertTrue = chrome.test.assertTrue;
12 var assertFalse = chrome.test.assertFalse;
12 var listenOnce = chrome.test.listenOnce; 13 var listenOnce = chrome.test.listenOnce;
13 14
14 var tabs = []; 15 var tabs = [];
16 var hangingTabProcess = -1;
15 17
16 function createTab(index, url) { 18 function createTab(index, url) {
17 chrome.tabs.create({"url": url}, pass(function(tab) { 19 chrome.tabs.create({"url": url}, pass(function(tab) {
18 tabs[index] = tab; 20 tabs[index] = tab;
19 })); 21 }));
20 } 22 }
21 23
22 var getProcessId = chrome.experimental.processes.getProcessIdForTab; 24 var getProcessId = chrome.experimental.processes.getProcessIdForTab;
23 25
24 function pageUrl(letter) { 26 function pageUrl(letter) {
25 return chrome.extension.getURL(letter + ".html"); 27 return chrome.extension.getURL(letter + ".html");
26 } 28 }
27 29
30 function dumpProcess(process) {
31 console.log("id " + process.id);
32 console.log("osProcId " + process.osProcessId);
33 console.log("type " + process.type);
34 console.log("profile " + process.profile);
35 console.log("tabs " + process.tabs);
36 console.log("cpu " + process.cpu);
37 console.log("privMem " + process.privateMemory);
38 console.log("network " + process.network);
39 console.log("jsMemAlloc " + process.jsMemoryAllocated);
40 console.log("jsMemUsed " + process.jsMemoryUsed);
41 console.log("sqliteMem " + process.sqliteMemory);
42 console.log("fps " + process.fps);
43 if ("imageCache" in process) {
44 console.log("imageCache.size " + process.imageCache.size);
45 console.log("imageCache.liveSize " + process.imageCache.liveSize);
46 }
47 if ("scriptCache" in process) {
48 console.log("scriptCache.size " + process.scriptCache.size);
49 console.log("scriptCache.liveSize " + process.scriptCache.liveSize);
50 }
51 if ("cssCache" in process) {
52 console.log("cssCache.size " + process.cssCache.size);
53 console.log("cssCache .liveSize " + process.cssCache.liveSize);
54 }
55 }
56
28 chrome.test.runTests([ 57 chrome.test.runTests([
29 function setupProcessTests() { 58 function setupProcessTests() {
30 // Open 4 tabs for test, then wait and create a 5th 59 // Open 4 tabs for test, then wait and create a 5th
31 createTab(0, "about:blank"); 60 createTab(0, "about:blank");
32 createTab(1, pageUrl("a")); 61 createTab(1, pageUrl("a"));
33 createTab(2, pageUrl("b")); 62 createTab(2, pageUrl("b"));
34 createTab(3, "chrome://newtab/"); 63 createTab(3, "chrome://newtab/");
35 64
36 // Wait for all loads to complete. 65 // Wait for all loads to complete.
37 var completedCount = 0; 66 var completedCount = 0;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 })); 122 }));
94 }, 123 },
95 124
96 function idsInUpdateEvent() { 125 function idsInUpdateEvent() {
97 listenOnce(chrome.experimental.processes.onUpdated, function(processes) { 126 listenOnce(chrome.experimental.processes.onUpdated, function(processes) {
98 // onUpdated should return a valid dictionary of processes, 127 // onUpdated should return a valid dictionary of processes,
99 // indexed by process ID. 128 // indexed by process ID.
100 var pids = Object.keys(processes); 129 var pids = Object.keys(processes);
101 // There should be at least 5 processes: 1 browser, 1 extension, and 3 130 // There should be at least 5 processes: 1 browser, 1 extension, and 3
102 // renderers (for the 5 tabs). 131 // renderers (for the 5 tabs).
103 assertTrue(pids.length >= 5); 132 assertTrue(pids.length >= 5, "Unexpected size of pids");
104 133
105 // Should be able to look up process object by ID. 134 // Should be able to look up process object by ID.
106 assertTrue(processes[pids[0]].id == pids[0]); 135 assertTrue(processes[pids[0]].id == pids[0]);
107 assertTrue(processes[pids[0]].id != processes[pids[1]].id); 136 assertTrue(processes[pids[0]].id != processes[pids[1]].id);
108 137
109 getProcessId(tabs[0].id, pass(function(pidTab0) { 138 getProcessId(tabs[0].id, pass(function(pidTab0) {
110 // Process ID for tab 0 should be listed in pids. 139 // Process ID for tab 0 should be listed in pids.
111 assertTrue(processes[pidTab0] != undefined); 140 assertTrue(processes[pidTab0] != undefined, "Undefined Process");
112 assertEq("renderer", processes[pidTab0].type); 141 assertEq("renderer", processes[pidTab0].type, "Tab0 is not renderer");
113 })); 142 }));
114 }); 143 });
115 }, 144 },
116 145
117 function typesInUpdateEvent() { 146 function typesInUpdateEvent() {
118 listenOnce(chrome.experimental.processes.onUpdated, function(processes) { 147 listenOnce(chrome.experimental.processes.onUpdated, function(processes) {
119 // Check types: 1 browser, 3 renderers, and 1 extension 148 // Check types: 1 browser, 3 renderers, and 1 extension
120 var browserCount = 0; 149 var browserCount = 0;
121 var rendererCount = 0; 150 var rendererCount = 0;
122 var extensionCount = 0; 151 var extensionCount = 0;
(...skipping 17 matching lines...) Expand all
140 assertTrue(rendererCount >= 3); 169 assertTrue(rendererCount >= 3);
141 assertTrue(extensionCount >= 1); 170 assertTrue(extensionCount >= 1);
142 }); 171 });
143 }, 172 },
144 173
145 function propertiesOfProcesses() { 174 function propertiesOfProcesses() {
146 listenOnce(chrome.experimental.processes.onUpdated, function(processes) { 175 listenOnce(chrome.experimental.processes.onUpdated, function(processes) {
147 for (pid in processes) { 176 for (pid in processes) {
148 var process = processes[pid]; 177 var process = processes[pid];
149 assertTrue("id" in process); 178 assertTrue("id" in process);
179 assertTrue("osProcessId" in process);
150 assertTrue("type" in process); 180 assertTrue("type" in process);
151 assertTrue("cpu" in process); 181 assertTrue("profile" in process);
152 assertTrue("network" in process); 182 assertFalse("privateMemory" in process);
153 assertTrue("sharedMemory" in process);
154 assertTrue("privateMemory" in process);
155 } 183 }
156 }); 184 });
157 }, 185 },
158 186
187 function propertiesOfProcessesWithMemory() {
188 listenOnce(chrome.experimental.processes.onUpdatedWithMemory,
189 function(processes) {
190 for (pid in processes) {
191 var process = processes[pid];
192 assertTrue("id" in process);
193 assertTrue("osProcessId" in process);
194 assertTrue("type" in process);
195 assertTrue("profile" in process);
196 assertTrue("privateMemory" in process);
197 }
198 });
199 },
200
201 function terminateProcess() {
202 createTab(5, pageUrl("a"));
203 listenOnce(chrome.experimental.processes.onExited,
204 function(processId, type, code) {
205 assertTrue(processId > 0);
206 });
207 getProcessId(tabs[4].id, function(pid0) {
208 chrome.experimental.processes.terminate(pid0, function(killed) {
209 chrome.test.assertTrue(killed);
210 });
211 });
212 },
213
214 function testOnCreated() {
215 listenOnce(chrome.experimental.processes.onCreated, function(id, process) {
216 assertTrue("id" in process, "process doesn't have id property");
217 assertTrue(id > 0, "id is not positive " + id);
218 });
219 createTab(5, "chrome://newtab/");
220 },
221
222 function testOnExited() {
223 createTab(5, "chrome://newtab/");
224 listenOnce(chrome.experimental.processes.onExited,
225 function(processId, type, code) {
226 assertTrue(type >= 0 && type < 5);
227 });
228 chrome.tabs.create({"url": "http://google.com/"}, pass(function(tab) {
229 chrome.tabs.remove(tab.id);
230 }));
231 },
232
233 function testGetProcessInfoList() {
234 chrome.experimental.processes.getProcessInfo([0, 2], false,
235 pass(function(processes) {
236 assertTrue(Object.keys(processes).length == 2);
237 }));
238 },
239
240 function testGetProcessInfoSingle() {
241 chrome.experimental.processes.getProcessInfo(0, false,
242 pass(function(processes) {
243 assertTrue(Object.keys(processes).length == 1);
244 }));
245 },
246
247 function testGetProcessInfoAll() {
248 chrome.experimental.processes.getProcessInfo([], false,
249 pass(function(processes) {
250 assertTrue(Object.keys(processes).length >= 1);
251 }));
252 },
253
254 function testGetProcessInfo() {
255 chrome.experimental.processes.getProcessInfo([], false,
256 pass(function(processes) {
257 for (pid in processes) {
258 var process = processes[pid];
259 assertTrue("id" in process);
260 assertTrue("osProcessId" in process);
261 assertTrue("type" in process);
262 assertTrue("profile" in process);
263 assertFalse("privateMemory" in process);
264 }
265 }));
266 },
267
268 function testGetProcessInfoWithMemory() {
269 chrome.experimental.processes.getProcessInfo(0, true,
270 pass(function(processes) {
271 for (pid in processes) {
272 var process = processes[pid];
273 assertTrue("privateMemory" in process);
274 }
275 }));
276 },
277
278 function testOnUnresponsive() {
279 listenOnce(chrome.experimental.processes.onUnresponsive,
280 function(process) {
281 assertTrue(process.id == hangingTabProcess);
282 // actually kill the process, just to make sure it won't hang the test
283 chrome.experimental.processes.terminate(process.id, function(killed) {
284 chrome.test.assertTrue(killed);
285 });
286 });
287 chrome.tabs.create({"url": "chrome://hang" }, function(tab) {
288 getProcessId(tab.id, function(pid0) {
289 hangingTabProcess = pid0;
290 });
291 chrome.tabs.update(tab.id, { "url": "chrome://flags" });
292 });
293 }
159 ]); 294 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698