| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 scoped_ptr<AppListTestViewDelegate> owned_delegate_; | 118 scoped_ptr<AppListTestViewDelegate> owned_delegate_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(AppsGridControllerTest); | 120 DISALLOW_COPY_AND_ASSIGN(AppsGridControllerTest); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 class AppListItemWithMenu : public AppListItemModel { | 123 class AppListItemWithMenu : public AppListItemModel { |
| 124 public: | 124 public: |
| 125 AppListItemWithMenu(const std::string& title) | 125 AppListItemWithMenu(const std::string& title) |
| 126 : menu_model_(NULL), | 126 : menu_model_(NULL), |
| 127 menu_ready_(true) { | 127 menu_ready_(true) { |
| 128 SetTitle(title); | 128 SetTitleAndFullName(title, title); |
| 129 menu_model_.AddItem(0, UTF8ToUTF16("Menu For: " + title)); | 129 menu_model_.AddItem(0, UTF8ToUTF16("Menu For: " + title)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void SetMenuReadyForTesting(bool ready) { | 132 void SetMenuReadyForTesting(bool ready) { |
| 133 menu_ready_ = ready; | 133 menu_ready_ = ready; |
| 134 } | 134 } |
| 135 | 135 |
| 136 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE { | 136 virtual ui::MenuModel* GetContextMenuModel() OVERRIDE { |
| 137 if (!menu_ready_) | 137 if (!menu_ready_) |
| 138 return NULL; | 138 return NULL; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 427 |
| 428 // Add an item (PopulateApps will create a duplicate "Item 0"). | 428 // Add an item (PopulateApps will create a duplicate "Item 0"). |
| 429 model()->PopulateApps(1); | 429 model()->PopulateApps(1); |
| 430 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); | 430 EXPECT_EQ(3u, [[GetPageAt(0) content] count]); |
| 431 NSButton* button = GetItemViewAt(2); | 431 NSButton* button = GetItemViewAt(2); |
| 432 EXPECT_NSEQ(@"Item 0", [button title]); | 432 EXPECT_NSEQ(@"Item 0", [button title]); |
| 433 EXPECT_EQ(std::string("|Item 0,Item 1,Item 0|"), GetViewContent()); | 433 EXPECT_EQ(std::string("|Item 0,Item 1,Item 0|"), GetViewContent()); |
| 434 | 434 |
| 435 // Update the title via the ItemModelObserver. | 435 // Update the title via the ItemModelObserver. |
| 436 app_list::AppListItemModel* item_model = model()->apps()->GetItemAt(2); | 436 app_list::AppListItemModel* item_model = model()->apps()->GetItemAt(2); |
| 437 item_model->SetTitle("UpdatedItem"); | 437 item_model->SetTitleAndFullName("UpdatedItem", "UpdatedItem"); |
| 438 EXPECT_NSEQ(@"UpdatedItem", [button title]); | 438 EXPECT_NSEQ(@"UpdatedItem", [button title]); |
| 439 EXPECT_EQ(std::string("|Item 0,Item 1,UpdatedItem|"), GetViewContent()); | 439 EXPECT_EQ(std::string("|Item 0,Item 1,UpdatedItem|"), GetViewContent()); |
| 440 | 440 |
| 441 // Test icon updates through the model observer by ensuring the icon changes. | 441 // Test icon updates through the model observer by ensuring the icon changes. |
| 442 NSSize icon_size = [[button image] size]; | 442 NSSize icon_size = [[button image] size]; |
| 443 EXPECT_EQ(0, icon_size.width); | 443 EXPECT_EQ(0, icon_size.width); |
| 444 EXPECT_EQ(0, icon_size.height); | 444 EXPECT_EQ(0, icon_size.height); |
| 445 | 445 |
| 446 SkBitmap bitmap; | 446 SkBitmap bitmap; |
| 447 const int kTestImageSize = 10; | 447 const int kTestImageSize = 10; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 460 | 460 |
| 461 // Test removing in the middle. | 461 // Test removing in the middle. |
| 462 model()->AddItem("Item 2"); | 462 model()->AddItem("Item 2"); |
| 463 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); | 463 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); |
| 464 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); | 464 EXPECT_EQ(std::string("|Item 0,Item 1,Item 2|"), GetViewContent()); |
| 465 model()->apps()->DeleteAt(1); | 465 model()->apps()->DeleteAt(1); |
| 466 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); | 466 EXPECT_EQ(2u, [apps_grid_controller_ itemCount]); |
| 467 EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent()); | 467 EXPECT_EQ(std::string("|Item 0,Item 2|"), GetViewContent()); |
| 468 | 468 |
| 469 // Test inserting in the middle. | 469 // Test inserting in the middle. |
| 470 model()->apps()->AddAt(1, model()->CreateItem("Item One")); | 470 model()->apps()->AddAt(1, model()->CreateItem("Item One", "Item One")); |
| 471 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); | 471 EXPECT_EQ(3u, [apps_grid_controller_ itemCount]); |
| 472 EXPECT_EQ(std::string("|Item 0,Item One,Item 2|"), GetViewContent()); | 472 EXPECT_EQ(std::string("|Item 0,Item One,Item 2|"), GetViewContent()); |
| 473 | 473 |
| 474 // Test swapping items (e.g. rearranging via sync). | 474 // Test swapping items (e.g. rearranging via sync). |
| 475 model()->apps()->Move(1, 2); | 475 model()->apps()->Move(1, 2); |
| 476 EXPECT_EQ(std::string("|Item 0,Item 2,Item One|"), GetViewContent()); | 476 EXPECT_EQ(std::string("|Item 0,Item 2,Item One|"), GetViewContent()); |
| 477 | 477 |
| 478 // Test removing multiple items via the model. | 478 // Test removing multiple items via the model. |
| 479 model()->apps()->DeleteAll(); | 479 model()->apps()->DeleteAll(); |
| 480 EXPECT_EQ(0u, [apps_grid_controller_ itemCount]); | 480 EXPECT_EQ(0u, [apps_grid_controller_ itemCount]); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 EXPECT_EQ(nil, menu); | 920 EXPECT_EQ(nil, menu); |
| 921 | 921 |
| 922 item_two_model->SetMenuReadyForTesting(true); | 922 item_two_model->SetMenuReadyForTesting(true); |
| 923 menu = [page menuForEvent:mouse_at_cell_1]; | 923 menu = [page menuForEvent:mouse_at_cell_1]; |
| 924 EXPECT_EQ(1, [menu numberOfItems]); | 924 EXPECT_EQ(1, [menu numberOfItems]); |
| 925 EXPECT_NSEQ(@"Menu For: Item Two", [[menu itemAtIndex:0] title]); | 925 EXPECT_NSEQ(@"Menu For: Item Two", [[menu itemAtIndex:0] title]); |
| 926 } | 926 } |
| 927 | 927 |
| 928 } // namespace test | 928 } // namespace test |
| 929 } // namespace app_list | 929 } // namespace app_list |
| OLD | NEW |