Make app list recommendations ignore KnownResults.
[chromium-blink-merge.git] / ash / test / shelf_view_test_api.cc
blob48d503b466179eaa6d9c70cad812910d2264c44c
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.
5 #include "ash/test/shelf_view_test_api.h"
7 #include "ash/shelf/overflow_button.h"
8 #include "ash/shelf/shelf_button.h"
9 #include "ash/shelf/shelf_constants.h"
10 #include "ash/shelf/shelf_model.h"
11 #include "ash/shelf/shelf_view.h"
12 #include "base/message_loop/message_loop.h"
13 #include "ui/views/animation/bounds_animator.h"
14 #include "ui/views/view_model.h"
16 namespace {
18 // A class used to wait for animations.
19 class TestAPIAnimationObserver : public views::BoundsAnimatorObserver {
20 public:
21 TestAPIAnimationObserver() {}
22 ~TestAPIAnimationObserver() override {}
24 // views::BoundsAnimatorObserver overrides:
25 void OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) override {}
26 void OnBoundsAnimatorDone(views::BoundsAnimator* animator) override {
27 base::MessageLoop::current()->Quit();
30 private:
31 DISALLOW_COPY_AND_ASSIGN(TestAPIAnimationObserver);
34 } // namespace
36 namespace ash {
37 namespace test {
39 ShelfViewTestAPI::ShelfViewTestAPI(ShelfView* shelf_view)
40 : shelf_view_(shelf_view) {}
42 ShelfViewTestAPI::~ShelfViewTestAPI() {
45 int ShelfViewTestAPI::GetButtonCount() {
46 return shelf_view_->view_model_->view_size();
49 ShelfButton* ShelfViewTestAPI::GetButton(int index) {
50 // App list button is not a ShelfButton.
51 if (shelf_view_->model_->items()[index].type == ash::TYPE_APP_LIST)
52 return NULL;
54 return static_cast<ShelfButton*>(shelf_view_->view_model_->view_at(index));
57 int ShelfViewTestAPI::GetFirstVisibleIndex() {
58 return shelf_view_->first_visible_index_;
61 int ShelfViewTestAPI::GetLastVisibleIndex() {
62 return shelf_view_->last_visible_index_;
65 bool ShelfViewTestAPI::IsOverflowButtonVisible() {
66 return shelf_view_->overflow_button_->visible();
69 void ShelfViewTestAPI::ShowOverflowBubble() {
70 if (!shelf_view_->IsShowingOverflowBubble())
71 shelf_view_->ToggleOverflowBubble();
74 const gfx::Rect& ShelfViewTestAPI::GetBoundsByIndex(int index) {
75 return shelf_view_->view_model_->view_at(index)->bounds();
78 const gfx::Rect& ShelfViewTestAPI::GetIdealBoundsByIndex(int index) {
79 return shelf_view_->view_model_->ideal_bounds(index);
82 void ShelfViewTestAPI::SetAnimationDuration(int duration_ms) {
83 shelf_view_->bounds_animator_->SetAnimationDuration(duration_ms);
86 void ShelfViewTestAPI::RunMessageLoopUntilAnimationsDone() {
87 if (!shelf_view_->bounds_animator_->IsAnimating())
88 return;
90 scoped_ptr<TestAPIAnimationObserver> observer(new TestAPIAnimationObserver());
91 shelf_view_->bounds_animator_->AddObserver(observer.get());
93 // This nested loop will quit when TestAPIAnimationObserver's
94 // OnBoundsAnimatorDone is called.
95 base::MessageLoop::current()->Run();
97 shelf_view_->bounds_animator_->RemoveObserver(observer.get());
100 OverflowBubble* ShelfViewTestAPI::overflow_bubble() {
101 return shelf_view_->overflow_bubble_.get();
104 gfx::Size ShelfViewTestAPI::GetPreferredSize() {
105 return shelf_view_->GetPreferredSize();
108 int ShelfViewTestAPI::GetButtonSize() {
109 return kShelfButtonSize;
112 int ShelfViewTestAPI::GetButtonSpacing() {
113 return kShelfButtonSpacing;
116 void ShelfViewTestAPI::ButtonPressed(views::Button* sender,
117 const ui::Event& event) {
118 return shelf_view_->ButtonPressed(sender, event);
121 bool ShelfViewTestAPI::SameDragType(ShelfItemType typea,
122 ShelfItemType typeb) const {
123 return shelf_view_->SameDragType(typea, typeb);
126 void ShelfViewTestAPI::SetShelfDelegate(ShelfDelegate* delegate) {
127 shelf_view_->delegate_ = delegate;
130 gfx::Rect ShelfViewTestAPI::GetBoundsForDragInsertInScreen() {
131 return shelf_view_->GetBoundsForDragInsertInScreen();
134 bool ShelfViewTestAPI::IsRippedOffFromShelf() {
135 return shelf_view_->dragged_off_shelf_;
138 bool ShelfViewTestAPI::DraggedItemFromOverflowToShelf() {
139 return shelf_view_->dragged_off_from_overflow_to_shelf_;
142 ShelfButtonPressedMetricTracker*
143 ShelfViewTestAPI::shelf_button_pressed_metric_tracker() {
144 return &(shelf_view_->shelf_button_pressed_metric_tracker_);
147 } // namespace test
148 } // namespace ash