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