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

Side by Side Diff: ash/launcher/launcher_view_unittest.cc

Issue 23606016: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for LauncherTest and observing LauncherModel in DelegateManager Created 7 years, 3 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 "ash/launcher/launcher_view.h" 5 #include "ash/launcher/launcher_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/launcher/launcher.h" 11 #include "ash/launcher/launcher.h"
12 #include "ash/launcher/launcher_button.h" 12 #include "ash/launcher/launcher_button.h"
13 #include "ash/launcher/launcher_icon_observer.h" 13 #include "ash/launcher/launcher_icon_observer.h"
14 #include "ash/launcher/launcher_item_delegate_manager.h"
14 #include "ash/launcher/launcher_model.h" 15 #include "ash/launcher/launcher_model.h"
15 #include "ash/launcher/launcher_tooltip_manager.h" 16 #include "ash/launcher/launcher_tooltip_manager.h"
16 #include "ash/launcher/launcher_types.h" 17 #include "ash/launcher/launcher_types.h"
17 #include "ash/root_window_controller.h" 18 #include "ash/root_window_controller.h"
18 #include "ash/shelf/shelf_layout_manager.h" 19 #include "ash/shelf/shelf_layout_manager.h"
19 #include "ash/shelf/shelf_widget.h" 20 #include "ash/shelf/shelf_widget.h"
20 #include "ash/shell.h" 21 #include "ash/shell.h"
21 #include "ash/shell_window_ids.h" 22 #include "ash/shell_window_ids.h"
22 #include "ash/test/ash_test_base.h" 23 #include "ash/test/ash_test_base.h"
23 #include "ash/test/launcher_view_test_api.h" 24 #include "ash/test/launcher_view_test_api.h"
24 #include "ash/test/shell_test_api.h" 25 #include "ash/test/shell_test_api.h"
25 #include "ash/test/test_launcher_delegate.h" 26 #include "ash/test/test_launcher_delegate.h"
27 #include "ash/test/test_launcher_item_delegate.h"
26 #include "base/basictypes.h" 28 #include "base/basictypes.h"
27 #include "base/command_line.h" 29 #include "base/command_line.h"
28 #include "base/compiler_specific.h" 30 #include "base/compiler_specific.h"
29 #include "base/memory/scoped_ptr.h" 31 #include "base/memory/scoped_ptr.h"
30 #include "grit/ash_resources.h" 32 #include "grit/ash_resources.h"
31 #include "ui/aura/root_window.h" 33 #include "ui/aura/root_window.h"
32 #include "ui/aura/test/aura_test_base.h" 34 #include "ui/aura/test/aura_test_base.h"
33 #include "ui/aura/test/event_generator.h" 35 #include "ui/aura/test/event_generator.h"
34 #include "ui/aura/window.h" 36 #include "ui/aura/window.h"
35 #include "ui/base/events/event.h" 37 #include "ui/base/events/event.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 model_ = test_api.launcher_model(); 206 model_ = test_api.launcher_model();
205 Launcher* launcher = Launcher::ForPrimaryDisplay(); 207 Launcher* launcher = Launcher::ForPrimaryDisplay();
206 launcher_view_ = launcher->GetLauncherViewForTest(); 208 launcher_view_ = launcher->GetLauncherViewForTest();
207 209
208 // The bounds should be big enough for 4 buttons + overflow chevron. 210 // The bounds should be big enough for 4 buttons + overflow chevron.
209 launcher_view_->SetBounds(0, 0, 500, 50); 211 launcher_view_->SetBounds(0, 0, 500, 50);
210 212
211 test_api_.reset(new LauncherViewTestAPI(launcher_view_)); 213 test_api_.reset(new LauncherViewTestAPI(launcher_view_));
212 test_api_->SetAnimationDuration(1); // Speeds up animation for test. 214 test_api_->SetAnimationDuration(1); // Speeds up animation for test.
213 215
216 item_manager_ =
217 ash::Shell::GetInstance()->launcher_item_delegate_manager();
218
214 // Add browser shortcut launcher item at index 0 for test. 219 // Add browser shortcut launcher item at index 0 for test.
215 AddBrowserShortcut(); 220 AddBrowserShortcut();
216 } 221 }
217 222
218 virtual void TearDown() OVERRIDE { 223 virtual void TearDown() OVERRIDE {
219 test_api_.reset(); 224 test_api_.reset();
220 AshTestBase::TearDown(); 225 AshTestBase::TearDown();
221 } 226 }
222 227
223 protected: 228 protected:
224 LauncherID AddBrowserShortcut() { 229 LauncherID AddBrowserShortcut() {
225 LauncherItem browser_shortcut; 230 LauncherItem browser_shortcut;
226 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 231 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
227 232
228 LauncherID id = model_->next_id(); 233 LauncherID id = model_->next_id();
229 model_->AddAt(browser_index_, browser_shortcut); 234 model_->AddAt(browser_index_, browser_shortcut);
235 item_manager_->RegisterLauncherItemDelegate(
236 id,
237 new ash::test::TestLauncherItemDelegate(NULL));
230 test_api_->RunMessageLoopUntilAnimationsDone(); 238 test_api_->RunMessageLoopUntilAnimationsDone();
231 return id; 239 return id;
232 } 240 }
233 241
234 LauncherID AddAppShortcut() { 242 LauncherID AddAppShortcut() {
235 LauncherItem item; 243 LauncherItem item;
236 item.type = TYPE_APP_SHORTCUT; 244 item.type = TYPE_APP_SHORTCUT;
237 item.status = STATUS_CLOSED; 245 item.status = STATUS_CLOSED;
238 246
239 LauncherID id = model_->next_id(); 247 LauncherID id = model_->next_id();
240 model_->Add(item); 248 model_->Add(item);
249 item_manager_->RegisterLauncherItemDelegate(
250 id,
251 new ash::test::TestLauncherItemDelegate(NULL));
241 test_api_->RunMessageLoopUntilAnimationsDone(); 252 test_api_->RunMessageLoopUntilAnimationsDone();
242 return id; 253 return id;
243 } 254 }
244 255
245 LauncherID AddPanel() { 256 LauncherID AddPanel() {
246 LauncherID id = AddPanelNoWait(); 257 LauncherID id = AddPanelNoWait();
247 test_api_->RunMessageLoopUntilAnimationsDone(); 258 test_api_->RunMessageLoopUntilAnimationsDone();
248 return id; 259 return id;
249 } 260 }
250 261
251 LauncherID AddPlatformAppNoWait() { 262 LauncherID AddPlatformAppNoWait() {
252 LauncherItem item; 263 LauncherItem item;
253 item.type = TYPE_PLATFORM_APP; 264 item.type = TYPE_PLATFORM_APP;
254 item.status = STATUS_RUNNING; 265 item.status = STATUS_RUNNING;
255 266
256 LauncherID id = model_->next_id(); 267 LauncherID id = model_->next_id();
257 model_->Add(item); 268 model_->Add(item);
269 item_manager_->RegisterLauncherItemDelegate(
270 id,
271 new ash::test::TestLauncherItemDelegate(NULL));
258 return id; 272 return id;
259 } 273 }
260 274
261 LauncherID AddPanelNoWait() { 275 LauncherID AddPanelNoWait() {
262 LauncherItem item; 276 LauncherItem item;
263 item.type = TYPE_APP_PANEL; 277 item.type = TYPE_APP_PANEL;
264 item.status = STATUS_RUNNING; 278 item.status = STATUS_RUNNING;
265 279
266 LauncherID id = model_->next_id(); 280 LauncherID id = model_->next_id();
267 model_->Add(item); 281 model_->Add(item);
282 item_manager_->RegisterLauncherItemDelegate(
283 id,
284 new ash::test::TestLauncherItemDelegate(NULL));
268 return id; 285 return id;
269 } 286 }
270 287
271 LauncherID AddPlatformApp() { 288 LauncherID AddPlatformApp() {
272 LauncherID id = AddPlatformAppNoWait(); 289 LauncherID id = AddPlatformAppNoWait();
273 test_api_->RunMessageLoopUntilAnimationsDone(); 290 test_api_->RunMessageLoopUntilAnimationsDone();
274 return id; 291 return id;
275 } 292 }
276 293
277 void RemoveByID(LauncherID id) { 294 void RemoveByID(LauncherID id) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return launcher_view_->tooltip_manager()->anchor_; 395 return launcher_view_->tooltip_manager()->anchor_;
379 } 396 }
380 397
381 void ShowTooltip() { 398 void ShowTooltip() {
382 launcher_view_->tooltip_manager()->ShowInternal(); 399 launcher_view_->tooltip_manager()->ShowInternal();
383 } 400 }
384 401
385 LauncherModel* model_; 402 LauncherModel* model_;
386 internal::LauncherView* launcher_view_; 403 internal::LauncherView* launcher_view_;
387 int browser_index_; 404 int browser_index_;
405 LauncherItemDelegateManager* item_manager_;
388 406
389 scoped_ptr<LauncherViewTestAPI> test_api_; 407 scoped_ptr<LauncherViewTestAPI> test_api_;
390 408
391 private: 409 private:
392 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); 410 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
393 }; 411 };
394 412
395 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest { 413 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest {
396 public: 414 public:
397 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() { 415 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() {
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 test_api_->GetButtonCount()); 1259 test_api_->GetButtonCount());
1242 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); 1260 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0);
1243 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); 1261 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1);
1244 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); 1262 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width());
1245 } 1263 }
1246 1264
1247 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); 1265 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool());
1248 1266
1249 } // namespace test 1267 } // namespace test
1250 } // namespace ash 1268 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698