OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac/scoped_nsobject.h" | 5 #include "base/mac/scoped_nsobject.h" |
6 #import "testing/gtest_mac.h" | 6 #import "testing/gtest_mac.h" |
7 #import "ui/app_list/cocoa/app_list_view_controller.h" | 7 #import "ui/app_list/cocoa/app_list_view_controller.h" |
8 #import "ui/app_list/cocoa/apps_grid_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" | 9 #import "ui/app_list/cocoa/test/apps_grid_controller_test_helper.h" |
10 #include "ui/app_list/test/app_list_test_model.h" | 10 #include "ui/app_list/test/app_list_test_model.h" |
11 #include "ui/app_list/test/app_list_test_view_delegate.h" | 11 #include "ui/app_list/test/app_list_test_view_delegate.h" |
12 | 12 |
13 namespace app_list { | 13 namespace app_list { |
14 namespace test { | 14 namespace test { |
15 | 15 |
16 class AppListViewControllerTest : public AppsGridControllerTestHelper { | 16 class AppListViewControllerTest : public AppsGridControllerTestHelper { |
17 public: | 17 public: |
18 AppListViewControllerTest() {} | 18 AppListViewControllerTest() {} |
19 | 19 |
20 virtual void SetUp() OVERRIDE { | 20 virtual void SetUp() OVERRIDE { |
21 app_list_view_controller_.reset([[AppListViewController alloc] init]); | 21 app_list_view_controller_.reset([[AppListViewController alloc] init]); |
22 scoped_ptr<AppListTestViewDelegate> delegate(new AppListTestViewDelegate); | 22 delegate_.reset(new AppListTestViewDelegate); |
23 [app_list_view_controller_ | 23 [app_list_view_controller_ setDelegate:delegate_.get()]; |
24 setDelegate:delegate.PassAs<app_list::AppListViewDelegate>()]; | |
25 SetUpWithGridController([app_list_view_controller_ appsGridController]); | 24 SetUpWithGridController([app_list_view_controller_ appsGridController]); |
26 [[test_window() contentView] addSubview:[app_list_view_controller_ view]]; | 25 [[test_window() contentView] addSubview:[app_list_view_controller_ view]]; |
27 } | 26 } |
28 | 27 |
29 virtual void TearDown() OVERRIDE { | 28 virtual void TearDown() OVERRIDE { |
30 [app_list_view_controller_ | 29 [app_list_view_controller_ setDelegate:NULL]; |
31 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()]; | |
32 app_list_view_controller_.reset(); | 30 app_list_view_controller_.reset(); |
33 AppsGridControllerTestHelper::TearDown(); | 31 AppsGridControllerTestHelper::TearDown(); |
34 } | 32 } |
35 | 33 |
36 void ReplaceTestModel(int item_count) { | 34 void ReplaceTestModel(int item_count) { |
37 [app_list_view_controller_ | 35 [app_list_view_controller_ setDelegate:NULL]; |
38 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()]; | 36 delegate_.reset(new AppListTestViewDelegate); |
39 scoped_ptr<AppListTestViewDelegate> delegate(new AppListTestViewDelegate); | 37 delegate_->ReplaceTestModel(item_count); |
40 delegate->ReplaceTestModel(item_count); | 38 [app_list_view_controller_ setDelegate:delegate_.get()]; |
41 [app_list_view_controller_ | |
42 setDelegate:delegate.PassAs<app_list::AppListViewDelegate>()]; | |
43 } | 39 } |
44 | 40 |
45 AppListTestViewDelegate* delegate() { | 41 AppListTestModel* model() { return delegate_->GetTestModel(); } |
46 return static_cast<AppListTestViewDelegate*>( | |
47 [app_list_view_controller_ delegate]); | |
48 } | |
49 | |
50 AppListTestModel* model() { | |
51 return delegate()->GetTestModel(); | |
52 } | |
53 | 42 |
54 protected: | 43 protected: |
| 44 scoped_ptr<AppListTestViewDelegate> delegate_; |
55 base::scoped_nsobject<AppListViewController> app_list_view_controller_; | 45 base::scoped_nsobject<AppListViewController> app_list_view_controller_; |
56 | 46 |
57 private: | 47 private: |
58 DISALLOW_COPY_AND_ASSIGN(AppListViewControllerTest); | 48 DISALLOW_COPY_AND_ASSIGN(AppListViewControllerTest); |
59 }; | 49 }; |
60 | 50 |
61 TEST_VIEW(AppListViewControllerTest, [app_list_view_controller_ view]); | 51 TEST_VIEW(AppListViewControllerTest, [app_list_view_controller_ view]); |
62 | 52 |
63 // Test that adding and removing pages updates the pager. | 53 // Test that adding and removing pages updates the pager. |
64 TEST_F(AppListViewControllerTest, PagerSegmentCounts) { | 54 TEST_F(AppListViewControllerTest, PagerSegmentCounts) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // Replace with a single page model, and ensure we go back to the first page. | 88 // Replace with a single page model, and ensure we go back to the first page. |
99 ReplaceTestModel(1); | 89 ReplaceTestModel(1); |
100 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 90 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
101 EXPECT_EQ(0, [pager selectedSegment]); | 91 EXPECT_EQ(0, [pager selectedSegment]); |
102 EXPECT_EQ(1, [pager segmentCount]); | 92 EXPECT_EQ(1, [pager segmentCount]); |
103 EXPECT_EQ(1.0, [apps_grid_controller_ visiblePortionOfPage:0]); | 93 EXPECT_EQ(1.0, [apps_grid_controller_ visiblePortionOfPage:0]); |
104 } | 94 } |
105 | 95 |
106 } // namespace test | 96 } // namespace test |
107 } // namespace app_list | 97 } // namespace app_list |
OLD | NEW |