Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 pass = chrome.test.callbackPass; | 5 var pass = chrome.test.callbackPass; |
| 6 var fail = chrome.test.callbackFail; | 6 var fail = chrome.test.callbackFail; |
| 7 var assertEq = chrome.test.assertEq; | 7 var assertEq = chrome.test.assertEq; |
| 8 var assertTrue = chrome.test.assertTrue; | 8 var assertTrue = chrome.test.assertTrue; |
| 9 var relativePath = | 9 var relativePath = |
| 10 '/extensions/api_test/executescript/basic/test_executescript.html'; | 10 '/extensions/api_test/executescript/basic/test_executescript.html'; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 {code: 'document.title = document.styleSheets.length'}, | 81 {code: 'document.title = document.styleSheets.length'}, |
| 82 function() { | 82 function() { |
| 83 chrome.tabs.get(tabId, pass(function(tab) { | 83 chrome.tabs.get(tabId, pass(function(tab) { |
| 84 assertEq('0', tab.title); | 84 assertEq('0', tab.title); |
| 85 })); | 85 })); |
| 86 }); | 86 }); |
| 87 }); | 87 }); |
| 88 }, | 88 }, |
| 89 | 89 |
| 90 function executeJavaScriptCodeShouldFail() { | 90 function executeJavaScriptCodeShouldFail() { |
| 91 chrome.tabs.update(tabId, { url: testFailureUrl }, function() { | 91 var doneListening = |
|
Devlin
2016/01/26 20:40:36
What's the reason for this change?
robwu
2016/01/26 23:57:58
Otherwise the test would fail, because chrome.tabs
Devlin
2016/01/27 18:33:48
Heh. That's the right choice, but I'm sure this i
| |
| 92 chrome.test.listenForever(chrome.tabs.onUpdated, onUpdated); | |
| 93 chrome.tabs.update(tabId, {url: testFailureUrl}); | |
| 94 | |
| 95 function onUpdated(updatedTabId, changeInfo) { | |
| 96 if (updatedTabId !== tabId || changeInfo.url === testFailureUrl) | |
| 97 return; | |
| 92 var script_file = {}; | 98 var script_file = {}; |
| 93 script_file.code = "document.title = 'executeScript';"; | 99 script_file.code = "document.title = 'executeScript';"; |
| 94 // The error message should contain the URL of the site for which it | 100 // The error message should contain the URL of the site for which it |
| 95 // failed because the extension has the tabs permission. | 101 // failed because the extension has the tabs permission. |
| 96 chrome.tabs.executeScript(tabId, script_file, fail( | 102 chrome.tabs.executeScript(tabId, script_file, fail( |
| 97 'Cannot access contents of url "' + testFailureUrl + | 103 'Cannot access contents of url "' + testFailureUrl + |
| 98 '". Extension manifest must request permission to access this ' + | 104 '". Extension manifest must request permission to access this ' + |
| 99 'host.')); | 105 'host.')); |
| 100 }); | 106 doneListening(); |
| 107 } | |
| 101 }, | 108 }, |
| 102 | 109 |
| 103 function executeJavaScriptWithNoneValueShouldFail() { | 110 function executeJavaScriptWithNoneValueShouldFail() { |
| 104 var script_file = {}; | 111 var script_file = {}; |
| 105 chrome.tabs.executeScript(tabId, script_file, fail( | 112 chrome.tabs.executeScript(tabId, script_file, fail( |
| 106 'No source code or file specified.')); | 113 'No source code or file specified.')); |
| 107 }, | 114 }, |
| 108 | 115 |
| 109 function executeJavaScriptWithTwoValuesShouldFail() { | 116 function executeJavaScriptWithTwoValuesShouldFail() { |
| 110 var script_file = {}; | 117 var script_file = {}; |
| 111 script_file.file = 'script1.js'; | 118 script_file.file = 'script1.js'; |
| 112 script_file.code = 'var test = 1;'; | 119 script_file.code = 'var test = 1;'; |
| 113 chrome.tabs.executeScript(tabId, script_file, fail( | 120 chrome.tabs.executeScript(tabId, script_file, fail( |
| 114 'Code and file should not be specified ' + | 121 'Code and file should not be specified ' + |
| 115 'at the same time in the second argument.')); | 122 'at the same time in the second argument.')); |
| 116 } | 123 } |
| 117 ]); | 124 ]); |
| 118 }); | 125 }); |
| 119 | 126 |
| 120 chrome.tabs.create({ url: testUrl }); | 127 chrome.tabs.create({ url: testUrl }); |
| 121 }); | 128 }); |
| 122 | 129 |
| OLD | NEW |