| 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("fps " + process.fps); | 47 console.log("fps " + process.fps); |
| 44 console.log("naclDebugPort " + process.naclDebugPort); | 48 console.log("naclDebugPort " + process.naclDebugPort); |
| 45 if ("imageCache" in process) { | 49 if ("imageCache" in process) { |
| 46 console.log("imageCache.size " + process.imageCache.size); | 50 console.log("imageCache.size " + process.imageCache.size); |
| 47 console.log("imageCache.liveSize " + process.imageCache.liveSize); | 51 console.log("imageCache.liveSize " + process.imageCache.liveSize); |
| 48 } | 52 } |
| 49 if ("scriptCache" in process) { | 53 if ("scriptCache" in process) { |
| 50 console.log("scriptCache.size " + process.scriptCache.size); | 54 console.log("scriptCache.size " + process.scriptCache.size); |
| 51 console.log("scriptCache.liveSize " + process.scriptCache.liveSize); | 55 console.log("scriptCache.liveSize " + process.scriptCache.liveSize); |
| 52 } | 56 } |
| 53 if ("cssCache" in process) { | 57 if ("cssCache" in process) { |
| 54 console.log("cssCache.size " + process.cssCache.size); | 58 console.log("cssCache.size " + process.cssCache.size); |
| 55 console.log("cssCache .liveSize " + process.cssCache.liveSize); | 59 console.log("cssCache .liveSize " + process.cssCache.liveSize); |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 | 62 |
| 59 function validateProcessProperties(process, updating, memory_included) { | 63 function validateProcessProperties(process, updating, memory_included) { |
| 60 // Always present. | 64 // Always present. |
| 61 assertTrue("id" in process); | 65 assertTrue("id" in process); |
| 62 assertTrue("title" in process); | |
| 63 assertTrue("naclDebugPort" in process); | 66 assertTrue("naclDebugPort" in process); |
| 64 assertTrue("osProcessId" in process); | 67 assertTrue("osProcessId" in process); |
| 65 assertTrue("type" in process); | 68 assertTrue("type" in process); |
| 66 assertTrue("profile" in process); | 69 assertTrue("profile" in process); |
| 67 assertTrue("tabs" in process); | 70 assertTrue("tasks" in process); |
| 71 assertTrue("title" in process.tasks[0]); |
| 68 | 72 |
| 69 // Present if onUpdate(WithMemory) listener is registered. | 73 // Present if onUpdate(WithMemory) listener is registered. |
| 70 assertEq(("cpu" in process), updating); | 74 assertEq(("cpu" in process), updating); |
| 71 assertEq(("network" in process), updating); | 75 assertEq(("network" in process), updating); |
| 72 assertEq(("fps" in process), updating); | |
| 73 | 76 |
| 74 // Present if memory details are requested. | 77 // Present if memory details are requested. |
| 75 assertEq(("privateMemory" in process), memory_included); | 78 assertEq(("privateMemory" in process), memory_included); |
| 76 | 79 |
| 77 // sqliteMemory is only reported for the browser process | 80 // sqliteMemory is only reported for the browser process |
| 78 if (process.type == "browser") { | 81 if (process.type == "browser") { |
| 79 assertEq(("sqliteMemory" in process), updating); | 82 assertEq(("sqliteMemory" in process), updating); |
| 80 } else if (process.type == "renderer") { | 83 } else if (process.type == "renderer") { |
| 81 // The rest are not present in the browser process | 84 // The rest are not present in the browser process |
| 82 assertEq(("jsMemoryAllocated" in process), updating); | 85 assertEq(("jsMemoryAllocated" in process), updating); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 getProcessId(tabs[1].id, pass(function(pid1) { | 144 getProcessId(tabs[1].id, pass(function(pid1) { |
| 142 getProcessId(tabs[2].id, pass(function(pid2) { | 145 getProcessId(tabs[2].id, pass(function(pid2) { |
| 143 // Pages from same extension should share a process | 146 // Pages from same extension should share a process |
| 144 assertEq(pid1, pid2); | 147 assertEq(pid1, pid2); |
| 145 chrome.processes.getProcessInfo(pid1, false, | 148 chrome.processes.getProcessInfo(pid1, false, |
| 146 function(pl1) { | 149 function(pl1) { |
| 147 chrome.processes.getProcessInfo(pid2, false, | 150 chrome.processes.getProcessInfo(pid2, false, |
| 148 function (pl2) { | 151 function (pl2) { |
| 149 var proc1 = pl1[pid1]; | 152 var proc1 = pl1[pid1]; |
| 150 var proc2 = pl2[pid2]; | 153 var proc2 = pl2[pid2]; |
| 151 assertTrue(proc1.tabs.length == proc2.tabs.length); | 154 assertTrue(proc1.tasks.length == proc2.tasks.length); |
| 152 for (var i = 0; i < proc1.tabs.length; ++i) { | 155 for (var i = 0; i < proc1.tasks.length; ++i) { |
| 153 assertEq(proc1.tabs[i], proc2.tabs[i]); | 156 assertEq(proc1.tasks[i], proc2.tasks[i]); |
| 154 } | 157 } |
| 155 }); | 158 }); |
| 156 }); | 159 }); |
| 157 })); | 160 })); |
| 158 })); | 161 })); |
| 159 }, | 162 }, |
| 160 | 163 |
| 161 function newTabPageInOwnProcess() { | 164 function newTabPageInOwnProcess() { |
| 162 getProcessId(tabs[0].id, pass(function(pid0) { | 165 getProcessId(tabs[0].id, pass(function(pid0) { |
| 163 getProcessId(tabs[3].id, pass(function(pid3) { | 166 getProcessId(tabs[3].id, pass(function(pid3) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 }); | 332 }); |
| 330 }); | 333 }); |
| 331 chrome.tabs.create({"url": "chrome://hang" }, function(tab) { | 334 chrome.tabs.create({"url": "chrome://hang" }, function(tab) { |
| 332 getProcessId(tab.id, function(pid0) { | 335 getProcessId(tab.id, function(pid0) { |
| 333 hangingTabProcess = pid0; | 336 hangingTabProcess = pid0; |
| 334 }); | 337 }); |
| 335 chrome.tabs.update(tab.id, { "url": "chrome://flags" }); | 338 chrome.tabs.update(tab.id, { "url": "chrome://flags" }); |
| 336 }); | 339 }); |
| 337 } | 340 } |
| 338 ]); | 341 ]); |
| OLD | NEW |