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"
11 TestRenderViewContextMenu::TestRenderViewContextMenu(
12 content::RenderFrameHost* render_frame_host,
13 content::ContextMenuParams params)
14 : RenderViewContextMenu(render_frame_host, params) {}
16 TestRenderViewContextMenu::~TestRenderViewContextMenu() {}
19 TestRenderViewContextMenu* TestRenderViewContextMenu::Create(
20 content::WebContents* web_contents,
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);
34 bool TestRenderViewContextMenu::GetAcceleratorForCommandId(
36 ui::Accelerator* accelerator) {
37 // None of our commands have accelerators, so always return false.
41 bool TestRenderViewContextMenu::IsItemPresent(int command_id) {
42 return menu_model_.GetIndexOfCommandId(command_id) != -1;
45 bool TestRenderViewContextMenu::GetMenuModelAndItemIndex(
47 MenuModel** found_model,
49 std::vector<MenuModel*> models_to_search;
50 models_to_search.push_back(&menu_model_);
52 while (!models_to_search.empty()) {
53 MenuModel* model = models_to_search.back();
54 models_to_search.pop_back();
55 for (int i = 0; i < model->GetItemCount(); i++) {
56 if (model->GetCommandIdAt(i) == command_id) {
60 } else if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) {
61 models_to_search.push_back(model->GetSubmenuModelAt(i));