| Index: chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| diff --git a/chrome/browser/extensions/extension_context_menu_browsertest.cc b/chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| index 9c6d98c195dc71e5e21d340d7692127aef3a5b38..f9ce770df6f39ca10d1950996888bca8f63e336f 100644
|
| --- a/chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| +++ b/chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include <stddef.h>
|
|
|
| +#include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "build/build_config.h"
|
| #include "chrome/browser/extensions/extension_browsertest.h"
|
| @@ -14,7 +15,10 @@
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| #include "content/public/common/context_menu_params.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "extensions/browser/extension_api_frame_id_map.h"
|
| #include "extensions/browser/extension_registry.h"
|
| #include "extensions/browser/process_manager.h"
|
| #include "extensions/browser/test_management_policy.h"
|
| @@ -108,6 +112,34 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
|
| return MenuHasExtensionItemWithLabel(menu.get(), label);
|
| }
|
|
|
| + // Click on a context menu identified by |target_menu_item_id|, and returns
|
| + // the result of chrome.test.sendMessage. The .js test file that sets up the
|
| + // context menu should call chrome.test.sendMessage in its onclick event.
|
| + std::string ClickMenuInFrame(content::RenderFrameHost* frame,
|
| + const std::string& target_menu_item_id) {
|
| + content::ContextMenuParams params;
|
| + if (frame->GetParent())
|
| + params.frame_url = frame->GetLastCommittedURL();
|
| + else
|
| + params.page_url = frame->GetLastCommittedURL();
|
| +
|
| + TestRenderViewContextMenu menu(frame, params);
|
| + menu.Init();
|
| +
|
| + MenuItem::Id menu_item_id;
|
| + menu_item_id.string_uid = target_menu_item_id;
|
| + int command_id = -1;
|
| + if (!FindCommandId(&menu, menu_item_id, &command_id))
|
| + return "Menu item not found: " + target_menu_item_id;
|
| +
|
| + ExtensionTestMessageListener listener(false);
|
| + menu.ExecuteCommand(command_id, 0);
|
| + if (!listener.WaitUntilSatisfied())
|
| + return "Onclick never fired for menu item: " + target_menu_item_id;
|
| +
|
| + return listener.message();
|
| + }
|
| +
|
| // This creates an extension that starts |enabled| and then switches to
|
| // |!enabled|.
|
| void TestEnabledContextMenu(bool enabled) {
|
| @@ -595,6 +627,31 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Frames) {
|
| page_url, GURL(), frame_url, std::string("Frame item")));
|
| }
|
|
|
| +// Tests that info.frameId is correctly set when the context menu is invoked.
|
| +IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, ClickInFrame) {
|
| + ExtensionTestMessageListener listener("created items", false);
|
| + ASSERT_TRUE(LoadContextMenuExtension("frames"));
|
| + GURL url_with_frame("data:text/html,<iframe name='child'>");
|
| + ui_test_utils::NavigateToURL(browser(), url_with_frame);
|
| + ASSERT_TRUE(listener.WaitUntilSatisfied());
|
| +
|
| + // Click on a menu item in the main frame.
|
| + EXPECT_EQ(
|
| + "pageUrl=" + url_with_frame.spec() + ", frameUrl=undefined, frameId=0",
|
| + ClickMenuInFrame(GetWebContents()->GetMainFrame(), "item1"));
|
| +
|
| + // Click on a menu item in the child frame.
|
| + content::RenderFrameHost* child_frame = content::FrameMatchingPredicate(
|
| + GetWebContents(), base::Bind(&content::FrameMatchesName, "child"));
|
| + ASSERT_TRUE(child_frame);
|
| + int extension_api_frame_id =
|
| + extensions::ExtensionApiFrameIdMap::GetFrameId(child_frame);
|
| + EXPECT_EQ(
|
| + base::StringPrintf("pageUrl=undefined, frameUrl=about:blank, frameId=%d",
|
| + extension_api_frame_id),
|
| + ClickMenuInFrame(child_frame, "item1"));
|
| +}
|
| +
|
| // Tests enabling and disabling a context menu item.
|
| IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) {
|
| TestEnabledContextMenu(true);
|
|
|