Bug 1286798 - Part 52: Rework tests to use async functions; r=asuth
authorJan Varga <jan.varga@gmail.com>
Thu, 29 Nov 2018 21:50:01 +0100
changeset 508050 d4212b87659b68493dda32877783bbbd1bf8e250
parent 508049 e21dc8a8b5b990ba6eac1def6dbc818b6691674a
child 508051 fd65b14ab7e8aba272dd49f84af229b3ecef6e0a
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1286798
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286798 - Part 52: Rework tests to use async functions; r=asuth
dom/localstorage/test/unit/head.js
dom/localstorage/test/unit/test_archive.js
dom/localstorage/test/unit/test_databaseShadowing1.js
dom/localstorage/test/unit/test_databaseShadowing2.js
dom/localstorage/test/unit/test_databaseShadowing_clearOrigin1.js
dom/localstorage/test/unit/test_databaseShadowing_clearOrigin2.js
dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPattern1.js
dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPattern2.js
dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPrefix1.js
dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPrefix2.js
dom/localstorage/test/unit/test_eviction.js
dom/localstorage/test/unit/test_groupLimit.js
dom/localstorage/test/unit/test_migration.js
dom/localstorage/test/unit/test_snapshotting.js
--- a/dom/localstorage/test/unit/head.js
+++ b/dom/localstorage/test/unit/head.js
@@ -24,42 +24,38 @@ function run_test()
 
 if (!this.runTest) {
   this.runTest = function()
   {
     do_get_profile();
 
     enableTesting();
 
-    do_test_pending();
-    testGenerator.next();
+    Assert.ok(typeof testSteps === "function",
+              "There should be a testSteps function");
+    Assert.ok(testSteps.constructor.name === "AsyncFunction",
+              "testSteps should be an async function");
+
+    registerCleanupFunction(resetTesting);
+
+    add_task(testSteps);
+
+    // Since we defined run_test, we must invoke run_next_test() to start the
+    // async test.
+    run_next_test();
   }
 }
 
