Bug 1358035: Move the check for persisting an invalid origin to test_bad_origin_directory.js and add skip beta/release flag on it since we don't check invaild origins on beta/release. r=janv
authorTom Tung <shes050117@gmail.com>
Thu, 20 Apr 2017 15:26:31 +0800
changeset 566306 9faa446314c3ab5888d64922f647019a5da5b748
parent 566305 ab3beca99070efa81bde4ee701885e2d911724a2
child 566307 aee196633a8655daea6099a9327059f47656c745
push id55180
push userjjong@mozilla.com
push dateFri, 21 Apr 2017 09:36:13 +0000
reviewersjanv
bugs1358035
milestone55.0a1
Bug 1358035: Move the check for persisting an invalid origin to test_bad_origin_directory.js and add skip beta/release flag on it since we don't check invaild origins on beta/release. r=janv MozReview-Commit-ID: GYcw4RYoIms
dom/quota/test/unit/test_bad_origin_directory.js
dom/quota/test/unit/test_persist.js
dom/quota/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/dom/quota/test/unit/test_bad_origin_directory.js
@@ -0,0 +1,38 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var testGenerator = testSteps();
+
+function* testSteps()
+{
+  const invalidOrigin = {
+    url: "ftp://ftp.invalid.origin",
+    path: "storage/default/ftp+++ftp.invalid.origin"
+  };
+
+  info("Persisting an invalid origin");
+
+  let invalidPrincipal = getPrincipal(invalidOrigin.url);
+
+  let request = persist(invalidPrincipal, continueToNextStepSync);
+  yield undefined;
+
+  ok(request.resultCode === NS_ERROR_FAILURE,
+     "Persist() failed because of the invalid origin");
+  ok(request.result === null, "The request result is null");
+
+  let originDir = getRelativeFile(invalidOrigin.path);
+  let exists = originDir.exists();
+  ok(!exists, "Directory for invalid origin doesn't exist");
+
+  request = persisted(invalidPrincipal, continueToNextStepSync);
+  yield undefined;
+
+  ok(request.resultCode === NS_OK, "Persisted() succeeded");
+  ok(!request.result,
+     "The origin isn't persisted since the operation failed");
+
+  finishTest();
+}
--- a/dom/quota/test/unit/test_persist.js
+++ b/dom/quota/test/unit/test_persist.js
@@ -2,33 +2,25 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
-  const origins = [
-    {
-      url: "http://default.test.persist",
-      path: "storage/default/http+++default.test.persist",
-      persistence: "default"
-    },
-
-    {
-      url: "ftp://ftp.invalid.origin",
-      path: "storage/default/ftp+++ftp.invalid.origin",
-      persistence: "default"
-    },
-  ];
+  const origin = {
+    url: "http://default.test.persist",
+    path: "storage/default/http+++default.test.persist",
+    persistence: "default"
+  };
 
   const metadataFileName = ".metadata-v2";
 
-  let principal = getPrincipal(origins[0].url);
+  let principal = getPrincipal(origin.url);
 
   info("Persisting an uninitialized origin");
 
   // Origin directory doesn't exist yet, so only check the result for
   // persisted().
   let request = persisted(principal, continueToNextStepSync);
   yield undefined;
 
@@ -37,17 +29,17 @@ function* testSteps()
 
   info("Verifying persist() does update the metadata");
 
   request = persist(principal, continueToNextStepSync);
   yield undefined;
 
   ok(request.resultCode === NS_OK, "Persist() succeeded");
 
-  let originDir = getRelativeFile(origins[0].path);
+  let originDir = getRelativeFile(origin.path);
   let exists = originDir.exists();
   ok(exists, "Origin directory does exist");
 
   info("Reading out contents of metadata file");
 
   let metadataFile = originDir.clone();
   metadataFile.append(metadataFileName);
 
@@ -69,22 +61,22 @@ function* testSteps()
 
   ok(request.resultCode === NS_OK, "Persisted() succeeded");
   ok(request.result === originPersisted, "Persisted() concurs with metadata");
 
   info("Clearing the origin");
 
   // Clear the origin since we'll test the same directory again under different
   // circumstances.
-  clearOrigin(principal, origins[0].persistence, continueToNextStepSync);
+  clearOrigin(principal, origin.persistence, continueToNextStepSync);
   yield undefined;
 
   info("Persisting an already initialized origin");
 
-  initOrigin(principal, origins[0].persistence, continueToNextStepSync);
+  initOrigin(principal, origin.persistence, continueToNextStepSync);
   yield undefined;
 
   info("Reading out contents of metadata file");
 
   fileReader = new FileReader();
   fileReader.onload = continueToNextStepSync;
   fileReader.readAsArrayBuffer(file);
   yield undefined;
@@ -120,32 +112,10 @@ function* testSteps()
   info("Verifying persisted()");
 
   request = persisted(principal, continueToNextStepSync);
   yield undefined;
 
   ok(request.resultCode === NS_OK, "Persisted() succeeded");
   ok(request.result === originPersisted, "Persisted() concurs with metadata");
 
-  info("Persisting an invalid origin");
-
-  let invalidPrincipal = getPrincipal(origins[1].url);
-
-  request = persist(invalidPrincipal, continueToNextStepSync);
-  yield undefined;
-
-  ok(request.resultCode === NS_ERROR_FAILURE,
-     "Persist() failed because of the invalid origin");
-  ok(request.result === null, "The request result is null");
-
-  originDir = getRelativeFile(origins[1].path);
-  exists = originDir.exists();
-  ok(!exists, "Directory for invalid origin doesn't exist");
-
-  request = persisted(invalidPrincipal, continueToNextStepSync);
-  yield undefined;
-
-  ok(request.resultCode === NS_OK, "Persisted() succeeded");
-  ok(!request.result,
-     "The origin isn't persisted since the operation failed");
-
   finishTest();
 }
--- a/dom/quota/test/unit/xpcshell.ini
+++ b/dom/quota/test/unit/xpcshell.ini
@@ -13,16 +13,18 @@ support-files =
   morgueCleanup_profile.zip
   obsoleteOriginAttributes_profile.zip
   originAttributesUpgrade_profile.zip
   removeAppsUpgrade_profile.zip
   storagePersistentUpgrade_profile.zip
   tempMetadataCleanup_profile.zip
 
 [test_basics.js]
+[test_bad_origin_directory.js]
+skip-if = release_or_beta
 [test_defaultStorageUpgrade.js]
 [test_getUsage.js]
 [test_idbSubdirUpgrade.js]
 [test_morgueCleanup.js]
 [test_obsoleteOriginAttributesUpgrade.js]
 [test_originAttributesUpgrade.js]
 [test_persist.js]
 [test_removeAppsUpgrade.js]