18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file. 48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/test/shelf_view_test_api.h" 68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/shelf/overflow_button.h" 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_button.h" 9a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ash/shelf/shelf_constants.h" 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model.h" 118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ash/shelf/shelf_view.h" 128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/message_loop/message_loop.h" 138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ui/views/animation/bounds_animator.h" 148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ui/views/view_model.h" 158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace { 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// A class used to wait for animations. 198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class TestAPIAnimationObserver : public views::BoundsAnimatorObserver { 208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public: 218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) TestAPIAnimationObserver() {} 228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual ~TestAPIAnimationObserver() {} 238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // views::BoundsAnimatorObserver overrides: 258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnBoundsAnimatorProgressed( 268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) views::BoundsAnimator* animator) OVERRIDE {} 278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE { 288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::MessageLoop::current()->Quit(); 298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private: 328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver); 338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}; 348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} // namespace 368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace ash { 388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace test { 398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochShelfViewTestAPI::ShelfViewTestAPI(ShelfView* shelf_view) 41c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch : shelf_view_(shelf_view) {} 428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)ShelfViewTestAPI::~ShelfViewTestAPI() { 448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int ShelfViewTestAPI::GetButtonCount() { 478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return shelf_view_->view_model_->view_size(); 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 50c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochShelfButton* ShelfViewTestAPI::GetButton(int index) { 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // App list button is not a ShelfButton. 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (shelf_view_->model_->items()[index].type == ash::TYPE_APP_LIST) 538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return NULL; 548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 55c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return static_cast<ShelfButton*>(shelf_view_->view_model_->view_at(index)); 568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)int ShelfViewTestAPI::GetFirstVisibleIndex() { 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return shelf_view_->first_visible_index_; 60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int ShelfViewTestAPI::GetLastVisibleIndex() { 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return shelf_view_->last_visible_index_; 648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)bool ShelfViewTestAPI::IsOverflowButtonVisible() { 678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return shelf_view_->overflow_button_->visible(); 688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void ShelfViewTestAPI::ShowOverflowBubble() { 718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (!shelf_view_->IsShowingOverflowBubble()) 728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) shelf_view_->ToggleOverflowBubble(); 738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) { 768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return shelf_view_->view_model_->view_at(index)->bounds(); 778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) { 808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return shelf_view_->view_model_->ideal_bounds(index); 818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) { 848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms); 858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() { 888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (!shelf_view_->bounds_animator_->IsAnimating()) 898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return; 908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver()); 928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) shelf_view_->bounds_animator_->AddObserver(observer.get()); 938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // This nested loop will quit when TestAPIAnimationObserver's 958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // OnBoundsAnimatorDone is called. 968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::MessageLoop::current()->Run(); 978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) shelf_view_->bounds_animator_->RemoveObserver(observer.get()); 998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 101c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochOverflowBubble* ShelfViewTestAPI::overflow_bubble() { 102f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return shelf_view_->overflow_bubble_.get(); 103f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 104f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 105f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)gfx::Size ShelfViewTestAPI::GetPreferredSize() { 106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return shelf_view_->GetPreferredSize(); 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)int ShelfViewTestAPI::GetButtonSize() { 110a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return kShelfButtonSize; 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 113f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)int ShelfViewTestAPI::GetButtonSpacing() { 114a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return kShelfButtonSpacing; 115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool ShelfViewTestAPI::SameDragType(ShelfItemType typea, 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShelfItemType typeb) const { 1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return shelf_view_->SameDragType(typea, typeb); 1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ShelfViewTestAPI::SetShelfDelegate(ShelfDelegate* delegate) { 123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) shelf_view_->delegate_ = delegate; 124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 126f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)gfx::Rect ShelfViewTestAPI::GetBoundsForDragInsertInScreen() { 127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return shelf_view_->GetBoundsForDragInsertInScreen(); 128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool ShelfViewTestAPI::IsRippedOffFromShelf() { 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return shelf_view_->dragged_off_shelf_; 132a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool ShelfViewTestAPI::DraggedItemFromOverflowToShelf() { 135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return shelf_view_->dragged_off_from_overflow_to_shelf_; 136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} // namespace test 1398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} // namespace ash 140