Commit 5bfcec61 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

wake lock: Add support for dedicated workers

This commit makes the technical changes required to make the wake lock code
in Blink aware of workers (i.e. use ExecutionContexts instead of Documents,
exposing the WakeLock interface to dedicated workers and making
WakeLockController support both Documents and DedicatedWorkerGlobalScopes).

From a user perspective, though, this is still not very useful, as dedicated
workers cannot acquire screen locks, and right now we always deny all
requests for system locks.

Bug: 967667
Change-Id: I6a775b1aac2b600006cb6f2ce0595514548bff17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1702378Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#678297}
parent 1395b11d
......@@ -14,6 +14,8 @@
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
namespace {
......@@ -49,35 +51,107 @@ class PermissionRequestObserver : public PermissionRequestManager::Observer {
DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
};
// Handles HTTP requests to |path| with |content| as the response body.
// |content| is expected to be JavaScript; the response mime type is always set
// to "text/javascript".
// Invokes |done_callback| after serving the HTTP request.
std::unique_ptr<net::test_server::HttpResponse> RespondWithJS(
const std::string& path,
const std::string& content,
base::OnceClosure done_callback,
const net::test_server::HttpRequest& request) {
GURL request_url = request.GetURL();
if (request_url.path() != path)
return nullptr;
auto response = std::make_unique<net::test_server::BasicHttpResponse>();
response->set_content_type("text/javascript");
response->set_content(content);
std::move(done_callback).Run();
return response;
}
} // namespace
class WakeLockBrowserTest : public InProcessBrowserTest {
protected:
// InProcessBrowserTest:
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpOnMainThread() override;
// Shorthand for starting the embedded web server and navigating to
// simple.html.
// Tests calling this usually call content::ExecuteScriptAndExtractString()
// afterwards to run custom code on the dummy page.
void NavigateToSimplePage();
// Registers a handle for "/js-response" in the embedded web server that
// responds with |script| as the response body, and then navigates to |path|.
// |path| usually points to a page that will somehow make a request to
// "/js-response".
void NavigateToAndRespondWithScript(const std::string& path,
const std::string& script);
};
void WakeLockBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, "WakeLock");
}
void WakeLockBrowserTest::SetUpOnMainThread() {
// Navigate to a secure context.
embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
void WakeLockBrowserTest::NavigateToSimplePage() {
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURL(browser(),
embedded_test_server()->GetURL("/simple.html"));
}
void WakeLockBrowserTest::NavigateToAndRespondWithScript(
const std::string& path,
const std::string& script) {
base::RunLoop loop;
embedded_test_server()->RegisterRequestHandler(base::BindRepeating(
&RespondWithJS, "/js-response", script, loop.QuitClosure()));
ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURL(
browser(),
embedded_test_server()->GetURL("localhost", "/simple_page.html"));
auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_THAT(
web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
testing::StartsWith("http://localhost:"));
ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(path));
loop.Run();
}
// https://w3c.github.io/wake-lock/#request-static-method
// Screen locks are never allowed from workers.
IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest, RequestScreenLockFromWorker) {
PermissionRequestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents());
const std::string kWorkerScript =
"WakeLock.request('screen').catch(err => self.postMessage(err.name))";
NavigateToAndRespondWithScript(
"/workers/create_dedicated_worker.html?worker_url=/js-response",
kWorkerScript);
EXPECT_EQ(
"NotAllowedError",
content::EvalJs(browser()->tab_strip_model()->GetActiveWebContents(),
"waitForMessage();"));
EXPECT_EQ(observer.request_shown(), false);
}
// Requests for a system lock should always be denied, and there should be no
// permission prompt.
IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest, RequestSystemLockFromWorker) {
PermissionRequestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents());
const std::string kWorkerScript =
"WakeLock.request('system').catch(err => self.postMessage(err.name))";
NavigateToAndRespondWithScript(
"/workers/create_dedicated_worker.html?worker_url=/js-response",
kWorkerScript);
EXPECT_EQ(
"NotAllowedError",
content::EvalJs(browser()->tab_strip_model()->GetActiveWebContents(),
"waitForMessage();"));
EXPECT_EQ(observer.request_shown(), false);
}
IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest, RequestPermissionScreen) {
// Requests for a screen lock should always be granted, and there should be no
// permission prompt.
NavigateToSimplePage();
PermissionRequestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents());
std::string response;
......@@ -94,6 +168,8 @@ IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest,
RequestPermissionScreenNoUserGesture) {
// Requests for a screen lock should always be granted, and there should be no
// permission prompt.
NavigateToSimplePage();
PermissionRequestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents());
std::string response;
......@@ -109,6 +185,8 @@ IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest,
IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest, RequestPermissionSystem) {
// Requests for a system lock should always be denied, and there should be no
// permission prompt.
NavigateToSimplePage();
PermissionRequestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents());
std::string response;
......@@ -125,6 +203,8 @@ IN_PROC_BROWSER_TEST_F(WakeLockBrowserTest,
RequestPermissionSystemNoUserGesture) {
// Requests for a system lock should always be denied, and there should be no
// permission prompt.
NavigateToSimplePage();
PermissionRequestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents());
std::string response;
......
......@@ -17,15 +17,6 @@
namespace blink {
namespace {
Document* GetDocument(ScriptState* script_state) {
ExecutionContext* execution_context = ExecutionContext::From(script_state);
return To<Document>(execution_context);
}
} // namespace
// static
ScriptPromise WakeLock::requestPermission(ScriptState* script_state,
const String& type) {
......@@ -38,9 +29,9 @@ ScriptPromise WakeLock::requestPermission(ScriptState* script_state,
// 2.1. Let state be the result of running and waiting for the obtain
// permission steps with type.
// 2.2. Resolve promise with state.
auto* document = GetDocument(script_state);
WakeLockController::From(*document).RequestPermission(ToWakeLockType(type),
resolver);
auto* document = To<Document>(ExecutionContext::From(script_state));
WakeLockController::From(document).RequestPermission(ToWakeLockType(type),
resolver);
return promise;
}
......@@ -49,36 +40,21 @@ ScriptPromise WakeLock::request(ScriptState* script_state,
const String& type,
WakeLockRequestOptions* options) {
// https://w3c.github.io/wake-lock/#request-static-method
// We only support [Exposed=Window] for now.
DCHECK(ExecutionContext::From(script_state)->IsDocument());
// 2. Let document be the responsible document of the current settings object.
auto* document = GetDocument(script_state);
// 3. If the current global object is the DedicatedWorkerGlobalScope object:
// 3.1. If the current global object's owner set is empty, reject promise with
// a "NotAllowedError" DOMException and return promise.
// 3.2. If type is "screen", reject promise with a "NotAllowedError"
// DOMException, and return promise.
// 4. Otherwise, if the current global object is the Window object:
// 4.1. If the document's browsing context is null, reject promise with a
// "NotAllowedError" DOMException and return promise.
if (!document) {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError,
"The document has no associated browsing context"));
}
auto* context = ExecutionContext::From(script_state);
DCHECK(context->IsDocument() || context->IsDedicatedWorkerGlobalScope());
// 2.1. If document is not allowed to use the policy-controlled feature named
// "wake-lock", reject promise with a "NotAllowedError" DOMException and
// return promise.
// [N.B. Per https://github.com/w3c/webappsec-feature-policy/issues/207 there
// is no official support for workers in the Feature Policy spec, but we can
// perform FP checks in workers in Blink]
// 2.2. If the user agent denies the wake lock of this type for document,
// reject promise with a "NotAllowedError" DOMException and return
// promise.
if (!document->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWakeLock,
ReportOptions::kReportOnFailure)) {
if (!context->GetSecurityContext().IsFeatureEnabled(
mojom::FeaturePolicyFeature::kWakeLock,
ReportOptions::kReportOnFailure)) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(
......@@ -86,23 +62,51 @@ ScriptPromise WakeLock::request(ScriptState* script_state,
"Access to WakeLock features is disallowed by feature policy"));
}
// 4.2. If document is not fully active, reject promise with a
// "NotAllowedError" DOMException, and return promise.
if (!document->IsActive()) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kNotAllowedError,
"The document is not active"));
}
// 4.3. If type is "screen" and the Document of the top-level browsing context
// is hidden, reject promise with a "NotAllowedError" DOMException, and
// return promise.
if (type == "screen" &&
!(document->GetPage() && document->GetPage()->IsPageVisible())) {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError,
"The requesting page is not visible"));
if (context->IsDedicatedWorkerGlobalScope()) {
// 3. If the current global object is the DedicatedWorkerGlobalScope object:
// 3.1. If the current global object's owner set is empty, reject promise
// with a "NotAllowedError" DOMException and return promise.
// 3.2. If type is "screen", reject promise with a "NotAllowedError"
// DOMException, and return promise.
if (type == "screen") {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError,
"Screen locks cannot be requested from workers"));
}
} else if (context->IsDocument()) {
// 2. Let document be the responsible document of the current settings
// object.
auto* document = To<Document>(context);
// 4. Otherwise, if the current global object is the Window object:
// 4.1. If the document's browsing context is null, reject promise with a
// "NotAllowedError" DOMException and return promise.
if (!document) {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError,
"The document has no associated browsing context"));
}
// 4.2. If document is not fully active, reject promise with a
// "NotAllowedError" DOMException, and return promise.
if (!document->IsActive()) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kNotAllowedError,
"The document is not active"));
}
// 4.3. If type is "screen" and the Document of the top-level browsing
// context is hidden, reject promise with a "NotAllowedError"
// DOMException, and return promise.
if (type == "screen" &&
!(document->GetPage() && document->GetPage()->IsPageVisible())) {
return ScriptPromise::RejectWithDOMException(
script_state, MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError,
"The requesting page is not visible"));
}
}
// 5. If options' signal member is present, then run the following steps:
......@@ -119,7 +123,7 @@ ScriptPromise WakeLock::request(ScriptState* script_state,
ScriptPromise promise = resolver->Promise();
WakeLockType wake_lock_type = ToWakeLockType(type);
WakeLockController& controller = WakeLockController::From(*document);
WakeLockController& controller = WakeLockController::From(context);
// 5.3. Otherwise, add to signal:
// 5.3.1. Run release a wake lock with promise and type.
......
......@@ -10,7 +10,7 @@ enum WakeLockType {
// https://w3c.github.io/wake-lock/#the-wakelock-interface
[
SecureContext,
Exposed=Window,
Exposed=(DedicatedWorker,Window),
RuntimeEnabled=WakeLock
] interface WakeLock {
[CallWith=ScriptState, Exposed=Window] static Promise<PermissionState> requestPermission(WakeLockType type);
......
......@@ -18,7 +18,7 @@ using mojom::blink::PermissionService;
using mojom::blink::PermissionStatus;
WakeLockController::WakeLockController(Document& document)
: Supplement<Document>(document),
: Supplement<ExecutionContext>(document),
ContextLifecycleObserver(&document),
PageVisibilityObserver(document.GetPage()),
state_records_{
......@@ -27,14 +27,34 @@ WakeLockController::WakeLockController(Document& document)
MakeGarbageCollected<WakeLockStateRecord>(&document,
WakeLockType::kSystem)} {}
WakeLockController::WakeLockController(DedicatedWorkerGlobalScope& worker_scope)
: Supplement<ExecutionContext>(worker_scope),
ContextLifecycleObserver(&worker_scope),
PageVisibilityObserver(nullptr),
state_records_{
MakeGarbageCollected<WakeLockStateRecord>(&worker_scope,
WakeLockType::kScreen),
MakeGarbageCollected<WakeLockStateRecord>(&worker_scope,
WakeLockType::kSystem)} {}
const char WakeLockController::kSupplementName[] = "WakeLockController";
WakeLockController& WakeLockController::From(Document& document) {
WakeLockController* controller =
Supplement<Document>::From<WakeLockController>(document);
// static
WakeLockController& WakeLockController::From(
ExecutionContext* execution_context) {
DCHECK(execution_context->IsDocument() ||
execution_context->IsDedicatedWorkerGlobalScope());
auto* controller =
Supplement<ExecutionContext>::From<WakeLockController>(execution_context);
if (!controller) {
controller = MakeGarbageCollected<WakeLockController>(document);
ProvideTo(document, controller);
if (execution_context->IsDocument()) {
controller = MakeGarbageCollected<WakeLockController>(
*To<Document>(execution_context));
} else {
controller = MakeGarbageCollected<WakeLockController>(
*To<DedicatedWorkerGlobalScope>(execution_context));
}
Supplement<ExecutionContext>::ProvideTo(*execution_context, controller);
}
return *controller;
}
......@@ -44,7 +64,7 @@ void WakeLockController::Trace(Visitor* visitor) {
visitor->Trace(state_record);
PageVisibilityObserver::Trace(visitor);
ContextLifecycleObserver::Trace(visitor);
Supplement<Document>::Trace(visitor);
Supplement<ExecutionContext>::Trace(visitor);
}
void WakeLockController::RequestWakeLock(WakeLockType type,
......@@ -192,16 +212,19 @@ void WakeLockController::ObtainPermission(
mojom::blink::WakeLockType::kSystem,
"WakeLockType and mojom::blink::WakeLockType must have identical values");
auto* local_frame = GetExecutionContext()->IsDocument()
? To<Document>(GetExecutionContext())->GetFrame()
: nullptr;
GetPermissionService().RequestPermission(
CreateWakeLockPermissionDescriptor(
static_cast<mojom::blink::WakeLockType>(type)),
LocalFrame::HasTransientUserActivation(GetSupplementable()->GetFrame()),
std::move(callback));
LocalFrame::HasTransientUserActivation(local_frame), std::move(callback));
}
PermissionService& WakeLockController::GetPermissionService() {
if (!permission_service_) {
ConnectToPermissionService(GetSupplementable(),
ConnectToPermissionService(GetExecutionContext(),
mojo::MakeRequest(&permission_service_));
}
return *permission_service_;
......
......@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/page/page_visibility_observer.h"
#include "third_party/blink/renderer/core/workers/dedicated_worker_global_scope.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/wake_lock/wake_lock_type.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
......@@ -18,6 +19,7 @@
namespace blink {
class AbortSignal;
class ExecutionContext;
class ScriptPromiseResolver;
class WakeLockStateRecord;
......@@ -25,7 +27,7 @@ class WakeLockStateRecord;
// Document changes appropriately.
class MODULES_EXPORT WakeLockController final
: public GarbageCollectedFinalized<WakeLockController>,
public Supplement<Document>,
public Supplement<ExecutionContext>,
public ContextLifecycleObserver,
public PageVisibilityObserver {
USING_GARBAGE_COLLECTED_MIXIN(WakeLockController);
......@@ -34,8 +36,9 @@ class MODULES_EXPORT WakeLockController final
static const char kSupplementName[];
explicit WakeLockController(Document&);
explicit WakeLockController(DedicatedWorkerGlobalScope&);
static WakeLockController& From(Document&);
static WakeLockController& From(ExecutionContext*);
void Trace(blink::Visitor*) override;
......
......@@ -20,7 +20,7 @@ namespace blink {
TEST(WakeLockControllerTest, RequestWakeLockGranted) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -46,7 +46,7 @@ TEST(WakeLockControllerTest, RequestWakeLockGranted) {
TEST(WakeLockControllerTest, RequestWakeLockDenied) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kSystem, mojom::blink::PermissionStatus::DENIED);
......@@ -80,7 +80,7 @@ TEST(WakeLockControllerTest, RequestWakeLockDenied) {
TEST(WakeLockControllerTest, RequestWakeLockAbortEarly) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -121,7 +121,7 @@ TEST(WakeLockControllerTest, RequestWakeLockAbortEarly) {
TEST(WakeLockControllerTest, AcquireScreenWakeLock) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
controller.AcquireWakeLock(
WakeLockType::kScreen,
......@@ -136,7 +136,7 @@ TEST(WakeLockControllerTest, AcquireScreenWakeLock) {
TEST(WakeLockControllerTest, AcquireSystemWakeLock) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
controller.AcquireWakeLock(
WakeLockType::kSystem,
......@@ -151,7 +151,7 @@ TEST(WakeLockControllerTest, AcquireSystemWakeLock) {
TEST(WakeLockControllerTest, AcquireMultipleLocks) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
controller.AcquireWakeLock(
WakeLockType::kScreen,
......@@ -177,7 +177,7 @@ TEST(WakeLockControllerTest, AcquireMultipleLocks) {
TEST(WakeLockControllerTest, ReleaseUnaquiredWakeLockRejectsPromise) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
MockWakeLock& screen_lock =
wake_lock_service.get_wake_lock(WakeLockType::kScreen);
......@@ -200,7 +200,7 @@ TEST(WakeLockControllerTest, ReleaseUnaquiredWakeLockRejectsPromise) {
TEST(WakeLockControllerTest, ReleaseWakeLock) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -229,7 +229,7 @@ TEST(WakeLockControllerTest, ReleaseWakeLock) {
TEST(WakeLockControllerTest, AbortSignal) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -262,7 +262,7 @@ TEST(WakeLockControllerTest, AbortSignal) {
TEST(WakeLockControllerTest, LossOfDocumentActivity) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
MockWakeLock& screen_lock =
wake_lock_service.get_wake_lock(WakeLockType::kScreen);
......@@ -308,7 +308,7 @@ TEST(WakeLockControllerTest, LossOfDocumentActivity) {
TEST(WakeLockControllerTest, PageVisibilityHidden) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -368,7 +368,7 @@ TEST(WakeLockControllerTest, PageVisibilityHidden) {
TEST(WakeLockControllerTest, PageVisibilityHiddenBeforeLockAcquisition) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -409,7 +409,7 @@ TEST(WakeLockControllerTest, PageVisibilityHiddenBeforeLockAcquisition) {
TEST(WakeLockControllerTest, PageVisibilityAndAbortSignal) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kScreen, mojom::blink::PermissionStatus::GRANTED);
......@@ -446,7 +446,7 @@ TEST(WakeLockControllerTest, PageVisibilityAndAbortSignal) {
TEST(WakeLockControllerTest, RequestPermissionGranted) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kSystem, mojom::blink::PermissionStatus::GRANTED);
......@@ -467,7 +467,7 @@ TEST(WakeLockControllerTest, RequestPermissionGranted) {
TEST(WakeLockControllerTest, RequestPermissionDenied) {
MockWakeLockService wake_lock_service;
WakeLockTestingContext context(&wake_lock_service);
auto& controller = WakeLockController::From(*context.GetDocument());
auto& controller = WakeLockController::From(context.GetDocument());
context.GetPermissionService().SetPermissionResponse(
WakeLockType::kSystem, mojom::blink::PermissionStatus::DENIED);
......
......@@ -8,15 +8,17 @@
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/mojom/wake_lock/wake_lock.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
WakeLockStateRecord::WakeLockStateRecord(Document* document, WakeLockType type)
: wake_lock_type_(ToMojomWakeLockType(type)), document_(document) {
DCHECK_NE(document, nullptr);
WakeLockStateRecord::WakeLockStateRecord(ExecutionContext* execution_context,
WakeLockType type)
: wake_lock_type_(ToMojomWakeLockType(type)),
execution_context_(execution_context) {
DCHECK_NE(execution_context, nullptr);
}
void WakeLockStateRecord::AcquireWakeLock(ScriptPromiseResolver* resolver) {
......@@ -35,7 +37,7 @@ void WakeLockStateRecord::AcquireWakeLock(ScriptPromiseResolver* resolver) {
// 4.3. Add lockPromise to record.[[WakeLockStateRecord]].
// 5. Return active.
if (!wake_lock_) {
auto* interface_provider = document_->GetInterfaceProvider();
auto* interface_provider = execution_context_->GetInterfaceProvider();
DCHECK(interface_provider);
mojom::blink::WakeLockServicePtr wake_lock_service;
interface_provider->GetInterface(mojo::MakeRequest(&wake_lock_service));
......@@ -96,7 +98,7 @@ void WakeLockStateRecord::OnWakeLockConnectionError() {
}
void WakeLockStateRecord::Trace(blink::Visitor* visitor) {
visitor->Trace(document_);
visitor->Trace(execution_context_);
visitor->Trace(active_locks_);
}
......
......@@ -13,7 +13,7 @@
namespace blink {
class Document;
class ExecutionContext;
class ScriptPromiseResolver;
// https://w3c.github.io/wake-lock/#concepts-and-state-record
......@@ -21,7 +21,7 @@ class ScriptPromiseResolver;
class MODULES_EXPORT WakeLockStateRecord
: public GarbageCollectedFinalized<WakeLockStateRecord> {
public:
WakeLockStateRecord(Document*, WakeLockType);
WakeLockStateRecord(ExecutionContext*, WakeLockType);
void AcquireWakeLock(ScriptPromiseResolver*);
void ReleaseWakeLock(ScriptPromiseResolver*);
......@@ -46,8 +46,8 @@ class MODULES_EXPORT WakeLockStateRecord
device::mojom::blink::WakeLockPtr wake_lock_;
device::mojom::blink::WakeLockType wake_lock_type_;
// Document from which we will connect to |wake_lock_service_|.
Member<Document> document_;
// ExecutionContext from which we will connect to |wake_lock_service_|.
Member<ExecutionContext> execution_context_;
FRIEND_TEST_ALL_PREFIXES(WakeLockStateRecordTest, AcquireWakeLock);
FRIEND_TEST_ALL_PREFIXES(WakeLockStateRecordTest, ReleaseAllWakeLocks);
......
This is a testharness.js-based test.
PASS idl_test setup
FAIL WakeLock interface: existence and properties of interface object assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
FAIL WakeLock interface object length assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
FAIL WakeLock interface object name assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
FAIL WakeLock interface: existence and properties of interface prototype object assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
FAIL WakeLock interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
FAIL WakeLock interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
FAIL WakeLock interface: member requestPermission Cannot use 'in' operator to search for 'requestPermission' in undefined
FAIL WakeLock interface: operation request(WakeLockType, WakeLockRequestOptions) assert_own_property: self does not have own property "WakeLock" expected property "WakeLock" missing
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL 'TypeError' is thrown when the signal option is not an AbortSignal promise_test: Unhandled rejection with value: object "ReferenceError: WakeLock is not defined"
FAIL A WakeLock request with an AbortSignal whose abort flag is set always aborts WakeLock is not defined
FAIL The same AbortSignal can be used to cause multiple wake locks to abort promise_test: Unhandled rejection with value: object "ReferenceError: WakeLock is not defined"
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL Screen wake lock should not be allowed in dedicated worker WakeLock is not defined
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL 'TypeError' is thrown when set an empty wake lock type promise_test: Unhandled rejection with value: object "ReferenceError: WakeLock is not defined"
FAIL 'TypeError' is thrown when set an invalid wake lock type WakeLock is not defined
Harness: the test ran to completion.
......@@ -1445,6 +1445,10 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter hasBeenActive
[Worker] getter isActive
[Worker] method constructor
[Worker] interface WakeLock
[Worker] static method request
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] interface WebGL2ComputeRenderingContext
[Worker] attribute @@toStringTag
[Worker] attribute ACTIVE_ATOMIC_COUNTER_BUFFERS
......
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