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

Side by Side Diff: chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc

Issue 1647723002: [win/cros/lin] Add back the spellcheck menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/mock_render_view_context_menu.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "components/prefs/pref_service.h"
10 #include "components/renderer_context_menu/render_view_context_menu_observer.h"
11 #include "content/public/browser/browser_context.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 MockRenderViewContextMenu::MockMenuItem::MockMenuItem()
15 : command_id(0), enabled(false), checked(false), hidden(true) {}
16
17 MockRenderViewContextMenu::MockMenuItem::~MockMenuItem() {}
18
19 MockRenderViewContextMenu::MockRenderViewContextMenu(bool incognito)
20 : observer_(nullptr),
21 original_profile_(TestingProfile::Builder().Build()),
22 profile_(incognito ? original_profile_->GetOffTheRecordProfile()
23 : original_profile_.get()) {}
24
25 MockRenderViewContextMenu::~MockRenderViewContextMenu() {}
26
27 bool MockRenderViewContextMenu::IsCommandIdChecked(int command_id) const {
28 return observer_->IsCommandIdChecked(command_id);
29 }
30
31 bool MockRenderViewContextMenu::IsCommandIdEnabled(int command_id) const {
32 return observer_->IsCommandIdEnabled(command_id);
33 }
34
35 void MockRenderViewContextMenu::ExecuteCommand(int command_id,
36 int event_flags) {
37 observer_->ExecuteCommand(command_id);
38 }
39
40 void MockRenderViewContextMenu::MenuWillShow(ui::SimpleMenuModel* source) {}
41
42 void MockRenderViewContextMenu::MenuClosed(ui::SimpleMenuModel* source) {}
43
44 bool MockRenderViewContextMenu::GetAcceleratorForCommandId(
45 int command_id,
46 ui::Accelerator* accelerator) {
47 return false;
48 }
49
50 void MockRenderViewContextMenu::AddMenuItem(int command_id,
51 const base::string16& title) {
52 MockMenuItem item;
53 item.command_id = command_id;
54 item.enabled = observer_->IsCommandIdEnabled(command_id);
55 item.checked = false;
56 item.hidden = false;
57 item.title = title;
58 items_.push_back(item);
59 }
60
61 void MockRenderViewContextMenu::AddCheckItem(int command_id,
62 const base::string16& title) {
63 MockMenuItem item;
64 item.command_id = command_id;
65 item.enabled = observer_->IsCommandIdEnabled(command_id);
66 item.checked = observer_->IsCommandIdChecked(command_id);
67 item.hidden = false;
68 item.title = title;
69 items_.push_back(item);
70 }
71
72 void MockRenderViewContextMenu::AddSeparator() {
73 MockMenuItem item;
74 item.command_id = -1;
75 item.enabled = false;
76 item.checked = false;
77 item.hidden = false;
78 items_.push_back(item);
79 }
80
81 void MockRenderViewContextMenu::AddSubMenu(int command_id,
82 const base::string16& label,
83 ui::MenuModel* model) {
84 MockMenuItem item;
85 item.command_id = -1;
86 item.enabled = false;
87 item.checked = false;
88 item.hidden = false;
89 items_.push_back(item);
90 }
91
92 void MockRenderViewContextMenu::UpdateMenuItem(int command_id,
93 bool enabled,
94 bool hidden,
95 const base::string16& title) {
96 for (auto& item : items_) {
97 if (item.command_id == command_id) {
98 item.enabled = enabled;
99 item.hidden = hidden;
100 item.title = title;
101 return;
102 }
103 }
104
105 FAIL() << "Menu observer is trying to change a menu item it doesn't own.";
106 }
107
108 content::RenderViewHost* MockRenderViewContextMenu::GetRenderViewHost() const {
109 return nullptr;
110 }
111
112 content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const {
113 return profile_;
114 }
115
116 content::WebContents* MockRenderViewContextMenu::GetWebContents() const {
117 return nullptr;
118 }
119
120 void MockRenderViewContextMenu::SetObserver(
121 RenderViewContextMenuObserver* observer) {
122 observer_ = observer;
123 }
124
125 size_t MockRenderViewContextMenu::GetMenuSize() const {
126 return items_.size();
127 }
128
129 bool MockRenderViewContextMenu::GetMenuItem(size_t index,
130 MockMenuItem* item) const {
131 if (index >= items_.size())
132 return false;
133 item->command_id = items_[index].command_id;
134 item->enabled = items_[index].enabled;
135 item->checked = items_[index].checked;
136 item->hidden = items_[index].hidden;
137 item->title = items_[index].title;
138 return true;
139 }
140
141 PrefService* MockRenderViewContextMenu::GetPrefs() {
142 return profile_->GetPrefs();
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698