Feature detection for subresource signed exchange prefetch

Currently there is no way to detect the availability of the subresource
signed exchange prefetch feature. This CL changes
RelList::ValidateTokenValue("allowed-alt-sxg") to return true for link
elements. So the developers can detect this feature by checking
document.createElement('link').relList.supports('allowed-alt-sxg').

Bug: 980828
Change-Id: Iedc379ee48ced0c796a62e60514909cf8e685712
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174114
Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#764605}
diff --git a/third_party/blink/renderer/core/html/rel_list.cc b/third_party/blink/renderer/core/html/rel_list.cc
index 880f905..dc25711 100644
--- a/third_party/blink/renderer/core/html/rel_list.cc
+++ b/third_party/blink/renderer/core/html/rel_list.cc
@@ -49,6 +49,11 @@
         token_value == "modulepreload") {
       return true;
     }
+    if (RuntimeEnabledFeatures::SignedExchangeSubresourcePrefetchEnabled(
+            &GetElement().GetDocument()) &&
+        token_value == "allowed-alt-sxg") {
+      return true;
+    }
   } else if ((GetElement().HasTagName(html_names::kATag) ||
               GetElement().HasTagName(html_names::kAreaTag)) &&
              SupportedTokensAnchorAndArea().Contains(token_value)) {
diff --git a/third_party/blink/web_tests/http/tests/loading/sxg/sxg-subresource-origin-trial.https.html b/third_party/blink/web_tests/http/tests/loading/sxg/sxg-subresource-origin-trial.https.html
index 85fafee0..b3409b9 100644
--- a/third_party/blink/web_tests/http/tests/loading/sxg/sxg-subresource-origin-trial.https.html
+++ b/third_party/blink/web_tests/http/tests/loading/sxg/sxg-subresource-origin-trial.https.html
@@ -1,37 +1,54 @@
 <!DOCTYPE html>
+
 <head>
-<title>Signed Exchange subresource Origin Trial</title>
-<!-- Generate token with the command:
-generate_token.py https://127.0.0.1:8443 SignedExchangeSubresourcePrefetch --expire-timestamp=2000000000
--->
-<meta http-equiv="origin-trial" content="AkPuNZ6wN6pkhO5BsawPJCR9+8TDqRn4NUKsrhif+5Hs6l3dbRCdhhBpImxV13ZM8luH7wYH+rC9LYwD9xIQOAwAAABqeyJvcmlnaW4iOiAiaHR0cHM6Ly8xMjcuMC4wLjE6ODQ0MyIsICJmZWF0dXJlIjogIlNpZ25lZEV4Y2hhbmdlU3VicmVzb3VyY2VQcmVmZXRjaCIsICJleHBpcnkiOiAyMDAwMDAwMDAwfQ==">
-<script src="./resources/sxg-util.js"></script>
+  <title>Signed Exchange subresource Origin Trial</title>
+  <script src="./resources/sxg-util.js"></script>
 </head>
+
 <body>
-<script>
-const kSignedExchangeSubresourcePrefetch = 2953; // see web_feature.mojom
-if (window.testRunner) {
-  testRunner.dumpAsText();
-  testRunner.waitUntilDone();
-}
-(async function() {
-  await waitUntilDidFinishLoadForFrame;
-  const sxg_path = "https://127.0.0.1:8443/loading/sxg/resources/sxg-subresource-origin-trial-page.php";
-  new PerformanceObserver((list) => {
-    for (let e of list.getEntries()) {
-      if (e.name.endsWith('sxg-subresource-script.sxg')) {
-        if (internals.isUseCounted(document,
-                                   kSignedExchangeSubresourcePrefetch)) {
-          location.href = sxg_path;
-        }
-      }
+  <script>
+    const kSignedExchangeSubresourcePrefetch = 2953; // see web_feature.mojom
+    if (window.testRunner) {
+      testRunner.dumpAsText();
+      testRunner.waitUntilDone();
     }
-  }).observe({ entryTypes: ['resource'] });
-  const link = document.createElement('link');
-  link.rel = 'prefetch';
-  link.href = sxg_path;
-  document.body.appendChild(link);
-})();
+    (async function () {
+      await waitUntilDidFinishLoadForFrame;
+      if (document.createElement('link').relList.supports('allowed-alt-sxg')) {
+        console.error("Subresource Signed Exchange prefetch should not be supported by default.");
+        testRunner.notifyDone();
+        return;
+      }
+
+      const meta = document.createElement('meta');
+      meta.httpEquiv = "origin-trial";
+      // Generate token with the command:
+      //   generate_token.py https://127.0.0.1:8443 SignedExchangeSubresourcePrefetch --expire-timestamp=2000000000
+      meta.content = "AkPuNZ6wN6pkhO5BsawPJCR9+8TDqRn4NUKsrhif+5Hs6l3dbRCdhhBpImxV13ZM8luH7wYH+rC9LYwD9xIQOAwAAABqeyJvcmlnaW4iOiAiaHR0cHM6Ly8xMjcuMC4wLjE6ODQ0MyIsICJmZWF0dXJlIjogIlNpZ25lZEV4Y2hhbmdlU3VicmVzb3VyY2VQcmVmZXRjaCIsICJleHBpcnkiOiAyMDAwMDAwMDAwfQ==";
+      document.head.appendChild(meta);
+
+      if (!document.createElement('link').relList.supports('allowed-alt-sxg')) {
+        console.error("Subresource Signed Exchange prefetch is not supported");
+        testRunner.notifyDone();
+        return;
+      }
+
+      const sxg_path = "https://127.0.0.1:8443/loading/sxg/resources/sxg-subresource-origin-trial-page.php";
+      new PerformanceObserver((list) => {
+        for (let e of list.getEntries()) {
+          if (e.name.endsWith('sxg-subresource-script.sxg')) {
+            if (internals.isUseCounted(document,
+              kSignedExchangeSubresourcePrefetch)) {
+              location.href = sxg_path;
+            }
+          }
+        }
+      }).observe({ entryTypes: ['resource'] });
+      const link = document.createElement('link');
+      link.rel = 'prefetch';
+      link.href = sxg_path;
+      document.body.appendChild(link);
+    })();
 // cache-control: public, max-age=600
-</script>
+  </script>
 </body>