| 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 var assertEq = chrome.test.assertEq; | 5 var assertEq = chrome.test.assertEq; |
| 6 var assertTrue = chrome.test.assertTrue; | 6 var assertTrue = chrome.test.assertTrue; |
| 7 var pass = chrome.test.callbackPass; | 7 var pass = chrome.test.callbackPass; |
| 8 var callbackFail = chrome.test.callbackFail; | 8 var callbackFail = chrome.test.callbackFail; |
| 9 var listenForever = chrome.test.listenForever; | 9 var listenForever = chrome.test.listenForever; |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 tab.id, {code: 'document.title = "success"'}, | 76 tab.id, {code: 'document.title = "success"'}, |
| 77 pass(function() { | 77 pass(function() { |
| 78 chrome.tabs.get(tab.id, pass(function(tab) { | 78 chrome.tabs.get(tab.id, pass(function(tab) { |
| 79 assertEq('success', tab.title); | 79 assertEq('success', tab.title); |
| 80 })); | 80 })); |
| 81 })); | 81 })); |
| 82 })); | 82 })); |
| 83 })); | 83 })); |
| 84 }, | 84 }, |
| 85 | 85 |
| 86 // Make sure we can't inject a script into a policy blocked host. |
| 87 function policyBlocksInjection() { |
| 88 createTestTab('example.com', pass(function(tab) { |
| 89 testTabId = tab.id; |
| 90 chrome.tabs.executeScript( |
| 91 tab.id, {code: 'document.title = "success"'}, |
| 92 callbackFail( |
| 93 'This page cannot be scripted due to ' + |
| 94 'an ExtensionsSettings policy.')); |
| 95 })); |
| 96 }, |
| 97 |
| 86 // Try the host again, except outside of the permissions.request callback. | 98 // Try the host again, except outside of the permissions.request callback. |
| 87 function sameHost() { | 99 function sameHost() { |
| 88 createTestTab('a.com', pass(function(tab) { | 100 createTestTab('a.com', pass(function(tab) { |
| 89 chrome.tabs.executeScript( | 101 chrome.tabs.executeScript( |
| 90 tab.id, {code: 'document.title = "success"'}, | 102 tab.id, {code: 'document.title = "success"'}, |
| 91 pass(function() { | 103 pass(function() { |
| 92 chrome.tabs.get(tab.id, pass(function(tab) { | 104 chrome.tabs.get(tab.id, pass(function(tab) { |
| 93 assertEq('success', tab.title); | 105 assertEq('success', tab.title); |
| 94 })); | 106 })); |
| 95 })); | 107 })); |
| 96 })); | 108 })); |
| 97 }, | 109 }, |
| 98 | 110 |
| 99 // Try injecting the script into a new tab with a new host. | 111 // Try injecting the script into a new tab with a new host. |
| 100 function newHost() { | 112 function newHost() { |
| 101 createTestTab('b.com', pass(function(tab) { | 113 createTestTab('b.com', pass(function(tab) { |
| 102 chrome.tabs.executeScript( | 114 chrome.tabs.executeScript( |
| 103 tab.id, {code: 'document.title = "success"'}, | 115 tab.id, {code: 'document.title = "success"'}, |
| 104 pass(function() { | 116 pass(function() { |
| 105 chrome.tabs.get(tab.id, pass(function(tab) { | 117 chrome.tabs.get(tab.id, pass(function(tab) { |
| 106 assertEq('success', tab.title); | 118 assertEq('success', tab.title); |
| 107 })); | 119 })); |
| 108 })); | 120 })); |
| 109 })); | 121 })); |
| 110 } | 122 } |
| 111 ]); | 123 ]); |
| 112 }); | 124 }); |
| OLD | NEW |