| 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/foundation_util.h" | 5 #include "base/mac/foundation_util.h" |
| 6 #include "base/mac/scoped_nsobject.h" | 6 #include "base/mac/scoped_nsobject.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "skia/ext/skia_utils_mac.h" | 8 #include "skia/ext/skia_utils_mac.h" |
| 9 #import "testing/gtest_mac.h" | 9 #import "testing/gtest_mac.h" |
| 10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 NSArray* subviews = [GetPageAt(0) subviews]; | 202 NSArray* subviews = [GetPageAt(0) subviews]; |
| 203 EXPECT_EQ(1u, [subviews count]); | 203 EXPECT_EQ(1u, [subviews count]); |
| 204 | 204 |
| 205 // Note that using GetItemViewAt(0) here also works, and returns non-nil even | 205 // Note that using GetItemViewAt(0) here also works, and returns non-nil even |
| 206 // without the delay, but a "click" on it does not register without the delay. | 206 // without the delay, but a "click" on it does not register without the delay. |
| 207 NSView* subview = [subviews objectAtIndex:0]; | 207 NSView* subview = [subviews objectAtIndex:0]; |
| 208 | 208 |
| 209 // Launch the item. | 209 // Launch the item. |
| 210 SimulateClick(subview); | 210 SimulateClick(subview); |
| 211 SinkEvents(); | 211 SinkEvents(); |
| 212 EXPECT_EQ(1, delegate()->activate_count()); | 212 EXPECT_EQ(1, model()->activate_count()); |
| 213 EXPECT_EQ(std::string("Item 0"), delegate()->last_activated()->title()); | 213 ASSERT_TRUE(model()->last_activated()); |
| 214 EXPECT_EQ(std::string("Item 0"), model()->last_activated()->title()); |
| 214 } | 215 } |
| 215 | 216 |
| 216 // Test activating an item on the second page (the 17th item). | 217 // Test activating an item on the second page (the 17th item). |
| 217 TEST_F(AppsGridControllerTest, DISABLED_TwoPageModel) { | 218 TEST_F(AppsGridControllerTest, DISABLED_TwoPageModel) { |
| 218 DelayForCollectionView(); | 219 DelayForCollectionView(); |
| 219 ReplaceTestModel(kItemsPerPage * 2); | 220 ReplaceTestModel(kItemsPerPage * 2); |
| 220 [apps_grid_controller_ scrollToPage:1]; | 221 [apps_grid_controller_ scrollToPage:1]; |
| 221 | 222 |
| 222 // The NSScrollView animator ignores the duration configured on the | 223 // The NSScrollView animator ignores the duration configured on the |
| 223 // NSAnimationContext (set by CocoaTest::Init), so we need to delay here. | 224 // NSAnimationContext (set by CocoaTest::Init), so we need to delay here. |
| 224 DelayForCollectionView(); | 225 DelayForCollectionView(); |
| 225 NSArray* subviews = [GetPageAt(1) subviews]; | 226 NSArray* subviews = [GetPageAt(1) subviews]; |
| 226 NSView* subview = [subviews objectAtIndex:0]; | 227 NSView* subview = [subviews objectAtIndex:0]; |
| 227 // Launch the item. | 228 // Launch the item. |
| 228 SimulateClick(subview); | 229 SimulateClick(subview); |
| 229 SinkEvents(); | 230 SinkEvents(); |
| 230 EXPECT_EQ(1, delegate()->activate_count()); | 231 EXPECT_EQ(1, model()->activate_count()); |
| 231 EXPECT_EQ(std::string("Item 16"), delegate()->last_activated()->title()); | 232 ASSERT_TRUE(model()->last_activated()); |
| 233 EXPECT_EQ(std::string("Item 16"), model()->last_activated()->title()); |
| 232 } | 234 } |
| 233 | 235 |
| 234 // Test setModel. | 236 // Test setModel. |
| 235 TEST_F(AppsGridControllerTest, ReplaceModel) { | 237 TEST_F(AppsGridControllerTest, ReplaceModel) { |
| 236 const size_t kOrigItems = 1; | 238 const size_t kOrigItems = 1; |
| 237 const size_t kNewItems = 2; | 239 const size_t kNewItems = 2; |
| 238 | 240 |
| 239 model()->PopulateApps(kOrigItems); | 241 model()->PopulateApps(kOrigItems); |
| 240 EXPECT_EQ(kOrigItems, [[GetPageAt(0) content] count]); | 242 EXPECT_EQ(kOrigItems, [[GetPageAt(0) content] count]); |
| 241 | 243 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 EXPECT_EQ(4u, [apps_grid_controller_ selectedItemIndex]); | 310 EXPECT_EQ(4u, [apps_grid_controller_ selectedItemIndex]); |
| 309 | 311 |
| 310 SimulateKeyAction(@selector(moveUp:)); | 312 SimulateKeyAction(@selector(moveUp:)); |
| 311 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); | 313 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); |
| 312 | 314 |
| 313 // Go to the third item, and launch it. | 315 // Go to the third item, and launch it. |
| 314 SimulateKeyAction(@selector(moveRight:)); | 316 SimulateKeyAction(@selector(moveRight:)); |
| 315 SimulateKeyAction(@selector(moveRight:)); | 317 SimulateKeyAction(@selector(moveRight:)); |
| 316 EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]); | 318 EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]); |
| 317 SimulateKeyAction(@selector(insertNewline:)); | 319 SimulateKeyAction(@selector(insertNewline:)); |
| 318 EXPECT_EQ(1, delegate()->activate_count()); | 320 EXPECT_EQ(1, model()->activate_count()); |
| 319 EXPECT_EQ(std::string("Item 2"), delegate()->last_activated()->title()); | 321 ASSERT_TRUE(model()->last_activated()); |
| 322 EXPECT_EQ(std::string("Item 2"), model()->last_activated()->title()); |
| 320 } | 323 } |
| 321 | 324 |
| 322 // Tests keyboard navigation across pages. | 325 // Tests keyboard navigation across pages. |
| 323 TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) { | 326 TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) { |
| 324 model()->PopulateApps(kItemsPerPage + 10); | 327 model()->PopulateApps(kItemsPerPage + 10); |
| 325 EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]); | 328 EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]); |
| 326 EXPECT_EQ(10u, [[GetPageAt(1) content] count]); | 329 EXPECT_EQ(10u, [[GetPageAt(1) content] count]); |
| 327 | 330 |
| 328 // Moving Left, Up, or PageUp from the top-left corner of the first page does | 331 // Moving Left, Up, or PageUp from the top-left corner of the first page does |
| 329 // nothing. | 332 // nothing. |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 EXPECT_EQ(nil, menu); | 923 EXPECT_EQ(nil, menu); |
| 921 | 924 |
| 922 item_two_model->SetMenuReadyForTesting(true); | 925 item_two_model->SetMenuReadyForTesting(true); |
| 923 menu = [page menuForEvent:mouse_at_cell_1]; | 926 menu = [page menuForEvent:mouse_at_cell_1]; |
| 924 EXPECT_EQ(1, [menu numberOfItems]); | 927 EXPECT_EQ(1, [menu numberOfItems]); |
| 925 EXPECT_NSEQ(@"Menu For: Item Two", [[menu itemAtIndex:0] title]); | 928 EXPECT_NSEQ(@"Menu For: Item Two", [[menu itemAtIndex:0] title]); |
| 926 } | 929 } |
| 927 | 930 |
| 928 } // namespace test | 931 } // namespace test |
| 929 } // namespace app_list | 932 } // namespace app_list |
| OLD | NEW |