| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../resources/js-test.js"></script> | |
| 4 </head> | |
| 5 <body> | |
| 6 <script type="text/javascript"> | |
| 7 description("This tests navigator.storageQuota.requestPersistentQuota."); | |
| 8 | |
| 9 var info; | |
| 10 var usage; | |
| 11 var grantedQuota; | |
| 12 | |
| 13 function onrejected(error) { | |
| 14 testFailed(error.name + ": " + error.message); | |
| 15 finishJSTest(); | |
| 16 } | |
| 17 | |
| 18 // Test body functions ---------------------------------------------------- | |
| 19 | |
| 20 function runRequestQuotaTest() { | |
| 21 debug("* Requesting persistent quota."); | |
| 22 navigator.storageQuota.requestPersistentQuota(1024).then(function(storageInf
o) { | |
| 23 | |
| 24 info = storageInfo; | |
| 25 shouldBe("info.__proto__", "Object.prototype"); | |
| 26 | |
| 27 usage = storageInfo.usage; | |
| 28 grantedQuota = storageInfo.quota; | |
| 29 | |
| 30 // Quota value would vary depending on the test environment. | |
| 31 shouldBeGreaterThanOrEqual("usage", "0"); | |
| 32 shouldBeNonZero("grantedQuota"); | |
| 33 | |
| 34 runNextTest(); | |
| 35 }, onrejected); | |
| 36 } | |
| 37 | |
| 38 function runRequestQuotaWithMisingArgumentTest() { | |
| 39 debug("* Requesting persistent quota with missing argument."); | |
| 40 navigator.storageQuota.requestPersistentQuota().then(function() { | |
| 41 testFailed('resolved unexpectedly'); | |
| 42 }, function(e) { | |
| 43 testPassed('rejected as expected: ' + e); | |
| 44 }).then(runNextTest); | |
| 45 } | |
| 46 | |
| 47 function runRequestQuotaWithNegativeValueTest() { | |
| 48 debug("* Requesting persistent quota with negative value."); | |
| 49 navigator.storageQuota.requestPersistentQuota(-1024).then(function(storageIn
fo) { | |
| 50 info = storageInfo; | |
| 51 shouldBe("info.__proto__", "Object.prototype"); | |
| 52 | |
| 53 usage = storageInfo.usage; | |
| 54 grantedQuota = storageInfo.quota; | |
| 55 | |
| 56 // Quota value would vary depending on the test environment. | |
| 57 shouldBeGreaterThanOrEqual("usage", "0"); | |
| 58 shouldBeZero("grantedQuota"); | |
| 59 | |
| 60 runNextTest(); | |
| 61 }, onrejected); | |
| 62 } | |
| 63 | |
| 64 // End of test body functions --------------------------------------------- | |
| 65 | |
| 66 var testsList = [ | |
| 67 runRequestQuotaTest, | |
| 68 runRequestQuotaWithMisingArgumentTest, | |
| 69 runRequestQuotaWithNegativeValueTest, | |
| 70 ]; | |
| 71 var testCounter = 0; | |
| 72 | |
| 73 function runNextTest() { | |
| 74 if (testCounter == testsList.length) { | |
| 75 debug("Finished running tests."); | |
| 76 finishJSTest(); | |
| 77 } else { | |
| 78 testsList[testCounter++](); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 if (navigator.storageQuota) { | |
| 83 window.jsTestIsAsync = true; | |
| 84 runNextTest(); | |
| 85 } else { | |
| 86 debug("This test requires navigator.storageQuota."); | |
| 87 } | |
| 88 </script> | |
| 89 </body> | |
| 90 </html> | |
| OLD | NEW |