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

Unified Diff: chrome/browser/renderer_context_menu/mock_render_view_context_menu.h

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.h
diff --git a/chrome/browser/renderer_context_menu/mock_render_view_context_menu.h b/chrome/browser/renderer_context_menu/mock_render_view_context_menu.h
new file mode 100644
index 0000000000000000000000000000000000000000..e75fa346f351e8878a87267c3d337e3817d4da1b
--- /dev/null
+++ b/chrome/browser/renderer_context_menu/mock_render_view_context_menu.h
@@ -0,0 +1,98 @@
+// 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.
+
+#ifndef CHROME_BROWSER_RENDERER_CONTEXT_MENU_MOCK_RENDER_VIEW_CONTEXT_MENU_H_
+#define CHROME_BROWSER_RENDERER_CONTEXT_MENU_MOCK_RENDER_VIEW_CONTEXT_MENU_H_
+
+#include <cstddef>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string16.h"
+#include "components/renderer_context_menu/render_view_context_menu_proxy.h"
+#include "ui/base/models/simple_menu_model.h"
+
+class PrefService;
+class Profile;
+class RenderViewContextMenuObserver;
+class TestingProfile;
+
+// A mock context menu used in tests. This class overrides virtual methods
+// derived from the RenderViewContextMenuProxy class to monitor calls from the
+// SpellingMenuObserver class.
+class MockRenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
+ public RenderViewContextMenuProxy {
+ public:
+ // A menu item used in this test.
+ struct MockMenuItem {
+ MockMenuItem();
+ ~MockMenuItem();
+
+ int command_id;
+ bool enabled;
+ bool checked;
+ bool hidden;
+ base::string16 title;
+ };
+
+ explicit MockRenderViewContextMenu(bool incognito);
+ ~MockRenderViewContextMenu() override;
+
+ // SimpleMenuModel::Delegate implementation.
+ bool IsCommandIdChecked(int command_id) const override;
+ bool IsCommandIdEnabled(int command_id) const override;
+ void ExecuteCommand(int command_id, int event_flags) override;
+ void MenuWillShow(ui::SimpleMenuModel* source) override;
+ void MenuClosed(ui::SimpleMenuModel* source) override;
+ bool GetAcceleratorForCommandId(int command_id,
+ ui::Accelerator* accelerator) override;
+
+ // RenderViewContextMenuProxy implementation.
+ void AddMenuItem(int command_id, const base::string16& title) override;
+ void AddCheckItem(int command_id, const base::string16& title) override;
+ void AddSeparator() override;
+ void AddSubMenu(int command_id,
+ const base::string16& label,
+ ui::MenuModel* model) override;
+ void UpdateMenuItem(int command_id,
+ bool enabled,
+ bool hidden,
+ const base::string16& title) override;
+ content::RenderViewHost* GetRenderViewHost() const override;
+ content::BrowserContext* GetBrowserContext() const override;
+ content::WebContents* GetWebContents() const override;
+
+ // Attaches a RenderViewContextMenuObserver to be tested.
+ void SetObserver(RenderViewContextMenuObserver* observer);
+
+ // Returns the number of items added by the test.
+ size_t GetMenuSize() const;
+
+ // Returns the i-th item.
+ bool GetMenuItem(size_t i, MockMenuItem* item) const;
lazyboy 2016/02/01 19:23:33 nit: s/i/index
please use gerrit instead 2016/02/01 20:20:57 Done.
+
+ // Returns the writable profile used in this test.
+ PrefService* GetPrefs();
+
+ private:
+ // An observer used for initializing the status of menu items added in this
+ // test. This is a weak pointer, the test is responsible for deleting this
lazyboy 2016/02/01 19:23:33 Instead of calling it a weak pointer ..., just say
please use gerrit instead 2016/02/01 20:20:57 Done.
+ // object.
+ RenderViewContextMenuObserver* observer_;
+
+ // A dummy profile used in this test. Call GetPrefs() when a test needs to
+ // change this profile and use PrefService methods.
+ scoped_ptr<TestingProfile> original_profile_;
+
+ // Either |original_profile_| or its incognito profile.
+ Profile* profile_;
+
+ // A list of menu items added by the SpellingMenuObserver class.
+ std::vector<MockMenuItem> items_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockRenderViewContextMenu);
+};
+
+#endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_MOCK_RENDER_VIEW_CONTEXT_MENU_H_

Powered by Google App Engine
This is Rietveld 408576698