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

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: Fix mac unit test 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
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));
Mike Wittman 2013/04/10 20:44:04 destroy the controller explicitly in a TearDown fu
Rune Fevang 2013/04/10 21:17:48 Done.
37 } 39 }
38 40
39 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { 41 scoped_ptr<ActionBoxMenuModel> CreateModel() {
40 return false; 42 return controller_->CreateMenuModel();
41 } 43 }
42 44
43 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {}
44
45 // Don't handle accelerators.
46 virtual bool GetAcceleratorForCommandId(
47 int command_id,
48 ui::Accelerator* accelerator) OVERRIDE { return false; }
49
50 void InitProfile(){ 45 void InitProfile(){
51 profile()->set_incognito(true); 46 profile()->set_incognito(true);
52 profile()->GetPrefs()->ClearPref(prefs::kChromeToMobileDeviceList); 47 profile()->GetPrefs()->ClearPref(prefs::kChromeToMobileDeviceList);
53 profile()->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); 48 profile()->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
54 } 49 }
55 50
56 void SetProfileHasMobiles() { 51 void SetProfileHasMobiles() {
57 ListValue mobiles; 52 ListValue mobiles;
58 DictionaryValue* mobile = new DictionaryValue(); 53 DictionaryValue* mobile = new DictionaryValue();
59 mobile->SetString("type", "Nexus"); 54 mobile->SetString("type", "Nexus");
(...skipping 16 matching lines...) Expand all
76 71
77 void NavigateToBookmarkablePage() { 72 void NavigateToBookmarkablePage() {
78 AddTab(browser(), GURL("http://www.google.com")); 73 AddTab(browser(), GURL("http://www.google.com"));
79 } 74 }
80 75
81 void NavigateToLocalPage() { 76 void NavigateToLocalPage() {
82 AddTab(browser(), GURL("chrome://blank")); 77 AddTab(browser(), GURL("chrome://blank"));
83 } 78 }
84 79
85 private: 80 private:
81 scoped_ptr<ActionBoxButtonController> controller_;
82
86 DISALLOW_COPY_AND_ASSIGN(ActionBoxMenuModelTest); 83 DISALLOW_COPY_AND_ASSIGN(ActionBoxMenuModelTest);
87 }; 84 };
88 85
89 // Tests that Chrome2Mobile is disabled on incognito profiles without devices. 86 // Tests that Chrome2Mobile is disabled on incognito profiles without devices.
90 TEST_F(ActionBoxMenuModelTest, IncongnitoNoMobiles) { 87 TEST_F(ActionBoxMenuModelTest, IncongnitoNoMobiles) {
91 InitProfile(); 88 InitProfile();
92 89
93 NavigateToLocalPage(); 90 NavigateToLocalPage();
94 // Create model. 91 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
95 ActionBoxMenuModel model(browser(), this);
96 92
97 // Expect no c2m command in model. 93 // Expect no c2m command in model.
98 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 94 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
99 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 95 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
100 96
101 NavigateToBookmarkablePage(); 97 NavigateToBookmarkablePage();
102 98
103 // Create model. 99 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
104 ActionBoxMenuModel model2(browser(), this);
105 100
106 // Expect c2m command not in model. 101 // Expect c2m command not in model.
107 EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 102 EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
108 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 103 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
109 } 104 }
110 105
111 // Tests that Chrome2Mobile is disabled on incognito profiles with devices. 106 // Tests that Chrome2Mobile is disabled on incognito profiles with devices.
112 TEST_F(ActionBoxMenuModelTest, IncongnitoHasMobiles) { 107 TEST_F(ActionBoxMenuModelTest, IncongnitoHasMobiles) {
113 InitProfile(); 108 InitProfile();
114 SetProfileHasMobiles(); 109 SetProfileHasMobiles();
115 110
116 NavigateToLocalPage(); 111 NavigateToLocalPage();
117 112
118 // Create model. 113 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
119 ActionBoxMenuModel model(browser(), this);
120 114
121 // Expect no c2m command in model. 115 // Expect no c2m command in model.
122 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 116 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
123 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 117 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
124 118
125 NavigateToBookmarkablePage(); 119 NavigateToBookmarkablePage();
126 120
127 // Create model. 121 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
128
129 ActionBoxMenuModel model2(browser(), this);
130 // Expect c2m command not in model. 122 // Expect c2m command not in model.
131 EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 123 EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
132 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 124 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
133 } 125 }
134 126
135 // Tests that Chrome2Mobile is disabled for signed-in profiles with no devices. 127 // Tests that Chrome2Mobile is disabled for signed-in profiles with no devices.
136 TEST_F(ActionBoxMenuModelTest, OnRecordNoMobiles) { 128 TEST_F(ActionBoxMenuModelTest, OnRecordNoMobiles) {
137 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(), 129 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(),
138 true); 130 true);
139 InitProfile(); 131 InitProfile();
140 SetProfileSignedIn(); 132 SetProfileSignedIn();
141 133
142 NavigateToLocalPage(); 134 NavigateToLocalPage();
143 135
144 // Create model. 136 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
145 ActionBoxMenuModel model(browser(), this);
146 137
147 // Expect no c2m command in model. 138 // Expect no c2m command in model.
148 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 139 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
149 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 140 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
150 141
151 NavigateToBookmarkablePage(); 142 NavigateToBookmarkablePage();
152 143
153 // Create model. 144 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
154 ActionBoxMenuModel model2(browser(), this);
155 145
156 // Expect c2m command not in model. 146 // Expect c2m command not in model.
157 EXPECT_EQ(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 147 EXPECT_EQ(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
158 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 148 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
159 } 149 }
160 150
161 // Tests that Chrome2Mobile is enabled for signed-in profiles with devices, and 151 // Tests that Chrome2Mobile is enabled for signed-in profiles with devices, and
162 // disabled if the profile is set to incognito mode. 152 // disabled if the profile is set to incognito mode.
163 TEST_F(ActionBoxMenuModelTest, HasMobilesOnRecordOrIncognito) { 153 TEST_F(ActionBoxMenuModelTest, HasMobilesOnRecordOrIncognito) {
164 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(), 154 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(),
165 true); 155 true);
166 InitProfile(); 156 InitProfile();
167 SetProfileSignedIn(); 157 SetProfileSignedIn();
168 SetProfileHasMobiles(); 158 SetProfileHasMobiles();
169 159
170 NavigateToLocalPage(); 160 NavigateToLocalPage();
171 161
172 // Create model. 162 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
173 ActionBoxMenuModel model(browser(), this);
174 163
175 // Expect no c2m command in model. 164 // Expect no c2m command in model.
176 EXPECT_EQ(-1, model.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 165 EXPECT_EQ(-1, model->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
177 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 166 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
178 167
179 NavigateToBookmarkablePage(); 168 NavigateToBookmarkablePage();
180 169
181 // Create model. 170 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
182 ActionBoxMenuModel model2(browser(), this);
183 171
184 // Expect c2m command in model. 172 // Expect c2m command in model.
185 EXPECT_NE(-1, model2.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 173 EXPECT_NE(-1, model2->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
186 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 174 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
187 175
188 // Incognito-ize profile. 176 // Incognito-ize profile.
189 profile()->set_incognito(true); 177 profile()->set_incognito(true);
190 178
191 // Create another model. 179 scoped_ptr<ActionBoxMenuModel> model3 = CreateModel();
192 ActionBoxMenuModel model3(browser(), this);
193 180
194 // Expect no c2m command in this model. 181 // Expect no c2m command in this model.
195 EXPECT_EQ(-1, model3.GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE)); 182 EXPECT_EQ(-1, model3->GetIndexOfCommandId(IDC_CHROME_TO_MOBILE_PAGE));
196 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE)); 183 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_CHROME_TO_MOBILE_PAGE));
197 184
198 // Un-incognito-ize for shutdown. 185 // Un-incognito-ize for shutdown.
199 profile()->set_incognito(false); 186 profile()->set_incognito(false);
200 } 187 }
201 188
202 // Tests that Bookmark Star is lit up only on bookmarked pages. 189 // Tests that Bookmark Star is lit up only on bookmarked pages.
203 TEST_F(ActionBoxMenuModelTest, BookmarkedPage) { 190 TEST_F(ActionBoxMenuModelTest, BookmarkedPage) {
204 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(), 191 FeatureSwitch::ScopedOverride enable_action_box(FeatureSwitch::action_box(),
205 true); 192 true);
206 // Set up bookmark model 193 // Set up bookmark model
207 profile()->CreateBookmarkModel(true); 194 profile()->CreateBookmarkModel(true);
208 ui_test_utils::WaitForBookmarkModelToLoad(profile()); 195 ui_test_utils::WaitForBookmarkModelToLoad(profile());
209 196
210 // Navigate to a url. 197 // Navigate to a url.
211 GURL url1("http://www.google.com"); 198 GURL url1("http://www.google.com");
212 AddTab(browser(), url1); 199 AddTab(browser(), url1);
213 200
214 // Create model. 201 scoped_ptr<ActionBoxMenuModel> model = CreateModel();
215 ActionBoxMenuModel model(browser(), this);
216 202
217 // Bokomark item should be in menu. 203 // Bokomark item should be in menu.
218 int bookmark_item_index = model.GetIndexOfCommandId( 204 int bookmark_item_index = model->GetIndexOfCommandId(
219 IDC_BOOKMARK_PAGE_FROM_STAR); 205 IDC_BOOKMARK_PAGE_FROM_STAR);
220 EXPECT_NE(-1, bookmark_item_index); 206 ASSERT_NE(-1, bookmark_item_index);
221 207
222 gfx::Image bookmark_icon; 208 gfx::Image bookmark_icon;
223 gfx::Image unlit_icon; 209 gfx::Image unlit_icon;
224 gfx::Image lit_icon; 210 gfx::Image lit_icon;
225 211
226 model.GetIconAt(bookmark_item_index, &bookmark_icon); 212 model->GetIconAt(bookmark_item_index, &bookmark_icon);
227 unlit_icon = 213 unlit_icon =
228 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR); 214 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR);
229 215
230 SkBitmap bookmark_icon_bitmap = *bookmark_icon.ToSkBitmap(); 216 SkBitmap bookmark_icon_bitmap = *bookmark_icon.ToSkBitmap();
231 SkBitmap unlit_icon_bitmap = *unlit_icon.ToSkBitmap(); 217 SkBitmap unlit_icon_bitmap = *unlit_icon.ToSkBitmap();
232 SkAutoLockPixels a(bookmark_icon_bitmap); 218 SkAutoLockPixels a(bookmark_icon_bitmap);
233 SkAutoLockPixels b(unlit_icon_bitmap); 219 SkAutoLockPixels b(unlit_icon_bitmap);
234 220
235 // Verify that the icon in the menu is the unlit icon. 221 // Verify that the icon in the menu is the unlit icon.
236 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap.getPixels(), 222 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap.getPixels(),
237 unlit_icon_bitmap.getPixels(), 223 unlit_icon_bitmap.getPixels(),
238 unlit_icon_bitmap.getSize())); 224 unlit_icon_bitmap.getSize()));
239 225
240 // Now bookmark it. 226 // Now bookmark it.
241 chrome::BookmarkCurrentPage(browser()); 227 chrome::BookmarkCurrentPage(browser());
242 228
243 // Create model. 229 scoped_ptr<ActionBoxMenuModel> model2 = CreateModel();
244 ActionBoxMenuModel model2(browser(), this);
245 230
246 model2.GetIconAt(bookmark_item_index, &bookmark_icon); 231 model2->GetIconAt(bookmark_item_index, &bookmark_icon);
247 lit_icon = 232 lit_icon =
248 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR_LIT); 233 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_STAR_LIT);
249 234
250 SkBitmap bookmark_icon_bitmap2 = *bookmark_icon.ToSkBitmap(); 235 SkBitmap bookmark_icon_bitmap2 = *bookmark_icon.ToSkBitmap();
251 SkBitmap lit_icon_bitmap = *lit_icon.ToSkBitmap(); 236 SkBitmap lit_icon_bitmap = *lit_icon.ToSkBitmap();
252 SkAutoLockPixels c(bookmark_icon_bitmap2); 237 SkAutoLockPixels c(bookmark_icon_bitmap2);
253 SkAutoLockPixels d(lit_icon_bitmap); 238 SkAutoLockPixels d(lit_icon_bitmap);
254 239
255 240
256 // Verify that the icon in the menu is the lit icon. 241 // Verify that the icon in the menu is the lit icon.
257 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap2.getPixels(), 242 EXPECT_EQ(0, memcmp(bookmark_icon_bitmap2.getPixels(),
258 lit_icon_bitmap.getPixels(), 243 lit_icon_bitmap.getPixels(),
259 lit_icon_bitmap.getSize())); 244 lit_icon_bitmap.getSize()));
260 } 245 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698