| 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 | 7 |
| 8 var tabId; | 8 var tabId; |
| 9 var debuggee; | 9 var debuggee; |
| 10 var debuggeeExtension; |
| 10 var protocolVersion = "1.0"; | 11 var protocolVersion = "1.0"; |
| 11 | 12 |
| 12 chrome.test.runTests([ | 13 chrome.test.runTests([ |
| 13 | 14 |
| 14 function attachMalformedVersion() { | 15 function attachMalformedVersion() { |
| 15 chrome.tabs.getSelected(null, function(tab) { | 16 chrome.tabs.getSelected(null, function(tab) { |
| 16 chrome.debugger.attach({tabId: tab.id}, "malformed-version", | 17 chrome.debugger.attach({tabId: tab.id}, "malformed-version", |
| 17 fail("Requested protocol version is not supported: malformed-version."
)); | 18 fail("Requested protocol version is not supported: malformed-version."
)); |
| 18 }); | 19 }); |
| 19 }, | 20 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 33 }, | 34 }, |
| 34 | 35 |
| 35 function attach() { | 36 function attach() { |
| 36 chrome.tabs.getSelected(null, function(tab) { | 37 chrome.tabs.getSelected(null, function(tab) { |
| 37 tabId = tab.id; | 38 tabId = tab.id; |
| 38 debuggee = {tabId: tab.id}; | 39 debuggee = {tabId: tab.id}; |
| 39 chrome.debugger.attach(debuggee, protocolVersion, pass()); | 40 chrome.debugger.attach(debuggee, protocolVersion, pass()); |
| 40 }); | 41 }); |
| 41 }, | 42 }, |
| 42 | 43 |
| 44 function attachToMissingTab() { |
| 45 var missingDebuggee = {tabId: -1}; |
| 46 chrome.debugger.attach(missingDebuggee, protocolVersion, |
| 47 fail("No tab with given id " + missingDebuggee.tabId + ".")); |
| 48 }, |
| 49 |
| 43 function attachAgain() { | 50 function attachAgain() { |
| 44 chrome.debugger.attach(debuggee, protocolVersion, | 51 chrome.debugger.attach(debuggee, protocolVersion, |
| 45 fail("Another debugger is already attached to the tab with id: " + | 52 fail("Another debugger is already attached to the tab with id: " + |
| 46 tabId + ".")); | 53 tabId + ".")); |
| 47 }, | 54 }, |
| 48 | 55 |
| 49 function sendCommand() { | 56 function sendCommand() { |
| 50 function onResponse() { | 57 function onResponse() { |
| 51 if (chrome.runtime.lastError && | 58 if (chrome.runtime.lastError && |
| 52 chrome.runtime.lastError.message.indexOf("invalidMethod") != -1) | 59 chrome.runtime.lastError.message.indexOf("invalidMethod") != -1) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 }); | 98 }); |
| 92 }, | 99 }, |
| 93 | 100 |
| 94 function attachToWebUI() { | 101 function attachToWebUI() { |
| 95 chrome.tabs.create({url:"chrome://version"}, function(tab) { | 102 chrome.tabs.create({url:"chrome://version"}, function(tab) { |
| 96 var debuggee = {tabId: tab.id}; | 103 var debuggee = {tabId: tab.id}; |
| 97 chrome.debugger.attach(debuggee, protocolVersion, | 104 chrome.debugger.attach(debuggee, protocolVersion, |
| 98 fail("Can not attach to the page with the \"chrome://\" scheme.")); | 105 fail("Can not attach to the page with the \"chrome://\" scheme.")); |
| 99 chrome.tabs.remove(tab.id); | 106 chrome.tabs.remove(tab.id); |
| 100 }); | 107 }); |
| 101 } | 108 }, |
| 102 | 109 |
| 110 function attachToExtension() { |
| 111 var extensionId = chrome.extension.getURL('').split('/')[2]; |
| 112 debuggeeExtension = {extensionId: extensionId}; |
| 113 chrome.debugger.attach(debuggeeExtension, protocolVersion, pass()); |
| 114 }, |
| 115 |
| 116 function attachToMissingExtension() { |
| 117 var missingDebuggee = {extensionId: "foo"}; |
| 118 chrome.debugger.attach(missingDebuggee, protocolVersion, |
| 119 fail("No extension with given id " + |
| 120 missingDebuggee.extensionId + ".")); |
| 121 }, |
| 122 |
| 123 function attachToInvalidTarget() { |
| 124 var emptyDebuggee = {}; |
| 125 chrome.debugger.attach(emptyDebuggee, protocolVersion, |
| 126 fail("Either tab id or extension id must be specified.")); |
| 127 }, |
| 128 |
| 129 function attachAgainToExtension() { |
| 130 chrome.debugger.attach(debuggeeExtension, protocolVersion, |
| 131 fail("Another debugger is already attached to the extension with id: " + |
| 132 debuggeeExtension.extensionId + ".")); |
| 133 }, |
| 134 |
| 135 function detachFromExtension() { |
| 136 chrome.debugger.detach(debuggeeExtension, pass()); |
| 137 }, |
| 138 |
| 139 function detachAgainFromExtension() { |
| 140 chrome.debugger.detach(debuggeeExtension, |
| 141 fail("Debugger is not attached to the extension with id: " + |
| 142 debuggeeExtension.extensionId + ".")); |
| 143 }, |
| 103 ]); | 144 ]); |
| OLD | NEW |