-function finishTest()
+function returnToEventLoop()
 {
-  resetTesting();
-
-  executeSoon(function() {
-    do_test_finished();
-  })
-}
-
-function continueToNextStep()
-{
-  executeSoon(function() {
-    testGenerator.next();
+  return new Promise(function(resolve) {
+    executeSoon(resolve);
   });
 }
 
-function continueToNextStepSync()
-{
-  testGenerator.next();
-}
-
 function enableTesting()
 {
   Services.prefs.setBoolPref("dom.storage.testing", true);
   Services.prefs.setBoolPref("dom.quotaManager.testing", true);
 }
 
 function resetTesting()
 {
@@ -83,70 +79,64 @@ function setOriginLimit(originLimit)
   Services.prefs.setIntPref("dom.storage.default_quota", originLimit);
 }
 
 function resetOriginLimit()
 {
   Services.prefs.clearUserPref("dom.storage.default_quota");
 }
 
-function getOriginUsage(principal, callback)
+function getOriginUsage(principal)
 {
-  let request = Services.qms.getUsageForPrincipal(principal, callback);
-  request.callback = callback;
+  let request = Services.qms.getUsageForPrincipal(principal, function() { });
 
   return request;
 }
 
-function clear(callback)
+function clear()
 {
   let request = Services.qms.clear();
-  request.callback = callback;
 
   return request;
 }
 
-function clearOriginsByPattern(pattern, callback)
+function clearOriginsByPattern(pattern)
 {
   let request = Services.qms.clearStoragesForOriginAttributesPattern(pattern);
-  request.callback = callback;
 
   return request;
 }
 
-function clearOriginsByPrefix(principal, persistence, callback)
+function clearOriginsByPrefix(principal, persistence)
 {
   let request =
     Services.qms.clearStoragesForPrincipal(principal, persistence, null, true);
-  request.callback = callback;
 
   return request;
 }
 
-function clearOrigin(principal, persistence, callback)
+function clearOrigin(principal, persistence)
 {
   let request = Services.qms.clearStoragesForPrincipal(principal, persistence);
-  request.callback = callback;
 
   return request;
 }
 
 function reset(callback)
 {
   let request = Services.qms.reset();
   request.callback = callback;
 
   return request;
 }
 
-function resetOrigin(principal, callback)
+function resetOrigin(principal)
 {
   let request =
     Services.qms.resetStoragesForPrincipal(principal, "default", "ls");
-  request.callback = callback;
 
   return request;
 }
 
 function installPackage(packageName)
 {
   let directoryService = Cc["@mozilla.org/file/directory_service;1"]
                          .getService(Ci.nsIProperties);
@@ -256,14 +246,26 @@ function getLocalStorage(principal)
 {
   if (!principal) {
     principal = getCurrentPrincipal();
   }
 
   return Services.domStorageManager.createStorage(null, principal, "");
 }
 
+function requestFinished(request) {
+  return new Promise(function(resolve, reject) {
+    request.callback = function(request) {
+      if (request.resultCode == Cr.NS_OK) {
+        resolve(request.result);
+      } else {
+        reject(request.resultCode);
+      }
+    }
+  });
+}
+
 function loadSubscript(path)
 {
   let file = do_get_file(path, false);
   let uri = Services.io.newFileURI(file);
   Services.scriptloader.loadSubScript(uri.spec);
 }
--- a/dom/localstorage/test/unit/test_archive.js
+++ b/dom/localstorage/test/unit/test_archive.js
@@ -1,16 +1,14 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
-function* testSteps()
+async function testSteps()
 {
   const lsArchiveFile = "storage/ls-archive.sqlite";
 
   const principalInfo = {
     url: "http://example.com",
     attrs: {}
   };
 
@@ -28,53 +26,51 @@ function* testSteps()
 
   info("Setting pref");
 
   Services.prefs.setBoolPref("dom.storage.next_gen", true);
 
   // Profile 1 - Archive file is a directory.
   info("Clearing");
 
-  clear(continueToNextStepSync);
-  yield undefined;
+  let request = clear();
+  await requestFinished(request);
 
   let archiveFile = getRelativeFile(lsArchiveFile);
 
   archiveFile.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8));
 
   checkStorage();
 
   // Profile 2 - Corrupted archive file.
   info("Clearing");
 
-  clear(continueToNextStepSync);
-  yield undefined;
+  request = clear();
+  await requestFinished(request);
 
   let ostream = Cc["@mozilla.org/network/file-output-stream;1"]
                 .createInstance(Ci.nsIFileOutputStream);
   ostream.init(archiveFile, -1, parseInt("0644", 8), 0);
   ostream.write("foobar", 6);
   ostream.close();
 
   checkStorage();
 
   // Profile 3 - Nonupdateable archive file.
   info("Clearing");
 
-  clear(continueToNextStepSync);
-  yield undefined;
+  request = clear();
+  await requestFinished(request);
 
   info("Installing package");
 
   // The profile contains storage.sqlite and storage/ls-archive.sqlite
   // storage/ls-archive.sqlite was taken from FF 54 to force an upgrade.
   // There's just one record in the webappsstore2 table. The record was
   // modified by renaming the origin attribute userContextId to userContextKey.
   // This triggers an error during the upgrade.
   installPackage("archive_profile");
 
   let fileSize = archiveFile.fileSize;
   ok(fileSize > 0, "archive file size is greater than zero");
 
   checkStorage();
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing1.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing1.js
@@ -1,27 +1,23 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   enableNextGenLocalStorage();
 
   storeData();
 
   verifyData([]);
 
   // Wait for all database connections to close.
-  reset(continueToNextStepSync);
-  yield undefined;
+  let request = reset();
+  await requestFinished(request);
 
   exportShadowDatabase("shadowdb.sqlite");
 
   // The shadow database is now prepared for test_databaseShadowing2.js
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing2.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing2.js
@@ -1,24 +1,19 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   // The shadow database was prepared in test_databaseShadowing1.js
 
   disableNextGenLocalStorage();
 
   if (!importShadowDatabase("shadowdb.sqlite")) {
-    finishTest();
     return;
   }
 
   verifyData([]);
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing_clearOrigin1.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing_clearOrigin1.js
@@ -1,34 +1,30 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   enableNextGenLocalStorage();
 
   storeData();
 
   verifyData([]);
 
   let principal = getPrincipal("http://origin.test", {});
-  clearOrigin(principal, "default", continueToNextStepSync);
-  yield undefined;
+  let request = clearOrigin(principal, "default");
+  await requestFinished(request);
 
   verifyData([1]);
 
   // Wait for all database connections to close.
-  reset(continueToNextStepSync);
-  yield undefined;
+  request = reset();
+  await requestFinished(request);
 
   exportShadowDatabase("shadowdb_clearedOrigin.sqlite");
 
   // The shadow database is now prepared for
   // test_databaseShadowing_clearOrigin2.js
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing_clearOrigin2.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing_clearOrigin2.js
@@ -1,24 +1,19 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   // The shadow database was prepared in test_databaseShadowing_clearOrigin1.js
 
   disableNextGenLocalStorage();
 
   if (!importShadowDatabase("shadowdb-clearedOrigin.sqlite")) {
-    finishTest();
     return;
   }
 
   verifyData([1]);
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPattern1.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPattern1.js
@@ -1,34 +1,29 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   enableNextGenLocalStorage();
 
   storeData();
 
   verifyData([]);
 
-  clearOriginsByPattern(JSON.stringify({ userContextId: 15 }),
-                        continueToNextStepSync);
-  yield undefined;
+  let request = clearOriginsByPattern(JSON.stringify({ userContextId: 15 }));
+  await requestFinished(request);
 
   verifyData([4,5,6]);
 
   // Wait for all database connections to close.
-  reset(continueToNextStepSync);
-  yield undefined;
+  request = reset();
+  await requestFinished(request);
 
   exportShadowDatabase("shadowdb-clearedOriginsByPattern.sqlite");
 
   // The shadow database is now prepared for
   // test_databaseShadowing_clearOriginsByPattern2.js
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPattern2.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPattern2.js
@@ -1,25 +1,20 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   // The shadow database was prepared in
   // test_databaseShadowing_clearOriginsByPattern1.js
 
   disableNextGenLocalStorage();
 
   if (!importShadowDatabase("shadowdb-clearedOriginsByPattern.sqlite")) {
-    finishTest();
     return;
   }
 
   verifyData([4,5,6]);
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPrefix1.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPrefix1.js
@@ -1,32 +1,28 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   enableNextGenLocalStorage();
 
   storeData();
 
   verifyData([]);
 
   let principal = getPrincipal("http://prefix.test", {});
-  clearOriginsByPrefix(principal, "default", continueToNextStepSync);
-  yield undefined;
+  let request = clearOriginsByPrefix(principal, "default");
+  await requestFinished(request);
 
   // Wait for all database connections to close.
-  reset(continueToNextStepSync);
-  yield undefined;
+  request = reset();
+  await requestFinished(request);
 
   exportShadowDatabase("shadowdb-clearedOriginsByPrefix.sqlite");
 
   // The shadow database is now prepared for
   // test_databaseShadowing_clearOriginsByPrefix2.js
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPrefix2.js
+++ b/dom/localstorage/test/unit/test_databaseShadowing_clearOriginsByPrefix2.js
@@ -1,25 +1,20 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
 loadSubscript("databaseShadowing-shared.js");
 
-function* testSteps()
+async function testSteps()
 {
   // The shadow database was prepared in
   // test_databaseShadowing_clearOriginsByPrefix1.js
 
   disableNextGenLocalStorage();
 
   if (!importShadowDatabase("shadowdb-clearedOriginsByPrefix.sqlite")) {
-    finishTest();
     return;
   }
 
   verifyData([2,3]);
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_eviction.js
+++ b/dom/localstorage/test/unit/test_eviction.js
@@ -1,16 +1,14 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
-function* testSteps()
+async function testSteps()
 {
   const globalLimitKB = 5 * 1024;
 
   const data = {};
   data.sizeKB = 1 * 1024;
   data.key = "A";
   data.value = repeatChar(data.sizeKB * 1024 - data.key.length, ".");
   data.urlCount = globalLimitKB / data.sizeKB;
@@ -23,18 +21,18 @@ function* testSteps()
 
   Services.prefs.setBoolPref("dom.storage.next_gen", true);
   Services.prefs.setBoolPref("dom.storage.snapshot_reusing", false);
 
   info("Setting limits");
 
   setGlobalLimit(globalLimitKB);
 
-  clear(continueToNextStepSync);
-  yield undefined;
+  let request = clear();
+  await requestFinished(request);
 
   info("Getting storages");
 
   let storages = [];
   for (let i = 0; i < data.urlCount; i++) {
     let storage = getLocalStorage(getPrincipal(getSpec(i)));
     storages.push(storage);
   }
@@ -60,33 +58,31 @@ function* testSteps()
   }
 
   info("Closing first origin");
 
   storages[0].close();
 
   let principal = getPrincipal("http://example0.com");
 
-  resetOrigin(principal, continueToNextStepSync);
-  yield undefined;
+  request = resetOrigin(principal);
+  await requestFinished(request);
 
   info("Getting usage for first origin");
 
-  let request = getOriginUsage(principal, continueToNextStepSync);
-  yield undefined;
+  request = getOriginUsage(principal);
+  await requestFinished(request);
 
   is(request.result.usage, data.sizeKB * 1024, "Correct usage");
 
   info("Verifying more data data can be written");
 
   for (let i = 1; i < data.urlCount; i++) {
     storages[i].setItem("B", "");
   }
 
   info("Getting usage for first origin");
 
-  request = getOriginUsage(principal, continueToNextStepSync);
-  yield undefined;
+  request = getOriginUsage(principal);
+  await requestFinished(request);
 
   is(request.result.usage, 0, "Zero usage");
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_groupLimit.js
+++ b/dom/localstorage/test/unit/test_groupLimit.js
@@ -1,16 +1,14 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
-function* testSteps()
+async function testSteps()
 {
   const groupLimitKB = 10 * 1024;
 
   const globalLimitKB = groupLimitKB * 5;
 
   const originLimit = 10 * 1024;
 
   const urls = [
@@ -29,18 +27,18 @@ function* testSteps()
   info("Setting pref");
 
   Services.prefs.setBoolPref("dom.storage.snapshot_reusing", false);
 
   info("Setting limits");
 
   setGlobalLimit(globalLimitKB);
 
-  clear(continueToNextStepSync);
-  yield undefined;
+  let request = clear();
+  await requestFinished(request);
 
   setOriginLimit(originLimit);
 
   info("Getting storages");
 
   let storages = [];
   for (let i = 0; i < urls.length; i++) {
     let storage = getLocalStorage(getPrincipal(urls[i]));
@@ -68,19 +66,16 @@ function* testSteps()
   }
 
   info("Clearing first origin");
 
   storages[0].clear();
 
   // Let the internal snapshot finish (usage is not descreased until all
   // snapshots finish)..
-  continueToNextStep();
-  yield undefined;
+  await returnToEventLoop();
 
   info("Verifying more data can be written");
 
   for (let i = 0; i < urls.length; i++) {
     storages[i].setItem("B", "");
   }
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_migration.js
+++ b/dom/localstorage/test/unit/test_migration.js
@@ -1,16 +1,14 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
-function* testSteps()
+async function testSteps()
 {
   const principalInfos = [
     { url: "http://localhost", attrs: {} },
     { url: "http://www.mozilla.org", attrs: {} },
     { url: "http://example.com", attrs: {} },
     { url: "http://example.org", attrs: { userContextId: 5 } },
 
     { url: "http://origin.test", attrs: {} },
@@ -54,77 +52,74 @@ function* testSteps()
   info("Setting pref");
 
   Services.prefs.setBoolPref("dom.storage.next_gen", true);
 
   info("Stage 1 - Testing archived data migration");
 
   info("Clearing");
 
-  clear(continueToNextStepSync);
-  yield undefined;
+  let request = clear();
+  await requestFinished(request);
 
   info("Installing package");
 
   // The profile contains storage.sqlite and webappsstore.sqlite. The file
   // create_db.js in the package was run locally, specifically it was
   // temporarily added to xpcshell.ini and then executed:
   // mach xpcshell-test --interactive dom/localstorage/test/unit/create_db.js
   installPackage("migration_profile");
 
   verifyData([]);
 
   info("Stage 2 - Testing archived data clearing");
 
   for (let type of ["origin", "prefix", "pattern"]) {
     info("Clearing");
 
-    clear(continueToNextStepSync);
-    yield undefined;
+    request = clear();
+    await requestFinished(request);
 
     info("Installing package");
 
     // See the comment for the first installPackage() call.
     installPackage("migration_profile");
 
     let clearedOrigins = [];
 
     switch (type) {
       case "origin": {
         let principal = getPrincipal("http://origin.test", {});
-        clearOrigin(principal, "default", continueToNextStepSync);
-        yield undefined;
+        request = clearOrigin(principal, "default");
+        await requestFinished(request);
 
         clearedOrigins.push(4);
 
         break;
       }
 
       case "prefix": {
         let principal = getPrincipal("http://prefix.test", {});
-        clearOriginsByPrefix(principal, "default", continueToNextStepSync);
-        yield undefined;
+        request = clearOriginsByPrefix(principal, "default");
+        await requestFinished(request);
 
         clearedOrigins.push(5, 6);
 
         break;
       }
 
       case "pattern": {
-        clearOriginsByPattern(JSON.stringify({ userContextId: 15 }),
-                              continueToNextStepSync);
-        yield undefined;
+        request = clearOriginsByPattern(JSON.stringify({ userContextId: 15 }));
+        await requestFinished(request);
 
         clearedOrigins.push(7, 8, 9);
 
         break;
       }
 
       default: {
         throw("Unknown type: " + type);
       }
     }
 
     verifyData(clearedOrigins);
   }
-
-  finishTest();
 }
--- a/dom/localstorage/test/unit/test_snapshotting.js
+++ b/dom/localstorage/test/unit/test_snapshotting.js
@@ -1,16 +1,14 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var testGenerator = testSteps();
-
-function* testSteps()
+async function testSteps()
 {
   const url = "http://example.com";
 
   const items = [
     { key: "key1", value: "value1" },
     { key: "key2", value: "value2" },
     { key: "key3", value: "value3" },
     { key: "key4", value: "value4" },
@@ -67,18 +65,17 @@ function* testSteps()
     // GetKey should match GetKeys
     for (let i = 0; i < savedKeys.length; i++) {
       is(storage.key(i), savedKeys[i], "Correct key");
     }
 
     info("Returning to event loop");
 
     // Returning to event loop forces the internal snapshot to finish.
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 2nd snapshot
 
     info("Verifying length");
 
     is(storage.length, items.length, "Correct length");
 
     info("Verifying key order");
@@ -94,18 +91,17 @@ function* testSteps()
     info("Verifying values");
 
     for (let item of items) {
       is(storage.getItem(item.key), item.value, "Correct value");
     }
 
     info("Returning to event loop");
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 3rd snapshot
 
     // Force key2 to load.
     storage.getItem("key2");
 
     // Fill out write infos a bit.
     storage.removeItem("key5");
@@ -131,18 +127,17 @@ function* testSteps()
     }
 
     storage.removeItem("key11");
 
     items.pop();
 
     info("Returning to event loop");
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 4th snapshot
 
     // Force loading of all items.
     info("Verifying length");
 
     is(storage.length, items.length, "Correct length");
 
@@ -151,18 +146,17 @@ function* testSteps()
     for (let item of items) {
       is(storage.getItem(item.key), item.value, "Correct value");
     }
 
     is(storage.getItem("key11"), null, "Correct value");
 
     info("Returning to event loop");
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 5th snapshot
 
     // Force loading of all keys.
     info("Saving key order");
 
     savedKeys = Object.keys(storage);
 
@@ -176,42 +170,39 @@ function* testSteps()
     for (let item of items) {
       is(storage.getItem(item.key), item.value, "Correct value");
     }
 
     is(storage.getItem("key11"), null, "Correct value");
 
     info("Returning to event loop");
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 6th snapshot
     info("Verifying unknown item");
 
     is(storage.getItem("key11"), null, "Correct value");
 
     info("Verifying unknown item again");
 
     is(storage.getItem("key11"), null, "Correct value");
 
     info("Returning to event loop");
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 7th snapshot
 
     // Save actual key order.
     info("Saving key order");
 
     savedKeys = Object.keys(storage);
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 8th snapshot
 
     // Force loading of all items, but in reverse order.
     info("Getting values");
 
     for (let i = items.length - 1; i >= 0; i--) {
       let item = items[i];
@@ -223,25 +214,21 @@ function* testSteps()
     keys = Object.keys(storage);
 
     is(keys.length, savedKeys.length);
 
     for (let i = 0; i < keys.length; i++) {
       is(keys[i], savedKeys[i], "Correct key");
     }
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
 
     // 9th snapshot
 
     info("Clearing");
 
     storage.clear();
 
     info("Returning to event loop");
 
-    continueToNextStep();
-    yield undefined;
+    await returnToEventLoop();
   }
-
-  finishTest();
 }