- add sources.
[platform/framework/web/crosswalk.git] / src / ash / test / shelf_view_test_api.cc
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.
4
5 #include "ash/test/shelf_view_test_api.h"
6
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"
14
15 namespace {
16
17 // A class used to wait for animations.
18 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver {
19  public:
20   TestAPIAnimationObserver() {}
21   virtual ~TestAPIAnimationObserver() {}
22
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();
28   }
29
30  private:
31   DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
32 };
33
34 }  // namespace
35
36 namespace ash {
37 namespace test {
38
39 ShelfViewTestAPI::ShelfViewTestAPI(internal::ShelfView* shelf_view)
40     : shelf_view_(shelf_view) {
41 }
42
43 ShelfViewTestAPI::~ShelfViewTestAPI() {
44 }
45
46 int ShelfViewTestAPI::GetButtonCount() {
47   return shelf_view_->view_model_->view_size();
48 }
49
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)
53     return NULL;
54
55   return static_cast<internal::LauncherButton*>(
56       shelf_view_->view_model_->view_at(index));
57 }
58
59 int ShelfViewTestAPI::GetLastVisibleIndex() {
60   return shelf_view_->last_visible_index_;
61 }
62
63 bool ShelfViewTestAPI::IsOverflowButtonVisible() {
64   return shelf_view_->overflow_button_->visible();
65 }
66
67 void ShelfViewTestAPI::ShowOverflowBubble() {
68   if (!shelf_view_->IsShowingOverflowBubble())
69     shelf_view_->ToggleOverflowBubble();
70 }
71
72 const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) {
73   return shelf_view_->view_model_->view_at(index)->bounds();
74 }
75
76 const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) {
77   return shelf_view_->view_model_->ideal_bounds(index);
78 }
79
80 void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) {
81   shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms);
82 }
83
84 void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() {
85   if (!shelf_view_->bounds_animator_->IsAnimating())
86     return;
87
88   scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver());
89   shelf_view_->bounds_animator_->AddObserver(observer.get());
90
91   // This nested loop will quit when TestAPIAnimationObserver's
92   // OnBoundsAnimatorDone is called.
93   base::MessageLoop::current()->Run();
94
95   shelf_view_->bounds_animator_->RemoveObserver(observer.get());
96 }
97
98 bool ShelfViewTestAPI::SameDragType(LauncherItemType typea,
99                                     LauncherItemType typeb) const {
100   return shelf_view_->SameDragType(typea, typeb);
101 }
102
103 }  // namespace test
104 }  // namespace ash