| OLD | NEW |
| (Empty) |
| 1 // Processes API test for Chrome. | |
| 2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Processes | |
| 3 | |
| 4 var pass = chrome.test.callbackPass; | |
| 5 var fail = chrome.test.callbackFail; | |
| 6 var assertEq = chrome.test.assertEq; | |
| 7 var assertTrue = chrome.test.assertTrue; | |
| 8 | |
| 9 var tabs = []; | |
| 10 | |
| 11 function createTab(index, url) { | |
| 12 chrome.tabs.create({"url": url}, pass(function(tab) { | |
| 13 tabs[index] = tab; | |
| 14 })); | |
| 15 } | |
| 16 | |
| 17 var getProcess = chrome.experimental.processes.getProcessForTab; | |
| 18 | |
| 19 function pageUrl(letter) { | |
| 20 return chrome.extension.getURL(letter + ".html"); | |
| 21 } | |
| 22 | |
| 23 chrome.test.runTests([ | |
| 24 function setupProcessTests() { | |
| 25 // Open 4 tabs for test, then wait and create a 5th | |
| 26 createTab(0, "about:blank"); | |
| 27 createTab(1, pageUrl("a")); | |
| 28 createTab(2, pageUrl("b")); | |
| 29 createTab(3, "chrome://newtab/"); | |
| 30 | |
| 31 // Wait for all loads to complete. | |
| 32 var completedCount = 0; | |
| 33 var onUpdatedCompleted = chrome.test.listenForever( | |
| 34 chrome.tabs.onUpdated, | |
| 35 function(changedTabId, changeInfo, changedTab) { | |
| 36 if (changedTab.status == "complete") { | |
| 37 completedCount++; | |
| 38 | |
| 39 // Once the NTP finishes loading, create another one. This ensures | |
| 40 // both NTPs end up in the same process. | |
| 41 if (changedTabId == tabs[3].id) { | |
| 42 createTab(4, "chrome://newtab/"); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 // Once all tabs are done loading, continue with the next test. | |
| 47 if (completedCount == 4) { | |
| 48 onUpdatedCompleted(); | |
| 49 } | |
| 50 } | |
| 51 ); | |
| 52 | |
| 53 }, | |
| 54 | |
| 55 function extensionPageInOwnProcess() { | |
| 56 getProcess(tabs[0].id, pass(function(process0) { | |
| 57 getProcess(tabs[1].id, pass(function(process1) { | |
| 58 // about:blank and extension page should not share a process | |
| 59 assertTrue(process0.id != process1.id); | |
| 60 })); | |
| 61 })); | |
| 62 }, | |
| 63 | |
| 64 function extensionPagesShareProcess() { | |
| 65 getProcess(tabs[1].id, pass(function(process1) { | |
| 66 getProcess(tabs[2].id, pass(function(process2) { | |
| 67 // Pages from same extension should share a process | |
| 68 assertEq(process1.id, process2.id); | |
| 69 })); | |
| 70 })); | |
| 71 }, | |
| 72 | |
| 73 function newTabPageInOwnProcess() { | |
| 74 getProcess(tabs[0].id, pass(function(process0) { | |
| 75 getProcess(tabs[3].id, pass(function(process3) { | |
| 76 // NTP should not share a process with current tabs | |
| 77 assertTrue(process0.id != process3.id); | |
| 78 })); | |
| 79 })); | |
| 80 }, | |
| 81 | |
| 82 function newTabPagesShareProcess() { | |
| 83 getProcess(tabs[3].id, pass(function(process3) { | |
| 84 getProcess(tabs[4].id, pass(function(process4) { | |
| 85 // Multiple NTPs should share a process | |
| 86 assertEq(process3.id, process4.id); | |
| 87 })); | |
| 88 })); | |
| 89 }, | |
| 90 | |
| 91 ]); | |
| OLD | NEW |