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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/renderer/api_binding_js_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/native_bindings_apitest.cc
diff --git a/chrome/browser/extensions/native_bindings_apitest.cc b/chrome/browser/extensions/native_bindings_apitest.cc
index 51a44aa9a82d176310522fd79cffb81e80065ce2..08869d46922bf48d67312773bd0b5fc0be148905 100644
--- a/chrome/browser/extensions/native_bindings_apitest.cc
+++ b/chrome/browser/extensions/native_bindings_apitest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <memory>
+
#include "base/command_line.h"
#include "base/run_loop.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
@@ -10,6 +12,8 @@
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/lazy_background_page_test_util.h"
+#include "chrome/browser/extensions/test_extension_dir.h"
+#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
@@ -145,4 +149,48 @@ IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, WebRequest) {
->GetLastCommittedURL());
}
+// Tests the context menu API, which includes calling sendRequest with an
+// different signature than specified and using functions as properties on an
+// object.
+IN_PROC_BROWSER_TEST_F(NativeBindingsApiTest, ContextMenusTest) {
+ TestExtensionDir test_dir;
+ test_dir.WriteManifest(
+ R"({
+ "name": "Context menus",
+ "manifest_version": 2,
+ "version": "0.1",
+ "permissions": ["contextMenus"],
+ "background": {
+ "scripts": ["background.js"]
+ }
+ })");
+ test_dir.WriteFile(
+ FILE_PATH_LITERAL("background.js"),
+ R"(chrome.contextMenus.create(
+ {
+ title: 'Context Menu Item',
+ onclick: () => { chrome.test.sendMessage('clicked'); },
+ }, () => { chrome.test.sendMessage('registered'); });)");
+
+ const Extension* extension = nullptr;
+ {
+ ExtensionTestMessageListener listener("registered", false);
+ extension = LoadExtension(test_dir.UnpackedPath());
+ ASSERT_TRUE(extension);
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+ }
+
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ std::unique_ptr<TestRenderViewContextMenu> menu(
+ TestRenderViewContextMenu::Create(
+ web_contents, GURL("https://www.example.com"), GURL(), GURL()));
+
+ ExtensionTestMessageListener listener("clicked", false);
+ int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0);
+ EXPECT_TRUE(menu->IsCommandIdEnabled(command_id));
+ menu->ExecuteCommand(command_id, 0);
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+}
+
} // namespace extensions
« 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