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/launcher_view_test_api.h"
7 #include "ash/launcher/launcher_button.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/launcher/launcher_view.h"
10 #include "ash/launcher/overflow_button.h"
11 #include "base/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 LauncherViewTestAPI::LauncherViewTestAPI(internal::LauncherView
* launcher_view
)
40 : launcher_view_(launcher_view
) {
43 LauncherViewTestAPI::~LauncherViewTestAPI() {
46 int LauncherViewTestAPI::GetButtonCount() {
47 return launcher_view_
->view_model_
->view_size();
50 internal::LauncherButton
* LauncherViewTestAPI::GetButton(int index
) {
51 // App list button is not a LauncherButton.
52 if (launcher_view_
->model_
->items()[index
].type
== ash::TYPE_APP_LIST
)
55 return static_cast<internal::LauncherButton
*>(
56 launcher_view_
->view_model_
->view_at(index
));
59 int LauncherViewTestAPI::GetLastVisibleIndex() {
60 return launcher_view_
->last_visible_index_
;
63 bool LauncherViewTestAPI::IsOverflowButtonVisible() {
64 return launcher_view_
->overflow_button_
->visible();
67 void LauncherViewTestAPI::ShowOverflowBubble() {
68 if (!launcher_view_
->IsShowingOverflowBubble())
69 launcher_view_
->ToggleOverflowBubble();
72 const gfx::Rect
& LauncherViewTestAPI::GetBoundsByIndex(int index
) {
73 return launcher_view_
->view_model_
->view_at(index
)->bounds();
76 const gfx::Rect
& LauncherViewTestAPI::GetIdealBoundsByIndex(int index
) {
77 return launcher_view_
->view_model_
->ideal_bounds(index
);
80 void LauncherViewTestAPI::SetAnimationDuration(int duration_ms
) {
81 launcher_view_
->bounds_animator_
->SetAnimationDuration(duration_ms
);
84 void LauncherViewTestAPI::RunMessageLoopUntilAnimationsDone() {
85 if (!launcher_view_
->bounds_animator_
->IsAnimating())
88 scoped_ptr
<TestAPIAnimationObserver
> observer(new TestAPIAnimationObserver());
89 launcher_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 launcher_view_
->bounds_animator_
->RemoveObserver(observer
.get());