Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / app_list / cocoa / app_list_view_controller_unittest.mm
blob5133ea81cd87fa8cb21e41ff66c957c2617dac8b
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.
5 #include "base/mac/scoped_nsobject.h"
6 #import "testing/gtest_mac.h"
7 #import "ui/app_list/cocoa/app_list_view_controller.h"
8 #import "ui/app_list/cocoa/apps_grid_controller.h"
9 #import "ui/app_list/cocoa/test/apps_grid_controller_test_helper.h"
10 #include "ui/app_list/test/app_list_test_model.h"
11 #include "ui/app_list/test/app_list_test_view_delegate.h"
13 namespace app_list {
14 namespace test {
16 class AppListViewControllerTest : public AppsGridControllerTestHelper {
17  public:
18   AppListViewControllerTest() {}
20   void SetUp() override {
21     app_list_view_controller_.reset([[AppListViewController alloc] init]);
22     delegate_.reset(new AppListTestViewDelegate);
23     [app_list_view_controller_ setDelegate:delegate_.get()];
24     SetUpWithGridController([app_list_view_controller_ appsGridController]);
25     [[test_window() contentView] addSubview:[app_list_view_controller_ view]];
26   }
28   void TearDown() override {
29     [app_list_view_controller_ setDelegate:NULL];
30     app_list_view_controller_.reset();
31     AppsGridControllerTestHelper::TearDown();
32   }
34   void ReplaceTestModel(int item_count) {
35     [app_list_view_controller_ setDelegate:NULL];
36     delegate_.reset(new AppListTestViewDelegate);
37     delegate_->ReplaceTestModel(item_count);
38     [app_list_view_controller_ setDelegate:delegate_.get()];
39   }
41   AppListTestModel* model() { return delegate_->GetTestModel(); }
43  protected:
44   scoped_ptr<AppListTestViewDelegate> delegate_;
45   base::scoped_nsobject<AppListViewController> app_list_view_controller_;
47  private:
48   DISALLOW_COPY_AND_ASSIGN(AppListViewControllerTest);
51 TEST_VIEW(AppListViewControllerTest, [app_list_view_controller_ view]);
53 // Test that adding and removing pages updates the pager.
54 TEST_F(AppListViewControllerTest, PagerSegmentCounts) {
55   NSSegmentedControl* pager = [app_list_view_controller_ pagerControl];
56   EXPECT_EQ(1, [pager segmentCount]);
58   ReplaceTestModel(kItemsPerPage * 2);
59   EXPECT_EQ(2, [pager segmentCount]);
60   model()->PopulateApps(1);
61   EXPECT_EQ(3, [pager segmentCount]);
63   ReplaceTestModel(1);
64   EXPECT_EQ(1, [pager segmentCount]);
67 // Test that clicking the pager changes pages.
68 TEST_F(AppListViewControllerTest, PagerChangingPage) {
69   NSSegmentedControl* pager = [app_list_view_controller_ pagerControl];
70   ReplaceTestModel(kItemsPerPage * 3);
71   EXPECT_EQ(3, [pager segmentCount]);
73   EXPECT_EQ(0, [pager selectedSegment]);
74   EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
75   EXPECT_EQ(1.0, [apps_grid_controller_ visiblePortionOfPage:0]);
76   EXPECT_EQ(0.0, [apps_grid_controller_ visiblePortionOfPage:1]);
78   // Emulate a click on the second segment to navigate to the second page.
79   [pager setSelectedSegment:1];
80   [[pager target] performSelector:[pager action]
81                        withObject:pager];
83   EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
84   EXPECT_EQ(1, [pager selectedSegment]);
85   EXPECT_EQ(0.0, [apps_grid_controller_ visiblePortionOfPage:0]);
86   EXPECT_EQ(1.0, [apps_grid_controller_ visiblePortionOfPage:1]);
88   // Replace with a single page model, and ensure we go back to the first page.
89   ReplaceTestModel(1);
90   EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
91   EXPECT_EQ(0, [pager selectedSegment]);
92   EXPECT_EQ(1, [pager segmentCount]);
93   EXPECT_EQ(1.0, [apps_grid_controller_ visiblePortionOfPage:0]);
96 }  // namespace test
97 }  // namespace app_list