apps_grid_controller_test_helper.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
1// Copyright 2013 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#ifndef UI_APP_LIST_COCOA_TEST_APPS_GRID_CONTROLLER_TEST_HELPER_H_
6#define UI_APP_LIST_COCOA_TEST_APPS_GRID_CONTROLLER_TEST_HELPER_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "base/message_loop/message_loop.h"
10#import "ui/base/test/ui_cocoa_test_helper.h"
11
12@class AppsGridController;
13
14namespace app_list {
15
16class AppListModel;
17
18namespace test {
19
20class AppListTestModel;
21
22class AppsGridControllerTestHelper : public ui::CocoaTest {
23 public:
24  static const size_t kItemsPerPage;
25
26  AppsGridControllerTestHelper();
27  virtual ~AppsGridControllerTestHelper();
28
29  void SetUpWithGridController(AppsGridController* grid_controller);
30
31 protected:
32  // Send a click to the test window in the centre of |view|.
33  void SimulateClick(NSView* view);
34
35  // Send a key action using handleCommandBySelector.
36  void SimulateKeyAction(SEL c);
37
38  void SimulateMouseEnterItemAt(size_t index);
39  void SimulateMouseExitItemAt(size_t index);
40
41  // Do a bulk replacement of the items in the grid.
42  void ReplaceTestModel(int item_count);
43
44  // Get a string representation of the items as they are currently ordered in
45  // the view. Each page will start and end with a | character.
46  std::string GetViewContent() const;
47
48  // Find the page containing |item_id|, and return the index of that page.
49  // Return NSNotFound if the item is not found, or if the item appears more
50  // than once.
51  size_t GetPageIndexForItem(int item_id) const;
52
53  void DelayForCollectionView();
54  void SinkEvents();
55
56  NSButton* GetItemViewAt(size_t index);
57  NSCollectionView* GetPageAt(size_t index);
58  NSView* GetSelectedView();
59
60  AppListTestModel* model();
61
62  virtual void ResetModel(scoped_ptr<AppListModel> model);
63
64  AppsGridController* apps_grid_controller_;
65
66 private:
67  base::MessageLoopForUI message_loop_;
68
69  DISALLOW_COPY_AND_ASSIGN(AppsGridControllerTestHelper);
70};
71
72}  // namespace test
73}  // namespace app_list
74
75#endif  // UI_APP_LIST_COCOA_TEST_APPS_GRID_CONTROLLER_TEST_HELPER_H_
76