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_model.h" 9 #include "ash/launcher/launcher_view.h" 10 #include "ash/launcher/overflow_button.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 LauncherViewTestAPI::LauncherViewTestAPI(internal::LauncherView* launcher_view) 40 : launcher_view_(launcher_view) { 41 } 42 43 LauncherViewTestAPI::~LauncherViewTestAPI() { 44 } 45 46 int LauncherViewTestAPI::GetButtonCount() { 47 return launcher_view_->view_model_->view_size(); 48 } 49 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; 54 55 return static_cast<internal::LauncherButton*>( 56 launcher_view_->view_model_->view_at(index)); 57 } 58 59 int LauncherViewTestAPI::GetLastVisibleIndex() { 60 return launcher_view_->last_visible_index_; 61 } 62 63 bool LauncherViewTestAPI::IsOverflowButtonVisible() { 64 return launcher_view_->overflow_button_->visible(); 65 } 66 67 void LauncherViewTestAPI::ShowOverflowBubble() { 68 if (!launcher_view_->IsShowingOverflowBubble()) 69 launcher_view_->ToggleOverflowBubble(); 70 } 71 72 const gfx::Rect& LauncherViewTestAPI::GetBoundsByIndex(int index) { 73 return launcher_view_->view_model_->view_at(index)->bounds(); 74 } 75 76 const gfx::Rect& LauncherViewTestAPI::GetIdealBoundsByIndex(int index) { 77 return launcher_view_->view_model_->ideal_bounds(index); 78 } 79 80 void LauncherViewTestAPI::SetAnimationDuration(int duration_ms) { 81 launcher_view_->bounds_animator_->SetAnimationDuration(duration_ms); 82 } 83 84 void LauncherViewTestAPI::RunMessageLoopUntilAnimationsDone() { 85 if (!launcher_view_->bounds_animator_->IsAnimating()) 86 return; 87 88 scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver()); 89 launcher_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 launcher_view_->bounds_animator_->RemoveObserver(observer.get()); 96 } 97 98 bool LauncherViewTestAPI::SameDragType(LauncherItemType typea, 99 LauncherItemType typeb) const { 100 return launcher_view_->SameDragType(typea, typeb); 101 } 102 103 } // namespace test 104 } // namespace ash 105