| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 var getProcessId = chrome.processes.getProcessIdForTab; | 24 var getProcessId = chrome.processes.getProcessIdForTab; |
| 25 | 25 |
| 26 function pageUrl(letter) { | 26 function pageUrl(letter) { |
| 27 return chrome.extension.getURL(letter + ".html"); | 27 return chrome.extension.getURL(letter + ".html"); |
| 28 } | 28 } |
| 29 | 29 |
| 30 function dumpProcess(process) { | 30 function dumpProcess(process) { |
| 31 console.log("id " + process.id); | 31 console.log("id " + process.id); |
| 32 console.log("title " + process.title); | |
| 33 console.log("osProcId " + process.osProcessId); | 32 console.log("osProcId " + process.osProcessId); |
| 34 console.log("type " + process.type); | 33 console.log("type " + process.type); |
| 35 console.log("profile " + process.profile); | 34 console.log("profile " + process.profile); |
| 36 console.log("tabs " + process.tabs); | 35 console.log("tasks " + process.tasks); |
| 36 for (var i = 0; i < process.tasks.length; ++i) { |
| 37 console.log("task["+ i + "].title " + process.tasks[i].title); |
| 38 if ("tabId" in process.tasks[i]) |
| 39 console.log("task["+ i + "].tabId " + process.tasks[i].tabId); |
| 40 } |
| 37 console.log("cpu " + process.cpu); | 41 console.log("cpu " + process.cpu); |
| 38 console.log("privMem " + process.privateMemory); | 42 console.log("privMem " + process.privateMemory); |
| 39 console.log("network " + process.network); | 43 console.log("network " + process.network); |
| 40 console.log("jsMemAlloc " + process.jsMemoryAllocated); | 44 console.log("jsMemAlloc " + process.jsMemoryAllocated); |
| 41 console.log("jsMemUsed " + process.jsMemoryUsed); | 45 console.log("jsMemUsed " + process.jsMemoryUsed); |
| 42 console.log("sqliteMem " + process.sqliteMemory); | 46 console.log("sqliteMem " + process.sqliteMemory); |
| 43 console.log("naclDebugPort " + process.naclDebugPort); | 47 console.log("naclDebugPort " + process.naclDebugPort); |
| 44 if ("imageCache" in process) { | 48 if ("imageCache" in process) { |
| 45 console.log("imageCache.size " + process.imageCache.size); | 49 console.log("imageCache.size " + process.imageCache.size); |
| 46 console.log("imageCache.liveSize " + process.imageCache.liveSize); | 50 console.log("imageCache.liveSize " + process.imageCache.liveSize); |
| 47 } | 51 } |
| 48 if ("scriptCache" in process) { | 52 if ("scriptCache" in process) { |
| 49 console.log("scriptCache.size " + process.scriptCache.size); | 53 console.log("scriptCache.size " + process.scriptCache.size); |
| 50 console.log("scriptCache.liveSize " + process.scriptCache.liveSize); | 54 console.log("scriptCache.liveSize " + process.scriptCache.liveSize); |
| 51 } | 55 } |
| 52 if ("cssCache" in process) { | 56 if ("cssCache" in process) { |
| 53 console.log("cssCache.size " + process.cssCache.size); | 57 console.log("cssCache.size " + process.cssCache.size); |
| 54 console.log("cssCache .liveSize " + process.cssCache.liveSize); | 58 console.log("cssCache .liveSize " + process.cssCache.liveSize); |
| 55 } | 59 } |
| 56 } | 60 } |
| 57 | 61 |
| 58 function validateProcessProperties(process, updating, memory_included) { | 62 function validateProcessProperties(process, updating, memory_included) { |
| 59 // Always present. | 63 // Always present. |
| 60 assertTrue("id" in process); | 64 assertTrue("id" in process); |
| 61 assertTrue("title" in process); | |
| 62 assertTrue("naclDebugPort" in process); | 65 assertTrue("naclDebugPort" in process); |
| 63 assertTrue("osProcessId" in process); | 66 assertTrue("osProcessId" in process); |
| 64 assertTrue("type" in process); | 67 assertTrue("type" in process); |
| 65 assertTrue("profile" in process); | 68 assertTrue("profile" in process); |
| 66 assertTrue("tabs" in process); | 69 assertTrue("tasks" in process); |
| 70 assertTrue("title" in process.tasks[0]); |
| 67 | 71 |
| 68 // Present if onUpdate(WithMemory) listener is registered. | 72 // Present if onUpdate(WithMemory) listener is registered. |
| 69 assertEq(("cpu" in process), updating); | 73 assertEq(("cpu" in process), updating); |
| 70 assertEq(("network" in process), updating); | 74 assertEq(("network" in process), updating); |
| 71 | 75 |
| 72 // Present if memory details are requested. | 76 // Present if memory details are requested. |
| 73 assertEq(("privateMemory" in process), memory_included); | 77 assertEq(("privateMemory" in process), memory_included); |
| 74 | 78 |
| 75 // sqliteMemory is only reported for the browser process | 79 // sqliteMemory is only reported for the browser process |
| 76 if (process.type == "browser") { | 80 if (process.type == "browser") { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 getProcessId(tabs[1].id, pass(function(pid1) { | 143 getProcessId(tabs[1].id, pass(function(pid1) { |
| 140 getProcessId(tabs[2].id, pass(function(pid2) { | 144 getProcessId(tabs[2].id, pass(function(pid2) { |
| 141 // Pages from same extension should share a process | 145 // Pages from same extension should share a process |
| 142 assertEq(pid1, pid2); | 146 assertEq(pid1, pid2); |
| 143 chrome.processes.getProcessInfo(pid1, false, | 147 chrome.processes.getProcessInfo(pid1, false, |
| 144 function(pl1) { | 148 function(pl1) { |
| 145 chrome.processes.getProcessInfo(pid2, false, | 149 chrome.processes.getProcessInfo(pid2, false, |
| 146 function (pl2) { | 150 function (pl2) { |
| 147 var proc1 = pl1[pid1]; | 151 var proc1 = pl1[pid1]; |
| 148 var proc2 = pl2[pid2]; | 152 var proc2 = pl2[pid2]; |
| 149 assertTrue(proc1.tabs.length == proc2.tabs.length); | 153 assertTrue(proc1.tasks.length == proc2.tasks.length); |
| 150 for (var i = 0; i < proc1.tabs.length; ++i) { | 154 for (var i = 0; i < proc1.tasks.length; ++i) { |
| 151 assertEq(proc1.tabs[i], proc2.tabs[i]); | 155 assertEq(proc1.tasks[i], proc2.tasks[i]); |
| 152 } | 156 } |
| 153 }); | 157 }); |
| 154 }); | 158 }); |
| 155 })); | 159 })); |
| 156 })); | 160 })); |
| 157 }, | 161 }, |
| 158 | 162 |
| 159 function newTabPageInOwnProcess() { | 163 function newTabPageInOwnProcess() { |
| 160 getProcessId(tabs[0].id, pass(function(pid0) { | 164 getProcessId(tabs[0].id, pass(function(pid0) { |
| 161 getProcessId(tabs[3].id, pass(function(pid3) { | 165 getProcessId(tabs[3].id, pass(function(pid3) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 }); | 258 }); |
| 255 }, | 259 }, |
| 256 | 260 |
| 257 function terminateProcessNonExisting() { | 261 function terminateProcessNonExisting() { |
| 258 chrome.processes.terminate(31337, fail("Process not found: 31337.")); | 262 chrome.processes.terminate(31337, fail("Process not found: 31337.")); |
| 259 }, | 263 }, |
| 260 | 264 |
| 261 function testOnCreated() { | 265 function testOnCreated() { |
| 262 listenOnce(chrome.processes.onCreated, function(process) { | 266 listenOnce(chrome.processes.onCreated, function(process) { |
| 263 assertTrue("id" in process, "process doesn't have id property"); | 267 assertTrue("id" in process, "process doesn't have id property"); |
| 268 // We don't report the creation of the browser process, hence process.id |
| 269 // is expected to be > 0. |
| 264 assertTrue(process.id > 0, "id is not positive " + process.id); | 270 assertTrue(process.id > 0, "id is not positive " + process.id); |
| 265 }); | 271 }); |
| 266 createTab(5, "chrome://newtab/"); | 272 createTab(5, "chrome://newtab/"); |
| 267 }, | 273 }, |
| 268 | 274 |
| 269 // DISABLED: crbug.com/345411 | 275 // DISABLED: crbug.com/345411 |
| 270 // Hangs consistently. | 276 // Hangs consistently (On Windows). |
| 271 /* | 277 /* |
| 272 function testOnExited() { | 278 function testOnExited() { |
| 273 listenOnce(chrome.processes.onExited, | 279 listenOnce(chrome.processes.onExited, |
| 274 function(processId, type, code) { | 280 function(processId, type, code) { |
| 275 assertTrue(type >= 0 && type < 5); | 281 assertTrue(type >= 0 && type < 5); |
| 276 }); | 282 }); |
| 277 chrome.tabs.create({"url": "http://google.com/"}, pass(function(tab) { | 283 chrome.tabs.create({"url": "http://google.com/"}, pass(function(tab) { |
| 278 chrome.tabs.remove(tab.id); | 284 chrome.tabs.remove(tab.id); |
| 279 })); | 285 })); |
| 280 }, | 286 }, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 }); | 333 }); |
| 328 }); | 334 }); |
| 329 chrome.tabs.create({"url": "chrome://hang" }, function(tab) { | 335 chrome.tabs.create({"url": "chrome://hang" }, function(tab) { |
| 330 getProcessId(tab.id, function(pid0) { | 336 getProcessId(tab.id, function(pid0) { |
| 331 hangingTabProcess = pid0; | 337 hangingTabProcess = pid0; |
| 332 }); | 338 }); |
| 333 chrome.tabs.update(tab.id, { "url": "chrome://flags" }); | 339 chrome.tabs.update(tab.id, { "url": "chrome://flags" }); |
| 334 }); | 340 }); |
| 335 } | 341 } |
| 336 ]); | 342 ]); |
| OLD | NEW |