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

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

Issue 2805123002: [Extensions Bindings] Allow schema violations through sendRequest (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>
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 "net/dns/mock_host_resolver.h" 25 #include "net/dns/mock_host_resolver.h"
22 26
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, FileSystemApiGetDisplayPath) { 116 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, FileSystemApiGetDisplayPath) {
113 base::FilePath test_dir = test_data_dir_.AppendASCII("native_bindings"); 117 base::FilePath test_dir = test_data_dir_.AppendASCII("native_bindings");
114 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( 118 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
115 "test_root", test_dir); 119 "test_root", test_dir);
116 base::FilePath test_file = test_dir.AppendASCII("text.txt"); 120 base::FilePath test_file = test_dir.AppendASCII("text.txt");
117 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 121 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
118 &test_file); 122 &test_file);
119 ASSERT_TRUE(RunPlatformAppTest("native_bindings/instance_of")) << message_; 123 ASSERT_TRUE(RunPlatformAppTest("native_bindings/instance_of")) << message_;
120 } 124 }
121 125
126 // Tests the context menu API, which includes calling sendRequest with an
127 // different signature than specified and using functions as properties on an
128 // object.
129 IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, ContextMenusTest) {
130 TestExtensionDir test_dir;
131 test_dir.WriteManifest(
132 R"({
133 "name": "Context menus",
134 "manifest_version": 2,
135 "version": "0.1",
136 "permissions": ["contextMenus"],
137 "background": {
138 "scripts": ["background.js"]
139 }
140 })");
141 test_dir.WriteFile(
142 FILE_PATH_LITERAL("background.js"),
143 R"(chrome.contextMenus.create(
144 {
145 title: 'Context Menu Item',
146 onclick: () => { chrome.test.sendMessage('clicked'); },
147 }, () => { chrome.test.sendMessage('registered'); });)");
148
149 const Extension* extension = nullptr;
150 {
151 ExtensionTestMessageListener listener("registered", false);
152 extension = LoadExtension(test_dir.UnpackedPath());
153 ASSERT_TRUE(extension);
154 EXPECT_TRUE(listener.WaitUntilSatisfied());
155 }
156
157 content::WebContents* web_contents =
158 browser()->tab_strip_model()->GetActiveWebContents();
159 std::unique_ptr<TestRenderViewContextMenu> menu(
160 TestRenderViewContextMenu::Create(
161 web_contents, GURL("https://www.example.com"), GURL(), GURL()));
162
163 ExtensionTestMessageListener listener("clicked", false);
164 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
165 EXPECT_TRUE(menu->IsCommandIdEnabled(command_id));
166 menu->ExecuteCommand(command_id, 0);
167 EXPECT_TRUE(listener.WaitUntilSatisfied());
168 }
169
122 } // namespace extensions 170 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_binding_js_util.cc » ('j') | extensions/renderer/resources/context_menus_handlers.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698