Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/ui/toolbar/action_box_menu_model_unittest.cc

Issue 13983002: Remove print and move bookmark to the top of the action box. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added TearDown Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/toolbar/action_box_menu_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/toolbar/action_box_menu_model.h" 5 #include "chrome/browser/ui/toolbar/action_box_menu_model.h"
6 6
7 #include "base/memory/scoped_ptr.h"
7 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chrome_to_mobile_service.h" 11 #include "chrome/browser/chrome_to_mobile_service.h"
11 #include "chrome/browser/chrome_to_mobile_service_factory.h" 12 #include "chrome/browser/chrome_to_mobile_service_factory.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_command_controller.h" 14 #include "chrome/browser/ui/browser_command_controller.h"
14 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/toolbar/action_box_button_controller.h"
15 #include "chrome/common/extensions/feature_switch.h" 17 #include "chrome/common/extensions/feature_switch.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/browser_with_test_window_test.h" 19 #include "chrome/test/base/browser_with_test_window_test.h"
18 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
19 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
20 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
22 #include "sync/notifier/invalidation_util.h" 24 #include "sync/notifier/invalidation_util.h"
23 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
26 28
27 using extensions::FeatureSwitch; 29 using extensions::FeatureSwitch;
28 30
29 class ActionBoxMenuModelTest : public BrowserWithTestWindowTest, 31 class ActionBoxMenuModelTest : public BrowserWithTestWindowTest,
30 public ui::SimpleMenuModel::Delegate { 32 public ActionBoxButtonController::Delegate {
31 public: 33 public:
32 ActionBoxMenuModelTest() {} 34 ActionBoxMenuModelTest() {}
33 35
34 // Testing overrides to ui::SimpleMenuModel::Delegate: 36 virtual void SetUp() OVERRIDE {
35 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { 37 BrowserWithTestWindowTest::SetUp();
36 return false; 38 controller_.reset(new ActionBoxButtonController(browser(), this));
37 } 39 }
38 40
39 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { 41 virtual void TearDown() OVERRIDE {
40 return false; 42 controller_.reset();
43 BrowserWithTestWindowTest::TearDown();
41 } 44 }
42 45
43 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {} 46 scoped_ptr<ActionBoxMenuModel> CreateModel() {
44 47 return controller_->CreateMenuModel();
45 // Don't handle accelerators. 48 }
46 virtual bool GetAcceleratorForCommandId(
47 int command_id,
48 ui::Accelerator* accelerator) OVERRIDE { return false; }
49 49
50 void InitProfile(){ 50 void InitProfile(){
51 profile()->set_incognito(true); 51 profile()->set_incognito(true);
52 profile()->GetPrefs()->ClearPref(prefs::kChromeToMobileDeviceList); 52 profile()->GetPrefs()->ClearPref(prefs::kChromeToMobileDeviceList);
53 profile()->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); 53 profile()->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
54 } 54 }
55 55
56 void SetProfileHasMobiles() { 56 void SetProfileHasMobiles() {
57 ListValue mobiles; 57 ListValue mobiles;
58 DictionaryValue* mobile = new DictionaryValue(); 58 DictionaryValue* mobile = new DictionaryValue();
(...skipping 17 matching lines...) Expand all
76 76
77 void NavigateToBookmarkablePage() { 77 void NavigateToBookmarkablePage() {
78 AddTab(browser(), GURL("http://www.google.com")); 78 AddTab(browser(), GURL("http://www.google.com"));
79 } 79 }
80 80
81 void NavigateToLocalPage() { 81 void NavigateToLocalPage() {
82 AddTab(browser(), GURL("chrome://blank")); 82 AddTab(browser(), GURL("chrome://blank"));
83 } 83 }
84 84
85 private: 85 private:
86 scoped_ptr<ActionBoxButtonController> controller_;
87
86 DISALLOW_COPY_AND_ASSIGN(ActionBoxMenuModelTest); 88 DISALLOW_COPY_AND_ASSIGN(ActionBoxMenuModelTest);
87 }; 89 };
88 90
89 // Tests that Chrome2Mobile is disabled on incognito profiles without devices. 91 // Tests that Chrome2Mobile is disabled on incognito profiles without devices.
90 TEST_F(ActionBoxMenuModelTest, IncongnitoNoMobiles) { 92 TEST_F(ActionBoxMenuModelTest, IncongnitoNoMobiles) {
91 InitProfile(); 93 InitProfile();
92 94
93 NavigateToLocalPage(); 95 NavigateToLocalPage();
94 // Create model. 96 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
95 ActionBoxMenuModel model(browser(), this);
96 97
97 // Expect no c2m command in model. 98 // Expect no c2m command in model.
98 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 99 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
99 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 100 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
100 101
101 NavigateToBookmarkablePage(); 102 NavigateToBookmarkablePage();
102 103
103 // Create model. 104 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
104 ActionBoxMenuModel model2(browser(), this);
105 105
106 // Expect c2m command not in model. 106 // Expect c2m command not in model.
107 EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 107 EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
108 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 108 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
109 } 109 }
110 110
111 // Tests that Chrome2Mobile is disabled on incognito profiles with devices. 111 // Tests that Chrome2Mobile is disabled on incognito profiles with devices.
112 TEST_F(ActionBoxMenuModelTest, IncongnitoHasMobiles) { 112 TEST_F(ActionBoxMenuModelTest, IncongnitoHasMobiles) {
113 InitProfile(); 113 InitProfile();
114 SetProfileHasMobiles(); 114 SetProfileHasMobiles();
115 115
116 NavigateToLocalPage(); 116 NavigateToLocalPage();
117 117
118 // Create model. 118 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
119 ActionBoxMenuModel model(browser(), this);
120 119
121 // Expect no c2m command in model. 120 // Expect no c2m command in model.
122 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 121 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
123 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 122 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
124 123
125 NavigateToBookmarkablePage(); 124 NavigateToBookmarkablePage();
126 125
127 // Create model. 126 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
128
129 ActionBoxMenuModel model2(browser(), this);
130 // Expect c2m command not in model. 127 // Expect c2m command not in model.
131 EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 128 EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
132 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 129 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
133 } 130 }
134 131
135 // Tests that Chrome2Mobile is disabled for signed-in profiles with no devices. 132 // Tests that Chrome2Mobile is disabled for signed-in profiles with no devices.
136 TEST_F(ActionBoxMenuModelTest, OnRecordNoMobiles) { 133 TEST_F(ActionBoxMenuModelTest, OnRecordNoMobiles) {
137 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(), 134 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(),
138 true); 135 true);
139 InitProfile(); 136 InitProfile();
140 SetProfileSignedIn(); 137 SetProfileSignedIn();
141 138
142 NavigateToLocalPage(); 139 NavigateToLocalPage();
143 140
144 // Create model. 141 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
145 ActionBoxMenuModel model(browser(), this);
146 142
147 // Expect no c2m command in model. 143 // Expect no c2m command in model.
148 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 144 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
149 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 145 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
150 146
151 NavigateToBookmarkablePage(); 147 NavigateToBookmarkablePage();
152 148
153 // Create model. 149 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
154 ActionBoxMenuModel model2(browser(), this);
155 150
156 // Expect c2m command not in model. 151 // Expect c2m command not in model.
157 EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 152 EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
158 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 153 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
159 } 154 }
160 155
161 // Tests that Chrome2Mobile is enabled for signed-in profiles with devices, and 156 // Tests that Chrome2Mobile is enabled for signed-in profiles with devices, and
162 // disabled if the profile is set to incognito mode. 157 // disabled if the profile is set to incognito mode.
163 TEST_F(ActionBoxMenuModelTest, HasMobilesOnRecordOrIncognito) { 158 TEST_F(ActionBoxMenuModelTest, HasMobilesOnRecordOrIncognito) {
164 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(), 159 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(),
165 true); 160 true);
166 InitProfile(); 161 InitProfile();
167 SetProfileSignedIn(); 162 SetProfileSignedIn();
168 SetProfileHasMobiles(); 163 SetProfileHasMobiles();
169 164
170 NavigateToLocalPage(); 165 NavigateToLocalPage();
171 166
172 // Create model. 167 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
173 ActionBoxMenuModel model(browser(), this);
174 168
175 // Expect no c2m command in model. 169 // Expect no c2m command in model.
176 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 170 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
177 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 171 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
178 172
179 NavigateToBookmarkablePage(); 173 NavigateToBookmarkablePage();
180 174
181 // Create model. 175 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
182 ActionBoxMenuModel model2(browser(), this);
183 176
184 // Expect c2m command in model. 177 // Expect c2m command in model.
185 EXPECT_NE(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 178 EXPECT_NE(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
186 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 179 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
187 180
188 // Incognito-ize profile. 181 // Incognito-ize profile.
189 profile()->set_incognito(true); 182 profile()->set_incognito(true);
190 183
191 // Create another model. 184 scoped_ptr<ActionBoxMenuModel> model3 = CreateModel();
192 ActionBoxMenuModel model3(browser(), this);
193 185
194 // Expect no c2m command in this model. 186 // Expect no c2m command in this model.
195 EXPECT_EQ(-1, model3.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 187 EXPECT_EQ(-1, model3->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
196 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 188 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
197 189
198 // Un-incognito-ize for shutdown. 190 // Un-incognito-ize for shutdown.
199 profile()->set_incognito(false); 191 profile()->set_incognito(false);
200 } 192 }
201 193
202 // Tests that Bookmark Star is lit up only on bookmarked pages. 194 // Tests that Bookmark Star is lit up only on bookmarked pages.
203 TEST_F(ActionBoxMenuModelTest, BookmarkedPage) { 195 TEST_F(ActionBoxMenuModelTest, BookmarkedPage) {
204 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(), 196 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(),
205 true); 197 true);
206 // Set up bookmark model 198 // Set up bookmark model
207 profile()->CreateBookmarkModel(true); 199 profile()->CreateBookmarkModel(true);
208 ui_test_utils::WaitForBookmarkModelToLoad(profile()); 200 ui_test_utils::WaitForBookmarkModelToLoad(profile());
209 201
210 // Navigate to a url. 202 // Navigate to a url.
211 GURL url1("http://www.google.com"); 203 GURL url1("http://www.google.com");
212 AddTab(browser(), url1); 204 AddTab(browser(), url1);
213 205
214 // Create model. 206 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
215 ActionBoxMenuModel model(browser(), this);
216 207
217 // Bokomark item should be in menu. 208 // Bokomark item should be in menu.
218 int bookmark_item_index = model.GetIndexOfCommandId( 209 int bookmark_item_index = model->GetIndexOfCommandId(
219 IDC_BOOKMARK_PAGE_FROM_STAR); 210 IDC_BOOKMARK_PAGE_FROM_STAR);
220 EXPECT_NE(-1, bookmark_item_index); 211 ASSERT_NE(-1, bookmark_item_index);
221 212
222 gfx::Image bookmark_icon; 213 gfx::Image bookmark_icon;
223 gfx::Image unlit_icon; 214 gfx::Image unlit_icon;
224 gfx::Image lit_icon; 215 gfx::Image lit_icon;
225 216
226 model.GetIconAt(bookmark_item_index, &bookmark_icon); 217 model->GetIconAt(bookmark_item_index, &bookmark_icon);
227 unlit_icon = 218 unlit_icon =
228 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR); 219 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR);
229 220
230 SkBitmap bookmark_icon_bitmap = *bookmark_icon.ToSkBitmap(); 221 SkBitmap bookmark_icon_bitmap = *bookmark_icon.ToSkBitmap();
231 SkBitmap unlit_icon_bitmap = *unlit_icon.ToSkBitmap(); 222 SkBitmap unlit_icon_bitmap = *unlit_icon.ToSkBitmap();
232 SkAutoLockPixels a(bookmark_icon_bitmap); 223 SkAutoLockPixels a(bookmark_icon_bitmap);
233 SkAutoLockPixels b(unlit_icon_bitmap); 224 SkAutoLockPixels b(unlit_icon_bitmap);
234 225
235 // Verify that the icon in the menu is the unlit icon. 226 // Verify that the icon in the menu is the unlit icon.
236 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap.getPixels(), 227 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap.getPixels(),
237 unlit_icon_bitmap.getPixels(), 228 unlit_icon_bitmap.getPixels(),
238 unlit_icon_bitmap.getSize())); 229 unlit_icon_bitmap.getSize()));
239 230
240 // Now bookmark it. 231 // Now bookmark it.
241 chrome::BookmarkCurrentPage(browser()); 232 chrome::BookmarkCurrentPage(browser());
242 233
243 // Create model. 234 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
244 ActionBoxMenuModel model2(browser(), this);
245 235
246 model2.GetIconAt(bookmark_item_index, &bookmark_icon); 236 model2->GetIconAt(bookmark_item_index, &bookmark_icon);
247 lit_icon = 237 lit_icon =
248 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR_LIT); 238 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR_LIT);
249 239
250 SkBitmap bookmark_icon_bitmap2 = *bookmark_icon.ToSkBitmap(); 240 SkBitmap bookmark_icon_bitmap2 = *bookmark_icon.ToSkBitmap();
251 SkBitmap lit_icon_bitmap = *lit_icon.ToSkBitmap(); 241 SkBitmap lit_icon_bitmap = *lit_icon.ToSkBitmap();
252 SkAutoLockPixels c(bookmark_icon_bitmap2); 242 SkAutoLockPixels c(bookmark_icon_bitmap2);
253 SkAutoLockPixels d(lit_icon_bitmap); 243 SkAutoLockPixels d(lit_icon_bitmap);
254 244
255 245
256 // Verify that the icon in the menu is the lit icon. 246 // Verify that the icon in the menu is the lit icon.
257 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap2.getPixels(), 247 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap2.getPixels(),
258 lit_icon_bitmap.getPixels(), 248 lit_icon_bitmap.getPixels(),
259 lit_icon_bitmap.getSize())); 249 lit_icon_bitmap.getSize()));
260 } 250 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/action_box_menu_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698