Skip to content

Commit

Permalink
Merge pull request #5094 from beverloo/background-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
tobie committed Mar 30, 2017
2 parents cc95ccf + 45e1bed commit 9cba588
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
2 changes: 2 additions & 0 deletions background-fetch/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@beverloo
@jakearchibald
15 changes: 15 additions & 0 deletions background-fetch/interfaces-worker.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API IDL tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>

<h1>idlharness test</h1>
<p>This test validates the WebIDL included in the Background Fetch API (Service Workers).</p>

<script>
'use strict';

service_worker_test('interfaces.worker.js', 'Service Worker-scoped tests.');
</script>
26 changes: 26 additions & 0 deletions background-fetch/interfaces.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API IDL tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>

<h1>idlharness test</h1>
<p>This test validates the WebIDL included in the Background Fetch API (Documents).</p>

<script>
'use strict';

promise_test(function() {
return fetch('interfaces.idl')
.then(response => response.text())
.then(idls => {
var idlArray = new IdlArray();
idlArray.add_untested_idls('interface ServiceWorkerRegistration {};');
idlArray.add_untested_idls('[Exposed=ServiceWorker] interface ServiceWorkerGlobalScope {};');
idlArray.add_idls(idls);
idlArray.test();
});
}, 'Exposed interfaces in a Document.');
</script>
115 changes: 115 additions & 0 deletions background-fetch/interfaces.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 3.1. Extensions to ServiceWorkerRegistration

partial interface ServiceWorkerRegistration {
readonly attribute BackgroundFetchManager backgroundFetch;
};

// 3.2. BackgroundFetchManager

[Exposed=(Window,Worker)]
interface BackgroundFetchManager {
Promise<BackgroundFetchRegistration> fetch(DOMString tag, (RequestInfo or sequence<RequestInfo>) requests, optional BackgroundFetchOptions options);
Promise<BackgroundFetchRegistration?> get(DOMString tag);
Promise<FrozenArray<DOMString>> getTags();
// TODO: in future this should become an async iterator for BackgroundFetchRegistration objects
};

dictionary BackgroundFetchOptions {
sequence<IconDefinition> icons;
DOMString title;
long totalDownloadSize;
};

// This is taken from https://w3c.github.io/manifest/#icons-member.
// This definition should probably be moved somewhere more general.
dictionary IconDefinition {
DOMString src;
DOMString sizes;
DOMString type;
};

// 3.3. BackgroundFetchRegistration

[Exposed=(Window,Worker)]
interface BackgroundFetchRegistration {
readonly attribute DOMString tag;
readonly attribute FrozenArray<IconDefinition> icons;
readonly attribute long totalDownloadSize;
readonly attribute DOMString title;
readonly attribute FrozenArray<BackgroundFetchActiveFetches> fetches;

void abort();
};

[Exposed=(Window,Worker)]
interface BackgroundFetchFetches {
readonly attribute Request request;
};

[Exposed=(Window,Worker)]
interface BackgroundFetchActiveFetches : BackgroundFetchFetches {
readonly attribute Promise<Response> responseReady;
// TODO: this will include fetch controller/observer objects
};

// 3.4. Events

partial interface ServiceWorkerGlobalScope {
attribute EventHandler onbackgroundfetched;
attribute EventHandler onbackgroundfetchfail;
attribute EventHandler onbackgroundfetchabort;
attribute EventHandler onbackgroundfetchclick;
};

// 3.4.1. BackgroundFetchEvent

[Constructor(DOMString type, BackgroundFetchEventInit init), Exposed=ServiceWorker]
interface BackgroundFetchEvent : ExtendableEvent {
readonly attribute DOMString tag;
};

dictionary BackgroundFetchEventInit : ExtendableEventInit {
required DOMString tag;
};

// 3.4.2. BackgroundFetchEndEvent

[Constructor(DOMString type, BackgroundFetchEndEventInit init), Exposed=ServiceWorker]
interface BackgroundFetchEndEvent : BackgroundFetchEvent {
readonly attribute FrozenArray<BackgroundFetchSettledFetches> completeFetches;

Promise<void> updateUI(DOMString title);
};

dictionary BackgroundFetchEndEventInit : BackgroundFetchEventInit {
required BackgroundFetchSettledFetches completeFetches;
};

[Exposed=ServiceWorker]
interface BackgroundFetchSettledFetches : BackgroundFetchFetches {
readonly attribute Response? response;
};

// 3.4.3. BackgroundFetchFailEvent

[Constructor(DOMString type, BackgroundFetchEndEventInit init), Exposed=ServiceWorker]
interface BackgroundFetchFailEvent : BackgroundFetchEndEvent {
readonly attribute FrozenArray<BackgroundFetchSettledFetches> failedFetches;
};

dictionary BackgroundFetchFailEventInit : BackgroundFetchEndEventInit {
required BackgroundFetchSettledFetches failedFetches;
};

// 3.4.4. BackgroundFetchClickEvent

[Constructor(DOMString type, BackgroundFetchEndEventInit init), Exposed=ServiceWorker]
interface BackgroundFetchClickEvent : BackgroundFetchEvent {
readonly attribute BackgroundFetchState state;
};

dictionary BackgroundFetchClickEventInit : BackgroundFetchEventInit {
required BackgroundFetchState state;
};

enum BackgroundFetchState { "pending", "succeeded", "failed" };
16 changes: 16 additions & 0 deletions background-fetch/interfaces.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

importScripts('/resources/testharness.js');
importScripts('/resources/WebIDLParser.js', '/resources/idlharness.js');

promise_test(function() {
return fetch('interfaces.idl')
.then(response => response.text())
.then(idls => {
var idlArray = new IdlArray();
idlArray.add_untested_idls('interface ServiceWorkerRegistration {};');
idlArray.add_untested_idls('[Exposed=ServiceWorker] interface ServiceWorkerGlobalScope {};');
idlArray.add_idls(idls);
idlArray.test();
});
}, 'Exposed interfaces in a Service Worker.');

0 comments on commit 9cba588

Please sign in to comment.