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

Unified Diff: chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc

Issue 1647723002: [win/cros/lin] Add back the spellcheck menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix signed/unsigned warning. 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/spelling_menu_observer_browsertest.cc
diff --git a/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc b/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc
index 5a68502d16de98ff275c3e783c4dd581d8b3e505..ba4e5b3cf4c348acebcd58dd946181331c28336f 100644
--- a/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc
+++ b/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc
@@ -6,201 +6,18 @@
#include <stddef.h>
-#include <vector>
-
#include "base/macros.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
+#include "chrome/browser/renderer_context_menu/mock_render_view_context_menu.h"
#include "chrome/browser/spellchecker/spelling_service_client.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
-#include "chrome/test/base/testing_profile.h"
-#include "components/renderer_context_menu/render_view_context_menu_observer.h"
-
-using content::RenderViewHost;
-using content::WebContents;
+#include "content/public/common/context_menu_params.h"
namespace {
-// A mock context menu used in this test. This class overrides virtual methods
-// derived from the RenderViewContextMenuProxy class to monitor calls from the
-// SpellingMenuObserver class.
-class MockRenderViewContextMenu : public RenderViewContextMenuProxy {
- public:
- // A menu item used in this test. This test uses a vector of this struct to
- // hold menu items added by this test.
- struct MockMenuItem {
- MockMenuItem()
- : command_id(0),
- enabled(false),
- checked(false),
- hidden(true) {
- }
- int command_id;
- bool enabled;
- bool checked;
- bool hidden;
- base::string16 title;
- };
-
- explicit MockRenderViewContextMenu(bool incognito);
- virtual ~MockRenderViewContextMenu();
-
- // 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;
- RenderViewHost* GetRenderViewHost() const override;
- WebContents* GetWebContents() const override;
- content::BrowserContext* GetBrowserContext() 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;
-
- // 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. A test should delete this RenderViewContextMenuObserver 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);
-};
-
-MockRenderViewContextMenu::MockRenderViewContextMenu(bool incognito)
- : observer_(NULL) {
- original_profile_ = TestingProfile::Builder().Build();
- profile_ = incognito ? original_profile_->GetOffTheRecordProfile()
- : original_profile_.get();
-}
-
-MockRenderViewContextMenu::~MockRenderViewContextMenu() {
-}
-
-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();
- it != items_.end(); ++it) {
- if (it->command_id == command_id) {
- it->enabled = enabled;
- it->hidden = hidden;
- it->title = title;
- return;
- }
- }
-
- // The SpellingMenuObserver class tries to change a menu item not added by the
- // class. This is an unexpected behavior and we should stop now.
- FAIL();
-}
-
-RenderViewHost* MockRenderViewContextMenu::GetRenderViewHost() const {
- return NULL;
-}
-
-WebContents* MockRenderViewContextMenu::GetWebContents() const {
- return NULL;
-}
-
-content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const {
- return profile_;
-}
-
-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;
-}
-
-void MockRenderViewContextMenu::SetObserver(
- RenderViewContextMenuObserver* observer) {
- observer_ = observer;
-}
-
-PrefService* MockRenderViewContextMenu::GetPrefs() {
- return profile_->GetPrefs();
-}
-
// A test class used in this file. This test should be a browser test because it
// accesses resources.
class SpellingMenuObserverTest : public InProcessBrowserTest {

Powered by Google App Engine
This is Rietveld 408576698