| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Returns the writable profile used in this test. | 74 // Returns the writable profile used in this test. |
| 75 PrefService* GetPrefs(); | 75 PrefService* GetPrefs(); |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 // An observer used for initializing the status of menu items added in this | 78 // An observer used for initializing the status of menu items added in this |
| 79 // test. A test should delete this RenderViewContextMenuObserver object. | 79 // test. A test should delete this RenderViewContextMenuObserver object. |
| 80 RenderViewContextMenuObserver* observer_; | 80 RenderViewContextMenuObserver* observer_; |
| 81 | 81 |
| 82 // A dummy profile used in this test. Call GetPrefs() when a test needs to | 82 // A dummy profile used in this test. Call GetPrefs() when a test needs to |
| 83 // change this profile and use PrefService methods. | 83 // change this profile and use PrefService methods. |
| 84 scoped_ptr<TestingProfile> profile_; | 84 scoped_ptr<TestingProfile> original_profile_; |
| 85 |
| 86 // Either |original_profile_| or its incognito profile. |
| 87 Profile* profile_; |
| 85 | 88 |
| 86 // A list of menu items added by the SpellingMenuObserver class. | 89 // A list of menu items added by the SpellingMenuObserver class. |
| 87 std::vector<MockMenuItem> items_; | 90 std::vector<MockMenuItem> items_; |
| 88 | 91 |
| 89 DISALLOW_COPY_AND_ASSIGN(MockRenderViewContextMenu); | 92 DISALLOW_COPY_AND_ASSIGN(MockRenderViewContextMenu); |
| 90 }; | 93 }; |
| 91 | 94 |
| 92 MockRenderViewContextMenu::MockRenderViewContextMenu(bool incognito) | 95 MockRenderViewContextMenu::MockRenderViewContextMenu(bool incognito) |
| 93 : observer_(NULL) { | 96 : observer_(NULL) { |
| 94 TestingProfile::Builder builder; | 97 original_profile_ = TestingProfile::Builder().Build(); |
| 95 if (incognito) | 98 profile_ = incognito ? original_profile_->GetOffTheRecordProfile() |
| 96 builder.SetIncognito(); | 99 : original_profile_.get(); |
| 97 profile_ = builder.Build(); | |
| 98 } | 100 } |
| 99 | 101 |
| 100 MockRenderViewContextMenu::~MockRenderViewContextMenu() { | 102 MockRenderViewContextMenu::~MockRenderViewContextMenu() { |
| 101 } | 103 } |
| 102 | 104 |
| 103 void MockRenderViewContextMenu::AddMenuItem(int command_id, | 105 void MockRenderViewContextMenu::AddMenuItem(int command_id, |
| 104 const base::string16& title) { | 106 const base::string16& title) { |
| 105 MockMenuItem item; | 107 MockMenuItem item; |
| 106 item.command_id = command_id; | 108 item.command_id = command_id; |
| 107 item.enabled = observer_->IsCommandIdEnabled(command_id); | 109 item.enabled = observer_->IsCommandIdEnabled(command_id); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 165 |
| 164 RenderViewHost* MockRenderViewContextMenu::GetRenderViewHost() const { | 166 RenderViewHost* MockRenderViewContextMenu::GetRenderViewHost() const { |
| 165 return NULL; | 167 return NULL; |
| 166 } | 168 } |
| 167 | 169 |
| 168 WebContents* MockRenderViewContextMenu::GetWebContents() const { | 170 WebContents* MockRenderViewContextMenu::GetWebContents() const { |
| 169 return NULL; | 171 return NULL; |
| 170 } | 172 } |
| 171 | 173 |
| 172 content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const { | 174 content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const { |
| 173 return profile_.get(); | 175 return profile_; |
| 174 } | 176 } |
| 175 | 177 |
| 176 size_t MockRenderViewContextMenu::GetMenuSize() const { | 178 size_t MockRenderViewContextMenu::GetMenuSize() const { |
| 177 return items_.size(); | 179 return items_.size(); |
| 178 } | 180 } |
| 179 | 181 |
| 180 bool MockRenderViewContextMenu::GetMenuItem(size_t i, | 182 bool MockRenderViewContextMenu::GetMenuItem(size_t i, |
| 181 MockMenuItem* item) const { | 183 MockMenuItem* item) const { |
| 182 if (i >= items_.size()) | 184 if (i >= items_.size()) |
| 183 return false; | 185 return false; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 ForceSuggestMode(); | 472 ForceSuggestMode(); |
| 471 InitMenu("asdfkj", NULL); | 473 InitMenu("asdfkj", NULL); |
| 472 | 474 |
| 473 // Should have at least 2 entries. Separator, suggestion. | 475 // Should have at least 2 entries. Separator, suggestion. |
| 474 EXPECT_LT(2U, menu()->GetMenuSize()); | 476 EXPECT_LT(2U, menu()->GetMenuSize()); |
| 475 menu()->GetMenuItem(0, &item); | 477 menu()->GetMenuItem(0, &item); |
| 476 EXPECT_EQ(-1, item.command_id); | 478 EXPECT_EQ(-1, item.command_id); |
| 477 menu()->GetMenuItem(1, &item); | 479 menu()->GetMenuItem(1, &item); |
| 478 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id); | 480 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id); |
| 479 } | 481 } |
| OLD | NEW |