Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/renderer_context_menu/mock_render_view_context_menu.h" | |
| 6 | |
| 7 #include "base/prefs/pref_service.h" | |
| 8 #include "chrome/test/base/testing_profile.h" | |
| 9 #include "components/renderer_context_menu/render_view_context_menu_observer.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 MockRenderViewContextMenu::MockMenuItem::MockMenuItem() | |
| 13 : command_id(0), enabled(false), checked(false), hidden(true) {} | |
| 14 | |
| 15 MockRenderViewContextMenu::MockMenuItem::~MockMenuItem() {} | |
| 16 | |
| 17 MockRenderViewContextMenu::MockRenderViewContextMenu(bool incognito) | |
| 18 : observer_(NULL), | |
| 19 original_profile_(TestingProfile::Builder().Build()), | |
| 20 profile_(incognito ? original_profile_->GetOffTheRecordProfile() | |
| 21 : original_profile_.get()) {} | |
| 22 | |
| 23 MockRenderViewContextMenu::~MockRenderViewContextMenu() {} | |
| 24 | |
| 25 bool MockRenderViewContextMenu::IsCommandIdChecked(int command_id) const { | |
| 26 return observer_->IsCommandIdChecked(command_id); | |
| 27 } | |
| 28 | |
| 29 bool MockRenderViewContextMenu::IsCommandIdEnabled(int command_id) const { | |
| 30 return observer_->IsCommandIdEnabled(command_id); | |
| 31 } | |
| 32 | |
| 33 void MockRenderViewContextMenu::ExecuteCommand(int command_id, | |
| 34 int event_flags) { | |
| 35 observer_->ExecuteCommand(command_id); | |
| 36 } | |
| 37 | |
| 38 void MockRenderViewContextMenu::MenuWillShow(ui::SimpleMenuModel* source) {} | |
| 39 | |
| 40 void MockRenderViewContextMenu::MenuClosed(ui::SimpleMenuModel* source) {} | |
| 41 | |
| 42 bool MockRenderViewContextMenu::GetAcceleratorForCommandId( | |
| 43 int command_id, | |
| 44 ui::Accelerator* accelerator) { | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 void MockRenderViewContextMenu::AddMenuItem(int command_id, | |
| 49 const base::string16& title) { | |
| 50 MockMenuItem item; | |
| 51 item.command_id = command_id; | |
| 52 item.enabled = observer_->IsCommandIdEnabled(command_id); | |
| 53 item.checked = false; | |
| 54 item.hidden = false; | |
| 55 item.title = title; | |
| 56 items_.push_back(item); | |
| 57 } | |
| 58 | |
| 59 void MockRenderViewContextMenu::AddCheckItem(int command_id, | |
| 60 const base::string16& title) { | |
| 61 MockMenuItem item; | |
| 62 item.command_id = command_id; | |
| 63 item.enabled = observer_->IsCommandIdEnabled(command_id); | |
| 64 item.checked = observer_->IsCommandIdChecked(command_id); | |
| 65 item.hidden = false; | |
| 66 item.title = title; | |
| 67 items_.push_back(item); | |
| 68 } | |
| 69 | |
| 70 void MockRenderViewContextMenu::AddSeparator() { | |
| 71 MockMenuItem item; | |
| 72 item.command_id = -1; | |
| 73 item.enabled = false; | |
| 74 item.checked = false; | |
| 75 item.hidden = false; | |
| 76 items_.push_back(item); | |
| 77 } | |
| 78 | |
| 79 void MockRenderViewContextMenu::AddSubMenu(int command_id, | |
| 80 const base::string16& label, | |
| 81 ui::MenuModel* model) { | |
| 82 MockMenuItem item; | |
| 83 item.command_id = -1; | |
| 84 item.enabled = false; | |
| 85 item.checked = false; | |
| 86 item.hidden = false; | |
| 87 items_.push_back(item); | |
| 88 } | |
| 89 | |
| 90 void MockRenderViewContextMenu::UpdateMenuItem(int command_id, | |
| 91 bool enabled, | |
| 92 bool hidden, | |
| 93 const base::string16& title) { | |
| 94 for (std::vector<MockMenuItem>::iterator it = items_.begin(); | |
|
lazyboy
2016/02/01 19:23:33
nit: use range loop.
please use gerrit instead
2016/02/01 20:20:57
Done.
| |
| 95 it != items_.end(); ++it) { | |
| 96 if (it->command_id == command_id) { | |
| 97 it->enabled = enabled; | |
| 98 it->hidden = hidden; | |
| 99 it->title = title; | |
| 100 return; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 // The menu observer tries to change a menu item not added by the class. This | |
| 105 // is an unexpected behavior and we should stop now. | |
| 106 FAIL(); | |
|
lazyboy
2016/02/01 19:23:33
Instead of commenting, we can add the message here
please use gerrit instead
2016/02/01 20:20:57
Done.
| |
| 107 } | |
| 108 | |
| 109 content::RenderViewHost* MockRenderViewContextMenu::GetRenderViewHost() const { | |
| 110 return NULL; | |
|
lazyboy
2016/02/01 19:23:33
(Here and in all other places throughout the CL) u
please use gerrit instead
2016/02/01 20:20:57
Done.
| |
| 111 } | |
| 112 | |
| 113 content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const { | |
| 114 return profile_; | |
| 115 } | |
| 116 | |
| 117 content::WebContents* MockRenderViewContextMenu::GetWebContents() const { | |
| 118 return NULL; | |
| 119 } | |
| 120 | |
| 121 void MockRenderViewContextMenu::SetObserver( | |
| 122 RenderViewContextMenuObserver* observer) { | |
| 123 observer_ = observer; | |
| 124 } | |
| 125 | |
| 126 size_t MockRenderViewContextMenu::GetMenuSize() const { | |
| 127 return items_.size(); | |
| 128 } | |
| 129 | |
| 130 bool MockRenderViewContextMenu::GetMenuItem(size_t i, | |
| 131 MockMenuItem* item) const { | |
| 132 if (i >= items_.size()) | |
| 133 return false; | |
| 134 item->command_id = items_[i].command_id; | |
| 135 item->enabled = items_[i].enabled; | |
| 136 item->checked = items_[i].checked; | |
| 137 item->hidden = items_[i].hidden; | |
| 138 item->title = items_[i].title; | |
| 139 return true; | |
| 140 } | |
| 141 | |
| 142 PrefService* MockRenderViewContextMenu::GetPrefs() { | |
| 143 return profile_->GetPrefs(); | |
| 144 } | |
| OLD | NEW |