Roll leveldb from r73 to r75.
[chromium-blink-merge.git] / ash / test / launcher_view_test_api.cc
blob094ef895782b740833153032f0aa00def4c53367
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"
15 namespace {
17 // A class used to wait for animations.
18 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver {
19 public:
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();
30 private:
31 DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
34 } // namespace
36 namespace ash {
37 namespace test {
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)
53 return NULL;
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())
86 return;
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());
98 } // namespace test
99 } // namespace ash