Revision 08c935c755a5f9cc0ef8a7b9f56091e5d2b040d9 authored by Kent Tamura on 13 April 2018, 04:39:21 UTC, committed by Blink WPT Bot on 13 April 2018, 05:02:00 UTC
Intent-to-implement-and-ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/zCQe7UkR07w

Bug: 819482
Change-Id: I5645d5711d7fe1323992533e6c73593ba59d1bca
Reviewed-on: https://chromium-review.googlesource.com/1009450
Reviewed-by: Hayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550513}
1 parent bdcafae
Raw File
resource.html
<!DOCTYPE html>
<html>
  <head>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="support/test_utils.sub.js"></script>
  </head>

  <body>
    <script>
      /**
       * @typedef{TestCase}
       * @type{object}
       * @property{string} frame The scheme of the url of the iframe.
       * @property{string} resource The scheme of the resource in the iframe.
       * @property{boolean} deleted Whether it is expected that Clear-Site-Data
       *     will be respected when loading |resource| in |frame|.
       */
      var TestCase;

      /** Array<TestCase> Test cases. */
      var test_cases = [
        { "frame": "https", "resource": "https", "deleted": true },
        { "frame": "http", "resource": "https", "deleted": true },
        { "frame": "https", "resource": "http", "deleted": false },
        { "frame": "http", "resource": "http", "deleted": false },
      ];

      /**
       * @param TestCase test_case The test case that is tested.
       * @param Dict.<string, boolean> report A map between a datatype name and
       *     whether it is empty.
       */
      function verifyDatatypes(test_case, report) {
        if (test_case.deleted) {
          assert_true(
              report["storage"],
              "Storage should have been cleared.");
        } else {
          assert_false(
              report["storage"],
              "Storage should NOT have been cleared.");
        }
      }

      test_cases.forEach(function(test_case) {
        var test_name =
            test_case.resource + " resource on a " + test_case.frame + " page";

        promise_test(function(test) {
          return new Promise(function(resolve_test, reject_test) {
            TestUtils.populateDatatypes()
                .then(function() {
                  // Navigate to a page with a resource that is loaded with
                  // the Clear-Site-Data header, then verify that storage
                  // has been deleted if and only if the resource was loaded
                  // via HTTPS.
                  return new Promise(function(resolve, reject) {
                    window.addEventListener("message", resolve);
                    var iframe = document.createElement("iframe");
                    iframe.src = TestUtils.getPageWithResourceUrl(
                        test_case.frame, test_case.resource);
                    document.body.appendChild(iframe);
                  }).then(function(messageEvent) {
                    verifyDatatypes(test_case, messageEvent.data);
                    resolve_test();
                  });
                });
          });
        }, test_name);
      });
    </script>
  </body>
</html>
back to top