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
3 // found in the LICENSE file.
5 #include "ash/test/shelf_view_test_api.h"
7 #include "ash/launcher/launcher_button.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/shelf/overflow_button.h"
10 #include "ash/shelf/shelf_view.h"
11 #include "base/message_loop/message_loop.h"
12 #include "ui/views/animation/bounds_animator.h"
13 #include "ui/views/view_model.h"
17 // A class used to wait for animations.
18 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver {
20 TestAPIAnimationObserver() {}
21 virtual ~TestAPIAnimationObserver() {}
23 // views::BoundsAnimatorObserver overrides:
24 virtual void OnBoundsAnimatorProgressed(
25 views::BoundsAnimator* animator) OVERRIDE {}
26 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE {
27 base::MessageLoop::current()->Quit();
31 DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
39 ShelfViewTestAPI::ShelfViewTestAPI(internal::ShelfView* shelf_view)
40 : shelf_view_(shelf_view) {
43 ShelfViewTestAPI::~ShelfViewTestAPI() {
46 int ShelfViewTestAPI::GetButtonCount() {
47 return shelf_view_->view_model_->view_size();
50 internal::LauncherButton* ShelfViewTestAPI::GetButton(int index) {
51 // App list button is not a LauncherButton.
52 if (shelf_view_->model_->items()[index].type == ash::TYPE_APP_LIST)
55 return static_cast<internal::LauncherButton*>(
56 shelf_view_->view_model_->view_at(index));
59 int ShelfViewTestAPI::GetLastVisibleIndex() {
60 return shelf_view_->last_visible_index_;
63 bool ShelfViewTestAPI::IsOverflowButtonVisible() {
64 return shelf_view_->overflow_button_->visible();
67 void ShelfViewTestAPI::ShowOverflowBubble() {
68 if (!shelf_view_->IsShowingOverflowBubble())
69 shelf_view_->ToggleOverflowBubble();
72 const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) {
73 return shelf_view_->view_model_->view_at(index)->bounds();
76 const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) {
77 return shelf_view_->view_model_->ideal_bounds(index);
80 void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) {
81 shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms);
84 void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() {
85 if (!shelf_view_->bounds_animator_->IsAnimating())
88 scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver());
89 shelf_view_->bounds_animator_->AddObserver(observer.get());
91 // This nested loop will quit when TestAPIAnimationObserver's
92 // OnBoundsAnimatorDone is called.
93 base::MessageLoop::current()->Run();
95 shelf_view_->bounds_animator_->RemoveObserver(observer.get());
98 bool ShelfViewTestAPI::SameDragType(LauncherItemType typea,
99 LauncherItemType typeb) const {
100 return shelf_view_->SameDragType(typea, typeb);