<webview>: Context menu API implementation CL.
[chromium-blink-merge.git] / chrome / browser / renderer_context_menu / render_view_context_menu_test_util.cc
blobe3b4eb8b599d78d53399d7adfbdd065015cc691d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
6 #include "content/public/browser/web_contents.h"
7 #include "ui/base/models/menu_model.h"
9 using ui::MenuModel;
11 TestRenderViewContextMenu::TestRenderViewContextMenu(
12 content::RenderFrameHost* render_frame_host,
13 content::ContextMenuParams params)
14 : RenderViewContextMenu(render_frame_host, params) {}
16 TestRenderViewContextMenu::~TestRenderViewContextMenu() {}
18 // static
19 TestRenderViewContextMenu* TestRenderViewContextMenu::Create(
20 content::WebContents* web_contents,
21 const GURL& page_url,
22 const GURL& link_url,
23 const GURL& frame_url) {
24 content::ContextMenuParams params;
25 params.page_url = page_url;
26 params.link_url = link_url;
27 params.frame_url = frame_url;
28 TestRenderViewContextMenu* menu =
29 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params);
30 menu->Init();
31 return menu;
34 void TestRenderViewContextMenu::PlatformInit() {}
36 void TestRenderViewContextMenu::PlatformCancel() {}
38 bool TestRenderViewContextMenu::GetAcceleratorForCommandId(
39 int command_id,
40 ui::Accelerator* accelerator) {
41 // None of our commands have accelerators, so always return false.
42 return false;
45 bool TestRenderViewContextMenu::IsItemPresent(int command_id) {
46 return menu_model_.GetIndexOfCommandId(command_id) != -1;
49 bool TestRenderViewContextMenu::GetMenuModelAndItemIndex(
50 int command_id,
51 MenuModel** found_model,
52 int* found_index) {
53 std::vector<MenuModel*> models_to_search;
54 models_to_search.push_back(&menu_model_);
56 while (!models_to_search.empty()) {
57 MenuModel* model = models_to_search.back();
58 models_to_search.pop_back();
59 for (int i = 0; i < model->GetItemCount(); i++) {
60 if (model->GetCommandIdAt(i) == command_id) {
61 *found_model = model;
62 *found_index = i;
63 return true;
64 } else if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) {
65 models_to_search.push_back(model->GetSubmenuModelAt(i));
70 return false;