1010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// found in the LICENSE file. 4010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_service_views.h" 6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/path_service.h" 8010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/run_loop.h" 9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/extensions/extension_browsertest.h" 10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h" 12010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/browser.h" 13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/common/chrome_paths.h" 14010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/app_list/app_list_switches.h" 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/app_list/views/app_list_view.h" 17010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/views/widget/widget.h" 18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS) 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/shell.h" 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/test/app_list_controller_test_api.h" 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Browser Test for AppListService on Views platforms. 25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)typedef InProcessBrowserTest AppListServiceViewsBrowserTest; 26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Test closing the native app list window as if via a request from the OS. 28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppListServiceViewsBrowserTest, NativeClose) { 29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AppListService* service = test::GetAppListService(); 30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_FALSE(service->GetAppListWindow()); 31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Since the profile is loaded, this will create a view immediately. This is 33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // important, because anything asynchronous would need an interactive_uitest 34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // due to the possibility of the app list being dismissed, and 35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // AppListService::GetAppListWindow returning NULL. 36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) service->ShowForProfile(browser()->profile()); 37010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) gfx::NativeWindow window = service->GetAppListWindow(); 38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_TRUE(window); 39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_TRUE(widget); 42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) widget->Close(); 43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Close is asynchronous (dismiss is not) so sink the message queue. 45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) base::RunLoop().RunUntilIdle(); 46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_FALSE(service->GetAppListWindow()); 47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Show again to get some code coverage for possibly stale pointers. 49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) service->ShowForProfile(browser()->profile()); 50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_TRUE(service->GetAppListWindow()); 51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) service->DismissAppList(); // Note: in Ash, this will invalidate the window. 52010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 53010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Note: no need to sink message queue. 54010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) EXPECT_FALSE(service->GetAppListWindow()); 55010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Browser Test for AppListController that ensures the App Info dialog opens 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// correctly. 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class AppListControllerAppInfoDialogBrowserTest : public ExtensionBrowserTest { 60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public: 61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AppListControllerAppInfoDialogBrowserTest() {} 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual ~AppListControllerAppInfoDialogBrowserTest() {} 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 64cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { 65cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ExtensionBrowserTest::SetUpCommandLine(command_line); 66cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 67cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private: 69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppListControllerAppInfoDialogBrowserTest); 70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}; 71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Test the DoShowAppInfoFlow function of the controller delegate. 73f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Crashes on all platforms some of the time (flaky). http://crbug.com/378251 74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(AppListControllerAppInfoDialogBrowserTest, 75f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) DISABLED_DoShowAppInfoFlow) { 76cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Install an extension to open the dialog for. 77cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::FilePath test_extension_path; 78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path)); 79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) test_extension_path = test_extension_path.AppendASCII("extensions") 80cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) .AppendASCII("platform_apps") 81cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) .AppendASCII("minimal"); 82cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const extensions::Extension* extension = InstallExtension( 83cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) test_extension_path, 1 /* expected_change: new install */); 84cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(extension); 85cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 86cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Open the app list window. 87cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AppListService* service = test::GetAppListService(); 88cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_FALSE(service->GetAppListWindow()); 89cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 90cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) service->ShowForProfile(browser()->profile()); 91cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) gfx::NativeWindow window = service->GetAppListWindow(); 92cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_TRUE(window); 93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 95cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(widget); 96cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 97cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Open the app info dialog. 98cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::Widget::Widgets owned_widgets; 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) widget->GetAllOwnedWidgets(window, &owned_widgets); 100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(0U, owned_widgets.size()); 101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 102cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) AppListControllerDelegate* controller = service->GetControllerDelegate(); 103cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(controller); 104cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) controller->DoShowAppInfoFlow(browser()->profile(), extension->id()); 105cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::RunLoop().RunUntilIdle(); 106cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) owned_widgets.clear(); 108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) widget->GetAllOwnedWidgets(window, &owned_widgets); 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(1U, owned_widgets.size()); 110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 111cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Close the app info dialog. 112cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) views::Widget* app_info_dialog = *owned_widgets.begin(); 113cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) app_info_dialog->Close(); 114cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::RunLoop().RunUntilIdle(); 115cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 116cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) owned_widgets.clear(); 117cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) widget->GetAllOwnedWidgets(window, &owned_widgets); 118cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) EXPECT_EQ(0U, owned_widgets.size()); 119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 120