Commit b6284505 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Fetch] Integrate with origin trials.

This CL adds the OriginTrialsEnabled idl attribute to all
BackgroundFetch idl files, and a LayoutTest to test that when
the origin trial is enabled, the properties in these interfaces
are available.

Change-Id: Ia71e28aaf5cbd03b943a5eff904d21e8f536ea84
Bug: 894448
Reviewed-on: https://chromium-review.googlesource.com/c/1261405Reviewed-by: default avatarJason Chase <chasej@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598811}
parent 889c4b11
<!DOCTYPE html>
<meta charset="utf-8">
<!-- Generate token with the command:
generate_token.py http://127.0.0.1:8000 BackgroundFetch --expire-timestamp=2000000000
-->
<meta http-equiv="origin-trial" content="AtDl/AukAuUX0Sw7KRz+mrV2vpSYrfDyVS4vdO3I1clqoNgKGqCX5Np5KIhlC6oQl8XcULXJz5bc9Y4CcYj9xA4AAABXeyJvcmlnaW4iOiAiaHR0cDovLzEyNy4wLjAuMTo4MDAwIiwgImZlYXR1cmUiOiAiQmFja2dyb3VuZEZldGNoIiwgImV4cGlyeSI6IDIwMDAwMDAwMDB9" />
<title>Background Fetch API - interfaces exposed by origin trial</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/origin-trials-helper.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<script>
test(t => {
OriginTrialsHelper.check_properties(this, {
'BackgroundFetchManager': ['fetch', 'get', 'getIds'],
'BackgroundFetchUpdateUIEvent': ['updateUI'],
'BackgroundFetchFetch': ['request'],
'BackgroundFetchRegistration': ['id', 'uploadTotal', 'uploaded',
'downloadTotal', 'downloaded', 'result',
'failureReason', 'recordsAvailable',
'onprogress'],
'ServiceWorkerRegistration': ['backgroundFetch'],
});
}, 'BackgroundFetch API interfaces and properties in Origin-Trial enabled document.');
fetch_tests_from_worker(new Worker('resources/backgroundfetch-origin-trial-interfaces-worker.js'));
</script>
importScripts('/resources/testharness.js',
'/resources/origin-trials-helper.js');
test(t => {
OriginTrialsHelper.check_properties(this, {
'ServiceWorkerRegistration': ['backgroundFetch'],
'BackgroundFetchFetch': ['request'],
'BackgroundFetchManager': ['fetch', 'get', 'getIds'],
'BackgroundFetchRegistration': ['id', 'uploadTotal', 'uploaded',
'downloadTotal', 'downloaded', 'result',
'failureReason', 'recordsAvailable',
'onprogress'],
});
}, 'Background Fetch API interfaces and properties in Origin-Trial enabled worker.');
done();
......@@ -7,7 +7,7 @@
[
Constructor(DOMString type, BackgroundFetchEventInit init),
Exposed=ServiceWorker,
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchEvent : ExtendableEvent {
readonly attribute BackgroundFetchRegistration registration;
};
......@@ -6,7 +6,7 @@
[
Exposed=(Window,Worker),
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchFetch {
readonly attribute Request request;
};
......@@ -6,7 +6,7 @@
[
Exposed=(Window,Worker),
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchManager {
[CallWith=ScriptState, RaisesException, MeasureAs=BackgroundFetchManagerFetch] Promise<BackgroundFetchRegistration> fetch(DOMString id, (RequestInfo or sequence<RequestInfo>) requests, optional BackgroundFetchOptions options);
[CallWith=ScriptState, MeasureAs=BackgroundFetchManagerGet] Promise<BackgroundFetchRegistration?> get(DOMString id);
......
......@@ -6,7 +6,7 @@
[
Exposed=(ServiceWorker),
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchRecord {
readonly attribute Request request;
[CallWith=ScriptState] readonly attribute Promise<Response> responseReady;
......
......@@ -22,7 +22,7 @@ enum BackgroundFetchResult { "", "success", "failure" };
[
Exposed=(Window,Worker),
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchRegistration : EventTarget {
readonly attribute DOMString id;
readonly attribute unsigned long long uploadTotal;
......
......@@ -7,7 +7,7 @@
[
Constructor(Request request, Response response),
Exposed=ServiceWorker,
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchSettledFetch : BackgroundFetchFetch {
readonly attribute Response? response;
};
......@@ -7,7 +7,7 @@
[
Constructor(DOMString type, BackgroundFetchEventInit init),
Exposed=ServiceWorker,
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] interface BackgroundFetchUpdateUIEvent : BackgroundFetchEvent {
[CallWith=ScriptState] Promise<void> updateUI(BackgroundFetchUIOptions options);
};
\ No newline at end of file
......@@ -6,7 +6,7 @@
[
ImplementedAs=ServiceWorkerGlobalScopeBackgroundFetch,
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] partial interface ServiceWorkerGlobalScope {
attribute EventHandler onbackgroundfetchsuccess;
attribute EventHandler onbackgroundfetchfail;
......
......@@ -7,7 +7,7 @@
[
Exposed=(Window,Worker),
ImplementedAs=ServiceWorkerRegistrationBackgroundFetch,
RuntimeEnabled=BackgroundFetch
OriginTrialEnabled=BackgroundFetch
] partial interface ServiceWorkerRegistration {
readonly attribute BackgroundFetchManager backgroundFetch;
};
......@@ -140,7 +140,8 @@ PermissionDescriptorPtr ParsePermission(ScriptState* script_state,
if (name == "payment-handler")
return CreatePermissionDescriptor(PermissionName::PAYMENT_HANDLER);
if (name == "background-fetch") {
if (!RuntimeEnabledFeatures::BackgroundFetchEnabled()) {
if (!OriginTrials::BackgroundFetchEnabled(
ExecutionContext::From(script_state))) {
exception_state.ThrowTypeError("Background Fetch is not enabled.");
return nullptr;
}
......
......@@ -114,6 +114,7 @@
},
{
name: "BackgroundFetch",
origin_trial_feature_name: "BackgroundFetch",
status: "experimental",
},
{
......
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