Commit 3de5a64d authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list: merges chrome's AppListControllerImpl into AppListClientImpl.

Since AppListClientImpl and AppListControllerImpl depend on each other
tightly, we can merge them. All Chrome components talk to Ash via the
AppListControllerDelegate interface, and AppListClientImpl implements
it. That's similar to the Ash AppListControllerImpl implementing
AppListViewDelegate.

This commit also merges app_list_controller_browsertest.cc with
app_list_browsertest.cc and renames those tests into AppListClient*.

Bug: 733662
Change-Id: I570d46b540d8bf23198f34e8ea8810dc3f026ab1
Reviewed-on: https://chromium-review.googlesource.com/1100554Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jiaquan He <hejq@google.com>
Cr-Commit-Position: refs/heads/master@{#567834}
parent 31bc2723
...@@ -1747,8 +1747,6 @@ split_static_library("ui") { ...@@ -1747,8 +1747,6 @@ split_static_library("ui") {
assert(enable_extensions) assert(enable_extensions)
assert(toolkit_views) assert(toolkit_views)
sources += [ sources += [
"app_list/app_list_controller_impl.cc",
"app_list/app_list_controller_impl.h",
"app_list/app_sync_ui_state.cc", "app_list/app_sync_ui_state.cc",
"app_list/app_sync_ui_state.h", "app_list/app_sync_ui_state.h",
"app_list/app_sync_ui_state_factory.cc", "app_list/app_sync_ui_state_factory.cc",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/chromeos/ash_config.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ui/app_list/app_list_controller_impl.h"
#include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/test/test_utils.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/test/event_generator.h"
#include "ui/wm/core/window_util.h"
using AppListTest = InProcessBrowserTest;
using AppListControllerDelegateImplTest = extensions::PlatformAppBrowserTest;
// TODO(crbug.com/759779, crbug.com/819386): Add back
// |ClickingContextMenuDoesNotDismiss|.
// Test AppListControllerDelegateImpl::IsAppOpen for extension apps.
IN_PROC_BROWSER_TEST_F(AppListControllerDelegateImplTest, IsExtensionAppOpen) {
AppListControllerDelegateImpl delegate;
EXPECT_FALSE(delegate.IsAppOpen("fake_extension_app_id"));
base::FilePath extension_path = test_data_dir_.AppendASCII("app");
const extensions::Extension* extension_app = LoadExtension(extension_path);
ASSERT_NE(nullptr, extension_app);
EXPECT_FALSE(delegate.IsAppOpen(extension_app->id()));
{
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
OpenApplication(AppLaunchParams(
profile(), extension_app, extensions::LAUNCH_CONTAINER_WINDOW,
WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST));
app_loaded_observer.Wait();
}
EXPECT_TRUE(delegate.IsAppOpen(extension_app->id()));
}
// Test AppListControllerDelegateImpl::IsAppOpen for platform apps.
IN_PROC_BROWSER_TEST_F(AppListControllerDelegateImplTest, IsPlatformAppOpen) {
AppListControllerDelegateImpl delegate;
EXPECT_FALSE(delegate.IsAppOpen("fake_platform_app_id"));
const extensions::Extension* app = InstallPlatformApp("minimal");
EXPECT_FALSE(delegate.IsAppOpen(app->id()));
{
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
LaunchPlatformApp(app);
app_loaded_observer.Wait();
}
EXPECT_TRUE(delegate.IsAppOpen(app->id()));
}
...@@ -29,9 +29,16 @@ ...@@ -29,9 +29,16 @@
#include "chrome/browser/ui/app_list/search/search_controller_factory.h" #include "chrome/browser/ui/app_list/search/search_controller_factory.h"
#include "chrome/browser/ui/app_list/search/search_resource_manager.h" #include "chrome/browser/ui/app_list/search/search_resource_manager.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "extensions/common/extension.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "ui/base/models/menu_model.h" #include "ui/base/models/menu_model.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -52,7 +59,6 @@ AppListClientImpl::AppListClientImpl() ...@@ -52,7 +59,6 @@ AppListClientImpl::AppListClientImpl()
ash::mojom::AppListClientPtr client; ash::mojom::AppListClientPtr client;
binding_.Bind(mojo::MakeRequest(&client)); binding_.Bind(mojo::MakeRequest(&client));
app_list_controller_->SetClient(std::move(client)); app_list_controller_->SetClient(std::move(client));
controller_delegate_.SetAppListController(app_list_controller_.get());
user_manager::UserManager::Get()->AddSessionStateObserver(this); user_manager::UserManager::Get()->AddSessionStateObserver(this);
DCHECK(!g_app_list_client_instance); DCHECK(!g_app_list_client_instance);
...@@ -74,7 +80,7 @@ AppListClientImpl* AppListClientImpl::GetInstance() { ...@@ -74,7 +80,7 @@ AppListClientImpl* AppListClientImpl::GetInstance() {
void AppListClientImpl::StartSearch(const base::string16& trimmed_query) { void AppListClientImpl::StartSearch(const base::string16& trimmed_query) {
if (search_controller_) { if (search_controller_) {
search_controller_->Start(trimmed_query); search_controller_->Start(trimmed_query);
controller_delegate_.OnSearchStarted(); OnSearchStarted();
} }
} }
...@@ -131,7 +137,7 @@ void AppListClientImpl::SearchResultContextMenuItemSelected( ...@@ -131,7 +137,7 @@ void AppListClientImpl::SearchResultContextMenuItemSelected(
} }
void AppListClientImpl::ViewClosing() { void AppListClientImpl::ViewClosing() {
controller_delegate_.SetAppListDisplayId(display::kInvalidDisplayId); display_id_ = display::kInvalidDisplayId;
} }
void AppListClientImpl::ViewShown(int64_t display_id) { void AppListClientImpl::ViewShown(int64_t display_id) {
...@@ -140,7 +146,7 @@ void AppListClientImpl::ViewShown(int64_t display_id) { ...@@ -140,7 +146,7 @@ void AppListClientImpl::ViewShown(int64_t display_id) {
base::UmaHistogramSparse("Apps.AppListBadgedAppsCount", base::UmaHistogramSparse("Apps.AppListBadgedAppsCount",
model_updater_->BadgedItemCount()); model_updater_->BadgedItemCount());
} }
controller_delegate_.SetAppListDisplayId(display_id); display_id_ = display_id;
} }
void AppListClientImpl::ActivateItem(const std::string& id, int event_flags) { void AppListClientImpl::ActivateItem(const std::string& id, int event_flags) {
...@@ -295,8 +301,8 @@ void AppListClientImpl::SetUpSearchUI() { ...@@ -295,8 +301,8 @@ void AppListClientImpl::SetUpSearchUI() {
search_resource_manager_.reset( search_resource_manager_.reset(
new app_list::SearchResourceManager(profile_, model_updater_)); new app_list::SearchResourceManager(profile_, model_updater_));
search_controller_ = app_list::CreateSearchController( search_controller_ =
profile_, model_updater_, &controller_delegate_); app_list::CreateSearchController(profile_, model_updater_, this);
} }
app_list::SearchController* AppListClientImpl::GetSearchControllerForTest() { app_list::SearchController* AppListClientImpl::GetSearchControllerForTest() {
...@@ -332,22 +338,114 @@ void AppListClientImpl::ShowAppList() { ...@@ -332,22 +338,114 @@ void AppListClientImpl::ShowAppList() {
app_list_controller_->ShowAppList(); app_list_controller_->ShowAppList();
} }
void AppListClientImpl::DismissAppList() { Profile* AppListClientImpl::GetCurrentAppListProfile() const {
return ChromeLauncherController::instance()->profile();
}
ash::mojom::AppListController* AppListClientImpl::GetAppListController() const {
return app_list_controller_.get();
}
void AppListClientImpl::DismissView() {
if (!app_list_controller_) if (!app_list_controller_)
return; return;
app_list_controller_->DismissAppList(); app_list_controller_->DismissAppList();
} }
Profile* AppListClientImpl::GetCurrentAppListProfile() const { int64_t AppListClientImpl::GetAppListDisplayId() {
return ChromeLauncherController::instance()->profile(); return display_id_;
} }
AppListControllerDelegate* AppListClientImpl::GetControllerDelegate() { void AppListClientImpl::GetAppInfoDialogBounds(
return &controller_delegate_; GetAppInfoDialogBoundsCallback callback) {
if (!app_list_controller_) {
LOG(ERROR) << "app_list_controller_ is null";
std::move(callback).Run(gfx::Rect());
return;
}
app_list_controller_->GetAppInfoDialogBounds(std::move(callback));
} }
ash::mojom::AppListController* AppListClientImpl::GetAppListController() const { bool AppListClientImpl::IsAppPinned(const std::string& app_id) {
return app_list_controller_.get(); return ChromeLauncherController::instance()->IsAppPinned(app_id);
}
bool AppListClientImpl::IsAppOpen(const std::string& app_id) const {
return ChromeLauncherController::instance()->IsOpen(ash::ShelfID(app_id));
}
void AppListClientImpl::PinApp(const std::string& app_id) {
ChromeLauncherController::instance()->PinAppWithID(app_id);
}
void AppListClientImpl::UnpinApp(const std::string& app_id) {
ChromeLauncherController::instance()->UnpinAppWithID(app_id);
}
AppListControllerDelegate::Pinnable AppListClientImpl::GetPinnable(
const std::string& app_id) {
return GetPinnableForAppID(app_id,
ChromeLauncherController::instance()->profile());
}
void AppListClientImpl::CreateNewWindow(Profile* profile, bool incognito) {
if (incognito)
chrome::NewEmptyWindow(profile->GetOffTheRecordProfile());
else
chrome::NewEmptyWindow(profile);
}
void AppListClientImpl::OpenURL(Profile* profile,
const GURL& url,
ui::PageTransition transition,
WindowOpenDisposition disposition) {
NavigateParams params(profile, url, transition);
params.disposition = disposition;
Navigate(&params);
}
void AppListClientImpl::ActivateApp(Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags) {
// Platform apps treat activations as a launch. The app can decide whether to
// show a new window or focus an existing window as it sees fit.
if (extension->is_platform_app()) {
LaunchApp(profile, extension, source, event_flags, GetAppListDisplayId());
return;
}
ChromeLauncherController::instance()->ActivateApp(
extension->id(), AppListSourceToLaunchSource(source), event_flags,
GetAppListDisplayId());
if (!IsHomeLauncherEnabledInTabletMode())
DismissView();
}
void AppListClientImpl::LaunchApp(Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags,
int64_t display_id) {
ChromeLauncherController::instance()->LaunchApp(
ash::ShelfID(extension->id()), AppListSourceToLaunchSource(source),
event_flags, display_id);
if (!IsHomeLauncherEnabledInTabletMode())
DismissView();
}
ash::ShelfLaunchSource AppListClientImpl::AppListSourceToLaunchSource(
AppListSource source) {
switch (source) {
case LAUNCH_FROM_APP_LIST:
return ash::LAUNCH_FROM_APP_LIST;
case LAUNCH_FROM_APP_LIST_SEARCH:
return ash::LAUNCH_FROM_APP_LIST_SEARCH;
default:
return ash::LAUNCH_FROM_UNKNOWN;
}
} }
void AppListClientImpl::FlushMojoForTesting() { void AppListClientImpl::FlushMojoForTesting() {
......
...@@ -10,17 +10,20 @@ ...@@ -10,17 +10,20 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/interfaces/app_list.mojom.h" #include "ash/public/interfaces/app_list.mojom.h"
#include "base/callback_forward.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/ui/app_list/app_list_controller_impl.h" #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "ui/display/types/display_constants.h"
namespace app_list { namespace app_list {
class SearchController; class SearchController;
...@@ -33,6 +36,7 @@ class Profile; ...@@ -33,6 +36,7 @@ class Profile;
class AppListClientImpl class AppListClientImpl
: public ash::mojom::AppListClient, : public ash::mojom::AppListClient,
public AppListControllerDelegate,
public user_manager::UserManager::UserSessionStateObserver, public user_manager::UserManager::UserSessionStateObserver,
public TemplateURLServiceObserver { public TemplateURLServiceObserver {
public: public:
...@@ -76,6 +80,30 @@ class AppListClientImpl ...@@ -76,6 +80,30 @@ class AppListClientImpl
// user_manager::UserManager::UserSessionStateObserver: // user_manager::UserManager::UserSessionStateObserver:
void ActiveUserChanged(const user_manager::User* active_user) override; void ActiveUserChanged(const user_manager::User* active_user) override;
// AppListControllerDelegate overrides:
void DismissView() override;
int64_t GetAppListDisplayId() override;
void GetAppInfoDialogBounds(GetAppInfoDialogBoundsCallback callback) override;
bool IsAppPinned(const std::string& app_id) override;
bool IsAppOpen(const std::string& app_id) const override;
void PinApp(const std::string& app_id) override;
void UnpinApp(const std::string& app_id) override;
Pinnable GetPinnable(const std::string& app_id) override;
void CreateNewWindow(Profile* profile, bool incognito) override;
void OpenURL(Profile* profile,
const GURL& url,
ui::PageTransition transition,
WindowOpenDisposition disposition) override;
void ActivateApp(Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags) override;
void LaunchApp(Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags,
int64_t display_id) override;
// Associates this client with the current active user, called when this // Associates this client with the current active user, called when this
// client is accessed or active user is changed. // client is accessed or active user is changed.
void UpdateProfile(); void UpdateProfile();
...@@ -85,7 +113,6 @@ class AppListClientImpl ...@@ -85,7 +113,6 @@ class AppListClientImpl
void ShowAndSwitchToState(ash::AppListState state); void ShowAndSwitchToState(ash::AppListState state);
void ShowAppList(); void ShowAppList();
void DismissAppList();
bool app_list_target_visibility() const { bool app_list_target_visibility() const {
return app_list_target_visibility_; return app_list_target_visibility_;
...@@ -113,6 +140,11 @@ class AppListClientImpl ...@@ -113,6 +140,11 @@ class AppListClientImpl
// Updates the speech webview and start page for the current |profile_|. // Updates the speech webview and start page for the current |profile_|.
void SetUpSearchUI(); void SetUpSearchUI();
ash::ShelfLaunchSource AppListSourceToLaunchSource(AppListSource source);
// The current display id showing the app list.
int64_t display_id_ = display::kInvalidDisplayId;
// Unowned pointer to the associated profile. May change if SetProfile is // Unowned pointer to the associated profile. May change if SetProfile is
// called. // called.
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
...@@ -131,8 +163,6 @@ class AppListClientImpl ...@@ -131,8 +163,6 @@ class AppListClientImpl
mojo::Binding<ash::mojom::AppListClient> binding_; mojo::Binding<ash::mojom::AppListClient> binding_;
ash::mojom::AppListControllerPtr app_list_controller_; ash::mojom::AppListControllerPtr app_list_controller_;
AppListControllerDelegateImpl controller_delegate_;
bool app_list_target_visibility_ = false; bool app_list_target_visibility_ = false;
bool app_list_visible_ = false; bool app_list_visible_ = false;
......
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/app_list/app_list_client_impl.h" #include <stddef.h>
#include <memory>
#include "ash/public/cpp/app_list/app_list_switches.h"
#include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/path_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h" #include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/chrome_app_list_item.h" #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
#include "chrome/browser/ui/app_list/search/search_controller.h"
#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h" #include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/chromeos_switches.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/user_manager/user_names.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/test/test_utils.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/aura/window.h"
#include "ui/base/models/menu_model.h" #include "ui/base/models/menu_model.h"
// Browser Test for AppListClientImpl. // Browser Test for AppListClientImpl.
using AppListClientImplBrowserTest = InProcessBrowserTest; using AppListClientImplBrowserTest = extensions::PlatformAppBrowserTest;
// Test AppListClient::IsAppOpen for extension apps.
IN_PROC_BROWSER_TEST_F(AppListClientImplBrowserTest, IsExtensionAppOpen) {
AppListControllerDelegate* delegate = AppListClientImpl::GetInstance();
EXPECT_FALSE(delegate->IsAppOpen("fake_extension_app_id"));
base::FilePath extension_path = test_data_dir_.AppendASCII("app");
const extensions::Extension* extension_app = LoadExtension(extension_path);
ASSERT_NE(nullptr, extension_app);
EXPECT_FALSE(delegate->IsAppOpen(extension_app->id()));
{
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
OpenApplication(AppLaunchParams(
profile(), extension_app, extensions::LAUNCH_CONTAINER_WINDOW,
WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST));
app_loaded_observer.Wait();
}
EXPECT_TRUE(delegate->IsAppOpen(extension_app->id()));
}
// Test AppListClient::IsAppOpen for platform apps.
IN_PROC_BROWSER_TEST_F(AppListClientImplBrowserTest, IsPlatformAppOpen) {
AppListControllerDelegate* delegate = AppListClientImpl::GetInstance();
EXPECT_FALSE(delegate->IsAppOpen("fake_platform_app_id"));
const extensions::Extension* app = InstallPlatformApp("minimal");
EXPECT_FALSE(delegate->IsAppOpen(app->id()));
{
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
LaunchPlatformApp(app);
app_loaded_observer.Wait();
}
EXPECT_TRUE(delegate->IsAppOpen(app->id()));
}
// Test the CreateNewWindow function of the controller delegate.
IN_PROC_BROWSER_TEST_F(AppListClientImplBrowserTest, CreateNewWindow) {
AppListClientImpl* client = AppListClientImpl::GetInstance();
AppListControllerDelegate* controller = client;
ASSERT_TRUE(controller);
EXPECT_EQ(1U, chrome::GetBrowserCount(browser()->profile()));
EXPECT_EQ(0U, chrome::GetBrowserCount(
browser()->profile()->GetOffTheRecordProfile()));
controller->CreateNewWindow(browser()->profile(), false);
EXPECT_EQ(2U, chrome::GetBrowserCount(browser()->profile()));
controller->CreateNewWindow(browser()->profile(), true);
EXPECT_EQ(1U, chrome::GetBrowserCount(
browser()->profile()->GetOffTheRecordProfile()));
}
// Test that all the items in the context menu for a hosted app have valid // Test that all the items in the context menu for a hosted app have valid
// labels. // labels.
...@@ -61,3 +137,91 @@ IN_PROC_BROWSER_TEST_F(AppListClientImplBrowserTest, ShowContextMenu) { ...@@ -61,3 +137,91 @@ IN_PROC_BROWSER_TEST_F(AppListClientImplBrowserTest, ShowContextMenu) {
EXPECT_FALSE(label.empty()); EXPECT_FALSE(label.empty());
} }
} }
// Browser Test for AppListClient that observes search result changes.
using AppListClientSearchResultsBrowserTest = extensions::ExtensionBrowserTest;
// Test showing search results, and uninstalling one of them while displayed.
IN_PROC_BROWSER_TEST_F(AppListClientSearchResultsBrowserTest,
UninstallSearchResult) {
base::FilePath test_extension_path;
ASSERT_TRUE(
base::PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path));
test_extension_path = test_extension_path.AppendASCII("extensions")
.AppendASCII("platform_apps")
.AppendASCII("minimal");
AppListClientImpl* client = AppListClientImpl::GetInstance();
ASSERT_TRUE(client);
// Associate |client| with the current profile.
client->UpdateProfile();
AppListModelUpdater* model_updater = test::GetModelUpdater(client);
ASSERT_TRUE(model_updater);
app_list::SearchController* search_controller =
client->GetSearchControllerForTest();
ASSERT_TRUE(search_controller);
// Install the extension.
const extensions::Extension* extension = InstallExtension(
test_extension_path, 1 /* expected_change: new install */);
ASSERT_TRUE(extension);
const std::string title = extension->name();
// Show the app list first, otherwise we won't have a search box to update.
client->ShowAppList();
client->FlushMojoForTesting();
// Currently the search box is empty, so we have no result.
EXPECT_FALSE(search_controller->GetResultByTitleForTest(title));
// Now a search finds the extension.
model_updater->UpdateSearchBox(base::ASCIIToUTF16(title),
true /* initiated_by_user */);
// Ensure everything is done, from Chrome to Ash and backwards.
client->FlushMojoForTesting();
EXPECT_TRUE(search_controller->GetResultByTitleForTest(title));
// Uninstall the extension.
UninstallExtension(extension->id());
// Ensure everything is done, from Chrome to Ash and backwards.
client->FlushMojoForTesting();
// We cannot find the extension any more.
EXPECT_FALSE(search_controller->GetResultByTitleForTest(title));
client->DismissView();
}
class AppListClientGuestModeBrowserTest : public InProcessBrowserTest {
public:
AppListClientGuestModeBrowserTest() {}
protected:
void SetUpCommandLine(base::CommandLine* command_line) override;
private:
DISALLOW_COPY_AND_ASSIGN(AppListClientGuestModeBrowserTest);
};
void AppListClientGuestModeBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) {
command_line->AppendSwitch(chromeos::switches::kGuestSession);
command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
user_manager::kGuestUserName);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
TestingProfile::kTestUserProfileDir);
command_line->AppendSwitch(switches::kIncognito);
}
// Test creating the initial app list in guest mode.
IN_PROC_BROWSER_TEST_F(AppListClientGuestModeBrowserTest, Incognito) {
AppListClientImpl* client = AppListClientImpl::GetInstance();
EXPECT_TRUE(client->GetCurrentAppListProfile());
client->ShowAppList();
EXPECT_EQ(browser()->profile(), client->GetCurrentAppListProfile());
}
...@@ -20,7 +20,7 @@ IN_PROC_BROWSER_TEST_F(AppListClientInteractiveTest, ShowAndDismiss) { ...@@ -20,7 +20,7 @@ IN_PROC_BROWSER_TEST_F(AppListClientInteractiveTest, ShowAndDismiss) {
client->ShowAppList(); client->ShowAppList();
client->FlushMojoForTesting(); client->FlushMojoForTesting();
ASSERT_TRUE(client->app_list_visible()); ASSERT_TRUE(client->app_list_visible());
client->DismissAppList(); client->DismissView();
client->FlushMojoForTesting(); client->FlushMojoForTesting();
ASSERT_FALSE(client->app_list_visible()); ASSERT_FALSE(client->app_list_visible());
} }
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include "ash/public/cpp/app_list/app_list_switches.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "chrome/browser/ui/app_list/search/search_controller.h"
#include "chrome/browser/ui/app_list/test/chrome_app_list_test_support.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/chromeos_switches.h"
#include "components/user_manager/user_names.h"
// Browser Test for AppListController that runs on all platforms supporting
// app_list.
using AppListControllerBrowserTest = InProcessBrowserTest;
// Test the CreateNewWindow function of the controller delegate.
IN_PROC_BROWSER_TEST_F(AppListControllerBrowserTest, CreateNewWindow) {
AppListClientImpl* client = AppListClientImpl::GetInstance();
AppListControllerDelegate* controller(client->GetControllerDelegate());
ASSERT_TRUE(controller);
EXPECT_EQ(1U, chrome::GetBrowserCount(browser()->profile()));
EXPECT_EQ(0U, chrome::GetBrowserCount(
browser()->profile()->GetOffTheRecordProfile()));
controller->CreateNewWindow(browser()->profile(), false);
EXPECT_EQ(2U, chrome::GetBrowserCount(browser()->profile()));
controller->CreateNewWindow(browser()->profile(), true);
EXPECT_EQ(1U, chrome::GetBrowserCount(
browser()->profile()->GetOffTheRecordProfile()));
}
// Browser Test for AppListController that observes search result changes.
using AppListControllerSearchResultsBrowserTest =
extensions::ExtensionBrowserTest;
// Test showing search results, and uninstalling one of them while displayed.
IN_PROC_BROWSER_TEST_F(AppListControllerSearchResultsBrowserTest,
UninstallSearchResult) {
base::FilePath test_extension_path;
ASSERT_TRUE(
base::PathService::Get(chrome::DIR_TEST_DATA, &test_extension_path));
test_extension_path = test_extension_path.AppendASCII("extensions")
.AppendASCII("platform_apps")
.AppendASCII("minimal");
AppListClientImpl* client = AppListClientImpl::GetInstance();
ASSERT_TRUE(client);
// Associate |client| with the current profile.
client->UpdateProfile();
AppListModelUpdater* model_updater = test::GetModelUpdater(client);
ASSERT_TRUE(model_updater);
app_list::SearchController* search_controller =
client->GetSearchControllerForTest();
ASSERT_TRUE(search_controller);
// Install the extension.
const extensions::Extension* extension = InstallExtension(
test_extension_path, 1 /* expected_change: new install */);
ASSERT_TRUE(extension);
const std::string title = extension->name();
// Show the app list first, otherwise we won't have a search box to update.
client->ShowAppList();
client->FlushMojoForTesting();
// Currently the search box is empty, so we have no result.
EXPECT_FALSE(search_controller->GetResultByTitleForTest(title));
// Now a search finds the extension.
model_updater->UpdateSearchBox(base::ASCIIToUTF16(title),
true /* initiated_by_user */);
// Ensure everything is done, from Chrome to Ash and backwards.
client->FlushMojoForTesting();
EXPECT_TRUE(search_controller->GetResultByTitleForTest(title));
// Uninstall the extension.
UninstallExtension(extension->id());
// Ensure everything is done, from Chrome to Ash and backwards.
client->FlushMojoForTesting();
// We cannot find the extension any more.
EXPECT_FALSE(search_controller->GetResultByTitleForTest(title));
client->DismissAppList();
}
class AppListControllerGuestModeBrowserTest : public InProcessBrowserTest {
public:
AppListControllerGuestModeBrowserTest() {}
protected:
void SetUpCommandLine(base::CommandLine* command_line) override;
private:
DISALLOW_COPY_AND_ASSIGN(AppListControllerGuestModeBrowserTest);
};
void AppListControllerGuestModeBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) {
command_line->AppendSwitch(chromeos::switches::kGuestSession);
command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
user_manager::kGuestUserName);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
TestingProfile::kTestUserProfileDir);
command_line->AppendSwitch(switches::kIncognito);
}
// Test creating the initial app list in guest mode.
IN_PROC_BROWSER_TEST_F(AppListControllerGuestModeBrowserTest, Incognito) {
AppListClientImpl* client = AppListClientImpl::GetInstance();
EXPECT_TRUE(client->GetCurrentAppListProfile());
client->ShowAppList();
EXPECT_EQ(browser()->profile(), client->GetCurrentAppListProfile());
}
...@@ -57,9 +57,6 @@ class AppListControllerDelegate { ...@@ -57,9 +57,6 @@ class AppListControllerDelegate {
// Gets display ID of app list window. // Gets display ID of app list window.
virtual int64_t GetAppListDisplayId() = 0; virtual int64_t GetAppListDisplayId() = 0;
// Sets display ID of app list window whenever it changes.
virtual void SetAppListDisplayId(int64_t display_id) = 0;
// Gets the content bounds of the app info dialog of the app list in the // Gets the content bounds of the app info dialog of the app list in the
// screen coordinates. On platforms that do not use views, this returns a 0x0 // screen coordinates. On platforms that do not use views, this returns a 0x0
// rectangle. // rectangle.
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_list/app_list_controller_impl.h"
#include <utility>
#include "ash/public/interfaces/app_list.mojom.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "extensions/common/extension.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h"
AppListControllerDelegateImpl::AppListControllerDelegateImpl() {}
AppListControllerDelegateImpl::~AppListControllerDelegateImpl() {}
void AppListControllerDelegateImpl::SetAppListController(
ash::mojom::AppListController* app_list_controller) {
app_list_controller_ = app_list_controller;
}
void AppListControllerDelegateImpl::DismissView() {
if (!app_list_controller_)
return;
app_list_controller_->DismissAppList();
}
int64_t AppListControllerDelegateImpl::GetAppListDisplayId() {
return display_id_;
}
void AppListControllerDelegateImpl::SetAppListDisplayId(int64_t display_id) {
display_id_ = display_id;
}
void AppListControllerDelegateImpl::GetAppInfoDialogBounds(
GetAppInfoDialogBoundsCallback callback) {
if (!app_list_controller_) {
LOG(ERROR) << "app_list_controller_ is null";
std::move(callback).Run(gfx::Rect());
return;
}
app_list_controller_->GetAppInfoDialogBounds(std::move(callback));
}
bool AppListControllerDelegateImpl::IsAppPinned(const std::string& app_id) {
return ChromeLauncherController::instance()->IsAppPinned(app_id);
}
bool AppListControllerDelegateImpl::IsAppOpen(const std::string& app_id) const {
return ChromeLauncherController::instance()->IsOpen(ash::ShelfID(app_id));
}
void AppListControllerDelegateImpl::PinApp(const std::string& app_id) {
ChromeLauncherController::instance()->PinAppWithID(app_id);
}
void AppListControllerDelegateImpl::UnpinApp(const std::string& app_id) {
ChromeLauncherController::instance()->UnpinAppWithID(app_id);
}
AppListControllerDelegate::Pinnable AppListControllerDelegateImpl::GetPinnable(
const std::string& app_id) {
return GetPinnableForAppID(app_id,
ChromeLauncherController::instance()->profile());
}
void AppListControllerDelegateImpl::CreateNewWindow(Profile* profile,
bool incognito) {
if (incognito)
chrome::NewEmptyWindow(profile->GetOffTheRecordProfile());
else
chrome::NewEmptyWindow(profile);
}
void AppListControllerDelegateImpl::OpenURL(Profile* profile,
const GURL& url,
ui::PageTransition transition,
WindowOpenDisposition disposition) {
NavigateParams params(profile, url, transition);
params.disposition = disposition;
Navigate(&params);
}
void AppListControllerDelegateImpl::ActivateApp(
Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags) {
// Platform apps treat activations as a launch. The app can decide whether to
// show a new window or focus an existing window as it sees fit.
if (extension->is_platform_app()) {
LaunchApp(profile, extension, source, event_flags, GetAppListDisplayId());
return;
}
ChromeLauncherController::instance()->ActivateApp(
extension->id(), AppListSourceToLaunchSource(source), event_flags,
GetAppListDisplayId());
if (!IsHomeLauncherEnabledInTabletMode())
DismissView();
}
void AppListControllerDelegateImpl::LaunchApp(
Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags,
int64_t display_id) {
ChromeLauncherController::instance()->LaunchApp(
ash::ShelfID(extension->id()), AppListSourceToLaunchSource(source),
event_flags, display_id);
if (!IsHomeLauncherEnabledInTabletMode())
DismissView();
}
ash::ShelfLaunchSource
AppListControllerDelegateImpl::AppListSourceToLaunchSource(
AppListSource source) {
switch (source) {
case LAUNCH_FROM_APP_LIST:
return ash::LAUNCH_FROM_APP_LIST;
case LAUNCH_FROM_APP_LIST_SEARCH:
return ash::LAUNCH_FROM_APP_LIST_SEARCH;
default:
return ash::LAUNCH_FROM_UNKNOWN;
}
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_CONTROLLER_IMPL_H_
#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_CONTROLLER_IMPL_H_
#include <string>
#include "ash/public/cpp/shelf_types.h"
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "ui/display/types/display_constants.h"
namespace ash {
namespace mojom {
class AppListController;
} // namespace mojom
} // namespace ash
class AppListControllerDelegateImpl : public AppListControllerDelegate {
public:
AppListControllerDelegateImpl();
~AppListControllerDelegateImpl() override;
// AppListControllerDelegate overrides:
void DismissView() override;
int64_t GetAppListDisplayId() override;
void SetAppListDisplayId(int64_t display_id) override;
void GetAppInfoDialogBounds(GetAppInfoDialogBoundsCallback callback) override;
bool IsAppPinned(const std::string& app_id) override;
bool IsAppOpen(const std::string& app_id) const override;
void PinApp(const std::string& app_id) override;
void UnpinApp(const std::string& app_id) override;
Pinnable GetPinnable(const std::string& app_id) override;
void CreateNewWindow(Profile* profile, bool incognito) override;
void OpenURL(Profile* profile,
const GURL& url,
ui::PageTransition transition,
WindowOpenDisposition disposition) override;
void ActivateApp(Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags) override;
void LaunchApp(Profile* profile,
const extensions::Extension* extension,
AppListSource source,
int event_flags,
int64_t display_id) override;
// Sets the pointer to the app list controller in Ash.
void SetAppListController(ash::mojom::AppListController* app_list_controller);
private:
ash::ShelfLaunchSource AppListSourceToLaunchSource(AppListSource source);
// The current display id showing the app list.
int64_t display_id_ = display::kInvalidDisplayId;
// Not owned.
ash::mojom::AppListController* app_list_controller_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateImpl);
};
#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_CONTROLLER_IMPL_H_
...@@ -401,10 +401,8 @@ void AppListSyncableService::BuildModel() { ...@@ -401,10 +401,8 @@ void AppListSyncableService::BuildModel() {
// TODO(calamity): make this a DCHECK after a dev channel release. // TODO(calamity): make this a DCHECK after a dev channel release.
CHECK(IsExtensionServiceReady()); CHECK(IsExtensionServiceReady());
AppListControllerDelegate* controller = NULL;
AppListClientImpl* client = AppListClientImpl::GetInstance(); AppListClientImpl* client = AppListClientImpl::GetInstance();
if (client) AppListControllerDelegate* controller = client;
controller = client->GetControllerDelegate();
apps_builder_.reset(new ExtensionAppModelBuilder(controller)); apps_builder_.reset(new ExtensionAppModelBuilder(controller));
if (arc::IsArcAllowedForProfile(profile_)) if (arc::IsArcAllowedForProfile(profile_))
arc_apps_builder_.reset(new ArcAppModelBuilder(controller)); arc_apps_builder_.reset(new ArcAppModelBuilder(controller));
......
...@@ -120,9 +120,8 @@ extensions::AppSorting* ChromeAppListItem::GetAppSorting() { ...@@ -120,9 +120,8 @@ extensions::AppSorting* ChromeAppListItem::GetAppSorting() {
} }
AppListControllerDelegate* ChromeAppListItem::GetController() { AppListControllerDelegate* ChromeAppListItem::GetController() {
return g_controller_for_test != nullptr return g_controller_for_test != nullptr ? g_controller_for_test
? g_controller_for_test : AppListClientImpl::GetInstance();
: AppListClientImpl::GetInstance()->GetControllerDelegate();
} }
void ChromeAppListItem::UpdateFromSync( void ChromeAppListItem::UpdateFromSync(
......
...@@ -21,8 +21,6 @@ int64_t TestAppListControllerDelegate::GetAppListDisplayId() { ...@@ -21,8 +21,6 @@ int64_t TestAppListControllerDelegate::GetAppListDisplayId() {
return display::kInvalidDisplayId; return display::kInvalidDisplayId;
} }
void TestAppListControllerDelegate::SetAppListDisplayId(int64_t display_id) {}
void TestAppListControllerDelegate::DismissView() {} void TestAppListControllerDelegate::DismissView() {}
bool TestAppListControllerDelegate::IsAppPinned(const std::string& app_id) { bool TestAppListControllerDelegate::IsAppPinned(const std::string& app_id) {
......
...@@ -17,7 +17,6 @@ class TestAppListControllerDelegate : public AppListControllerDelegate { ...@@ -17,7 +17,6 @@ class TestAppListControllerDelegate : public AppListControllerDelegate {
~TestAppListControllerDelegate() override; ~TestAppListControllerDelegate() override;
int64_t GetAppListDisplayId() override; int64_t GetAppListDisplayId() override;
void SetAppListDisplayId(int64_t display_id) override;
void DismissView() override; void DismissView() override;
bool IsAppPinned(const std::string& app_id) override; bool IsAppPinned(const std::string& app_id) override;
void PinApp(const std::string& app_id) override; void PinApp(const std::string& app_id) override;
......
...@@ -492,7 +492,7 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, IsAppOpen) { ...@@ -492,7 +492,7 @@ IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, IsAppOpen) {
const std::string app_id = GetTestApp1Id(kTestAppPackage); const std::string app_id = GetTestApp1Id(kTestAppPackage);
AppListClientImpl* client = AppListClientImpl::GetInstance(); AppListClientImpl* client = AppListClientImpl::GetInstance();
AppListControllerDelegate* delegate = client->GetControllerDelegate(); AppListControllerDelegate* delegate = client;
EXPECT_FALSE(delegate->IsAppOpen(app_id)); EXPECT_FALSE(delegate->IsAppOpen(app_id));
arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON);
EXPECT_FALSE(delegate->IsAppOpen(app_id)); EXPECT_FALSE(delegate->IsAppOpen(app_id));
......
...@@ -1690,7 +1690,6 @@ test("browser_tests") { ...@@ -1690,7 +1690,6 @@ test("browser_tests") {
"../browser/notifications/notification_platform_bridge_chromeos_browsertest.cc", "../browser/notifications/notification_platform_bridge_chromeos_browsertest.cc",
"../browser/resources/chromeos/zip_archiver/test/zip_archiver_jstest.cc", "../browser/resources/chromeos/zip_archiver/test/zip_archiver_jstest.cc",
"../browser/signin/chromeos_mirror_account_consistency_browsertest.cc", "../browser/signin/chromeos_mirror_account_consistency_browsertest.cc",
"../browser/ui/app_list/app_list_browsertest.cc",
"../browser/ui/app_list/arc/arc_usb_host_permission_browsertest.cc", "../browser/ui/app_list/arc/arc_usb_host_permission_browsertest.cc",
"../browser/ui/ash/accelerator_commands_browsertest.cc", "../browser/ui/ash/accelerator_commands_browsertest.cc",
"../browser/ui/ash/chrome_new_window_client_browsertest.cc", "../browser/ui/ash/chrome_new_window_client_browsertest.cc",
...@@ -2002,7 +2001,6 @@ test("browser_tests") { ...@@ -2002,7 +2001,6 @@ test("browser_tests") {
if (enable_app_list) { if (enable_app_list) {
sources += [ sources += [
"../browser/ui/app_list/app_list_client_impl_browsertest.cc", "../browser/ui/app_list/app_list_client_impl_browsertest.cc",
"../browser/ui/app_list/app_list_controller_browsertest.cc",
"../browser/ui/app_list/search/webstore/webstore_provider_browsertest.cc", "../browser/ui/app_list/search/webstore/webstore_provider_browsertest.cc",
] ]
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment