Skip to content

Commit

Permalink
[fuchsia] Support CreateContextParams data_quota_bytes field.
Browse files Browse the repository at this point in the history
Bug: 1071393
Bug: b/154204041
Test: web_engine_unittests
Change-Id: I3ba86964279ef7f467506d0781bee1e75b169a0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571699
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833805}
  • Loading branch information
Wez authored and Chromium LUCI CQ committed Dec 4, 2020
1 parent 51e1580 commit 41d3de7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
12 changes: 9 additions & 3 deletions fuchsia/engine/context_provider_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ void ContextProviderImpl::Create(
launch_options.handles_to_transfer.push_back(
{kContextRequestHandleId, context_request.channel().get()});

base::CommandLine launch_command(*base::CommandLine::ForCurrentProcess());

// Bind |data_directory| to /data directory, if provided.
zx::channel data_directory_channel;
if (params.has_data_directory()) {
Expand All @@ -285,10 +287,13 @@ void ContextProviderImpl::Create(
}
launch_options.paths_to_transfer.push_back(
base::PathToTransfer{data_path, data_directory_channel.release()});
}

base::CommandLine launch_command = *base::CommandLine::ForCurrentProcess();
std::vector<zx::channel> devtools_listener_channels;
if (params.has_data_quota_bytes()) {
launch_command.AppendSwitchNative(
switches::kDataQuotaBytes,
base::NumberToString(params.data_quota_bytes()));
}
}

// Process command-line settings specified in our package config-data.
base::Value web_engine_config;
Expand All @@ -310,6 +315,7 @@ void ContextProviderImpl::Create(
base::NumberToString(params.remote_debugging_port()));
}

std::vector<zx::channel> devtools_listener_channels;
if (devtools_listeners_.size() != 0) {
// Connect DevTools listeners to the new Context process.
std::vector<std::string> handles_ids;
Expand Down
79 changes: 78 additions & 1 deletion fuchsia/engine/context_provider_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "base/test/multiprocess_test.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "fuchsia/engine/context_provider_impl.h"
#include "fuchsia/engine/fake_context.h"
#include "fuchsia/engine/switches.h"
Expand All @@ -45,9 +46,13 @@ namespace {

constexpr char kTestDataFileIn[] = "DataFileIn";
constexpr char kTestDataFileOut[] = "DataFileOut";

constexpr char kUrl[] = "chrome://:emorhc";
constexpr char kTitle[] = "Palindrome";

constexpr uint64_t kTestQuotaBytes = 1024;
constexpr char kTestQuotaBytesSwitchValue[] = "1024";

MULTIPROCESS_TEST_MAIN(SpawnContextServer) {
base::test::SingleThreadTaskEnvironment task_environment(
base::test::SingleThreadTaskEnvironment::MainThreadType::IO);
Expand Down Expand Up @@ -344,7 +349,7 @@ TEST_F(ContextProviderImplTest, WithProfileDir) {
fuchsia::web::CreateContextParams create_params = BuildCreateContextParams();

// Setup data dir.
EXPECT_TRUE(profile_temp_dir.CreateUniqueTempDir());
ASSERT_TRUE(profile_temp_dir.CreateUniqueTempDir());
ASSERT_EQ(
base::WriteFile(profile_temp_dir.GetPath().AppendASCII(kTestDataFileIn),
nullptr, 0),
Expand Down Expand Up @@ -559,3 +564,75 @@ TEST(ContextProviderImplParamsTest, WithInsecureOriginsAsSecure) {

loop.Run();
}

TEST(ContextProviderImplConfigTest, WithDataQuotaBytes) {
const base::test::SingleThreadTaskEnvironment task_environment_{
base::test::SingleThreadTaskEnvironment::MainThreadType::IO};

base::RunLoop loop;
ContextProviderImpl context_provider;
context_provider.SetLaunchCallbackForTest(
base::BindLambdaForTesting([&loop](const base::CommandLine& command,
const base::LaunchOptions& options) {
EXPECT_EQ(command.GetSwitchValueASCII("data-quota-bytes"),
kTestQuotaBytesSwitchValue);
loop.Quit();
return base::Process();
}));

fuchsia::web::ContextPtr context;
context.set_error_handler([&loop](zx_status_t status) {
ZX_LOG(ERROR, status);
ADD_FAILURE();
loop.Quit();
});

fuchsia::web::CreateContextParams create_params = BuildCreateContextParams();
base::ScopedTempDir profile_temp_dir;
ASSERT_TRUE(profile_temp_dir.CreateUniqueTempDir());
create_params.set_data_directory(
base::OpenDirectoryHandle(profile_temp_dir.GetPath()));
create_params.set_data_quota_bytes(kTestQuotaBytes);
context_provider.Create(std::move(create_params), context.NewRequest());

loop.Run();
}

// TODO(crbug.com/1013412): This test doesn't actually exercise DRM, so could
// be executed everywhere if DRM support were configurable.
#if defined(ARCH_CPU_ARM64)
TEST(ContextProviderImplConfigTest, WithCdmDataQuotaBytes) {
const base::test::SingleThreadTaskEnvironment task_environment_{
base::test::SingleThreadTaskEnvironment::MainThreadType::IO};

base::RunLoop loop;
ContextProviderImpl context_provider;
context_provider.SetLaunchCallbackForTest(
base::BindLambdaForTesting([&loop](const base::CommandLine& command,
const base::LaunchOptions& options) {
EXPECT_EQ(command.GetSwitchValueASCII("cdm-data-quota-bytes"),
kTestQuotaBytesSwitchValue);
loop.Quit();
return base::Process();
}));

fuchsia::web::ContextPtr context;
context.set_error_handler([&loop](zx_status_t status) {
ZX_LOG(ERROR, status);
ADD_FAILURE();
loop.Quit();
});

fuchsia::web::CreateContextParams create_params = BuildCreateContextParams();
base::ScopedTempDir profile_temp_dir;
ASSERT_TRUE(profile_temp_dir.CreateUniqueTempDir());
create_params.set_cdm_data_directory(
base::OpenDirectoryHandle(profile_temp_dir.GetPath()));
create_params.set_features(fuchsia::web::ContextFeatureFlags::HEADLESS |
fuchsia::web::ContextFeatureFlags::WIDEVINE_CDM);
create_params.set_cdm_data_quota_bytes(kTestQuotaBytes);
context_provider.Create(std::move(create_params), context.NewRequest());

loop.Run();
}
#endif // defined(ARCH_CPU_ARM64)

0 comments on commit 41d3de7

Please sign in to comment.