| OLD | NEW |
| (Empty) | |
| 1 <script> |
| 2 var pass = chrome.test.callbackPass; |
| 3 var assertEq = chrome.test.assertEq; |
| 4 var assertTrue = chrome.test.assertTrue; |
| 5 |
| 6 var win, tab; |
| 7 var inIncognitoContext = chrome.extension.inIncognitoContext; |
| 8 |
| 9 // Listen to some events to make sure we don't get events from the other |
| 10 // profile. |
| 11 |
| 12 chrome.tabs.onUpdated.addListener(function(id, info, tab) { |
| 13 if (inIncognitoContext != tab.incognito) { |
| 14 chrome.test.notifyFail( |
| 15 "[FAIL] Split-mode incognito test received an event for " + |
| 16 (tab.incognito ? "an incognito" : "a normal") + |
| 17 " tab in the wrong profile."); |
| 18 } |
| 19 }); |
| 20 |
| 21 chrome.extension.onRequest.addListener( |
| 22 function(request, sender, sendResponse) { |
| 23 if (inIncognitoContext != sender.tab.incognito) { |
| 24 chrome.test.notifyFail( |
| 25 "[FAIL] Split-mode incognito test received a message from " + |
| 26 (sender.tab.incognito ? "an incognito" : "a normal") + |
| 27 " tab in the wrong profile."); |
| 28 } |
| 29 }); |
| 30 |
| 31 chrome.test.runTests([ |
| 32 function setupWindows() { |
| 33 // The test harness should have set us up with 2 windows: 1 incognito |
| 34 // and 1 regular. Since we are in split mode, we should only see the |
| 35 // window for our profile. |
| 36 chrome.windows.getAll({populate: true}, pass(function(windows) { |
| 37 assertEq(1, windows.length); |
| 38 |
| 39 win = windows[0]; |
| 40 tab = win.tabs[0]; |
| 41 assertEq(inIncognitoContext, win.incognito); |
| 42 })); |
| 43 }, |
| 44 |
| 45 // Tests that we can update an incognito tab and get the event for it. |
| 46 function tabUpdate() { |
| 47 var newUrl = "about:blank"; |
| 48 |
| 49 // Prepare the event listeners first. |
| 50 var done = chrome.test.listenForever(chrome.tabs.onUpdated, |
| 51 function(id, info, tab) { |
| 52 assertEq(tab.id, id); |
| 53 assertEq(inIncognitoContext, tab.incognito); |
| 54 assertEq(newUrl, tab.url); |
| 55 if (info.status == "complete") |
| 56 done(); |
| 57 }); |
| 58 |
| 59 // Update our tab. |
| 60 chrome.tabs.update(tab.id, {"url": newUrl}, pass()); |
| 61 }, |
| 62 |
| 63 // Tests content script injection to verify that the script can tell its |
| 64 // in incongnito. |
| 65 function contentScriptTestIncognito() { |
| 66 var testUrl = "http://localhost:1337/files/extensions/test_file.html"; |
| 67 |
| 68 // Test that chrome.extension.inIncognitoContext is true for incognito |
| 69 // tabs. |
| 70 chrome.tabs.create({windowId: win.id, url: testUrl}, |
| 71 pass(function(tab) { |
| 72 chrome.tabs.executeScript(tab.id, |
| 73 {code: 'chrome.extension.sendRequest({' + |
| 74 ' inIncognitoContext: chrome.extension.inIncognitoContext' + |
| 75 '});'}, |
| 76 pass(function() { |
| 77 assertEq(undefined, chrome.extension.lastError); |
| 78 })); |
| 79 })); |
| 80 |
| 81 var done = chrome.test.listenForever(chrome.extension.onRequest, |
| 82 function(request, sender, sendResponse) { |
| 83 assertEq(inIncognitoContext, request.inIncognitoContext); |
| 84 sendResponse(); |
| 85 done(); |
| 86 }); |
| 87 } |
| 88 ]); |
| 89 </script> |
| OLD | NEW |