Attachment #9137954: DO NOT LAND. TEST. Experimental changes to WPT test to use clear-site-data to induce Factory::Abort, doesn't crash things though. for bug #1626728

View | Details | Raw Unified | Return to bug 1626728
Collapse All | Expand All

(-)a/testing/web-platform/meta/clear-site-data/storage.https.html.ini (-1 lines)
Line     Link Here 
 Lines 1-2    Link Here 
1
[storage.https.html]
1
[storage.https.html]
2
  disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1456995
(-)a/testing/web-platform/tests/clear-site-data/storage.https.html (-34 / +4 lines)
Line     Link Here 
 Lines 27-110    Link Here 
27
      setup({"explicit_done": true});
27
      setup({"explicit_done": true});
28
28
29
      // There must be at least one test added synchronously, otherwise
29
      // There must be at least one test added synchronously, otherwise
30
      // testharness will complain.
30
      // testharness will complain.
31
      // TODO(@msramek): Find a way to avoid this dummy test.
31
      // TODO(@msramek): Find a way to avoid this dummy test.
32
      test(function() {}, "Populate backends.");
32
      test(function() {}, "Populate backends.");
33
33
34
      TestUtils.populateStorage()
34
      TestUtils.populateStorage()
35
          .then(() => {
36
            return new Promise(function(resolve, reject) {
37
              promise_test(function(t) {
38
                return navigator.serviceWorker.getRegistration("support/").then(function(reg) {
39
                  return wait_for_state(t, reg.installing || reg.waiting || reg.active, 'activated');
40
                }).then(resolve, reject);
41
              });
42
            });
43
          })
44
          .then(() => {
45
            return new Promise(function (resolve) {
46
              // Create iFrame in the service worker's scope. This page will make a request
47
              // for another page that is only served by the service worker
48
              serviceWorkerTestPageIFrame = document.createElement("iframe");
49
              serviceWorkerTestPageIFrame.src = "support/page_using_service_worker.html";
50
              serviceWorkerTestPageIFrame.onload = function() { resolve(); };
51
              document.body.appendChild(serviceWorkerTestPageIFrame);
52
            });
53
          })
54
          .then(() => {
55
            const serviceWorkerResponseBody = fetchFromIFrame();
56
57
            promise_test(function() {
58
              return serviceWorkerResponseBody.then(function(body) {
59
                assert_equals(body, "FROM_SERVICE_WORKER", "Response should be from service worker");
60
              });
61
            }, "Baseline: Service worker responds to request");
62
63
            return serviceWorkerResponseBody;
64
          })
65
          .then(function() {
35
          .then(function() {
66
            const waitForControllerChange = new Promise(function(resolve) {
67
              serviceWorkerTestPageIFrame.contentWindow
68
                .navigator.serviceWorker.addEventListener("controllerchange", resolve);
69
            });
70
            // Navigate to a resource with a Clear-Site-Data header in
36
            // Navigate to a resource with a Clear-Site-Data header in
71
            // an iframe, then verify that all backends of the "storage"
37
            // an iframe, then verify that all backends of the "storage"
72
            // datatype have been deleted.
38
            // datatype have been deleted.
73
            return new Promise(function(resolve, reject) {
39
            return new Promise(function(resolve, reject) {
40
              dump("!!!!! initiating clear-site-data invocation\n");
74
              window.addEventListener("message", resolve);
41
              window.addEventListener("message", resolve);
75
              var iframe = document.createElement("iframe");
42
              var iframe = document.createElement("iframe");
76
              iframe.src = TestUtils.getClearSiteDataUrl([storage]);
43
              iframe.src = TestUtils.getClearSiteDataUrl([storage]);
77
              document.body.appendChild(iframe);
44
              document.body.appendChild(iframe);
78
            }).then(function() {
45
            }).then(function() {
46
              dump("!!!!! clear-site-data completed\n")
79
              TestUtils.STORAGE.forEach(function(backend) {
47
              TestUtils.STORAGE.forEach(function(backend) {
80
                var test_name =
48
                var test_name =
81
                    "Clear backend when 'storage' is deleted: " + backend.name;
49
                    "Clear backend when 'storage' is deleted: " + backend.name;
82
50
83
                promise_test(function() {
51
                promise_test(function() {
84
                  return backend.isEmpty().then(function(isEmpty) {
52
                  return backend.isEmpty().then(function(isEmpty) {
85
                    assert_true(
53
                    assert_true(
86
                      isEmpty,
54
                      isEmpty,
87
                      backend.name + " should have been cleared.");
55
                      backend.name + " should have been cleared.");
88
                  });
56
                  });
89
                }, test_name);
57
                }, test_name);
90
              });
58
              });
91
59
60
              /*
92
              promise_test(function() {
61
              promise_test(function() {
93
                return fetchFromIFrame().then(function(body) {
62
                return fetchFromIFrame().then(function(body) {
94
                  assert_equals(body, "FROM_NETWORK", "Response should be from network and not from the service worker");
63
                  assert_equals(body, "FROM_NETWORK", "Response should be from network and not from the service worker");
95
                });
64
                });
96
              }, "Service worker no longer responds to requests");
65
              }, "Service worker no longer responds to requests");
97
66
98
              promise_test(function() {
67
              promise_test(function() {
99
                return waitForControllerChange.then(function() {
68
                return waitForControllerChange.then(function() {
100
                  assert_false(!!serviceWorkerTestPageIFrame.contentWindow.navigator.serviceWorker.controller,
69
                  assert_false(!!serviceWorkerTestPageIFrame.contentWindow.navigator.serviceWorker.controller,
101
                    "Client should not have a controller");
70
                    "Client should not have a controller");
102
                });
71
                });
103
              }, "controllerchange event fires and client no longer has controller");
72
              }, "controllerchange event fires and client no longer has controller");
73
              */
104
74
105
              done();
75
              done();
106
            });
76
            });
107
          });
77
          });
