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.queryInfo."); | |
8 | |
9 var info; | |
10 var usage; | |
11 var quota; | |
12 | |
13 function onrejected(error) { | |
14 testFailed(error.name + ": " + error.message); | |
15 finishJSTest(); | |
16 } | |
17 | |
18 // Test body functions ---------------------------------------------------- | |
19 | |
20 function runQueryTemporaryTest() { | |
21 debug("* Querying about temporary storage."); | |
22 navigator.storageQuota.queryInfo("temporary").then(function(storageInfo) { | |
23 info = storageInfo; | |
24 shouldBe("info.__proto__", "Object.prototype"); | |
25 | |
26 usage = storageInfo.usage; | |
27 quota = storageInfo.quota; | |
28 | |
29 // Quota value would vary depending on the test environment. | |
30 shouldBeGreaterThanOrEqual("usage", "0"); | |
31 shouldBeGreaterThanOrEqual("quota", "usage"); | |
32 | |
33 runNextTest(); | |
34 }, onrejected); | |
35 } | |
36 | |
37 function runQueryPersistentTest() { | |
38 debug("* Querying about persistent storage."); | |
39 navigator.storageQuota.queryInfo("persistent").then(function(storageInfo) { | |
40 info = storageInfo; | |
41 shouldBe("info.__proto__", "Object.prototype"); | |
42 | |
43 usage = storageInfo.usage; | |
44 quota = storageInfo.quota; | |
45 | |
46 // Quota value would vary depending on the test environment. | |
47 shouldBeGreaterThanOrEqual("usage", "0"); | |
48 shouldBeGreaterThanOrEqual("quota", "usage"); | |
49 | |
50 runNextTest(); | |
51 }, onrejected); | |
52 } | |
53 | |
54 function runQueryUnknownTest() { | |
55 debug("* Querying about unknown storage."); | |
56 navigator.storageQuota.queryInfo('unknown').then(function() { | |
57 testFailed('resolved unexpectedly'); | |
58 }, function(e) { | |
59 testPassed('rejected as expected: ' + e); | |
60 }).then(runNextTest); | |
61 } | |
62 | |
63 function runQueryWithMissingArgumentTest() { | |
64 debug("* Querying with missing storage type."); | |
65 navigator.storageQuota.queryInfo().then(function() { | |
66 testFailed('resolved unexpectedly'); | |
67 }, function(e) { | |
68 testPassed('rejected as expected: ' + e); | |
69 }).then(runNextTest); | |
70 } | |
71 | |
72 // End of test body functions --------------------------------------------- | |
73 | |
74 var testsList = [ | |
75 runQueryTemporaryTest, | |
76 runQueryPersistentTest, | |
77 runQueryUnknownTest, | |
78 runQueryWithMissingArgumentTest, | |
79 ]; | |
80 var testCounter = 0; | |
81 | |
82 function runNextTest() { | |
83 if (testCounter == testsList.length) { | |
84 debug("Finished running tests."); | |
85 finishJSTest(); | |
86 } else { | |
87 testsList[testCounter++](); | |
88 } | |
89 } | |
90 | |
91 if (navigator.storageQuota) { | |
92 window.jsTestIsAsync = true; | |
93 runNextTest(); | |
94 } else { | |
95 debug("This test requires navigator.storageQuota."); | |
96 } | |
97 </script> | |
98 </body> | |
99 </html> | |
OLD | NEW |