| 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/spelling_menu_observer.h" | 5 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 bool enabled; | 39 bool enabled; |
| 40 bool checked; | 40 bool checked; |
| 41 bool hidden; | 41 bool hidden; |
| 42 base::string16 title; | 42 base::string16 title; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 explicit MockRenderViewContextMenu(bool incognito); | 45 explicit MockRenderViewContextMenu(bool incognito); |
| 46 virtual ~MockRenderViewContextMenu(); | 46 virtual ~MockRenderViewContextMenu(); |
| 47 | 47 |
| 48 // RenderViewContextMenuProxy implementation. | 48 // RenderViewContextMenuProxy implementation. |
| 49 virtual void AddMenuItem(int command_id, | 49 void AddMenuItem(int command_id, const base::string16& title) override; |
| 50 const base::string16& title) override; | 50 void AddCheckItem(int command_id, const base::string16& title) override; |
| 51 virtual void AddCheckItem(int command_id, | 51 void AddSeparator() override; |
| 52 const base::string16& title) override; | 52 void AddSubMenu(int command_id, |
| 53 virtual void AddSeparator() override; | 53 const base::string16& label, |
| 54 virtual void AddSubMenu(int command_id, | 54 ui::MenuModel* model) override; |
| 55 const base::string16& label, | 55 void UpdateMenuItem(int command_id, |
| 56 ui::MenuModel* model) override; | 56 bool enabled, |
| 57 virtual void UpdateMenuItem(int command_id, | 57 bool hidden, |
| 58 bool enabled, | 58 const base::string16& title) override; |
| 59 bool hidden, | 59 RenderViewHost* GetRenderViewHost() const override; |
| 60 const base::string16& title) override; | 60 WebContents* GetWebContents() const override; |
| 61 virtual RenderViewHost* GetRenderViewHost() const override; | 61 content::BrowserContext* GetBrowserContext() const override; |
| 62 virtual WebContents* GetWebContents() const override; | |
| 63 virtual content::BrowserContext* GetBrowserContext() const override; | |
| 64 | 62 |
| 65 // Attaches a RenderViewContextMenuObserver to be tested. | 63 // Attaches a RenderViewContextMenuObserver to be tested. |
| 66 void SetObserver(RenderViewContextMenuObserver* observer); | 64 void SetObserver(RenderViewContextMenuObserver* observer); |
| 67 | 65 |
| 68 // Returns the number of items added by the test. | 66 // Returns the number of items added by the test. |
| 69 size_t GetMenuSize() const; | 67 size_t GetMenuSize() const; |
| 70 | 68 |
| 71 // Returns the i-th item. | 69 // Returns the i-th item. |
| 72 bool GetMenuItem(size_t i, MockMenuItem* item) const; | 70 bool GetMenuItem(size_t i, MockMenuItem* item) const; |
| 73 | 71 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 PrefService* MockRenderViewContextMenu::GetPrefs() { | 197 PrefService* MockRenderViewContextMenu::GetPrefs() { |
| 200 return profile_->GetPrefs(); | 198 return profile_->GetPrefs(); |
| 201 } | 199 } |
| 202 | 200 |
| 203 // A test class used in this file. This test should be a browser test because it | 201 // A test class used in this file. This test should be a browser test because it |
| 204 // accesses resources. | 202 // accesses resources. |
| 205 class SpellingMenuObserverTest : public InProcessBrowserTest { | 203 class SpellingMenuObserverTest : public InProcessBrowserTest { |
| 206 public: | 204 public: |
| 207 SpellingMenuObserverTest(); | 205 SpellingMenuObserverTest(); |
| 208 | 206 |
| 209 virtual void SetUpOnMainThread() override { | 207 void SetUpOnMainThread() override { Reset(false); } |
| 210 Reset(false); | |
| 211 } | |
| 212 | 208 |
| 213 virtual void TearDownOnMainThread() override { | 209 void TearDownOnMainThread() override { |
| 214 observer_.reset(); | 210 observer_.reset(); |
| 215 menu_.reset(); | 211 menu_.reset(); |
| 216 } | 212 } |
| 217 | 213 |
| 218 void Reset(bool incognito) { | 214 void Reset(bool incognito) { |
| 219 observer_.reset(); | 215 observer_.reset(); |
| 220 menu_.reset(new MockRenderViewContextMenu(incognito)); | 216 menu_.reset(new MockRenderViewContextMenu(incognito)); |
| 221 observer_.reset(new SpellingMenuObserver(menu_.get())); | 217 observer_.reset(new SpellingMenuObserver(menu_.get())); |
| 222 menu_->SetObserver(observer_.get()); | 218 menu_->SetObserver(observer_.get()); |
| 223 } | 219 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 ForceSuggestMode(); | 468 ForceSuggestMode(); |
| 473 InitMenu("asdfkj", NULL); | 469 InitMenu("asdfkj", NULL); |
| 474 | 470 |
| 475 // Should have at least 2 entries. Separator, suggestion. | 471 // Should have at least 2 entries. Separator, suggestion. |
| 476 EXPECT_LT(2U, menu()->GetMenuSize()); | 472 EXPECT_LT(2U, menu()->GetMenuSize()); |
| 477 menu()->GetMenuItem(0, &item); | 473 menu()->GetMenuItem(0, &item); |
| 478 EXPECT_EQ(-1, item.command_id); | 474 EXPECT_EQ(-1, item.command_id); |
| 479 menu()->GetMenuItem(1, &item); | 475 menu()->GetMenuItem(1, &item); |
| 480 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id); | 476 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id); |
| 481 } | 477 } |
| OLD | NEW |