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

Unified 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: Add missing includes. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc
diff --git a/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc b/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e4c803ff731abbc45040a23143bea1087cedb19
--- /dev/null
+++ b/chrome/browser/renderer_context_menu/mock_render_view_context_menu.cc
@@ -0,0 +1,144 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/renderer_context_menu/mock_render_view_context_menu.h"
+
+#include "base/prefs/pref_service.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/renderer_context_menu/render_view_context_menu_observer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+MockRenderViewContextMenu::MockMenuItem::MockMenuItem()
+ : command_id(0), enabled(false), checked(false), hidden(true) {}
+
+MockRenderViewContextMenu::MockMenuItem::~MockMenuItem() {}
+
+MockRenderViewContextMenu::MockRenderViewContextMenu(bool incognito)
+ : observer_(NULL),
+ original_profile_(TestingProfile::Builder().Build()),
+ profile_(incognito ? original_profile_->GetOffTheRecordProfile()
+ : original_profile_.get()) {}
+
+MockRenderViewContextMenu::~MockRenderViewContextMenu() {}
+
+bool MockRenderViewContextMenu::IsCommandIdChecked(int command_id) const {
+ return observer_->IsCommandIdChecked(command_id);
+}
+
+bool MockRenderViewContextMenu::IsCommandIdEnabled(int command_id) const {
+ return observer_->IsCommandIdEnabled(command_id);
+}
+
+void MockRenderViewContextMenu::ExecuteCommand(int command_id,
+ int event_flags) {
+ observer_->ExecuteCommand(command_id);
+}
+
+void MockRenderViewContextMenu::MenuWillShow(ui::SimpleMenuModel* source) {}
+
+void MockRenderViewContextMenu::MenuClosed(ui::SimpleMenuModel* source) {}
+
+bool MockRenderViewContextMenu::GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) {
+ return false;
+}
+
+void MockRenderViewContextMenu::AddMenuItem(int command_id,
+ const base::string16& title) {
+ MockMenuItem item;
+ item.command_id = command_id;
+ item.enabled = observer_->IsCommandIdEnabled(command_id);
+ item.checked = false;
+ item.hidden = false;
+ item.title = title;
+ items_.push_back(item);
+}
+
+void MockRenderViewContextMenu::AddCheckItem(int command_id,
+ const base::string16& title) {
+ MockMenuItem item;
+ item.command_id = command_id;
+ item.enabled = observer_->IsCommandIdEnabled(command_id);
+ item.checked = observer_->IsCommandIdChecked(command_id);
+ item.hidden = false;
+ item.title = title;
+ items_.push_back(item);
+}
+
+void MockRenderViewContextMenu::AddSeparator() {
+ MockMenuItem item;
+ item.command_id = -1;
+ item.enabled = false;
+ item.checked = false;
+ item.hidden = false;
+ items_.push_back(item);
+}
+
+void MockRenderViewContextMenu::AddSubMenu(int command_id,
+ const base::string16& label,
+ ui::MenuModel* model) {
+ MockMenuItem item;
+ item.command_id = -1;
+ item.enabled = false;
+ item.checked = false;
+ item.hidden = false;
+ items_.push_back(item);
+}
+
+void MockRenderViewContextMenu::UpdateMenuItem(int command_id,
+ bool enabled,
+ bool hidden,
+ const base::string16& title) {
+ for (std::vector<MockMenuItem>::iterator it = items_.begin();
lazyboy 2016/02/01 19:23:33 nit: use range loop.
please use gerrit instead 2016/02/01 20:20:57 Done.
+ it != items_.end(); ++it) {
+ if (it->command_id == command_id) {
+ it->enabled = enabled;
+ it->hidden = hidden;
+ it->title = title;
+ return;
+ }
+ }
+
+ // The menu observer tries to change a menu item not added by the class. This
+ // is an unexpected behavior and we should stop now.
+ FAIL();
lazyboy 2016/02/01 19:23:33 Instead of commenting, we can add the message here
please use gerrit instead 2016/02/01 20:20:57 Done.
+}
+
+content::RenderViewHost* MockRenderViewContextMenu::GetRenderViewHost() const {
+ return NULL;
lazyboy 2016/02/01 19:23:33 (Here and in all other places throughout the CL) u
please use gerrit instead 2016/02/01 20:20:57 Done.
+}
+
+content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const {
+ return profile_;
+}
+
+content::WebContents* MockRenderViewContextMenu::GetWebContents() const {
+ return NULL;
+}
+
+void MockRenderViewContextMenu::SetObserver(
+ RenderViewContextMenuObserver* observer) {
+ observer_ = observer;
+}
+
+size_t MockRenderViewContextMenu::GetMenuSize() const {
+ return items_.size();
+}
+
+bool MockRenderViewContextMenu::GetMenuItem(size_t i,
+ MockMenuItem* item) const {
+ if (i >= items_.size())
+ return false;
+ item->command_id = items_[i].command_id;
+ item->enabled = items_[i].enabled;
+ item->checked = items_[i].checked;
+ item->hidden = items_[i].hidden;
+ item->title = items_[i].title;
+ return true;
+}
+
+PrefService* MockRenderViewContextMenu::GetPrefs() {
+ return profile_->GetPrefs();
+}

Powered by Google App Engine
This is Rietveld 408576698