test_defaultStorageUpgrade.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/default/http+++localhost
  10. { url: "http://localhost", dbName: "dbA", dbVersion: 1 },
  11. // This one lives in storage/default/http+++www.mozilla.org
  12. { url: "http://www.mozilla.org", dbName: "dbB", dbVersion: 1 },
  13. // This one lives in storage/default/http+++www.mozilla.org+8080
  14. { url: "http://www.mozilla.org:8080", dbName: "dbC", dbVersion: 1 },
  15. // This one lives in storage/default/https+++www.mozilla.org
  16. { url: "https://www.mozilla.org", dbName: "dbD", dbVersion: 1 },
  17. // This one lives in storage/default/https+++www.mozilla.org+8080
  18. { url: "https://www.mozilla.org:8080", dbName: "dbE", dbVersion: 1 },
  19. // This one lives in storage/permanent/indexeddb+++fx-devtools
  20. { url: "indexeddb://fx-devtools", dbName: "dbF",
  21. dbOptions: { version: 1, storage: "persistent" } },
  22. // This one lives in storage/permanent/moz-safe-about+home
  23. { url: "moz-safe-about:home", dbName: "dbG",
  24. dbOptions: { version: 1, storage: "persistent" } },
  25. // This one lives in storage/default/file++++Users+joe+
  26. { url: "file:///Users/joe/", dbName: "dbH", dbVersion: 1 },
  27. // This one lives in storage/default/file++++Users+joe+index.html
  28. { url: "file:///Users/joe/index.html", dbName: "dbI", dbVersion: 1 },
  29. // This one lives in storage/default/file++++c++Users+joe+
  30. { url: "file:///c:/Users/joe/", dbName: "dbJ", dbVersion: 1 },
  31. // This one lives in storage/default/file++++c++Users+joe+index.html
  32. { url: "file:///c:/Users/joe/index.html", dbName: "dbK", dbVersion: 1 },
  33. // This one lives in storage/permanent/chrome
  34. { dbName: "dbL", dbVersion: 1 },
  35. // This one lives in storage/default/1007+t+https+++developer.cdn.mozilla.net
  36. { appId: 1007, inIsolatedMozBrowser: true, url: "https://developer.cdn.mozilla.net",
  37. dbName: "dbN", dbVersion: 1 },
  38. // This one lives in storage/default/http+++127.0.0.1
  39. { url: "http://127.0.0.1", dbName: "dbO", dbVersion: 1 },
  40. // This one lives in storage/default/file++++
  41. { url: "file:///", dbName: "dbP", dbVersion: 1 },
  42. // This one lives in storage/default/file++++c++
  43. { url: "file:///c:/", dbName: "dbQ", dbVersion: 1 },
  44. // This one lives in storage/default/file++++Users+joe+c+++index.html
  45. { url: "file:///Users/joe/c++/index.html", dbName: "dbR", dbVersion: 1 },
  46. // This one lives in storage/default/file++++Users+joe+c+++index.html
  47. { url: "file:///Users/joe/c///index.html", dbName: "dbR", dbVersion: 1 },
  48. // This one lives in storage/default/file++++++index.html
  49. { url: "file:///+/index.html", dbName: "dbS", dbVersion: 1 },
  50. // This one lives in storage/default/file++++++index.html
  51. { url: "file://///index.html", dbName: "dbS", dbVersion: 1 },
  52. // This one lives in storage/permanent/resource+++fx-share-addon-at-mozilla-dot-org-fx-share-addon-data
  53. { url: "resource://fx-share-addon-at-mozilla-dot-org-fx-share-addon-data",
  54. dbName: "dbU", dbOptions: { version: 1, storage: "persistent" } },
  55. // This one lives in storage/temporary/http+++localhost+81
  56. // The .metadata file was intentionally removed for this origin directory
  57. // to test restoring during upgrade.
  58. { url: "http://localhost:81", dbName: "dbV",
  59. dbOptions: { version: 1, storage: "temporary" } },
  60. // This one lives in storage/temporary/http+++localhost+82
  61. // The .metadata file was intentionally truncated for this origin directory
  62. // to test restoring during upgrade.
  63. { url: "http://localhost:82", dbName: "dbW",
  64. dbOptions: { version: 1, storage: "temporary" } },
  65. // This one lives in storage/temporary/1007+t+https+++developer.cdn.mozilla.net
  66. { appId: 1007, inIsolatedMozBrowser: true, url: "https://developer.cdn.mozilla.net",
  67. dbName: "dbY", dbOptions: { version: 1, storage: "temporary" } },
  68. // This one lives in storage/temporary/http+++localhost
  69. { url: "http://localhost", dbName: "dbZ",
  70. dbOptions: { version: 1, storage: "temporary" } }
  71. ];
  72. let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
  73. .getService(SpecialPowers.Ci.nsIIOService);
  74. let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
  75. .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
  76. function openDatabase(params) {
  77. let request;
  78. if ("url" in params) {
  79. let uri = ios.newURI(params.url, null, null);
  80. let principal =
  81. ssm.createCodebasePrincipal(uri,
  82. {appId: params.appId || ssm.NO_APPID,
  83. inIsolatedMozBrowser: params.inIsolatedMozBrowser});
  84. if ("dbVersion" in params) {
  85. request = indexedDB.openForPrincipal(principal, params.dbName,
  86. params.dbVersion);
  87. } else {
  88. request = indexedDB.openForPrincipal(principal, params.dbName,
  89. params.dbOptions);
  90. }
  91. } else {
  92. if ("dbVersion" in params) {
  93. request = indexedDB.open(params.dbName, params.dbVersion);
  94. } else {
  95. request = indexedDB.open(params.dbName, params.dbOptions);
  96. }
  97. }
  98. return request;
  99. }
  100. clearAllDatabases(continueToNextStepSync);
  101. yield undefined;
  102. installPackagedProfile("defaultStorageUpgrade_profile");
  103. for (let params of openParams) {
  104. let request = openDatabase(params);
  105. request.onerror = errorHandler;
  106. request.onupgradeneeded = unexpectedSuccessHandler;
  107. request.onsuccess = grabEventAndContinueHandler;
  108. let event = yield undefined;
  109. is(event.type, "success", "Correct event type");
  110. }
  111. resetAllDatabases(continueToNextStepSync);
  112. yield undefined;
  113. for (let params of openParams) {
  114. let request = openDatabase(params);
  115. request.onerror = errorHandler;
  116. request.onupgradeneeded = unexpectedSuccessHandler;
  117. request.onsuccess = grabEventAndContinueHandler;
  118. let event = yield undefined;
  119. is(event.type, "success", "Correct event type");
  120. }
  121. finishTest();
  122. yield undefined;
  123. }