Skip to content

Commit

Permalink
Create weblayer_browsertests target and one simple test.
Browse files Browse the repository at this point in the history
This will be added to FYI bots in a followup cl.

Change-Id: I8ca2e3ce61e628cf6e342a8ab4fc604975c0d225
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809897
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Auto-Submit: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697497}
  • Loading branch information
John Abd-El-Malek authored and Commit Bot committed Sep 18, 2019
1 parent e59b493 commit 002abf2
Show file tree
Hide file tree
Showing 21 changed files with 502 additions and 110 deletions.
5 changes: 5 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ group("gn_all") {
deps += [ "//weblayer/shell:weblayer_shell" ]
}

# TODO: enable this on Android.
if (is_win || (is_linux && !is_chromeos)) {
deps += [ "//weblayer/test:weblayer_browsertests" ]
}

if (!is_ios && !is_android) {
deps += [
"//components/cronet:cronet_tests",
Expand Down
12 changes: 11 additions & 1 deletion weblayer/browser/browser_main_parts_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void StopMessageLoop(base::OnceClosure quit_closure) {
BrowserMainPartsImpl::BrowserMainPartsImpl(
MainParams* params,
const content::MainFunctionParams& main_function_params)
: params_(params) {}
: params_(params), main_function_params_(main_function_params) {}

BrowserMainPartsImpl::~BrowserMainPartsImpl() = default;

Expand All @@ -83,6 +83,16 @@ int BrowserMainPartsImpl::PreEarlyInitialization() {
void BrowserMainPartsImpl::PreMainMessageLoopRun() {
ui::MaterialDesignController::Initialize();
params_->delegate->PreMainMessageLoopRun();

if (main_function_params_.ui_task) {
main_function_params_.ui_task->Run();
delete main_function_params_.ui_task;
run_message_loop_ = false;
}
}

bool BrowserMainPartsImpl::MainMessageLoopRun(int* result_code) {
return !run_message_loop_;
}

void BrowserMainPartsImpl::PreDefaultMainMessageLoopRun(
Expand Down
5 changes: 5 additions & 0 deletions weblayer/browser/browser_main_parts_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ class BrowserMainPartsImpl : public content::BrowserMainParts {
int PreEarlyInitialization() override;
void PreMainMessageLoopStart() override;
void PreMainMessageLoopRun() override;
bool MainMessageLoopRun(int* result_code) override;
void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;

private:
MainParams* params_;

// For running weblayer_browsertests.
const content::MainFunctionParams main_function_params_;
bool run_message_loop_ = true;

DISALLOW_COPY_AND_ASSIGN(BrowserMainPartsImpl);
};

Expand Down
14 changes: 10 additions & 4 deletions weblayer/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ declare_args() {
jumbo_static_library("weblayer_shell_lib") {
testonly = true
sources = [
"app/shell_main_params.cc",
"app/shell_main_params.h",
"browser/shell.cc",
"browser/shell.h",
"common/shell_switches.cc",
"common/shell_switches.h",
]

configs += [
Expand All @@ -34,6 +38,11 @@ jumbo_static_library("weblayer_shell_lib") {
"//build/config/compiler:no_size_t_to_int_warning",
]

defines = [
"WEBLAYER_SHELL_VERSION=\"$weblayer_shell_version\"",
"WEBLAYER_SHELL_MAJOR_VERSION=\"$weblayer_shell_major_version\"",
]

public_deps = [
"//weblayer:weblayer_lib",
]
Expand Down Expand Up @@ -239,10 +248,7 @@ if (is_android) {
sources += [ "app/shell.rc" ]
}

defines = [
"WEBLAYER_SHELL_VERSION=\"$weblayer_shell_version\"",
"WEBLAYER_SHELL_MAJOR_VERSION=\"$weblayer_shell_major_version\"",
]
defines = []

deps = [
":pak",
Expand Down
109 changes: 4 additions & 105 deletions weblayer/shell/app/shell_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/callback.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "net/base/filename_util.h"
#include "url/gurl.h"
#include "weblayer/public/main.h"
#include "weblayer/public/profile.h"
#include "weblayer/shell/browser/shell.h"

#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#endif

namespace {

GURL GetStartupURL() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
const base::CommandLine::StringVector& args = command_line->GetArgs();

#if defined(OS_ANDROID)
// Delay renderer creation on Android until surface is ready.
return GURL();
#endif

if (args.empty())
return GURL("https://www.google.com/");

GURL url(args[0]);
if (url.is_valid() && url.has_scheme())
return url;

return net::FilePathToFileURL(
base::MakeAbsoluteFilePath(base::FilePath(args[0])));
}

class MainDelegateImpl : public weblayer::MainDelegate {
public:
void PreMainMessageLoopRun() override {
InitializeProfiles();

weblayer::Shell::Initialize();

weblayer::Shell::CreateNewWindow(profile_.get(), GetStartupURL(),
gfx::Size());
}

void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) override {
weblayer::Shell::SetMainMessageLoopQuitClosure(std::move(quit_closure));
}

private:
void InitializeProfiles() {
base::FilePath path;
#if defined(OS_WIN)
CHECK(base::PathService::Get(base::DIR_LOCAL_APP_DATA, &path));
path = path.AppendASCII("web_shell");
#elif defined(OS_LINUX)
std::unique_ptr<base::Environment> env(base::Environment::Create());
base::FilePath config_dir(base::nix::GetXDGDirectory(
env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir));
path = config_dir.AppendASCII("web_shell");
#elif defined(OS_ANDROID)
CHECK(base::PathService::Get(base::DIR_ANDROID_APP_DATA, &path));
path = path.AppendASCII("web_shell");
#else
NOTIMPLEMENTED();
#endif

if (!base::PathExists(path))
base::CreateDirectory(path);

profile_ = weblayer::Profile::Create(path);

// TODO: create an incognito profile as well.
}

std::unique_ptr<weblayer::Profile> profile_;
};

weblayer::MainParams CreateMainParams() {
static const base::NoDestructor<MainDelegateImpl> weblayer_delegate;
weblayer::MainParams params;
params.delegate = const_cast<MainDelegateImpl*>(&(*weblayer_delegate));

base::PathService::Get(base::DIR_EXE, &params.log_filename);
params.log_filename = params.log_filename.AppendASCII("weblayer_shell.log");

params.pak_name = "weblayer.pak";

params.brand = "weblayer_shell";
params.full_version = WEBLAYER_SHELL_VERSION;
params.major_version = WEBLAYER_SHELL_MAJOR_VERSION;
return params;
}

} // namespace
#include "weblayer/shell/app/shell_main_params.h"

#if defined(OS_WIN)

#if defined(WIN_CONSOLE_APP)
int main() {
return weblayer::Main(CreateMainParams());
return weblayer::Main(weblayer::CreateMainParams());
#else
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
return weblayer::Main(CreateMainParams(), instance);
return weblayer::Main(weblayer::CreateMainParams(), instance);
#endif
}

#else

int main(int argc, const char** argv) {
return weblayer::Main(CreateMainParams(), argc, argv);
return weblayer::Main(weblayer::CreateMainParams(), argc, argv);
}

#endif // OS_POSIX
127 changes: 127 additions & 0 deletions weblayer/shell/app/shell_main_params.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// 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 "weblayer/shell/app/shell_main_params.h"

#include "base/callback.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "net/base/filename_util.h"
#include "url/gurl.h"
#include "weblayer/public/main.h"
#include "weblayer/public/profile.h"
#include "weblayer/shell/browser/shell.h"
#include "weblayer/shell/common/shell_switches.h"

#if defined(OS_WIN)
#include "base/base_paths_win.h"
#elif defined(OS_LINUX)
#include "base/nix/xdg_util.h"
#endif

namespace weblayer {

namespace {

GURL GetStartupURL() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
const base::CommandLine::StringVector& args = command_line->GetArgs();

#if defined(OS_ANDROID)
// Delay renderer creation on Android until surface is ready.
return GURL();
#endif

if (args.empty())
return GURL("https://www.google.com/");

GURL url(args[0]);
if (url.is_valid() && url.has_scheme())
return url;

return net::FilePathToFileURL(
base::MakeAbsoluteFilePath(base::FilePath(args[0])));
}

class MainDelegateImpl : public MainDelegate {
public:
void PreMainMessageLoopRun() override {
InitializeProfiles();

Shell::Initialize();

Shell::CreateNewWindow(profile_.get(), GetStartupURL(), gfx::Size());
}

void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) override {
Shell::SetMainMessageLoopQuitClosure(std::move(quit_closure));
}

private:
void InitializeProfiles() {
base::FilePath path;

base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kWebLayerShellDataPath)) {
path = cmd_line->GetSwitchValuePath(switches::kWebLayerShellDataPath);
if (base::DirectoryExists(path) || base::CreateDirectory(path)) {
// Profile needs an absolute path, which we would normally get via
// PathService. In this case, manually ensure the path is absolute.
if (!path.IsAbsolute())
path = base::MakeAbsoluteFilePath(path);
} else {
LOG(ERROR) << "Unable to create data-path directory: " << path.value();
}
} else {
#if defined(OS_WIN)
CHECK(base::PathService::Get(base::DIR_LOCAL_APP_DATA, &path));
path = path.AppendASCII("web_shell");
#elif defined(OS_LINUX)
std::unique_ptr<base::Environment> env(base::Environment::Create());
base::FilePath config_dir(
base::nix::GetXDGDirectory(env.get(), base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir));
path = config_dir.AppendASCII("web_shell");
#elif defined(OS_ANDROID)
CHECK(base::PathService::Get(base::DIR_ANDROID_APP_DATA, &path));
path = path.AppendASCII("web_shell");
#else
NOTIMPLEMENTED();
#endif
if (!base::PathExists(path))
base::CreateDirectory(path);
}

profile_ = Profile::Create(path);

// TODO: create an incognito profile as well.
}

std::unique_ptr<Profile> profile_;
};

} // namespace

MainParams CreateMainParams() {
static const base::NoDestructor<MainDelegateImpl> weblayer_delegate;
MainParams params;
params.delegate = const_cast<MainDelegateImpl*>(&(*weblayer_delegate));

base::PathService::Get(base::DIR_EXE, &params.log_filename);
params.log_filename = params.log_filename.AppendASCII("weblayer_shell.log");

params.pak_name = "weblayer.pak";

params.brand = "weblayer_shell";
params.full_version = WEBLAYER_SHELL_VERSION;
params.major_version = WEBLAYER_SHELL_MAJOR_VERSION;
return params;
}

} // namespace weblayer
15 changes: 15 additions & 0 deletions weblayer/shell/app/shell_main_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 WEBLAYER_SHELL_APP_SHELL_MAIN_PARAMS_H_
#define WEBLAYER_SHELL_APP_SHELL_MAIN_PARAMS_H_

namespace weblayer {
struct MainParams;

weblayer::MainParams CreateMainParams();

} // namespace weblayer

#endif // WEBLAYER_SHELL_APP_SHELL_MAIN_PARAMS_H_
5 changes: 5 additions & 0 deletions weblayer/shell/browser/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Shell : public BrowserObserver {
const GURL& url,
const gfx::Size& initial_size);

// Returns the currently open windows.
static std::vector<Shell*>& windows() { return windows_; }

// Closes all windows, pumps teardown tasks, then returns. The main message
// loop will be signalled to quit, before the call returns.
static void CloseAllWindows();
Expand All @@ -64,6 +67,8 @@ class Shell : public BrowserObserver {
// instance is destroyed.
static void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure);

BrowserController* browser_controller() { return browser_controller_.get(); }

gfx::NativeWindow window() { return window_; }

static gfx::Size GetShellDefaultSize();
Expand Down
12 changes: 12 additions & 0 deletions weblayer/shell/common/shell_switches.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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 "weblayer/shell/common/shell_switches.h"

namespace switches {

// Makes WebLayer Shell use the given path for its data directory.
const char kWebLayerShellDataPath[] = "data-path";

} // namespace switches
Loading

0 comments on commit 002abf2

Please sign in to comment.