OLD | NEW |
---|---|
(Empty) | |
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/launcher_view_test_api.h" | |
6 | |
7 #include "ash/launcher/launcher_button.h" | |
8 #include "ash/launcher/launcher_view.h" | |
9 #include "base/message_loop.h" | |
10 #include "ui/views/animation/bounds_animator.h" | |
11 #include "ui/views/controls/button/image_button.h" | |
12 #include "ui/views/view_model.h" | |
13 | |
14 namespace { | |
15 | |
16 // A class used to wait for animations. | |
17 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver { | |
18 public: | |
19 TestAPIAnimationObserver() {} | |
20 virtual ~TestAPIAnimationObserver() {} | |
21 | |
22 // views::BoundsAnimatorObserver overrides: | |
23 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE { | |
24 MessageLoop::current()->Quit(); | |
25 } | |
26 | |
27 private: | |
28 DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver); | |
29 }; | |
30 | |
31 } // namespace | |
32 | |
33 namespace ash { | |
34 namespace test { | |
35 | |
36 LauncherViewTestAPI::LauncherViewTestAPI(internal::LauncherView* launcher_view) | |
37 : launcher_view_(launcher_view) { | |
38 } | |
39 | |
40 LauncherViewTestAPI::~LauncherViewTestAPI() { | |
41 } | |
42 | |
43 int LauncherViewTestAPI::GetButtonCount() { | |
44 return launcher_view_->view_model_->view_size(); | |
45 } | |
46 | |
47 internal::LauncherButton* LauncherViewTestAPI::GetButton(int index) { | |
48 // App list button is not a LauncherButton. | |
49 if (index == GetButtonCount() - 1) | |
50 return NULL; | |
51 | |
52 return static_cast<internal::LauncherButton*>( | |
53 launcher_view_->view_model_->view_at(index)); | |
54 } | |
55 | |
56 int LauncherViewTestAPI::GetLastVisibleIndex() { | |
57 return launcher_view_->last_visible_index_; | |
58 } | |
59 | |
60 bool LauncherViewTestAPI::IsOverflowButtonVisible() { | |
61 return launcher_view_->overflow_button_->visible(); | |
62 } | |
63 | |
64 void LauncherViewTestAPI::SetAnimationDuration(int duration_ms) { | |
65 launcher_view_->bounds_animator_->SetAnimationDuration(duration_ms); | |
66 } | |
67 | |
68 void LauncherViewTestAPI::RunMessageLoopUntilAnimationsDone() { | |
69 if (!launcher_view_->bounds_animator_->IsAnimating()) | |
70 return; | |
71 | |
72 scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver()); | |
73 launcher_view_->bounds_animator_->AddObserver(observer.get()); | |
74 | |
75 // This nest loop will quit when TestAPIAnimationObserver's | |
sky
2012/04/23 20:47:25
nested
xiyuan
2012/04/23 21:01:21
Done.
| |
76 // OnBoundsAnimatorDone is called. | |
77 MessageLoop::current()->Run(); | |
78 | |
79 launcher_view_->bounds_animator_->RemoveObserver(observer.get()); | |
80 } | |
81 | |
82 } // namespace test | |
83 } // namespace ash | |
OLD | NEW |