OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" | 5 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 checked(false), | 32 checked(false), |
33 hidden(true) {} | 33 hidden(true) {} |
34 int command_id; | 34 int command_id; |
35 bool enabled; | 35 bool enabled; |
36 bool checked; | 36 bool checked; |
37 bool hidden; | 37 bool hidden; |
38 base::string16 title; | 38 base::string16 title; |
39 }; | 39 }; |
40 | 40 |
41 MockRenderViewContextMenu() : observer_(NULL), profile_(new TestingProfile) {} | 41 MockRenderViewContextMenu() : observer_(NULL), profile_(new TestingProfile) {} |
42 virtual ~MockRenderViewContextMenu() {} | 42 ~MockRenderViewContextMenu() override {} |
43 | 43 |
44 // SimpleMenuModel::Delegate implementation. | 44 // SimpleMenuModel::Delegate implementation. |
45 virtual bool IsCommandIdChecked(int command_id) const override { | 45 bool IsCommandIdChecked(int command_id) const override { |
46 return observer_->IsCommandIdChecked(command_id); | 46 return observer_->IsCommandIdChecked(command_id); |
47 } | 47 } |
48 virtual bool IsCommandIdEnabled(int command_id) const override { | 48 bool IsCommandIdEnabled(int command_id) const override { |
49 return observer_->IsCommandIdEnabled(command_id); | 49 return observer_->IsCommandIdEnabled(command_id); |
50 } | 50 } |
51 virtual void ExecuteCommand(int command_id, int event_flags) override { | 51 void ExecuteCommand(int command_id, int event_flags) override { |
52 observer_->ExecuteCommand(command_id); | 52 observer_->ExecuteCommand(command_id); |
53 } | 53 } |
54 virtual void MenuWillShow(ui::SimpleMenuModel* source) override {} | 54 void MenuWillShow(ui::SimpleMenuModel* source) override {} |
55 virtual void MenuClosed(ui::SimpleMenuModel* source) override {} | 55 void MenuClosed(ui::SimpleMenuModel* source) override {} |
56 virtual bool GetAcceleratorForCommandId( | 56 bool GetAcceleratorForCommandId(int command_id, |
57 int command_id, | 57 ui::Accelerator* accelerator) override { |
58 ui::Accelerator* accelerator) override { | |
59 return false; | 58 return false; |
60 } | 59 } |
61 | 60 |
62 // RenderViewContextMenuProxy implementation. | 61 // RenderViewContextMenuProxy implementation. |
63 virtual void AddMenuItem(int command_id, | 62 void AddMenuItem(int command_id, const base::string16& title) override {} |
64 const base::string16& title) override {} | 63 void AddCheckItem(int command_id, const base::string16& title) override {} |
65 virtual void AddCheckItem(int command_id, | 64 void AddSeparator() override {} |
66 const base::string16& title) override {} | 65 void AddSubMenu(int command_id, |
67 virtual void AddSeparator() override {} | 66 const base::string16& label, |
68 virtual void AddSubMenu(int command_id, | 67 ui::MenuModel* model) override {} |
69 const base::string16& label, | 68 void UpdateMenuItem(int command_id, |
70 ui::MenuModel* model) override {} | 69 bool enabled, |
71 virtual void UpdateMenuItem(int command_id, | 70 bool hidden, |
72 bool enabled, | 71 const base::string16& title) override {} |
73 bool hidden, | 72 RenderViewHost* GetRenderViewHost() const override { return NULL; } |
74 const base::string16& title) override {} | 73 content::BrowserContext* GetBrowserContext() const override { |
75 virtual RenderViewHost* GetRenderViewHost() const override { | |
76 return NULL; | |
77 } | |
78 virtual content::BrowserContext* GetBrowserContext() const override { | |
79 return profile_.get(); | 74 return profile_.get(); |
80 } | 75 } |
81 virtual content::WebContents* GetWebContents() const override { | 76 content::WebContents* GetWebContents() const override { return NULL; } |
82 return NULL; | |
83 } | |
84 | 77 |
85 // Attaches a RenderViewContextMenuObserver to be tested. | 78 // Attaches a RenderViewContextMenuObserver to be tested. |
86 void SetObserver(RenderViewContextMenuObserver* observer) { | 79 void SetObserver(RenderViewContextMenuObserver* observer) { |
87 observer_ = observer; | 80 observer_ = observer; |
88 } | 81 } |
89 | 82 |
90 // Returns the number of items added by the test. | 83 // Returns the number of items added by the test. |
91 size_t GetMenuSize() const { | 84 size_t GetMenuSize() const { |
92 return 0; | 85 return 0; |
93 } | 86 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 EXPECT_TRUE(menu->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING)); | 141 EXPECT_TRUE(menu->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING)); |
149 | 142 |
150 // Select this item and verify that the "Check Spelling While Typing" item is | 143 // Select this item and verify that the "Check Spelling While Typing" item is |
151 // not checked. Also, verify that the value of "browser.enable_spellchecking" | 144 // not checked. Also, verify that the value of "browser.enable_spellchecking" |
152 // is now false. | 145 // is now false. |
153 menu->ExecuteCommand(IDC_CHECK_SPELLING_WHILE_TYPING, 0); | 146 menu->ExecuteCommand(IDC_CHECK_SPELLING_WHILE_TYPING, 0); |
154 EXPECT_FALSE( | 147 EXPECT_FALSE( |
155 menu->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); | 148 menu->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); |
156 EXPECT_FALSE(menu->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING)); | 149 EXPECT_FALSE(menu->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING)); |
157 } | 150 } |
OLD | NEW |