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

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

Issue 3597016: Expands the chrome.experimental.processes extension API.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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 // 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
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 assertEq(5, pids.length);
98
99 // Should be able to look up process object by ID.
100 assertTrue(processes[pids[0]].id == pids[0]);
101 assertTrue(processes[pids[0]].id != processes[pids[1]].id);
102
103 getProcessId(tabs[0].id, pass(function(pidTab0) {
104 // Process ID for tab 0 should be listed in pids.
105 assertTrue(processes[pidTab0] != undefined);
106 assertEq("renderer", processes[pidTab0].type);
107 }));
108 });
109 },
110
111 function typesInUpdateEvent() {
112 listenOnce(chrome.experimental.processes.onUpdated, function(processes) {
113 // Check types: 1 browser, 3 renderers, and 1 extension
114 var browserCount = 0;
115 var rendererCount = 0;
116 var extensionCount = 0;
117 for (pid in processes) {
118 switch (processes[pid].type) {
119 case "browser":
120 browserCount++;
121 break;
122 case "renderer":
123 rendererCount++;
124 break;
125 case "extension":
126 extensionCount++;
127 break;
128 default:
129 fail("Unexpected process type:" + processes[pid].type);
130 }
131 }
132 assertEq(1, browserCount);
133 assertEq(3, rendererCount);
134 assertEq(1, extensionCount);
135 });
136 },
137
138 function propertiesOfProcesses() {
139 listenOnce(chrome.experimental.processes.onUpdated, function(processes) {
140 for (pid in processes) {
141 var process = processes[pid];
142 assertTrue("id" in process);
143 assertTrue("type" in process);
144 assertTrue("cpu" in process);
145 assertTrue("network" in process);
146 assertTrue("sharedMemory" in process);
147 assertTrue("privateMemory" in process);
148 }
149 });
150 },
91 ]); 151 ]);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/processes/api/test.html ('k') | chrome/test/data/extensions/api_test/processes/b.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698