app_list_service_mac_interactive_uitest.mm revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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#include "chrome/browser/ui/app_list/app_list_service_mac.h" 6 7#include <vector> 8 9#include "apps/app_shim/app_shim_handler_mac.h" 10#include "base/command_line.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 16using apps::AppShimHandler; 17 18namespace { 19 20// Browser test for mac-specific AppListService functionality. 21class AppListServiceMacInteractiveTest : public InProcessBrowserTest, 22 public AppShimHandler::Host { 23 public: 24 AppListServiceMacInteractiveTest() : launch_count_(0) {} 25 26 protected: 27 void LaunchShim() { 28 // AppList shims always launch normally (never relaunched via dock icon). 29 AppShimHandler::GetForAppMode(app_mode::kAppListModeId)-> 30 OnShimLaunch(this, 31 apps::APP_SHIM_LAUNCH_NORMAL, 32 std::vector<base::FilePath>()); 33 } 34 35 // AppShimHandler::Host overrides: 36 virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result) OVERRIDE { 37 // AppList shims are always given APP_SHIM_LAUNCH_DUPLICATE_HOST, indicating 38 // that the shim process should immediately close. 39 EXPECT_EQ(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST, result); 40 ++launch_count_; 41 } 42 virtual void OnAppClosed() OVERRIDE { 43 NOTREACHED(); 44 } 45 virtual void OnAppHide() OVERRIDE {} 46 virtual void OnAppRequestUserAttention() OVERRIDE {} 47 virtual base::FilePath GetProfilePath() const OVERRIDE { 48 NOTREACHED(); // Currently unused in this test. 49 return base::FilePath(); 50 } 51 virtual std::string GetAppId() const OVERRIDE { 52 return app_mode::kAppListModeId; 53 } 54 55 int launch_count_; 56 57 private: 58 DISALLOW_COPY_AND_ASSIGN(AppListServiceMacInteractiveTest); 59}; 60 61} // namespace 62 63IN_PROC_BROWSER_TEST_F(AppListServiceMacInteractiveTest, 64 ShowAppListUsingShim) { 65 // Check that AppListService has registered as a shim handler for "app_list". 66 EXPECT_TRUE(AppShimHandler::GetForAppMode(app_mode::kAppListModeId)); 67 68 AppListService* service = 69 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); 70 EXPECT_FALSE(service->IsAppListVisible()); 71 72 // With no saved profile, the default profile should be chosen and saved. 73 service->Show(); 74 EXPECT_EQ(browser()->profile(), service->GetCurrentAppListProfile()); 75 EXPECT_TRUE(service->IsAppListVisible()); 76 EXPECT_EQ(0, launch_count_); 77 service->DismissAppList(); 78 EXPECT_FALSE(service->IsAppListVisible()); 79 80 // Test showing the app list via the shim. The shim should immediately close 81 // leaving the app list visible. 82 LaunchShim(); 83 EXPECT_TRUE(service->IsAppListVisible()); 84 EXPECT_EQ(1, launch_count_); 85 86 // Launching again should toggle the app list. 87 LaunchShim(); 88 EXPECT_FALSE(service->IsAppListVisible()); 89 EXPECT_EQ(2, launch_count_); 90 91 // Test showing the app list via the shim, then dismissing the app list. 92 LaunchShim(); 93 EXPECT_TRUE(service->IsAppListVisible()); 94 EXPECT_EQ(3, launch_count_); 95 service->DismissAppList(); 96 EXPECT_FALSE(service->IsAppListVisible()); 97} 98