This source file includes following definitions.
- profile_
- IsCommandIdChecked
- IsCommandIdEnabled
- ExecuteCommand
- MenuWillShow
- MenuClosed
- GetAcceleratorForCommandId
- AddMenuItem
- AddCheckItem
- AddSeparator
- AddSubMenu
- UpdateMenuItem
- GetRenderViewHost
- GetProfile
- GetWebContents
- SetObserver
- GetMenuSize
- GetMenuItem
- GetPrefs
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.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/render_view_context_menu_observer.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
using content::RenderViewHost;
using content::WebContents;
namespace {
class MockRenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
public RenderViewContextMenuProxy {
public:
struct MockMenuItem {
MockMenuItem()
: command_id(0),
enabled(false),
checked(false),
hidden(true) {}
int command_id;
bool enabled;
bool checked;
bool hidden;
base::string16 title;
};
MockRenderViewContextMenu() : observer_(NULL), profile_(new TestingProfile) {}
virtual ~MockRenderViewContextMenu() {}
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE {
return observer_->IsCommandIdChecked(command_id);
}
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE {
return observer_->IsCommandIdEnabled(command_id);
}
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {
observer_->ExecuteCommand(command_id);
}
virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE {}
virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE {}
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE {
return false;
}
virtual void AddMenuItem(int command_id,
const base::string16& title) OVERRIDE {}
virtual void AddCheckItem(int command_id,
const base::string16& title) OVERRIDE {}
virtual void AddSeparator() OVERRIDE {}
virtual void AddSubMenu(int command_id,
const base::string16& label,
ui::MenuModel* model) OVERRIDE {}
virtual void UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
const base::string16& title) OVERRIDE {}
virtual RenderViewHost* GetRenderViewHost() const OVERRIDE {
return NULL;
}
virtual Profile* GetProfile() const OVERRIDE {
return profile_.get();
}
virtual content::WebContents* GetWebContents() const OVERRIDE {
return NULL;
}
void SetObserver(RenderViewContextMenuObserver* observer) {
observer_ = observer;
}
size_t GetMenuSize() const {
return 0;
}
bool GetMenuItem(size_t i, MockMenuItem* item) const {
return false;
}
PrefService* GetPrefs() {
return profile_->GetPrefs();
}
private:
RenderViewContextMenuObserver* observer_;
scoped_ptr<TestingProfile> profile_;
DISALLOW_COPY_AND_ASSIGN(MockRenderViewContextMenu);
};
class SpellCheckerSubMenuObserverTest : public InProcessBrowserTest {
public:
SpellCheckerSubMenuObserverTest() {}
virtual ~SpellCheckerSubMenuObserverTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(SpellCheckerSubMenuObserverTest);
};
}
IN_PROC_BROWSER_TEST_F(SpellCheckerSubMenuObserverTest, ToggleSpelling) {
scoped_ptr<MockRenderViewContextMenu> menu(new MockRenderViewContextMenu);
scoped_ptr<SpellCheckerSubMenuObserver> observer(
new SpellCheckerSubMenuObserver(menu.get(), menu.get(), 1));
menu->SetObserver(observer.get());
menu->GetPrefs()->SetString(prefs::kAcceptLanguages, "en-US");
menu->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en-US");
menu->GetPrefs()->SetBoolean(prefs::kEnableContinuousSpellcheck, true);
content::ContextMenuParams params;
observer->InitMenu(params);
EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CHECK_SPELLING_WHILE_TYPING));
EXPECT_TRUE(menu->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING));
menu->ExecuteCommand(IDC_CHECK_SPELLING_WHILE_TYPING, 0);
EXPECT_FALSE(
menu->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck));
EXPECT_FALSE(menu->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING));
}