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 "chrome/browser/ui/app_list/app_list_service_mac.h"
9 #include "base/command_line.h"
10 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/mac/app_mode_common.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #import "ui/app_list/cocoa/app_list_window_controller.h"
17 using apps::AppShimHandler;
21 class AppListServiceMacTestApi {
23 static AppListWindowController* window_controller() {
24 return AppListServiceMac::GetInstance()->window_controller_;
32 // Browser test for mac-specific AppListService functionality.
33 class AppListServiceMacInteractiveTest : public InProcessBrowserTest,
34 public AppShimHandler::Host {
36 AppListServiceMacInteractiveTest() : launch_count_(0) {}
40 // AppList shims always launch normally (never relaunched via dock icon).
41 AppShimHandler::GetForAppMode(app_mode::kAppListModeId)->
43 apps::APP_SHIM_LAUNCH_NORMAL,
44 std::vector<base::FilePath>());
47 AppListViewController* GetViewController() {
48 return [test::AppListServiceMacTestApi::window_controller()
49 appListViewController];
52 // testing::Test overrides:
53 virtual void TearDown() OVERRIDE {
54 // At tear-down, NOTIFICATION_APP_TERMINATING should have been sent for the
55 // browser shutdown. References to browser-owned objects must be removed
56 // from the app list UI.
57 AppListViewController* view_controller = GetViewController();
58 // Note this first check will fail if the test doesn't ever show the
59 // app list, but currently all tests in this file do.
60 EXPECT_TRUE(view_controller);
61 EXPECT_FALSE([view_controller delegate]);
64 // AppShimHandler::Host overrides:
65 virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result) OVERRIDE {
66 // AppList shims are always given APP_SHIM_LAUNCH_DUPLICATE_HOST, indicating
67 // that the shim process should immediately close.
68 EXPECT_EQ(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST, result);
71 virtual void OnAppClosed() OVERRIDE {
74 virtual void OnAppHide() OVERRIDE {}
75 virtual void OnAppRequestUserAttention(
76 apps::AppShimAttentionType type) OVERRIDE {}
77 virtual base::FilePath GetProfilePath() const OVERRIDE {
78 NOTREACHED(); // Currently unused in this test.
79 return base::FilePath();
81 virtual std::string GetAppId() const OVERRIDE {
82 return app_mode::kAppListModeId;
88 DISALLOW_COPY_AND_ASSIGN(AppListServiceMacInteractiveTest);
93 IN_PROC_BROWSER_TEST_F(AppListServiceMacInteractiveTest, ShowAppListUsingShim) {
94 // Check that AppListService has registered as a shim handler for "app_list".
95 EXPECT_TRUE(AppShimHandler::GetForAppMode(app_mode::kAppListModeId));
97 AppListService* service =
98 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE);
99 EXPECT_FALSE(service->IsAppListVisible());
101 // Creation should be lazy.
102 EXPECT_FALSE(GetViewController());
104 // With no saved profile, the default profile should be chosen and saved.
106 EXPECT_EQ(browser()->profile(), service->GetCurrentAppListProfile());
107 EXPECT_TRUE(service->IsAppListVisible());
108 EXPECT_EQ(0, launch_count_);
109 service->DismissAppList();
110 EXPECT_FALSE(service->IsAppListVisible());
112 // Test showing the app list via the shim. The shim should immediately close
113 // leaving the app list visible.
115 EXPECT_TRUE(service->IsAppListVisible());
116 EXPECT_EQ(1, launch_count_);
118 // Launching again should toggle the app list.
120 EXPECT_FALSE(service->IsAppListVisible());
121 EXPECT_EQ(2, launch_count_);
123 // Test showing the app list via the shim, then dismissing the app list.
125 EXPECT_TRUE(service->IsAppListVisible());
126 EXPECT_EQ(3, launch_count_);
127 service->DismissAppList();
128 EXPECT_FALSE(service->IsAppListVisible());
130 // View sticks around until shutdown.
131 AppListViewController* view_controller = GetViewController();
132 EXPECT_TRUE(view_controller);
133 EXPECT_TRUE([view_controller delegate]);