MediaResourceLoader should set its fetch destination
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Apr 2018 21:21:17 +0000 (21:21 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Apr 2018 21:21:17 +0000 (21:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184746

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/fetch-request-resources.https-expected.txt:
* web-platform-tests/service-workers/service-worker/fetch-request-resources.https.html:
* web-platform-tests/service-workers/service-worker/resources/fetch-request-resources-iframe.https.html:
* web-platform-tests/service-workers/service-worker/resources/fetch-request-resources-worker.js:

Source/WebCore:

Covered by updated test.

* loader/MediaResourceLoader.cpp:
(WebCore::MediaResourceLoader::requestResource):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230781 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-resources.https-expected.txt
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-resources.https.html
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-request-resources-iframe.https.html
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/fetch-request-resources-worker.js
Source/WebCore/ChangeLog
Source/WebCore/loader/MediaResourceLoader.cpp

index a01d1e4..732903f 100644 (file)
@@ -1,3 +1,15 @@
+2018-04-18  Youenn Fablet  <youenn@apple.com>
+
+        MediaResourceLoader should set its fetch destination
+        https://bugs.webkit.org/show_bug.cgi?id=184746
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/service-workers/service-worker/fetch-request-resources.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/fetch-request-resources.https.html:
+        * web-platform-tests/service-workers/service-worker/resources/fetch-request-resources-iframe.https.html:
+        * web-platform-tests/service-workers/service-worker/resources/fetch-request-resources-worker.js:
+
 2018-04-18  Ms2ger  <Ms2ger@igalia.com>
 
         Test gardening.
index 0ccd067..d8c4269 100644 (file)
@@ -56,4 +56,10 @@ PASS Audio load (url:https://localhost:9443/service-workers/service-worker/resou
 PASS Audio load (url:https://127.0.0.1:9443/service-workers/service-worker/resources/dummy?test54 cross_origin:) 
 PASS Audio load (url:https://127.0.0.1:9443/service-workers/service-worker/resources/dummy?test55 cross_origin:anonymous) 
 PASS Audio load (url:https://127.0.0.1:9443/service-workers/service-worker/resources/dummy?test56 cross_origin:use-credentials) 
+PASS Video load (url:https://localhost:9443/service-workers/service-worker/resources/dummy?test57 cross_origin:) 
+PASS Video load (url:https://localhost:9443/service-workers/service-worker/resources/dummy?test58 cross_origin:anonymous) 
+PASS Video load (url:https://localhost:9443/service-workers/service-worker/resources/dummy?test59 cross_origin:use-credentials) 
+PASS Video load (url:https://127.0.0.1:9443/service-workers/service-worker/resources/dummy?test60 cross_origin:) 
+PASS Video load (url:https://127.0.0.1:9443/service-workers/service-worker/resources/dummy?test61 cross_origin:anonymous) 
+PASS Video load (url:https://127.0.0.1:9443/service-workers/service-worker/resources/dummy?test62 cross_origin:use-credentials) 
 
index eeafad6..b0640ec 100644 (file)
@@ -26,6 +26,7 @@ function image_test(frame, url, cross_origin, expected_mode,
       credentials: expected_credentials,
       redirect: 'follow',
       integrity: '',
+      destination: 'image',
       message: 'Image load (url:' +
                actual_url + ' cross_origin:' + cross_origin + ')'
     };
@@ -42,6 +43,7 @@ function script_test(frame, url, cross_origin, expected_mode,
       credentials: expected_credentials,
       redirect: 'follow',
       integrity: '',
+      destination: 'script',
       message: 'Script load (url:' +
                actual_url + ' cross_origin:' + cross_origin + ')'
     };
@@ -58,6 +60,7 @@ function css_test(frame, url, cross_origin, expected_mode,
       credentials: expected_credentials,
       redirect: 'follow',
       integrity: '',
+      destination: 'style',
       message: 'CSS load (url:' +
                actual_url + ' cross_origin:' + cross_origin + ')'
     };
@@ -73,6 +76,7 @@ function font_face_test(frame, url, expected_mode, expected_credentials) {
       credentials: expected_credentials,
       redirect: 'follow',
       integrity: '',
+      destination: 'font',
       message: 'FontFace load (url:' + actual_url + ')'
     };
   frame.contentWindow.load_font(actual_url);
@@ -87,6 +91,7 @@ function script_integrity_test(frame, url, integrity, expected_integrity) {
       credentials: 'include',
       redirect: 'follow',
       integrity: expected_integrity,
+      destination: 'script',
       message: 'Script load (url:' + actual_url + ')'
     };
   frame.contentWindow.load_script_with_integrity(actual_url, integrity);
@@ -101,6 +106,7 @@ function css_integrity_test(frame, url, integrity, expected_integrity) {
       credentials: 'include',
       redirect: 'follow',
       integrity: expected_integrity,
+      destination: 'style',
       message: 'CSS load (url:' + actual_url + ')'
     };
   frame.contentWindow.load_css_with_integrity(actual_url, integrity);
@@ -115,6 +121,7 @@ function fetch_test(frame, url, mode, credentials,
       credentials: expected_credentials,
       redirect: 'follow',
       integrity: '',
+      destination: '',
       message: 'fetch (url:' + actual_url + ' mode:' + mode + ' credentials:' +
                credentials + ')'
     };
@@ -132,6 +139,7 @@ function audio_test(frame, url, cross_origin,
       credentials: expected_credentials,
       redirect: 'follow',
       integrity: '',
+      destination: 'audio',
       message: 'Audio load (url:' + actual_url + ' cross_origin:' +
                cross_origin + ')'
     };
@@ -139,6 +147,23 @@ function audio_test(frame, url, cross_origin,
   return add_promise_to_test(actual_url);
 }
 
+
+function video_test(frame, url, cross_origin,
+                    expected_mode, expected_credentials) {
+  var actual_url = url + (++url_count);
+  expected_results[actual_url] = {
+      mode: expected_mode,
+      credentials: expected_credentials,
+      redirect: 'follow',
+      integrity: '',
+      destination: 'video',
+      message: 'Video load (url:' + actual_url + ' cross_origin:' +
+               cross_origin + ')'
+    };
+  frame.contentWindow.load_video(actual_url, cross_origin);
+  return add_promise_to_test(actual_url);
+}
+
 promise_test(function(t) {
     var SCOPE = 'resources/fetch-request-resources-iframe.https.html';
     var SCRIPT = 'resources/fetch-request-resources-worker.js';
@@ -184,6 +209,10 @@ promise_test(function(t) {
                     result.integrity, expected.integrity,
                     'integrity of ' + expected.message +  ' must be ' +
                     expected.integrity + '.');
+                  assert_equals(
+                    result.destination, expected.destination,
+                    'destination of ' + expected.message +  ' must be ' +
+                    expected.destination + '.');
                 }, expected.message);
                 expected.resolve();
                 delete expected_results[result.url];
@@ -269,6 +298,13 @@ promise_test(function(t) {
         await audio_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin');
         await audio_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
 
+        await video_test(f, LOCAL_URL, '', 'no-cors', 'include');
+        await video_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin');
+        await video_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
+        await video_test(f, REMOTE_URL, '', 'no-cors', 'include');
+        await video_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin');
+        await video_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
+
         frame.remove();
         service_worker_unregister(t, SCOPE);
       }).catch(unreached_rejection(t));
index 2e5d7df..fca5722 100644 (file)
@@ -71,5 +71,14 @@ function load_audio(url, cross_origin) {
   audio.src = url;
   document.body.appendChild(audio);
 }
+
+function load_video(url, cross_origin) {
+  var video = document.createElement('video');
+  if (cross_origin != '') {
+    video.crossOrigin = cross_origin;
+  }
+  video.src = url;
+  document.body.appendChild(video);
+}
 </script>
 </body>
index e732da0..d85f714 100644 (file)
@@ -19,7 +19,8 @@ self.addEventListener('fetch', function(event) {
         mode: event.request.mode,
         redirect: event.request.redirect,
         credentials: event.request.credentials,
-        integrity: event.request.integrity
+        integrity: event.request.integrity,
+        destination: event.request.destination
       });
     event.respondWith(Promise.reject());
   });
index 82a5596..39f7484 100644 (file)
@@ -1,3 +1,15 @@
+2018-04-18  Youenn Fablet  <youenn@apple.com>
+
+        MediaResourceLoader should set its fetch destination
+        https://bugs.webkit.org/show_bug.cgi?id=184746
+
+        Reviewed by Eric Carlson.
+
+        Covered by updated test.
+
+        * loader/MediaResourceLoader.cpp:
+        (WebCore::MediaResourceLoader::requestResource):
+
 2018-04-18  Jer Noble  <jer.noble@apple.com>
 
         Fix runtime errors in simulator while playing media
index 1482643..3d7c4d4 100644 (file)
@@ -76,7 +76,9 @@ RefPtr<PlatformMediaResource> MediaResourceLoader::requestResource(ResourceReque
 #endif
 
     ContentSecurityPolicyImposition contentSecurityPolicyImposition = m_mediaElement && m_mediaElement->isInUserAgentShadowTree() ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
-    CachedResourceRequest cacheRequest(WTFMove(request), ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, bufferingPolicy, StoredCredentialsPolicy::Use, ClientCredentialPolicy::MayAskClientForCredentials, FetchOptions::Credentials::Include, DoSecurityCheck, FetchOptions::Mode::NoCors, DoNotIncludeCertificateInfo, contentSecurityPolicyImposition, DefersLoadingPolicy::AllowDefersLoading, cachingPolicy));
+    ResourceLoaderOptions loaderOptions { SendCallbacks, DoNotSniffContent, bufferingPolicy, StoredCredentialsPolicy::Use, ClientCredentialPolicy::MayAskClientForCredentials, FetchOptions::Credentials::Include,  DoSecurityCheck, FetchOptions::Mode::NoCors, DoNotIncludeCertificateInfo, contentSecurityPolicyImposition, DefersLoadingPolicy::AllowDefersLoading, cachingPolicy };
+    loaderOptions.destination = m_mediaElement && !m_mediaElement->isVideo() ? FetchOptions::Destination::Audio : FetchOptions::Destination::Video;
+    CachedResourceRequest cacheRequest { WTFMove(request), WTFMove(loaderOptions) };
     cacheRequest.setAsPotentiallyCrossOrigin(m_crossOriginMode, *m_document);
     if (m_mediaElement)
         cacheRequest.setInitiator(*m_mediaElement.get());