Commit ef66d5de authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Improve ash content shell and test harness

* Make browser auto managed so that it behaves like chrome when created.
* Install event rewriter so that function keys are properly mapped.
* Install new window delegate that creates browser and SKV

Bug:979440
Test: None

Change-Id: Ib672693d61ad6b0d2ca339ee6259f1514b38e894
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1706641
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678473}
parent ea79ce2e
......@@ -1515,6 +1515,8 @@ static_library("ash_shell_lib_with_content") {
"shell/content/client/shell_content_browser_client.h",
"shell/content/client/shell_main_delegate.cc",
"shell/content/client/shell_main_delegate.h",
"shell/content/client/shell_new_window_delegate.cc",
"shell/content/client/shell_new_window_delegate.h",
"shell/content/embedded_browser.cc",
"shell/content/embedded_browser.h",
]
......@@ -1531,7 +1533,6 @@ static_library("ash_shell_lib_with_content") {
# TODO(https://crbug.com/644336): Make CrasAudioHandler Chrome or Ash only.
"//chromeos/audio",
"//chromeos/constants",
"//chromeos/dbus",
"//chromeos/dbus/biod",
"//chromeos/dbus/power",
"//chromeos/services/network_config/public/cpp:manifest",
......@@ -1550,6 +1551,7 @@ static_library("ash_shell_lib_with_content") {
"//ui/base",
"//ui/base/ime/chromeos",
"//ui/base/ime/init",
"//ui/chromeos/events",
"//ui/compositor",
"//ui/display",
"//ui/events/devices",
......
......@@ -26,24 +26,25 @@ class OverviewAnimationsTest
void SetUpOnMainThread() override {
AshContentTest::SetUpOnMainThread();
int additional_browsers = std::get<0>(GetParam());
int n_browsers = std::get<0>(GetParam());
bool browser = std::get<1>(GetParam());
tablet_mode_ = std::get<2>(GetParam());
if (tablet_mode_)
ash::ShellTestApi().SetTabletModeEnabledForTest(true);
GURL ntp_url("chrome://newtab");
const GURL google_url("https://www.google.com");
for (int i = additional_browsers; i >= 0; i--) {
auto* window = browser ? CreateBrowserWindow() : CreateTestWindow();
for (int i = 0; i < n_browsers; ++i) {
auto* window = browser ? CreateBrowserWindow(google_url)
: CreateBrowserWindow(GURL());
if (!window_)
window_ = window;
}
float cost_per_browser = browser ? 0.5 : 0.1;
int wait_seconds = (base::SysInfo::IsRunningOnChromeOS() ? 5 : 0) +
additional_browsers * cost_per_browser;
n_browsers * cost_per_browser;
base::RunLoop run_loop;
base::PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(wait_seconds));
......@@ -78,6 +79,7 @@ ASH_CONTENT_TEST_P(OverviewAnimationsTest, EnterExit) {
/*command=*/false);
ash::ShellTestApi().WaitForOverviewAnimationState(
ash::OverviewAnimationState::kEnterAnimationComplete);
// TODO(oshima): Wait until frame animation ends.
ui_controls::SendKeyPress(window(), ui::VKEY_MEDIA_LAUNCH_APP1,
/*control=*/false,
/*shift=*/false,
......
......@@ -9,8 +9,10 @@
#include "ash/keyboard/test_keyboard_ui.h"
#include "ash/login_status.h"
#include "ash/public/cpp/event_rewriter_controller.h"
#include "ash/session/test_pref_service_provider.h"
#include "ash/shell.h"
#include "ash/shell/content/client/shell_new_window_delegate.h"
#include "ash/shell/content/embedded_browser.h"
#include "ash/shell/example_app_list_client.h"
#include "ash/shell/example_session_controller_client.h"
......@@ -19,6 +21,7 @@
#include "ash/shell/window_type_launcher.h"
#include "ash/shell/window_watcher.h"
#include "ash/shell_init_params.h"
#include "ash/sticky_keys/sticky_keys_controller.h"
#include "ash/test/ash_test_helper.h"
#include "base/bind.h"
#include "base/command_line.h"
......@@ -35,6 +38,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ui_base_features.h"
#include "ui/chromeos/events/event_rewriter_chromeos.h"
#include "ui/views/examples/examples_window_with_content.h"
namespace ash {
......@@ -81,14 +85,17 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
content::GetSystemConnector());
AshTestHelper::InitParams init_params;
// TODO(oshima): Separate the class for ash_shell to reduce the test binary
// size.
if (parameters_.ui_task)
init_params.config_type = AshTestHelper::kPerfTest;
else
else {
new_window_delegate_ = std::make_unique<ShellNewWindowDelegate>();
init_params.config_type = AshTestHelper::kShell;
}
ShellInitParams shell_init_params;
shell_init_params.delegate =
std::make_unique<ash::shell::ShellDelegateImpl>();
shell_init_params.delegate = std::make_unique<shell::ShellDelegateImpl>();
shell_init_params.context_factory = content::GetContextFactory();
shell_init_params.context_factory_private =
content::GetContextFactoryPrivate();
......@@ -100,11 +107,17 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
window_watcher_ = std::make_unique<WindowWatcher>();
ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
Shell::GetPrimaryRootWindow()->GetHost()->Show();
ash::Shell::Get()->InitWaylandServer(nullptr);
Shell::Get()->InitWaylandServer(nullptr);
if (!parameters_.ui_task) {
// Install Rewriter so that function keys are properly re-mapped.
auto* event_rewriter_controller = EventRewriterController::Get();
event_rewriter_controller->AddEventRewriter(
std::make_unique<ui::EventRewriterChromeOS>(
nullptr, Shell::Get()->sticky_keys_controller()));
// Initialize session controller client and create fake user sessions. The
// fake user sessions makes ash into the logged in state.
example_session_controller_client_ =
......@@ -116,7 +129,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
example_app_list_client_ = std::make_unique<ExampleAppListClient>(
Shell::Get()->app_list_controller());
ash::shell::InitWindowTypeLauncher(
shell::InitWindowTypeLauncher(
base::BindRepeating(views::examples::ShowExamplesWindowWithContent,
base::Passed(base::OnceClosure()),
base::Unretained(browser_context_.get()), nullptr),
......
......@@ -32,6 +32,7 @@ class AshTestHelper;
namespace shell {
class ExampleAppListClient;
class ExampleSessionControllerClient;
class ShellNewWindowDelegate;
class WindowWatcher;
class ShellBrowserMainParts : public content::BrowserMainParts {
......@@ -61,6 +62,7 @@ class ShellBrowserMainParts : public content::BrowserMainParts {
std::unique_ptr<ash::AshTestHelper> ash_test_helper_;
std::unique_ptr<chromeos::network_config::CrosNetworkConfigTestHelper>
network_config_helper_;
std::unique_ptr<ShellNewWindowDelegate> new_window_delegate_;
content::MainFunctionParams parameters_;
DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts);
......
// Copyright 2019 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 "ash/shell/content/client/shell_new_window_delegate.h"
#include "ash/public/cpp/keyboard_shortcut_viewer.h"
#include "ash/shell/content/client/shell_browser_main_parts.h"
#include "ash/shell/content/embedded_browser.h"
namespace ash {
namespace shell {
ShellNewWindowDelegate::ShellNewWindowDelegate() = default;
ShellNewWindowDelegate::~ShellNewWindowDelegate() = default;
void ShellNewWindowDelegate::NewTab() {
EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(),
GURL("https://www.google.com"));
}
void ShellNewWindowDelegate::NewTabWithUrl(const GURL& url,
bool from_user_interaction) {
EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(), url);
}
void ShellNewWindowDelegate::NewWindow(bool incognito) {
EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(),
GURL("https://www.google.com"));
}
void ShellNewWindowDelegate::OpenFileManager() {}
void ShellNewWindowDelegate::OpenCrosh() {}
void ShellNewWindowDelegate::OpenGetHelp() {}
void ShellNewWindowDelegate::RestoreTab() {}
void ShellNewWindowDelegate::ShowKeyboardShortcutViewer() {
ash::ToggleKeyboardShortcutViewer();
}
void ShellNewWindowDelegate::ShowTaskManager() {}
void ShellNewWindowDelegate::OpenFeedbackPage(bool from_assistant) {}
} // namespace shell
} // namespace ash
// Copyright 2019 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 ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_
#define ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_
#include <memory>
#include <string>
#include "ash/public/cpp/new_window_delegate.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/browser/content_browser_client.h"
namespace ash {
namespace shell {
class ShellNewWindowDelegate : public ash::NewWindowDelegate {
public:
ShellNewWindowDelegate();
~ShellNewWindowDelegate() override;
// ash::NewWindowDelegate:
void NewTab() override;
void NewTabWithUrl(const GURL& url, bool from_user_interaction) override;
void NewWindow(bool incognito) override;
void OpenFileManager() override;
void OpenCrosh() override;
void OpenGetHelp() override;
void RestoreTab() override;
void ShowKeyboardShortcutViewer() override;
void ShowTaskManager() override;
void OpenFeedbackPage(bool from_assistant) override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellNewWindowDelegate);
};
} // namespace shell
} // namespace ash
#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_
......@@ -5,6 +5,7 @@
#include "ash/shell/content/embedded_browser.h"
#include "ash/public/cpp/app_types.h"
#include "ash/wm/window_state.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/fill_layout.h"
......@@ -30,10 +31,12 @@ class BrowserWidgetDelegateView : public views::WidgetDelegateView {
// views::WidgetDelegateView:
base::string16 GetWindowTitle() const override {
const static base::string16 title =
base::ASCIIToUTF16("Classic: Embed by NativeViewHost");
const static base::string16 title = base::ASCIIToUTF16("WebView Browser");
return title;
}
bool CanResize() const override { return true; }
bool CanMaximize() const override { return true; }
bool CanMinimize() const override { return true; }
private:
DISALLOW_COPY_AND_ASSIGN(BrowserWidgetDelegateView);
......@@ -45,9 +48,11 @@ EmbeddedBrowser::EmbeddedBrowser(content::BrowserContext* context,
const GURL& url)
: widget_(new views::Widget) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(20, 0, 800, 600);
params.bounds = gfx::Rect(20, 20, 800, 600);
params.delegate = new BrowserWidgetDelegateView(context, url);
widget_->Init(params);
wm::GetWindowState(widget_->GetNativeWindow())
->SetWindowPositionManaged(true);
widget_->Show();
}
......
......@@ -162,10 +162,9 @@ void AshContentTest::TearDownOnMainThread() {
content::ContentBrowserTest::TearDownOnMainThread();
}
aura::Window* AshContentTest::CreateBrowserWindow() {
aura::Window* AshContentTest::CreateBrowserWindow(const GURL& url) {
return ash::shell::EmbeddedBrowser::Create(
ash::shell::ShellBrowserMainParts::GetBrowserContext(),
GURL("https://www.google.com"));
ash::shell::ShellBrowserMainParts::GetBrowserContext(), url);
}
aura::Window* AshContentTest::CreateTestWindow() {
......
......@@ -25,7 +25,7 @@ class AshContentTest : public content::ContentBrowserTest {
void PostRunTestOnMainThread() override;
protected:
aura::Window* CreateBrowserWindow();
aura::Window* CreateBrowserWindow(const GURL& url);
aura::Window* CreateTestWindow();
virtual std::vector<std::string> GetUMAHistogramNames() const;
......
......@@ -184,7 +184,8 @@ void AshTestHelper::SetUp(const InitParams& init_params,
app_list_test_helper_ = std::make_unique<AppListTestHelper>();
new_window_delegate_ = std::make_unique<TestNewWindowDelegate>();
if (!NewWindowDelegate::GetInstance())
new_window_delegate_ = std::make_unique<TestNewWindowDelegate>();
// Post shell creation config init.
switch (init_params.config_type) {
......
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