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 "ui/app_list/views/test/apps_grid_view_test_api.h"
6
7#include "ui/app_list/views/app_list_item_view.h"
8#include "ui/app_list/views/apps_grid_view.h"
9#include "ui/events/event.h"
10
11namespace app_list {
12namespace test {
13
14AppsGridViewTestApi::AppsGridViewTestApi(AppsGridView* view)
15    : view_(view) {
16}
17
18AppsGridViewTestApi::~AppsGridViewTestApi() {
19}
20
21views::View* AppsGridViewTestApi::GetViewAtModelIndex(int index) const {
22  return view_->view_model_.view_at(index);
23}
24
25void AppsGridViewTestApi::LayoutToIdealBounds() {
26  view_->bounds_animator_.Cancel();
27  view_->Layout();
28}
29
30void AppsGridViewTestApi::SetPageFlipDelay(int page_flip_delay_in_ms) {
31  view_->page_flip_delay_in_ms_ = page_flip_delay_in_ms;
32}
33
34void AppsGridViewTestApi::PressItemAt(int index) {
35  GetViewAtModelIndex(index)->OnKeyPressed(
36      ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, false));
37}
38
39void AppsGridViewTestApi::DisableSynchronousDrag() {
40#if defined(OS_WIN)
41  DCHECK(view_->synchronous_drag_ == NULL) << "DisableSynchronousDrag needs to "
42                                              "be called before "
43                                              "synchronous_drag_ is set up.";
44  view_->use_synchronous_drag_ = false;
45#endif
46}
47
48bool AppsGridViewTestApi::HasPendingPageFlip() const {
49  return view_->page_flip_timer_.IsRunning() ||
50         view_->pagination_model()->has_transition();
51}
52
53}  // namespace test
54}  // namespace app_list
55