| OLD | NEW |
| (Empty) |
| 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 #import "base/mac/scoped_nsobject.h" | |
| 6 #include "base/macros.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #import "testing/gtest_mac.h" | |
| 9 #include "ui/app_list/app_list_view_delegate.h" | |
| 10 #import "ui/app_list/cocoa/app_list_view_controller.h" | |
| 11 #import "ui/app_list/cocoa/app_list_window_controller.h" | |
| 12 #include "ui/app_list/search_box_model.h" | |
| 13 #include "ui/app_list/test/app_list_test_view_delegate.h" | |
| 14 #import "ui/gfx/test/ui_cocoa_test_helper.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class AppListWindowControllerTest : public ui::CocoaTest { | |
| 19 public: | |
| 20 AppListWindowControllerTest(); | |
| 21 | |
| 22 protected: | |
| 23 void TearDown() override; | |
| 24 | |
| 25 base::scoped_nsobject<AppListWindowController> controller_; | |
| 26 | |
| 27 app_list::test::AppListTestViewDelegate* delegate() { | |
| 28 return delegate_.get(); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 std::unique_ptr<app_list::test::AppListTestViewDelegate> delegate_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(AppListWindowControllerTest); | |
| 35 }; | |
| 36 | |
| 37 AppListWindowControllerTest::AppListWindowControllerTest() | |
| 38 : delegate_(new app_list::test::AppListTestViewDelegate) { | |
| 39 Init(); | |
| 40 controller_.reset([[AppListWindowController alloc] init]); | |
| 41 [[controller_ appListViewController] setDelegate:delegate()]; | |
| 42 } | |
| 43 | |
| 44 void AppListWindowControllerTest::TearDown() { | |
| 45 EXPECT_TRUE(controller_.get()); | |
| 46 [[controller_ window] close]; | |
| 47 [[controller_ appListViewController] setDelegate:NULL]; | |
| 48 controller_.reset(); | |
| 49 ui::CocoaTest::TearDown(); | |
| 50 } | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 // Test showing, hiding and closing the app list window. | |
| 55 TEST_F(AppListWindowControllerTest, ShowHideCloseRelease) { | |
| 56 EXPECT_TRUE([controller_ window]); | |
| 57 [[controller_ window] makeKeyAndOrderFront:nil]; | |
| 58 EXPECT_TRUE([[controller_ window] isVisible]); | |
| 59 EXPECT_TRUE([[[controller_ window] contentView] superview]); | |
| 60 [[controller_ window] close]; // Hide. | |
| 61 EXPECT_FALSE([[controller_ window] isVisible]); | |
| 62 [[controller_ window] makeKeyAndOrderFront:nil]; | |
| 63 } | |
| 64 | |
| 65 // Test that the key bound to cancel (usually Escape) asks the controller to | |
| 66 // dismiss the window. | |
| 67 TEST_F(AppListWindowControllerTest, DismissWithEscape) { | |
| 68 [[controller_ window] makeKeyAndOrderFront:nil]; | |
| 69 EXPECT_EQ(0, delegate()->dismiss_count()); | |
| 70 [[controller_ window] cancelOperation:controller_]; | |
| 71 EXPECT_EQ(1, delegate()->dismiss_count()); | |
| 72 } | |
| 73 | |
| 74 // Test that search results are cleared when the window closes, not when a | |
| 75 // search result is selected. If cleared upon selection, the animation showing | |
| 76 // the results sliding away is seen as the window closes, which looks weird. | |
| 77 TEST_F(AppListWindowControllerTest, CloseClearsSearch) { | |
| 78 [[controller_ window] makeKeyAndOrderFront:nil]; | |
| 79 app_list::SearchBoxModel* model = delegate()->GetModel()->search_box(); | |
| 80 AppListViewController* view_controller = [controller_ appListViewController]; | |
| 81 | |
| 82 EXPECT_FALSE([view_controller showingSearchResults]); | |
| 83 | |
| 84 const base::string16 search_text(base::ASCIIToUTF16("test")); | |
| 85 model->SetText(search_text); | |
| 86 EXPECT_TRUE([view_controller showingSearchResults]); | |
| 87 | |
| 88 EXPECT_EQ(0, delegate()->open_search_result_count()); | |
| 89 [view_controller openResult:nil]; | |
| 90 EXPECT_EQ(1, delegate()->open_search_result_count()); | |
| 91 | |
| 92 EXPECT_TRUE([view_controller showingSearchResults]); | |
| 93 [[controller_ window] close]; // Hide. | |
| 94 EXPECT_FALSE([view_controller showingSearchResults]); | |
| 95 } | |
| OLD | NEW |