Chromium Code Reviews| Index: ash/test/launcher_view_test_api.cc |
| diff --git a/ash/test/launcher_view_test_api.cc b/ash/test/launcher_view_test_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f9293a9a455c307a6b793470759a617dc77b6914 |
| --- /dev/null |
| +++ b/ash/test/launcher_view_test_api.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/test/launcher_view_test_api.h" |
| + |
| +#include "ash/launcher/launcher_button.h" |
| +#include "ash/launcher/launcher_view.h" |
| +#include "base/message_loop.h" |
| +#include "ui/views/animation/bounds_animator.h" |
| +#include "ui/views/controls/button/image_button.h" |
| +#include "ui/views/view_model.h" |
| + |
| +namespace { |
| + |
| +// A class used to wait for animations. |
| +class TestAPIAnimationObserver : public views::BoundsAnimatorObserver { |
| + public: |
| + TestAPIAnimationObserver() {} |
| + virtual ~TestAPIAnimationObserver() {} |
| + |
| + // views::BoundsAnimatorObserver overrides: |
| + virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE { |
| + MessageLoop::current()->Quit(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver); |
| +}; |
| + |
| +} // namespace |
| + |
| +namespace ash { |
| +namespace test { |
| + |
| +LauncherViewTestAPI::LauncherViewTestAPI(internal::LauncherView* launcher_view) |
| + : launcher_view_(launcher_view) { |
| +} |
| + |
| +LauncherViewTestAPI::~LauncherViewTestAPI() { |
| +} |
| + |
| +int LauncherViewTestAPI::GetButtonCount() { |
| + return launcher_view_->view_model_->view_size(); |
| +} |
| + |
| +internal::LauncherButton* LauncherViewTestAPI::GetButton(int index) { |
| + // App list button is not a LauncherButton. |
| + if (index == GetButtonCount() - 1) |
| + return NULL; |
| + |
| + return static_cast<internal::LauncherButton*>( |
| + launcher_view_->view_model_->view_at(index)); |
| +} |
| + |
| +int LauncherViewTestAPI::GetLastVisibleIndex() { |
| + return launcher_view_->last_visible_index_; |
| +} |
| + |
| +bool LauncherViewTestAPI::IsOverflowButtonVisible() { |
| + return launcher_view_->overflow_button_->visible(); |
| +} |
| + |
| +void LauncherViewTestAPI::SetAnimationDuration(int duration_ms) { |
| + launcher_view_->bounds_animator_->SetAnimationDuration(duration_ms); |
| +} |
| + |
| +void LauncherViewTestAPI::RunMessageLoopUntilAnimationsDone() { |
| + if (!launcher_view_->bounds_animator_->IsAnimating()) |
| + return; |
| + |
| + scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver()); |
| + launcher_view_->bounds_animator_->AddObserver(observer.get()); |
| + |
| + // This nest loop will quit when TestAPIAnimationObserver's |
|
sky
2012/04/23 20:47:25
nested
xiyuan
2012/04/23 21:01:21
Done.
|
| + // OnBoundsAnimatorDone is called. |
| + MessageLoop::current()->Run(); |
| + |
| + launcher_view_->bounds_animator_->RemoveObserver(observer.get()); |
| +} |
| + |
| +} // namespace test |
| +} // namespace ash |