test_idbSubdirUpgrade.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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+++www.mozilla.org
  10. { url: "http://www.mozilla.org", dbName: "dbB", dbVersion: 1 },
  11. // This one lives in storage/default/1007+t+https+++developer.cdn.mozilla.net
  12. { appId: 1007, inIsolatedMozBrowser: true, url: "https://developer.cdn.mozilla.net",
  13. dbName: "dbN", dbVersion: 1 },
  14. ];
  15. let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
  16. .getService(SpecialPowers.Ci.nsIIOService);
  17. let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
  18. .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
  19. function openDatabase(params) {
  20. let uri = ios.newURI(params.url, null, null);
  21. let principal =
  22. ssm.createCodebasePrincipal(uri,
  23. {appId: params.appId || ssm.NO_APPID,
  24. inIsolatedMozBrowser: params.inIsolatedMozBrowser});
  25. let request = indexedDB.openForPrincipal(principal, params.dbName,
  26. params.dbVersion);
  27. return request;
  28. }
  29. for (let i = 1; i <= 2; i++) {
  30. clearAllDatabases(continueToNextStepSync);
  31. yield undefined;
  32. installPackagedProfile("idbSubdirUpgrade" + i + "_profile");
  33. for (let params of openParams) {
  34. let request = openDatabase(params);
  35. request.onerror = errorHandler;
  36. request.onupgradeneeded = unexpectedSuccessHandler;
  37. request.onsuccess = grabEventAndContinueHandler;
  38. let event = yield undefined;
  39. is(event.type, "success", "Correct event type");
  40. }
  41. resetAllDatabases(continueToNextStepSync);
  42. yield undefined;
  43. for (let params of openParams) {
  44. let request = openDatabase(params);
  45. request.onerror = errorHandler;
  46. request.onupgradeneeded = unexpectedSuccessHandler;
  47. request.onsuccess = grabEventAndContinueHandler;
  48. let event = yield undefined;
  49. is(event.type, "success", "Correct event type");
  50. }
  51. }
  52. finishTest();
  53. yield undefined;
  54. }