test_metadata2Restore.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. var testGenerator = testSteps();
  6. function testSteps()
  7. {
  8. const openParams = [
  9. // This one lives in storage/permanent/chrome
  10. // The .metadata-v2 file was intentionally removed for this origin directory
  11. // to test restoring.
  12. { dbName: "dbA",
  13. dbOptions: { version: 1, storage: "persistent" } },
  14. // This one lives in storage/temporary/http+++localhost
  15. // The .metadata-v2 file was intentionally removed for this origin directory
  16. // to test restoring.
  17. { url: "http://localhost", dbName: "dbB",
  18. dbOptions: { version: 1, storage: "temporary" } },
  19. // This one lives in storage/default/http+++localhost+81^userContextId=1
  20. // The .metadata-v2 file was intentionally removed for this origin directory
  21. // to test restoring.
  22. { attrs: { userContextId: 1 }, url: "http://localhost:81", dbName: "dbC",
  23. dbOptions: { version: 1, storage: "default" } },
  24. // This one lives in storage/default/http+++localhost+82^userContextId=1
  25. // The .metadata-v2 file was intentionally truncated for this origin directory
  26. // to test restoring.
  27. { attrs: { userContextId: 1 }, url: "http://localhost:82", dbName: "dbD",
  28. dbOptions: { version: 1, storage: "default" } },
  29. // This one lives in storage/default/http+++localhost+83^userContextId=1
  30. // The .metadata-v2 file was intentionally modified to contain only
  31. // 4 bytes of the 64 bit timestamp
  32. // for this origin directory to test restoring.
  33. { attrs: { userContextId: 1 }, url: "http://localhost:83", dbName: "dbE",
  34. dbOptions: { version: 1, storage: "default" } },
  35. // This one lives in storage/default/http+++localhost+84^userContextId=1
  36. // The .metadata-v2 file was intentionally modified to contain only
  37. // the 64 bit timestamp
  38. // for this origin directory to test restoring.
  39. { attrs: { userContextId: 1 }, url: "http://localhost:84", dbName: "dbF",
  40. dbOptions: { version: 1, storage: "default" } },
  41. // This one lives in storage/default/http+++localhost+85^userContextId=1
  42. // The .metadata-v2 file was intentionally modified to contain only
  43. // the 64 bit timestamp and
  44. // the 8 bit persisted flag
  45. // for this origin directory to test restoring.
  46. { attrs: { userContextId: 1 }, url: "http://localhost:85", dbName: "dbG",
  47. dbOptions: { version: 1, storage: "default" } },
  48. // This one lives in storage/default/http+++localhost+86^userContextId=1
  49. // The .metadata-v2 file was intentionally modified to contain only
  50. // the 64 bit timestamp,
  51. // the 8 bit persisted flag and
  52. // 2 bytes of the 32 bit reserved data 1
  53. // for this origin directory to test restoring.
  54. { attrs: { userContextId: 1 }, url: "http://localhost:86", dbName: "dbH",
  55. dbOptions: { version: 1, storage: "default" } },
  56. // This one lives in storage/default/http+++localhost+87^userContextId=1
  57. // The .metadata-v2 file was intentionally modified to contain only
  58. // the 64 bit timestamp,
  59. // the 8 bit persisted flag and
  60. // the 32 bit reserved data 1
  61. // for this origin directory to test restoring.
  62. { attrs: { userContextId: 1 }, url: "http://localhost:87", dbName: "dbI",
  63. dbOptions: { version: 1, storage: "default" } },
  64. // This one lives in storage/default/http+++localhost+88^userContextId=1
  65. // The .metadata-v2 file was intentionally modified to contain only
  66. // the 64 bit timestamp,
  67. // the 8 bit persisted flag,
  68. // the 32 bit reserved data 1 and
  69. // 2 bytes of the 32 bit reserved data 2
  70. // for this origin directory to test restoring.
  71. { attrs: { userContextId: 1 }, url: "http://localhost:88", dbName: "dbJ",
  72. dbOptions: { version: 1, storage: "default" } },
  73. // This one lives in storage/default/http+++localhost+89^userContextId=1
  74. // The .metadata-v2 file was intentionally modified to contain only
  75. // the 64 bit timestamp,
  76. // the 8 bit persisted flag,
  77. // the 32 bit reserved data 1 and
  78. // the 32 bit reserved data 2
  79. // for this origin directory to test restoring.
  80. { attrs: { userContextId: 1 }, url: "http://localhost:89", dbName: "dbK",
  81. dbOptions: { version: 1, storage: "default" } },
  82. // This one lives in storage/default/http+++localhost+90^userContextId=1
  83. // The .metadata-v2 file was intentionally modified to contain only
  84. // the 64 bit timestamp,
  85. // the 8 bit persisted flag,
  86. // the 32 bit reserved data 1,
  87. // the 32 bit reserved data 2 and
  88. // 2 bytes of the 32 bit suffix length
  89. // for this origin directory to test restoring.
  90. { attrs: { userContextId: 1 }, url: "http://localhost:90", dbName: "dbL",
  91. dbOptions: { version: 1, storage: "default" } },
  92. // This one lives in storage/default/http+++localhost+91^userContextId=1
  93. // The .metadata-v2 file was intentionally modified to contain only
  94. // the 64 bit timestamp,
  95. // the 8 bit persisted flag,
  96. // the 32 bit reserved data 1,
  97. // the 32 bit reserved data 2,
  98. // the 32 bit suffix length and
  99. // first 5 chars of the suffix
  100. // for this origin directory to test restoring.
  101. { attrs: { userContextId: 1 }, url: "http://localhost:91", dbName: "dbM",
  102. dbOptions: { version: 1, storage: "default" } },
  103. // This one lives in storage/default/http+++localhost+92^userContextId=1
  104. // The .metadata-v2 file was intentionally modified to contain only
  105. // the 64 bit timestamp,
  106. // the 8 bit persisted flag,
  107. // the 32 bit reserved data 1,
  108. // the 32 bit reserved data 2,
  109. // the 32 bit suffix length and
  110. // the suffix
  111. // for this origin directory to test restoring.
  112. { attrs: { userContextId: 1 }, url: "http://localhost:92", dbName: "dbN",
  113. dbOptions: { version: 1, storage: "default" } },
  114. // This one lives in storage/default/http+++localhost+93^userContextId=1
  115. // The .metadata-v2 file was intentionally modified to contain only
  116. // the 64 bit timestamp,
  117. // the 8 bit persisted flag,
  118. // the 32 bit reserved data 1,
  119. // the 32 bit reserved data 2,
  120. // the 32 bit suffix length,
  121. // the suffix and
  122. // 2 bytes of the 32 bit group length
  123. // for this origin directory to test restoring.
  124. { attrs: { userContextId: 1 }, url: "http://localhost:93", dbName: "dbO",
  125. dbOptions: { version: 1, storage: "default" } },
  126. // This one lives in storage/default/http+++localhost+94^userContextId=1
  127. // The .metadata-v2 file was intentionally modified to contain only
  128. // the 64 bit timestamp,
  129. // the 8 bit persisted flag,
  130. // the 32 bit reserved data 1,
  131. // the 32 bit reserved data 2,
  132. // the 32 bit suffix length,
  133. // the suffix,
  134. // the 32 bit group length and
  135. // first 5 chars of the group
  136. // for this origin directory to test restoring.
  137. { attrs: { userContextId: 1 }, url: "http://localhost:94", dbName: "dbP",
  138. dbOptions: { version: 1, storage: "default" } },
  139. // This one lives in storage/default/http+++localhost+95^userContextId=1
  140. // The .metadata-v2 file was intentionally modified to contain only
  141. // the 64 bit timestamp,
  142. // the 8 bit persisted flag,
  143. // the 32 bit reserved data 1,
  144. // the 32 bit reserved data 2,
  145. // the 32 bit suffix length,
  146. // the suffix,
  147. // the 32 bit group length and
  148. // the group
  149. // for this origin directory to test restoring.
  150. { attrs: { userContextId: 1 }, url: "http://localhost:95", dbName: "dbQ",
  151. dbOptions: { version: 1, storage: "default" } },
  152. // This one lives in storage/default/http+++localhost+96^userContextId=1
  153. // The .metadata-v2 file was intentionally modified to contain only
  154. // the 64 bit timestamp,
  155. // the 8 bit persisted flag,
  156. // the 32 bit reserved data 1,
  157. // the 32 bit reserved data 2,
  158. // the 32 bit suffix length,
  159. // the suffix,
  160. // the 32 bit group length,
  161. // the group and
  162. // 2 bytes of the 32 bit origin length
  163. // for this origin directory to test restoring.
  164. { attrs: { userContextId: 1 }, url: "http://localhost:96", dbName: "dbR",
  165. dbOptions: { version: 1, storage: "default" } },
  166. // This one lives in storage/default/http+++localhost+97^userContextId=1
  167. // The .metadata-v2 file was intentionally modified to contain only
  168. // the 64 bit timestamp,
  169. // the 8 bit persisted flag,
  170. // the 32 bit reserved data 1,
  171. // the 32 bit reserved data 2,
  172. // the 32 bit suffix length,
  173. // the suffix,
  174. // the 32 bit group length,
  175. // the group,
  176. // the 32 bit origin length and
  177. // first 12 char of the origin
  178. // for this origin directory to test restoring.
  179. { attrs: { userContextId: 1 }, url: "http://localhost:97", dbName: "dbS",
  180. dbOptions: { version: 1, storage: "default" } },
  181. // This one lives in storage/default/http+++localhost+98^userContextId=1
  182. // The .metadata-v2 file was intentionally modified to contain only
  183. // the 64 bit timestamp,
  184. // the 8 bit persisted flag,
  185. // the 32 bit reserved data 1,
  186. // the 32 bit reserved data 2,
  187. // the 32 bit suffix length,
  188. // the suffix,
  189. // the 32 bit group length,
  190. // the group,
  191. // the 32 bit origin length and
  192. // the origin
  193. // for this origin directory to test restoring.
  194. { attrs: { userContextId: 1 }, url: "http://localhost:98", dbName: "dbT",
  195. dbOptions: { version: 1, storage: "default" } }
  196. ];
  197. let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
  198. .getService(SpecialPowers.Ci.nsIIOService);
  199. let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
  200. .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
  201. function openDatabase(params) {
  202. let request;
  203. if ("url" in params) {
  204. let uri = ios.newURI(params.url, null, null);
  205. let principal = ssm.createCodebasePrincipal(uri, params.attrs || {});
  206. request = indexedDB.openForPrincipal(principal, params.dbName,
  207. params.dbOptions);
  208. } else {
  209. request = indexedDB.open(params.dbName, params.dbOptions);
  210. }
  211. return request;
  212. }
  213. clearAllDatabases(continueToNextStepSync);
  214. yield undefined;
  215. installPackagedProfile("metadata2Restore_profile");
  216. for (let params of openParams) {
  217. let request = openDatabase(params);
  218. request.onerror = errorHandler;
  219. request.onupgradeneeded = unexpectedSuccessHandler;
  220. request.onsuccess = grabEventAndContinueHandler;
  221. let event = yield undefined;
  222. is(event.type, "success", "Correct event type");
  223. }
  224. resetAllDatabases(continueToNextStepSync);
  225. yield undefined;
  226. for (let params of openParams) {
  227. let request = openDatabase(params);
  228. request.onerror = errorHandler;
  229. request.onupgradeneeded = unexpectedSuccessHandler;
  230. request.onsuccess = grabEventAndContinueHandler;
  231. let event = yield undefined;
  232. is(event.type, "success", "Correct event type");
  233. }
  234. finishTest();
  235. yield undefined;
  236. }