• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
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"
8 
9 using ui::MenuModel;
10 
TestRenderViewContextMenu(content::RenderFrameHost * render_frame_host,content::ContextMenuParams params)11 TestRenderViewContextMenu::TestRenderViewContextMenu(
12     content::RenderFrameHost* render_frame_host,
13     content::ContextMenuParams params)
14     : RenderViewContextMenu(render_frame_host, params) {}
15 
~TestRenderViewContextMenu()16 TestRenderViewContextMenu::~TestRenderViewContextMenu() {}
17 
18 // static
Create(content::WebContents * web_contents,const GURL & page_url,const GURL & link_url,const GURL & frame_url)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;
32 }
33 
PlatformInit()34 void TestRenderViewContextMenu::PlatformInit() {}
35 
PlatformCancel()36 void TestRenderViewContextMenu::PlatformCancel() {}
37 
GetAcceleratorForCommandId(int command_id,ui::Accelerator * accelerator)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;
43 }
44 
IsItemPresent(int command_id)45 bool TestRenderViewContextMenu::IsItemPresent(int command_id) {
46   return menu_model_.GetIndexOfCommandId(command_id) != -1;
47 }
48 
GetMenuModelAndItemIndex(int command_id,MenuModel ** found_model,int * found_index)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_);
55 
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));
66       }
67     }
68   }
69 
70   return false;
71 }
72