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

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

Issue 2805123002: [Extensions Bindings] Allow schema violations through sendRequest (Closed)
Patch Set: Rebase 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
« no previous file with comments | « no previous file | extensions/renderer/api_binding_js_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
6
5 #include "base/command_line.h" 7 #include "base/command_line.h"
6 #include "base/run_loop.h" 8 #include "base/run_loop.h"
7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
8 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
9 #include "chrome/browser/extensions/extension_action.h" 11 #include "chrome/browser/extensions/extension_action.h"
10 #include "chrome/browser/extensions/extension_action_manager.h" 12 #include "chrome/browser/extensions/extension_action_manager.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 13 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/extensions/lazy_background_page_test_util.h" 14 #include "chrome/browser/extensions/lazy_background_page_test_util.h"
15 #include "chrome/browser/extensions/test_extension_dir.h"
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
13 #include "chrome/browser/sessions/session_tab_helper.h" 17 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
17 #include "extensions/browser/event_router.h" 21 #include "extensions/browser/event_router.h"
18 #include "extensions/browser/process_manager.h" 22 #include "extensions/browser/process_manager.h"
19 #include "extensions/common/switches.h" 23 #include "extensions/common/switches.h"
20 #include "extensions/test/extension_test_message_listener.h" 24 #include "extensions/test/extension_test_message_listener.h"
21 #include "extensions/test/result_catcher.h" 25 #include "extensions/test/result_catcher.h"
22 #include "net/dns/mock_host_resolver.h" 26 #include "net/dns/mock_host_resolver.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 "example.com", "/native_bindings/simple.html")); 142 "example.com", "/native_bindings/simple.html"));
139 143
140 GURL expected_url = embedded_test_server()->GetURL( 144 GURL expected_url = embedded_test_server()->GetURL(
141 "example.com", "/native_bindings/simple2.html"); 145 "example.com", "/native_bindings/simple2.html");
142 EXPECT_EQ(expected_url, browser() 146 EXPECT_EQ(expected_url, browser()
143 ->tab_strip_model() 147 ->tab_strip_model()
144 ->GetActiveWebContents() 148 ->GetActiveWebContents()
145 ->GetLastCommittedURL()); 149 ->GetLastCommittedURL());
146 } 150 }
147 151
152 // Tests the context menu API, which includes calling sendRequest with an
153 // different signature than specified and using functions as properties on an
154 // object.
155 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, ContextMenusTest) {
156 TestExtensionDir test_dir;
157 test_dir.WriteManifest(
158 R"({
159 "name": "Context menus",
160 "manifest_version": 2,
161 "version": "0.1",
162 "permissions": ["contextMenus"],
163 "background": {
164 "scripts": ["background.js"]
165 }
166 })");
167 test_dir.WriteFile(
168 FILE_PATH_LITERAL("background.js"),
169 R"(chrome.contextMenus.create(
170 {
171 title: 'Context Menu Item',
172 onclick: () => { chrome.test.sendMessage('clicked'); },
173 }, () => { chrome.test.sendMessage('registered'); });)");
174
175 const Extension* extension = nullptr;
176 {
177 ExtensionTestMessageListener listener("registered", false);
178 extension = LoadExtension(test_dir.UnpackedPath());
179 ASSERT_TRUE(extension);
180 EXPECT_TRUE(listener.WaitUntilSatisfied());
181 }
182
183 content::WebContents* web_contents =
184 browser()->tab_strip_model()->GetActiveWebContents();
185 std::unique_ptr<TestRenderViewContextMenu> menu(
186 TestRenderViewContextMenu::Create(
187 web_contents, GURL("https://www.example.com"), GURL(), GURL()));
188
189 ExtensionTestMessageListener listener("clicked", false);
190 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
191 EXPECT_TRUE(menu->IsCommandIdEnabled(command_id));
192 menu->ExecuteCommand(command_id, 0);
193 EXPECT_TRUE(listener.WaitUntilSatisfied());
194 }
195
148 } // namespace extensions 196 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_binding_js_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698