browser_forgetThisSite.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm");
  6. const domains = [
  7. "mochi.test:8888",
  8. "www.example.com"
  9. ];
  10. const addPath = "/browser/dom/indexedDB/test/browser_forgetThisSiteAdd.html";
  11. const getPath = "/browser/dom/indexedDB/test/browser_forgetThisSiteGet.html";
  12. const testPageURL1 = "http://" + domains[0] + addPath;
  13. const testPageURL2 = "http://" + domains[1] + addPath;
  14. const testPageURL3 = "http://" + domains[0] + getPath;
  15. const testPageURL4 = "http://" + domains[1] + getPath;
  16. function test()
  17. {
  18. requestLongerTimeout(2);
  19. waitForExplicitFinish();
  20. // Avoids the prompt
  21. setPermission(testPageURL1, "indexedDB");
  22. setPermission(testPageURL2, "indexedDB");
  23. executeSoon(test1);
  24. }
  25. function test1()
  26. {
  27. // Set database version for domain 1
  28. gBrowser.selectedTab = gBrowser.addTab();
  29. gBrowser.selectedBrowser.addEventListener("load", function () {
  30. gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
  31. setFinishedCallback(function(result, exception) {
  32. ok(result == 11, "Set version on database in " + testPageURL1);
  33. ok(!exception, "No exception");
  34. gBrowser.removeCurrentTab();
  35. executeSoon(test2);
  36. });
  37. }, true);
  38. content.location = testPageURL1;
  39. }
  40. function test2()
  41. {
  42. // Set database version for domain 2
  43. gBrowser.selectedTab = gBrowser.addTab();
  44. gBrowser.selectedBrowser.addEventListener("load", function () {
  45. gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
  46. setFinishedCallback(function(result, exception) {
  47. ok(result == 11, "Set version on database in " + testPageURL2);
  48. ok(!exception, "No exception");
  49. gBrowser.removeCurrentTab();
  50. executeSoon(test3);
  51. });
  52. }, true);
  53. content.location = testPageURL2;
  54. }
  55. function test3()
  56. {
  57. // Remove database from domain 2
  58. ForgetAboutSite.removeDataFromDomain(domains[1]).then(() => {
  59. setPermission(testPageURL4, "indexedDB");
  60. executeSoon(test4);
  61. });
  62. }
  63. function test4()
  64. {
  65. // Get database version for domain 1
  66. gBrowser.selectedTab = gBrowser.addTab();
  67. gBrowser.selectedBrowser.addEventListener("load", function () {
  68. gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
  69. setFinishedCallback(function(result, exception) {
  70. ok(result == 11, "Got correct version on database in " + testPageURL3);
  71. ok(!exception, "No exception");
  72. gBrowser.removeCurrentTab();
  73. executeSoon(test5);
  74. });
  75. }, true);
  76. content.location = testPageURL3;
  77. }
  78. function test5()
  79. {
  80. // Get database version for domain 2
  81. gBrowser.selectedTab = gBrowser.addTab();
  82. gBrowser.selectedBrowser.addEventListener("load", function () {
  83. gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
  84. setFinishedCallback(function(result, exception) {
  85. ok(result == 1, "Got correct version on database in " + testPageURL4);
  86. ok(!exception, "No exception");
  87. gBrowser.removeCurrentTab();
  88. executeSoon(finish);
  89. });
  90. }, true);
  91. content.location = testPageURL4;
  92. }