OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 TestRenderViewContextMenu::Create( | 195 TestRenderViewContextMenu::Create( |
196 web_contents, GURL("https://www.example.com"), GURL(), GURL())); | 196 web_contents, GURL("https://www.example.com"), GURL(), GURL())); |
197 | 197 |
198 ExtensionTestMessageListener listener("clicked", false); | 198 ExtensionTestMessageListener listener("clicked", false); |
199 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); | 199 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); |
200 EXPECT_TRUE(menu->IsCommandIdEnabled(command_id)); | 200 EXPECT_TRUE(menu->IsCommandIdEnabled(command_id)); |
201 menu->ExecuteCommand(command_id, 0); | 201 menu->ExecuteCommand(command_id, 0); |
202 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 202 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
203 } | 203 } |
204 | 204 |
| 205 // Tests that unchecked errors don't impede future calls. |
| 206 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, ErrorsInCallbackTest) { |
| 207 host_resolver()->AddRule("*", "127.0.0.1"); |
| 208 embedded_test_server()->ServeFilesFromDirectory(test_data_dir_); |
| 209 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 210 |
| 211 TestExtensionDir test_dir; |
| 212 test_dir.WriteManifest( |
| 213 R"({ |
| 214 "name": "Errors In Callback", |
| 215 "manifest_version": 2, |
| 216 "version": "0.1", |
| 217 "permissions": ["contextMenus"], |
| 218 "background": { |
| 219 "scripts": ["background.js"] |
| 220 } |
| 221 })"); |
| 222 test_dir.WriteFile( |
| 223 FILE_PATH_LITERAL("background.js"), |
| 224 R"(chrome.tabs.query({}, function(tabs) { |
| 225 chrome.tabs.executeScript(tabs[0].id, {code: 'x'}, function() { |
| 226 // There's an error here (we don't have permission to access the |
| 227 // host), but we don't check it so that it gets surfaced as an |
| 228 // unchecked runtime.lastError. |
| 229 // We should still be able to invoke other APIs and get correct |
| 230 // callbacks. |
| 231 chrome.tabs.query({}, function(tabs) { |
| 232 chrome.tabs.query({}, function(tabs) { |
| 233 chrome.test.sendMessage('callback'); |
| 234 }); |
| 235 }); |
| 236 }); |
| 237 });)"); |
| 238 |
| 239 ui_test_utils::NavigateToURL( |
| 240 browser(), embedded_test_server()->GetURL( |
| 241 "example.com", "/native_bindings/simple.html")); |
| 242 |
| 243 ExtensionTestMessageListener listener("callback", false); |
| 244 ASSERT_TRUE(LoadExtension(test_dir.UnpackedPath())); |
| 245 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 246 } |
| 247 |
205 } // namespace extensions | 248 } // namespace extensions |
OLD | NEW |