Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1095)

Side by Side Diff: chrome/browser/extensions/native_bindings_apitest.cc

Issue 2819683002: [Extenisons Bindings] Don't throw unchecked errors; add console errors (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 TestRenderViewContextMenu::Create( 186 TestRenderViewContextMenu::Create(
187 web_contents, GURL("https://www.example.com"), GURL(), GURL())); 187 web_contents, GURL("https://www.example.com"), GURL(), GURL()));
188 188
189 ExtensionTestMessageListener listener("clicked", false); 189 ExtensionTestMessageListener listener("clicked", false);
190 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); 190 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
191 EXPECT_TRUE(menu->IsCommandIdEnabled(command_id)); 191 EXPECT_TRUE(menu->IsCommandIdEnabled(command_id));
192 menu->ExecuteCommand(command_id, 0); 192 menu->ExecuteCommand(command_id, 0);
193 EXPECT_TRUE(listener.WaitUntilSatisfied()); 193 EXPECT_TRUE(listener.WaitUntilSatisfied());
194 } 194 }
195 195
196 // Tests that unchecked errors don't impede future calls.
197 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, ErrorsInCallbackTest) {
198 host_resolver()->AddRule("*", "127.0.0.1");
199 embedded_test_server()->ServeFilesFromDirectory(test_data_dir_);
200 ASSERT_TRUE(StartEmbeddedTestServer());
201
202 TestExtensionDir test_dir;
203 test_dir.WriteManifest(
204 R"({
205 "name": "Errors In Callback",
206 "manifest_version": 2,
207 "version": "0.1",
208 "permissions": ["contextMenus"],
209 "background": {
210 "scripts": ["background.js"]
211 }
212 })");
213 test_dir.WriteFile(
214 FILE_PATH_LITERAL("background.js"),
215 R"(chrome.tabs.query({}, function(tabs) {
216 chrome.tabs.executeScript(tabs[0].id, {code: 'x'}, function() {
217 // There's an error here (we don't have permission to access the
218 // host), but we don't check it so that it gets surfaced as an
219 // unchecked runtime.lastError.
220 // We should still be able to invoke other APIs and get correct
221 // callbacks.
222 chrome.tabs.query({}, function(tabs) {
223 chrome.tabs.query({}, function(tabs) {
Devlin 2017/04/14 00:43:17 Interestingly, this level of nesting is necessary
224 chrome.test.sendMessage('callback');
225 });
226 });
227 });
228 });)");
229
230 ui_test_utils::NavigateToURL(
231 browser(), embedded_test_server()->GetURL(
232 "example.com", "/native_bindings/simple.html"));
233
234 const Extension* extension = nullptr;
jbroman 2017/04/19 17:45:04 nit: Since there's nothing below the below block,
Devlin 2017/04/19 19:45:33 Whoops, copy-paste leftovers. Cleaned.
235 {
236 ExtensionTestMessageListener listener("callback", false);
237 extension = LoadExtension(test_dir.UnpackedPath());
238 ASSERT_TRUE(extension);
239 EXPECT_TRUE(listener.WaitUntilSatisfied());
240 }
241 }
242
196 } // namespace extensions 243 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_binding_unittest.cc » ('j') | extensions/renderer/api_last_error.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698