| 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 72fa852d2d951dc184d4bda5df6d059e48b53561..ffde1c0c7b1d79c09b514c9774bb11d18c6f9222 100644
|
| --- a/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc
|
| +++ b/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc
|
| @@ -4,203 +4,20 @@
|
|
|
| #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"
|
|
|
| -#include <stddef.h>
|
| -
|
| -#include <vector>
|
| -
|
| #include "base/macros.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/values.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/prefs/pref_service.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"
|
| +#include "testing/gtest/include/gtest/gtest.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 {
|
| @@ -263,14 +80,14 @@ SpellingMenuObserverTest::~SpellingMenuObserverTest() {
|
|
|
| // Tests that right-clicking a correct word does not add any items.
|
| IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, InitMenuWithCorrectWord) {
|
| - InitMenu("", NULL);
|
| + InitMenu("", nullptr);
|
| EXPECT_EQ(static_cast<size_t>(0), menu()->GetMenuSize());
|
| }
|
|
|
| // Tests that right-clicking a misspelled word adds three items:
|
| // "Add to dictionary", "Ask Google for suggestions", and a separator.
|
| IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, InitMenuWithMisspelledWord) {
|
| - InitMenu("wiimode", NULL);
|
| + InitMenu("wiimode", nullptr);
|
| EXPECT_EQ(3U, menu()->GetMenuSize());
|
|
|
| // Read all the context-menu items added by this test and verify they are
|
| @@ -300,7 +117,7 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, InitMenuWithMisspelledWord) {
|
| IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest,
|
| EnableSpellingServiceWithCorrectWord) {
|
| menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
|
| - InitMenu("", NULL);
|
| + InitMenu("", nullptr);
|
|
|
| EXPECT_TRUE(
|
| observer()->IsCommandIdChecked(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE));
|
| @@ -315,7 +132,7 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, EnableSpellingService) {
|
| base::ListValue dictionary;
|
| menu()->GetPrefs()->Set(prefs::kSpellCheckDictionaries, dictionary);
|
|
|
| - InitMenu("wiimode", NULL);
|
| + InitMenu("wiimode", nullptr);
|
| EXPECT_EQ(3U, menu()->GetMenuSize());
|
|
|
| // To avoid duplicates, this test reads only the "Ask Google for suggestions"
|
| @@ -400,7 +217,7 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest,
|
| EXPECT_FALSE(SpellingServiceClient::IsAvailable(
|
| menu()->GetBrowserContext(), SpellingServiceClient::SPELLCHECK));
|
|
|
| - InitMenu("sjxdjiiiiii", NULL);
|
| + InitMenu("sjxdjiiiiii", nullptr);
|
|
|
| // There should not be a "No more Google suggestions" (from SpellingService)
|
| // or a separator. The next 2 items should be "Add to Dictionary" followed
|
| @@ -426,7 +243,7 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SuggestionsForceTopSeparator) {
|
| menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, false);
|
|
|
| // First case: Misspelled word, no suggestions, no spellcheck service.
|
| - InitMenu("asdfkj", NULL);
|
| + InitMenu("asdfkj", nullptr);
|
| // See SpellingMenuObserverTest.InitMenuWithMisspelledWord on why 3 items.
|
| EXPECT_EQ(3U, menu()->GetMenuSize());
|
| MockRenderViewContextMenu::MockMenuItem item;
|
| @@ -447,7 +264,7 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SuggestionsForceTopSeparator) {
|
| // Case #3. Misspelled word, suggestion service is on.
|
| Reset(false);
|
| ForceSuggestMode();
|
| - InitMenu("asdfkj", NULL);
|
| + InitMenu("asdfkj", nullptr);
|
|
|
| // Should have at least 2 entries. Separator, suggestion.
|
| EXPECT_LT(2U, menu()->GetMenuSize());
|
|
|