108
    </script>
78
    </script>
109
  </body>
79
  </body>
110
</html>
80
</html>
(-)a/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js (-129 / +79 lines)
Line     Link Here 
 Lines 22-171   var TestUtils = (function() { Link Here 
22
  var TestUtils = {};
22
  var TestUtils = {};
23
23
24
  /**
24
  /**
25
   * Various storage backends that are part of the 'storage' datatype.
25
   * Various storage backends that are part of the 'storage' datatype.
26
   * @param{Array.<Datatype>}
26
   * @param{Array.<Datatype>}
27
   */
27
   */
28
  TestUtils.STORAGE = [
28
  TestUtils.STORAGE = [
29
    {
29
    {
30
      "name": "local storage",
30
      "name": "Cache API",
31
      "supported": function() { !!window.localStorage; },
31
      "supported": function() { return true; },
32
      "add": function() {
32
      "add": async function() {
33
        return new Promise(function(resolve, reject) {
33
        let FILES_TO_CACHE = [
34
          localStorage.setItem(randomString(), randomString());
34
          "navigation-insecure.html",
35
          resolve();
35
          "navigation.https.html",
36
        });
36
          "resource.html",
37
      },
37
          "storage.https.html",
38
      "isEmpty": function() {
38
          "support/iframe_executionContexts.html",
39
        return new Promise(function(resolve, reject) {
39
          "support/page_using_service_worker.html",
40
          resolve(!localStorage.length);
40
          "support/send_report.html",
41
        });
41
        ];
42
      }
42
43
    },
43
        const REPEAT_COUNT = 100;
44
    {
44
        REQUESTS_TO_CACHE = [];
45
      "name": "Indexed DB",
45
        for (let i = 0; i < REPEAT_COUNT; i++) {
46
      "supported": function() { return !!window.indexedDB; },
46
          for (const filename of FILES_TO_CACHE) {
47
      "add": function() {
47
            REQUESTS_TO_CACHE.push(`${filename}?foo=${i}`);
48
        return new Promise(function(resolve, reject) {
48
          }
49
          var request = window.indexedDB.open("database");
49
        }
50
          request.onupgradeneeded = function() {
50
51
            request.result.createObjectStore("store");
51
        const cache = await caches.open("foo");
52
          };
52
53
          request.onsuccess = function() {
53
        // try sticking a thing in that will never complete;
54
            request.result.close();
54
        /*
55
            resolve();
55
        dump("creating stream\n");
56
        const myStream = window.MY_STREAM = new ReadableStream({
57
          start(controller) {
58
            this.controller = controller;
59
            controller.enqueue("foo");
56
          }
60
          }
57
        });
61
        });
62
        dump("stream instantiated\n");
63
        const myStreamResp = window.MY_RESP = new Response(myStream, { status : 200 });
64
        dump("putting stream\n");
65
        cache.put("/foo", myStreamResp);
66
        dump("stream put is running\n");
67
        */
68
69
        await cache.addAll(REQUESTS_TO_CACHE);
70
        const pendingResponses = Promise.all(REQUESTS_TO_CACHE.map((url) => {
71
          return cache.match(url);
72
        }));
73
        const responses = await pendingResponses;
74
        let iNext = 0;
75
76
        const tarpit = window.STREAM_TARPIT = [];
77
        const kickNext = () => {
78
          const resp = responses[iNext++];
79
80
          dump(`starting stream of ${resp.url}\n`);
81
          const reader = resp.body.getReader();
82
          const firstDataPromise = reader.read().then(() => {
83
            dump(`  got some data for ${resp.url}\n`);
84
            if (iNext < responses.length) {
85
              kickNext();
86
            }
87
          });
88
          tarpit.push({ reader, firstDataPromise });
89
          return firstDataPromise;
90
        };
91
        const PRE_WAIT_COUNT = 10;
92
        const POST_WAIT_COUNT = 10;
93
        let sampleAt = 4;
94
        let samplePromise;
95
        for (let z = 0; z < PRE_WAIT_COUNT; z++) {
96
          let prom = kickNext();
97
          if (--sampleAt === 0) {
98
            samplePromise = prom;
99
          }
100
        }
101
        // wait for the pipeline to have been primed
102
        await samplePromise;
103
        dump("~~~~~DONE WAITING FOR SAMPLE\n");
104
        for (let z = 0; z < POST_WAIT_COUNT; z++) {
105
          kickNext();
106
        }
58
      },
107
      },
59
      "isEmpty": function() {
108
      "isEmpty": async function() {
60
        return new Promise(function(resolve, reject) {
109
        const hasCache = await caches.has("foo");
61
          var request = window.indexedDB.open("database");
110
        const knownCaches = await caches.keys();
62
          request.onsuccess = function() {
111
        return !hasCache && knownCaches.length === 0;
63
            var database = request.result;
64
            try {
65
              var transaction = database.transaction(["store"]);
66
              resolve(false);
67
            } catch(error) {
68
              // The database is empty. However, by testing that, we have also
69
              // created it, which means that |onupgradeneeded| in the "add"
70
              // method will not run the next time. Delete the database before
71
              // reporting that it was empty.
72
              var deletion = window.indexedDB.deleteDatabase("database");
73
              deletion.onsuccess = resolve.bind(this, true);
74
            } finally {
75
              database.close();
76
            }
77
          };
78
        });
79
      }
112
      }
80
    },
113
    },
81
    {
82
      // TODO(@msramek): We should also test the PERSISTENT filesystem, however,
83
      // that might require storage permissions.
84
      "name": "filesystems",
85
      "supported": function() {
86
        return window.requestFileSystem || window.webkitRequestFileSystem;
87
      },
88
      "add": function() {
89
        return new Promise(function(resolve, reject) {
90
          var onSuccess = function(fileSystem) {
91
            fileSystem.root.getFile('file', {"create": true}, resolve, resolve);
92
          }
93
          var onFailure = resolve;
94
95
          var requestFileSystem =
96
              window.requestFileSystem || window.webkitRequestFileSystem;
97
          requestFileSystem(window.TEMPORARY, 1 /* 1B */,
98
                            onSuccess, onFailure);
99
        });
100
      },
101
      "isEmpty": function() {
102
        return new Promise(function(resolve, reject) {
103
          var onSuccess = function(fileSystem) {
104
            fileSystem.root.getFile(
105
                'file', {},
106
                resolve.bind(this, false) /* opened successfully */,
107
                resolve.bind(this, true) /* failed to open */);
108
          }
109
          var onFailure = resolve.bind(this, true);
110
111
          var requestFileSystem =
112
              window.requestFileSystem || window.webkitRequestFileSystem;
113
          requestFileSystem(window.TEMPORARY, 1 /* 1B */,
114
                            onSuccess, onFailure);
115
        });
116
      }
117
    },
118
    {
119
      "name": "service workers",
120
      "supported": function() { return !!navigator.serviceWorker; },
121
      "add": function() {
122
        return navigator.serviceWorker.register(
123
            "support/service_worker.js",
124
            { scope: "support/"});
125
      },
126
      "isEmpty": function() {
127
        return new Promise(function(resolve, reject) {
128
          navigator.serviceWorker.getRegistrations()
129
              .then(function(registrations) {
130
                resolve(!registrations.length);
131
              });
132
        });
133
      }
134
    },
135
    {
136
      "name": "WebSQL",
137
      "supported": function() { return !!window.openDatabase; },
138
      "add": function() {
139
        return new Promise(function(resolve, reject) {
140
          var database = window.openDatabase(
141
              "database", "1.0", "database", 1024 /* 1 kB */);
142
          database.transaction(function(context) {
143
            context.executeSql("CREATE TABLE IF NOT EXISTS data (column)");
144
            context.executeSql(
145
                "INSERT INTO data (column) VALUES (1)", [], resolve);
146
          });
147
        });
148
      },
149
      "isEmpty": function() {
150
        return new Promise(function(resolve, reject) {
151
          var database = window.openDatabase(
152
              "database", "1.0", "database", 1024 /* 1 kB */);
153
          database.transaction(function(context) {
154
            context.executeSql("CREATE TABLE IF NOT EXISTS data (column)");
155
            context.executeSql(
156
                "SELECT * FROM data", [],
157
                function(transaction, result) {
158
                  resolve(!result.rows.length);
159
                });
160
          });
161
        });
162
      }
163
    }
164
  ].filter(function(backend) { return backend.supported(); });
114
  ].filter(function(backend) { return backend.supported(); });
165
115
166
  /**
116
  /**
167
   * All datatypes supported by Clear-Site-Data.
117
   * All datatypes supported by Clear-Site-Data.
168
   * @param{Array.<Datatype>}
118
   * @param{Array.<Datatype>}
169
   */
119
   */
170
  TestUtils.DATATYPES = [
120
  TestUtils.DATATYPES = [
171
    {
121
    {

Return to bug 1626728