compute pressure: Add a content_shell code path for virtual pressure source calls
This is similar to https://crrev.com/c/4770865 for sensors: it exposes some new calls in the Internals object that are routed to content/web_test via a separate Mojo interface exposed only when content_shell is run in web tests mode, WebPressureManagerAutomation. Noteworthy items: - The testdriver calls have not been written yet, but one can play with the new calls in WPT by directly calling e.g. await internals.createVirtualPressureSource("cpu"); - The Internals object is only exposed to the Window global, so the above does not work for workers directly. Workers are supposed to make calls via testdriver.js on a Window object. Bug: 347031400 Change-Id: Ib341bb63a6ebcec1571140e35f501d570a67a108 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5665299 Reviewed-by: danakj <danakj@chromium.org> Commit-Queue: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com> Reviewed-by: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/main@{#1332385}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e94fc3bc4c
commit
12851b35a7
@ -137,6 +137,8 @@ static_library("web_test_browser") {
|
||||
"browser/web_test_origin_trial_throttle.h",
|
||||
"browser/web_test_permission_manager.cc",
|
||||
"browser/web_test_permission_manager.h",
|
||||
"browser/web_test_pressure_manager.cc",
|
||||
"browser/web_test_pressure_manager.h",
|
||||
"browser/web_test_push_messaging_service.cc",
|
||||
"browser/web_test_push_messaging_service.h",
|
||||
"browser/web_test_sensor_provider_manager.cc",
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include "content/web_test/browser/web_test_fedcm_manager.h"
|
||||
#include "content/web_test/browser/web_test_origin_trial_throttle.h"
|
||||
#include "content/web_test/browser/web_test_permission_manager.h"
|
||||
#include "content/web_test/browser/web_test_pressure_manager.h"
|
||||
#include "content/web_test/browser/web_test_sensor_provider_manager.h"
|
||||
#include "content/web_test/browser/web_test_storage_access_manager.h"
|
||||
#include "content/web_test/browser/web_test_tts_platform.h"
|
||||
@ -558,6 +559,10 @@ void WebTestContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
|
||||
map->Add<blink::test::mojom::WebSensorProviderAutomation>(base::BindRepeating(
|
||||
&WebTestContentBrowserClient::BindWebSensorProviderAutomation,
|
||||
base::Unretained(this)));
|
||||
map->Add<blink::test::mojom::WebPressureManagerAutomation>(
|
||||
base::BindRepeating(
|
||||
&WebTestContentBrowserClient::BindWebPressureManagerAutomation,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
bool WebTestContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
|
||||
@ -639,6 +644,15 @@ void WebTestContentBrowserClient::ResetWebSensorProviderAutomation() {
|
||||
sensor_provider_manager_.reset();
|
||||
}
|
||||
|
||||
void WebTestContentBrowserClient::BindWebPressureManagerAutomation(
|
||||
RenderFrameHost* render_frame_host,
|
||||
mojo::PendingReceiver<blink::test::mojom::WebPressureManagerAutomation>
|
||||
receiver) {
|
||||
WebTestPressureManager::GetOrCreate(
|
||||
WebContents::FromRenderFrameHost(render_frame_host))
|
||||
->Bind(std::move(receiver));
|
||||
}
|
||||
|
||||
std::unique_ptr<LoginDelegate> WebTestContentBrowserClient::CreateLoginDelegate(
|
||||
const net::AuthChallengeInfo& auth_info,
|
||||
content::WebContents* web_contents,
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "services/service_manager/public/cpp/binder_registry.h"
|
||||
#include "third_party/blink/public/mojom/badging/badging.mojom.h"
|
||||
#include "third_party/blink/public/mojom/clipboard/clipboard.mojom.h"
|
||||
#include "third_party/blink/public/mojom/compute_pressure/web_pressure_manager_automation.mojom-forward.h"
|
||||
#include "third_party/blink/public/mojom/cookie_manager/cookie_manager_automation.mojom-forward.h"
|
||||
#include "third_party/blink/public/mojom/device_posture/device_posture_provider_automation.mojom-forward.h"
|
||||
#include "third_party/blink/public/mojom/permissions/permission_automation.mojom-forward.h"
|
||||
@ -178,6 +179,11 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient {
|
||||
mojo::PendingReceiver<blink::test::mojom::WebSensorProviderAutomation>
|
||||
receiver);
|
||||
|
||||
void BindWebPressureManagerAutomation(
|
||||
RenderFrameHost* render_frame_host,
|
||||
mojo::PendingReceiver<blink::test::mojom::WebPressureManagerAutomation>
|
||||
receiver);
|
||||
|
||||
void BindWebTestControlHost(
|
||||
int render_process_id,
|
||||
mojo::PendingAssociatedReceiver<mojom::WebTestControlHost> receiver);
|
||||
|
@ -8,9 +8,6 @@
|
||||
#endif
|
||||
|
||||
#include "content/web_test/browser/web_test_control_host.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@ -28,11 +25,14 @@
|
||||
#include "base/base64.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "base/location.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/ranges/algorithm.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
@ -91,6 +91,7 @@
|
||||
#include "content/web_test/browser/web_test_devtools_bindings.h"
|
||||
#include "content/web_test/browser/web_test_first_device_bluetooth_chooser.h"
|
||||
#include "content/web_test/browser/web_test_permission_manager.h"
|
||||
#include "content/web_test/browser/web_test_pressure_manager.h"
|
||||
#include "content/web_test/common/web_test_constants.h"
|
||||
#include "content/web_test/common/web_test_string_util.h"
|
||||
#include "content/web_test/common/web_test_switches.h"
|
||||
@ -756,6 +757,23 @@ void WebTestControlHost::ResetBrowserAfterWebTest() {
|
||||
ShellContentBrowserClient::Get()->browser_context();
|
||||
browser_context->ResetFederatedPermissionContext();
|
||||
|
||||
// Delete any ScopedVirtualPressureSourceForDevTools and
|
||||
// WebTestPressureManager instances created by WebTestContentBrowserClient.
|
||||
// At this point all other windows have been closed and their WebContents
|
||||
// have been destroyed, so we only need to worry about |main_window_|.
|
||||
//
|
||||
// Note that if other windows were using WebTestPressureManager there might
|
||||
// be a race condition between ScopedVirtualPressureSourceForDevTools and
|
||||
// WebContentsPressureManagerProxy because both the latter and
|
||||
// WebTestPressureManager inherit from WebContentsUserData so their
|
||||
// destruction order can vary. This is not a problem though -- in the worst
|
||||
// case, some virtual pressure sources will remain valid but unused in
|
||||
// //services during content_shell's lifetime.
|
||||
if (main_window_) {
|
||||
main_window_->web_contents()->RemoveUserData(
|
||||
WebTestPressureManager::UserDataKey());
|
||||
}
|
||||
|
||||
// Delete all cookies, Attribution Reporting data and Aggregation service data
|
||||
{
|
||||
StoragePartition* storage_partition =
|
||||
|
82
content/web_test/browser/web_test_pressure_manager.cc
Normal file
82
content/web_test/browser/web_test_pressure_manager.cc
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "content/web_test/browser/web_test_pressure_manager.h"
|
||||
|
||||
#include "content/browser/compute_pressure/web_contents_pressure_manager_proxy.h"
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
WebTestPressureManager::WebTestPressureManager(WebContents* web_contents)
|
||||
: WebContentsUserData<WebTestPressureManager>(*web_contents) {}
|
||||
|
||||
WebTestPressureManager::~WebTestPressureManager() = default;
|
||||
|
||||
// static
|
||||
WebTestPressureManager* WebTestPressureManager::GetOrCreate(
|
||||
WebContents* web_contents) {
|
||||
WebContentsUserData<WebTestPressureManager>::CreateForWebContents(
|
||||
web_contents);
|
||||
return WebContentsUserData<WebTestPressureManager>::FromWebContents(
|
||||
web_contents);
|
||||
}
|
||||
|
||||
void WebTestPressureManager::Bind(
|
||||
mojo::PendingReceiver<blink::test::mojom::WebPressureManagerAutomation>
|
||||
receiver) {
|
||||
receivers_.Add(this, std::move(receiver));
|
||||
}
|
||||
|
||||
void WebTestPressureManager::CreateVirtualPressureSource(
|
||||
device::mojom::PressureSource source,
|
||||
device::mojom::VirtualPressureSourceMetadataPtr metadata,
|
||||
CreateVirtualPressureSourceCallback callback) {
|
||||
if (pressure_source_overrides_.contains(source)) {
|
||||
std::move(callback).Run(
|
||||
blink::test::mojom::CreateVirtualPressureSourceResult::
|
||||
kSourceTypeAlreadyOverridden);
|
||||
return;
|
||||
}
|
||||
|
||||
auto virtual_pressure_source =
|
||||
WebContentsPressureManagerProxy::GetOrCreate(&GetWebContents())
|
||||
->CreateVirtualPressureSourceForDevTools(source, std::move(metadata));
|
||||
CHECK(virtual_pressure_source);
|
||||
pressure_source_overrides_[source] = std::move(virtual_pressure_source);
|
||||
|
||||
std::move(callback).Run(
|
||||
blink::test::mojom::CreateVirtualPressureSourceResult::kSuccess);
|
||||
}
|
||||
|
||||
void WebTestPressureManager::RemoveVirtualPressureSource(
|
||||
device::mojom::PressureSource source,
|
||||
RemoveVirtualPressureSourceCallback callback) {
|
||||
pressure_source_overrides_.erase(source);
|
||||
std::move(callback).Run();
|
||||
}
|
||||
|
||||
void WebTestPressureManager::UpdateVirtualPressureSourceState(
|
||||
device::mojom::PressureSource source,
|
||||
device::mojom::PressureState state,
|
||||
UpdateVirtualPressureSourceStateCallback callback) {
|
||||
auto it = pressure_source_overrides_.find(source);
|
||||
if (it == pressure_source_overrides_.end()) {
|
||||
std::move(callback).Run(
|
||||
blink::test::mojom::UpdateVirtualPressureSourceStateResult::
|
||||
kSourceTypeNotOverridden);
|
||||
return;
|
||||
}
|
||||
|
||||
it->second->UpdateVirtualPressureSourceState(
|
||||
state,
|
||||
base::BindOnce(std::move(callback),
|
||||
blink::test::mojom::
|
||||
UpdateVirtualPressureSourceStateResult::kSuccess));
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebTestPressureManager);
|
||||
|
||||
} // namespace content
|
67
content/web_test/browser/web_test_pressure_manager.h
Normal file
67
content/web_test/browser/web_test_pressure_manager.h
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CONTENT_WEB_TEST_BROWSER_WEB_TEST_PRESSURE_MANAGER_H_
|
||||
#define CONTENT_WEB_TEST_BROWSER_WEB_TEST_PRESSURE_MANAGER_H_
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
#include "mojo/public/cpp/bindings/receiver_set.h"
|
||||
#include "services/device/public/mojom/pressure_update.mojom-shared.h"
|
||||
#include "third_party/blink/public/mojom/compute_pressure/web_pressure_manager_automation.mojom.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
class ScopedVirtualPressureSourceForDevTools;
|
||||
class WebContents;
|
||||
|
||||
// Implementation of the WebPressureManagerAutomation Mojo interface for use by
|
||||
// Blink's InternalsComputePressure. It implements the required method calls
|
||||
// exposed by testdriver.js by forwarding the calls to
|
||||
// WebContentsPressureManagerProxy.
|
||||
class WebTestPressureManager
|
||||
: public blink::test::mojom::WebPressureManagerAutomation,
|
||||
public WebContentsUserData<WebTestPressureManager> {
|
||||
public:
|
||||
static WebTestPressureManager* GetOrCreate(WebContents*);
|
||||
|
||||
WebTestPressureManager(const WebTestPressureManager&) = delete;
|
||||
WebTestPressureManager& operator=(const WebTestPressureManager&) = delete;
|
||||
|
||||
~WebTestPressureManager() override;
|
||||
|
||||
void Bind(
|
||||
mojo::PendingReceiver<blink::test::mojom::WebPressureManagerAutomation>
|
||||
receiver);
|
||||
|
||||
// blink::mojom::WebPressureManagerAutomation overrides.
|
||||
void CreateVirtualPressureSource(
|
||||
device::mojom::PressureSource source,
|
||||
device::mojom::VirtualPressureSourceMetadataPtr metadata,
|
||||
CreateVirtualPressureSourceCallback callback) override;
|
||||
void RemoveVirtualPressureSource(
|
||||
device::mojom::PressureSource source,
|
||||
RemoveVirtualPressureSourceCallback callback) override;
|
||||
void UpdateVirtualPressureSourceState(
|
||||
device::mojom::PressureSource source,
|
||||
device::mojom::PressureState state,
|
||||
UpdateVirtualPressureSourceStateCallback callback) override;
|
||||
|
||||
private:
|
||||
explicit WebTestPressureManager(WebContents* web_contents);
|
||||
|
||||
base::flat_map<device::mojom::PressureSource,
|
||||
std::unique_ptr<ScopedVirtualPressureSourceForDevTools>>
|
||||
pressure_source_overrides_;
|
||||
|
||||
mojo::ReceiverSet<blink::test::mojom::WebPressureManagerAutomation>
|
||||
receivers_;
|
||||
|
||||
friend WebContentsUserData;
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_WEB_TEST_BROWSER_WEB_TEST_PRESSURE_MANAGER_H_
|
1
third_party/blink/public/mojom/BUILD.gn
vendored
1
third_party/blink/public/mojom/BUILD.gn
vendored
@ -50,6 +50,7 @@ mojom("mojom_platform") {
|
||||
"close_watcher/close_listener.mojom",
|
||||
"commit_result/commit_result.mojom",
|
||||
"compute_pressure/web_pressure_manager.mojom",
|
||||
"compute_pressure/web_pressure_manager_automation.mojom",
|
||||
"content_extraction/inner_html.mojom",
|
||||
"content_extraction/inner_text.mojom",
|
||||
"content_index/content_index.mojom",
|
||||
|
42
third_party/blink/public/mojom/compute_pressure/web_pressure_manager_automation.mojom
vendored
Normal file
42
third_party/blink/public/mojom/compute_pressure/web_pressure_manager_automation.mojom
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
module blink.test.mojom;
|
||||
|
||||
import "services/device/public/mojom/pressure_manager.mojom";
|
||||
import "services/device/public/mojom/pressure_update.mojom";
|
||||
|
||||
// Result of CreateVirtualPressureSource
|
||||
enum CreateVirtualPressureSourceResult {
|
||||
kSuccess,
|
||||
kSourceTypeAlreadyOverridden,
|
||||
};
|
||||
|
||||
// Result of UpdateVirtualPressureSourceState
|
||||
enum UpdateVirtualPressureSourceStateResult {
|
||||
kSuccess,
|
||||
kSourceTypeNotOverridden,
|
||||
};
|
||||
|
||||
// Provides a way to set and update virtual pressure sources as described in
|
||||
// https://w3c.github.io/compute-pressure/#automation
|
||||
//
|
||||
// This interface exists solely for the content_shell and
|
||||
// InternalsComputePressure implementation, as the ChromeDriver-based code path
|
||||
// uses CDP to achieve the same results.
|
||||
interface WebPressureManagerAutomation {
|
||||
// Creates a new virtual pressure source of type |source|.
|
||||
CreateVirtualPressureSource(
|
||||
device.mojom.PressureSource source,
|
||||
device.mojom.VirtualPressureSourceMetadata metadata) =>
|
||||
(CreateVirtualPressureSourceResult result);
|
||||
|
||||
// Removes a previously created virtual pressure source.
|
||||
RemoveVirtualPressureSource(device.mojom.PressureSource source) => ();
|
||||
|
||||
// Sends a state update for a given virtual pressure source.
|
||||
UpdateVirtualPressureSourceState(
|
||||
device.mojom.PressureSource source, device.mojom.PressureState state) =>
|
||||
(UpdateVirtualPressureSourceStateResult result);
|
||||
};
|
@ -3397,6 +3397,8 @@ generated_interface_extra_sources_in_modules = [
|
||||
# Generated sources for testing
|
||||
|
||||
generated_dictionary_sources_for_testing_in_modules = [
|
||||
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_create_virtual_pressure_source_options.cc",
|
||||
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_create_virtual_pressure_source_options.h",
|
||||
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_create_virtual_sensor_options.cc",
|
||||
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_create_virtual_sensor_options.h",
|
||||
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_virtual_sensor_information.cc",
|
||||
|
@ -1368,6 +1368,8 @@ if (!target_os_is_android) {
|
||||
# These IDL definitions are used only for testing.
|
||||
static_idl_files_in_modules_for_testing = [
|
||||
"//third_party/blink/renderer/modules/accessibility/testing/internals_accessibility.idl",
|
||||
"//third_party/blink/renderer/modules/compute_pressure/testing/create_virtual_pressure_source_options.idl",
|
||||
"//third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.idl",
|
||||
"//third_party/blink/renderer/modules/credentialmanagement/testing/internals_fed_cm.idl",
|
||||
"//third_party/blink/renderer/modules/device_posture/testing/internals_device_posture.idl",
|
||||
"//third_party/blink/renderer/modules/fuzzing/internals_fuzzing.idl",
|
||||
|
2
third_party/blink/renderer/modules/BUILD.gn
vendored
2
third_party/blink/renderer/modules/BUILD.gn
vendored
@ -222,6 +222,8 @@ source_set("modules_testing") {
|
||||
sources = [
|
||||
"accessibility/testing/internals_accessibility.cc",
|
||||
"accessibility/testing/internals_accessibility.h",
|
||||
"compute_pressure/testing/internals_compute_pressure.cc",
|
||||
"compute_pressure/testing/internals_compute_pressure.h",
|
||||
"credentialmanagement/testing/internals_fed_cm.cc",
|
||||
"credentialmanagement/testing/internals_fed_cm.h",
|
||||
"device_posture/testing/internals_device_posture.cc",
|
||||
|
9
third_party/blink/renderer/modules/compute_pressure/testing/create_virtual_pressure_source_options.idl
vendored
Normal file
9
third_party/blink/renderer/modules/compute_pressure/testing/create_virtual_pressure_source_options.idl
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Represents the optional parameters described in
|
||||
// https://w3c.github.io/compute-pressure/#create-virtual-pressure-source
|
||||
dictionary CreateVirtualPressureSourceOptions {
|
||||
boolean available = true;
|
||||
};
|
184
third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.cc
vendored
Normal file
184
third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.cc
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.h"
|
||||
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "services/device/public/mojom/pressure_manager.mojom-blink.h"
|
||||
#include "services/device/public/mojom/pressure_update.mojom-shared.h"
|
||||
#include "third_party/blink/public/mojom/compute_pressure/web_pressure_manager_automation.mojom-blink.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
|
||||
#include "third_party/blink/renderer/bindings/modules/v8/v8_create_virtual_pressure_source_options.h"
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/script_state.h"
|
||||
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
|
||||
#include "third_party/blink/renderer/platform/heap/persistent.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
namespace {
|
||||
|
||||
device::mojom::blink::VirtualPressureSourceMetadataPtr ToMojoPressureMetadata(
|
||||
CreateVirtualPressureSourceOptions* options) {
|
||||
if (!options) {
|
||||
return device::mojom::blink::VirtualPressureSourceMetadata::New();
|
||||
}
|
||||
|
||||
auto metadata = device::mojom::blink::VirtualPressureSourceMetadata::New();
|
||||
metadata->available = options->available();
|
||||
return metadata;
|
||||
}
|
||||
|
||||
device::mojom::blink::PressureSource ToMojoPressureSource(
|
||||
V8PressureSource::Enum source) {
|
||||
switch (source) {
|
||||
case blink::V8PressureSource::Enum::kCpu:
|
||||
return device::mojom::blink::PressureSource::kCpu;
|
||||
}
|
||||
}
|
||||
|
||||
device::mojom::blink::PressureState ToMojoPressureState(
|
||||
V8PressureState::Enum state) {
|
||||
switch (state) {
|
||||
case blink::V8PressureState::Enum::kNominal:
|
||||
return device::mojom::blink::PressureState::kNominal;
|
||||
case blink::V8PressureState::Enum::kFair:
|
||||
return device::mojom::blink::PressureState::kFair;
|
||||
case blink::V8PressureState::Enum::kSerious:
|
||||
return device::mojom::blink::PressureState::kSerious;
|
||||
case blink::V8PressureState::Enum::kCritical:
|
||||
return device::mojom::blink::PressureState::kCritical;
|
||||
}
|
||||
}
|
||||
|
||||
ExecutionContext* GetExecutionContext(ScriptState* script_state) {
|
||||
// Although this API is available for workers as well, the
|
||||
// InternalsComputePressure calls are always made on a Window object via
|
||||
// testdriver.js.
|
||||
LocalDOMWindow* window = LocalDOMWindow::From(script_state);
|
||||
CHECK(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
ScriptPromiseUntyped InternalsComputePressure::createVirtualPressureSource(
|
||||
ScriptState* script_state,
|
||||
Internals&,
|
||||
V8PressureSource source,
|
||||
CreateVirtualPressureSourceOptions* options) {
|
||||
auto* execution_context = GetExecutionContext(script_state);
|
||||
mojo::Remote<test::mojom::blink::WebPressureManagerAutomation>
|
||||
web_pressure_manager_automation;
|
||||
execution_context->GetBrowserInterfaceBroker().GetInterface(
|
||||
web_pressure_manager_automation.BindNewPipeAndPassReceiver());
|
||||
|
||||
auto* resolver =
|
||||
MakeGarbageCollected<ScriptPromiseResolver<IDLUndefined>>(script_state);
|
||||
auto promise = resolver->Promise();
|
||||
auto* raw_pressure_manager_automation = web_pressure_manager_automation.get();
|
||||
raw_pressure_manager_automation->CreateVirtualPressureSource(
|
||||
ToMojoPressureSource(source.AsEnum()), ToMojoPressureMetadata(options),
|
||||
WTF::BindOnce(
|
||||
// While we only really need |resolver|, we also take the
|
||||
// mojo::Remote<> so that it remains alive after this function exits.
|
||||
[](ScriptPromiseResolver<IDLUndefined>* resolver,
|
||||
mojo::Remote<test::mojom::blink::WebPressureManagerAutomation>,
|
||||
test::mojom::blink::CreateVirtualPressureSourceResult result) {
|
||||
switch (result) {
|
||||
case test::mojom::blink::CreateVirtualPressureSourceResult::
|
||||
kSuccess:
|
||||
resolver->Resolve();
|
||||
break;
|
||||
case test::mojom::blink::CreateVirtualPressureSourceResult::
|
||||
kSourceTypeAlreadyOverridden:
|
||||
resolver->Reject(
|
||||
"This pressure source type has already been created");
|
||||
break;
|
||||
}
|
||||
resolver->Resolve();
|
||||
},
|
||||
WrapPersistent(resolver),
|
||||
std::move(web_pressure_manager_automation)));
|
||||
return promise;
|
||||
}
|
||||
|
||||
// static
|
||||
ScriptPromiseUntyped InternalsComputePressure::removeVirtualPressureSource(
|
||||
ScriptState* script_state,
|
||||
Internals&,
|
||||
V8PressureSource source) {
|
||||
auto* execution_context = GetExecutionContext(script_state);
|
||||
mojo::Remote<test::mojom::blink::WebPressureManagerAutomation>
|
||||
web_pressure_manager_automation;
|
||||
execution_context->GetBrowserInterfaceBroker().GetInterface(
|
||||
web_pressure_manager_automation.BindNewPipeAndPassReceiver());
|
||||
|
||||
auto* resolver =
|
||||
MakeGarbageCollected<ScriptPromiseResolver<IDLUndefined>>(script_state);
|
||||
auto promise = resolver->Promise();
|
||||
auto* raw_pressure_manager_automation = web_pressure_manager_automation.get();
|
||||
raw_pressure_manager_automation->RemoveVirtualPressureSource(
|
||||
ToMojoPressureSource(source.AsEnum()),
|
||||
WTF::BindOnce(
|
||||
// While we only really need |resolver|, we also take the
|
||||
// mojo::Remote<> so that it remains alive after this function exits.
|
||||
[](ScriptPromiseResolver<IDLUndefined>* resolver,
|
||||
mojo::Remote<test::mojom::blink::WebPressureManagerAutomation>) {
|
||||
resolver->Resolve();
|
||||
},
|
||||
WrapPersistent(resolver),
|
||||
std::move(web_pressure_manager_automation)));
|
||||
return promise;
|
||||
}
|
||||
|
||||
// static
|
||||
ScriptPromiseUntyped InternalsComputePressure::updateVirtualPressureSource(
|
||||
ScriptState* script_state,
|
||||
Internals&,
|
||||
V8PressureSource source,
|
||||
V8PressureState state) {
|
||||
auto* execution_context = GetExecutionContext(script_state);
|
||||
mojo::Remote<test::mojom::blink::WebPressureManagerAutomation>
|
||||
web_pressure_manager_automation;
|
||||
execution_context->GetBrowserInterfaceBroker().GetInterface(
|
||||
web_pressure_manager_automation.BindNewPipeAndPassReceiver());
|
||||
|
||||
auto* resolver =
|
||||
MakeGarbageCollected<ScriptPromiseResolver<IDLUndefined>>(script_state);
|
||||
auto promise = resolver->Promise();
|
||||
auto* raw_pressure_manager_automation = web_pressure_manager_automation.get();
|
||||
raw_pressure_manager_automation->UpdateVirtualPressureSourceState(
|
||||
ToMojoPressureSource(source.AsEnum()),
|
||||
ToMojoPressureState(state.AsEnum()),
|
||||
WTF::BindOnce(
|
||||
// While we only really need |resolver|, we also take the
|
||||
// mojo::Remote<> so that it remains alive after this function exits.
|
||||
[](ScriptPromiseResolver<IDLUndefined>* resolver,
|
||||
mojo::Remote<test::mojom::blink::WebPressureManagerAutomation>,
|
||||
test::mojom::UpdateVirtualPressureSourceStateResult result) {
|
||||
switch (result) {
|
||||
case test::mojom::blink::UpdateVirtualPressureSourceStateResult::
|
||||
kSuccess: {
|
||||
resolver->Resolve();
|
||||
break;
|
||||
}
|
||||
case test::mojom::blink::UpdateVirtualPressureSourceStateResult::
|
||||
kSourceTypeNotOverridden:
|
||||
resolver->Reject(
|
||||
"A virtual pressure source with this type has not been "
|
||||
"created");
|
||||
break;
|
||||
}
|
||||
},
|
||||
WrapPersistent(resolver),
|
||||
std::move(web_pressure_manager_automation)));
|
||||
return promise;
|
||||
}
|
||||
|
||||
} // namespace blink
|
43
third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.h
vendored
Normal file
43
third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_COMPUTE_PRESSURE_TESTING_INTERNALS_COMPUTE_PRESSURE_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_COMPUTE_PRESSURE_TESTING_INTERNALS_COMPUTE_PRESSURE_H_
|
||||
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
|
||||
#include "third_party/blink/renderer/bindings/modules/v8/v8_pressure_source.h"
|
||||
#include "third_party/blink/renderer/bindings/modules/v8/v8_pressure_state.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class CreateVirtualPressureSourceOptions;
|
||||
class Internals;
|
||||
class ScriptState;
|
||||
|
||||
class InternalsComputePressure {
|
||||
STATIC_ONLY(InternalsComputePressure);
|
||||
|
||||
public:
|
||||
static ScriptPromiseUntyped createVirtualPressureSource(
|
||||
ScriptState* script_state,
|
||||
Internals&,
|
||||
V8PressureSource source,
|
||||
CreateVirtualPressureSourceOptions*);
|
||||
|
||||
static ScriptPromiseUntyped removeVirtualPressureSource(
|
||||
ScriptState* script_state,
|
||||
Internals&,
|
||||
V8PressureSource source);
|
||||
|
||||
static ScriptPromiseUntyped updateVirtualPressureSource(
|
||||
ScriptState* script_state,
|
||||
Internals&,
|
||||
V8PressureSource posture,
|
||||
V8PressureState state);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_COMPUTE_PRESSURE_TESTING_INTERNALS_COMPUTE_PRESSURE_H_
|
11
third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.idl
vendored
Normal file
11
third_party/blink/renderer/modules/compute_pressure/testing/internals_compute_pressure.idl
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
[
|
||||
ImplementedAs=InternalsComputePressure
|
||||
] partial interface Internals {
|
||||
[CallWith=ScriptState] Promise<undefined> createVirtualPressureSource(PressureSource source, CreateVirtualPressureSourceOptions options);
|
||||
[CallWith=ScriptState] Promise<undefined> removeVirtualPressureSource(PressureSource source);
|
||||
[CallWith=ScriptState] Promise<undefined> updateVirtualPressureSource(PressureSource source, PressureState state);
|
||||
};
|
Reference in New Issue
Block a user