OLD | NEW |
1 // Processes API test for Chrome. | 1 // Processes API test for Chrome. |
2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Processes | 2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Processes |
3 | 3 |
4 var pass = chrome.test.callbackPass; | 4 var pass = chrome.test.callbackPass; |
5 var fail = chrome.test.callbackFail; | 5 var fail = chrome.test.callbackFail; |
6 var assertEq = chrome.test.assertEq; | 6 var assertEq = chrome.test.assertEq; |
7 var assertTrue = chrome.test.assertTrue; | 7 var assertTrue = chrome.test.assertTrue; |
| 8 var listenOnce = chrome.test.listenOnce; |
8 | 9 |
9 var tabs = []; | 10 var tabs = []; |
10 | 11 |
11 function createTab(index, url) { | 12 function createTab(index, url) { |
12 chrome.tabs.create({"url": url}, pass(function(tab) { | 13 chrome.tabs.create({"url": url}, pass(function(tab) { |
13 tabs[index] = tab; | 14 tabs[index] = tab; |
14 })); | 15 })); |
15 } | 16 } |
16 | 17 |
17 var getProcess = chrome.experimental.processes.getProcessForTab; | 18 var getProcessId = chrome.experimental.processes.getProcessIdForTab; |
18 | 19 |
19 function pageUrl(letter) { | 20 function pageUrl(letter) { |
20 return chrome.extension.getURL(letter + ".html"); | 21 return chrome.extension.getURL(letter + ".html"); |
21 } | 22 } |
22 | 23 |
23 chrome.test.runTests([ | 24 chrome.test.runTests([ |
24 function setupProcessTests() { | 25 function setupProcessTests() { |
25 // Open 4 tabs for test, then wait and create a 5th | 26 // Open 4 tabs for test, then wait and create a 5th |
26 createTab(0, "about:blank"); | 27 createTab(0, "about:blank"); |
27 createTab(1, pageUrl("a")); | 28 createTab(1, pageUrl("a")); |
(...skipping 18 matching lines...) Expand all Loading... |
46 // Once all tabs are done loading, continue with the next test. | 47 // Once all tabs are done loading, continue with the next test. |
47 if (completedCount == 4) { | 48 if (completedCount == 4) { |
48 onUpdatedCompleted(); | 49 onUpdatedCompleted(); |
49 } | 50 } |
50 } | 51 } |
51 ); | 52 ); |
52 | 53 |
53 }, | 54 }, |
54 | 55 |
55 function extensionPageInOwnProcess() { | 56 function extensionPageInOwnProcess() { |
56 getProcess(tabs[0].id, pass(function(process0) { | 57 getProcessId(tabs[0].id, pass(function(pid0) { |
57 getProcess(tabs[1].id, pass(function(process1) { | 58 getProcessId(tabs[1].id, pass(function(pid1) { |
58 // about:blank and extension page should not share a process | 59 // about:blank and extension page should not share a process |
59 assertTrue(process0.id != process1.id); | 60 assertTrue(pid0 != pid1); |
60 })); | 61 })); |
61 })); | 62 })); |
62 }, | 63 }, |
63 | 64 |
64 function extensionPagesShareProcess() { | 65 function extensionPagesShareProcess() { |
65 getProcess(tabs[1].id, pass(function(process1) { | 66 getProcessId(tabs[1].id, pass(function(pid1) { |
66 getProcess(tabs[2].id, pass(function(process2) { | 67 getProcessId(tabs[2].id, pass(function(pid2) { |
67 // Pages from same extension should share a process | 68 // Pages from same extension should share a process |
68 assertEq(process1.id, process2.id); | 69 assertEq(pid1, pid2); |
69 })); | 70 })); |
70 })); | 71 })); |
71 }, | 72 }, |
72 | 73 |
73 function newTabPageInOwnProcess() { | 74 function newTabPageInOwnProcess() { |
74 getProcess(tabs[0].id, pass(function(process0) { | 75 getProcessId(tabs[0].id, pass(function(pid0) { |
75 getProcess(tabs[3].id, pass(function(process3) { | 76 getProcessId(tabs[3].id, pass(function(pid3) { |
76 // NTP should not share a process with current tabs | 77 // NTP should not share a process with current tabs |
77 assertTrue(process0.id != process3.id); | 78 assertTrue(pid0 != pid3); |
78 })); | 79 })); |
79 })); | 80 })); |
80 }, | 81 }, |
81 | 82 |
82 function newTabPagesShareProcess() { | 83 function newTabPagesShareProcess() { |
83 getProcess(tabs[3].id, pass(function(process3) { | 84 getProcessId(tabs[3].id, pass(function(pid3) { |
84 getProcess(tabs[4].id, pass(function(process4) { | 85 getProcessId(tabs[4].id, pass(function(pid4) { |
85 // Multiple NTPs should share a process | 86 // Multiple NTPs should share a process |
86 assertEq(process3.id, process4.id); | 87 assertEq(pid3, pid4); |
87 })); | 88 })); |
88 })); | 89 })); |
89 }, | 90 }, |
90 | 91 |
| 92 function idsInUpdateEvent() { |
| 93 listenOnce(chrome.experimental.processes.onUpdated, function(processes) { |
| 94 // onUpdated should return a valid dictionary of processes, |
| 95 // indexed by process ID. |
| 96 var pids = Object.keys(processes); |
| 97 // There should be at least 5 processes: 1 browser, 1 extension, and 3 |
| 98 // renderers (for the 5 tabs). |
| 99 assertTrue(pids.length >= 5); |
| 100 |
| 101 // Should be able to look up process object by ID. |
| 102 assertTrue(processes[pids[0]].id == pids[0]); |
| 103 assertTrue(processes[pids[0]].id != processes[pids[1]].id); |
| 104 |
| 105 getProcessId(tabs[0].id, pass(function(pidTab0) { |
| 106 // Process ID for tab 0 should be listed in pids. |
| 107 assertTrue(processes[pidTab0] != undefined); |
| 108 assertEq("renderer", processes[pidTab0].type); |
| 109 })); |
| 110 }); |
| 111 }, |
| 112 |
| 113 function typesInUpdateEvent() { |
| 114 listenOnce(chrome.experimental.processes.onUpdated, function(processes) { |
| 115 // Check types: 1 browser, 3 renderers, and 1 extension |
| 116 var browserCount = 0; |
| 117 var rendererCount = 0; |
| 118 var extensionCount = 0; |
| 119 var otherCount = 0; |
| 120 for (pid in processes) { |
| 121 switch (processes[pid].type) { |
| 122 case "browser": |
| 123 browserCount++; |
| 124 break; |
| 125 case "renderer": |
| 126 rendererCount++; |
| 127 break; |
| 128 case "extension": |
| 129 extensionCount++; |
| 130 break; |
| 131 default: |
| 132 otherCount++; |
| 133 } |
| 134 } |
| 135 assertEq(1, browserCount); |
| 136 assertTrue(rendererCount >= 3); |
| 137 assertTrue(extensionCount >= 1); |
| 138 }); |
| 139 }, |
| 140 |
| 141 function propertiesOfProcesses() { |
| 142 listenOnce(chrome.experimental.processes.onUpdated, function(processes) { |
| 143 for (pid in processes) { |
| 144 var process = processes[pid]; |
| 145 assertTrue("id" in process); |
| 146 assertTrue("type" in process); |
| 147 assertTrue("cpu" in process); |
| 148 assertTrue("network" in process); |
| 149 assertTrue("sharedMemory" in process); |
| 150 assertTrue("privateMemory" in process); |
| 151 } |
| 152 }); |
| 153 }, |
| 154 |
91 ]); | 155 ]); |
OLD | NEW |