browser_permissionsPromptDeny.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. const testPageURL = "http://mochi.test:8888/browser/" +
  6. "dom/indexedDB/test/browser_permissionsPrompt.html";
  7. const notificationID = "indexedDB-permissions-prompt";
  8. function promiseMessage(aMessage, browser) {
  9. return ContentTask.spawn(browser.selectedBrowser, aMessage, function* (aMessage) {
  10. yield new Promise((resolve, reject) => {
  11. content.addEventListener("message", function messageListener(event) {
  12. content.removeEventListener("message", messageListener);
  13. is(event.data, aMessage, "received " + aMessage);
  14. if (event.data == aMessage)
  15. resolve();
  16. else
  17. reject();
  18. });
  19. });
  20. });
  21. }
  22. add_task(function test1() {
  23. removePermission(testPageURL, "indexedDB");
  24. info("creating tab");
  25. gBrowser.selectedTab = gBrowser.addTab();
  26. info("loading test page: " + testPageURL);
  27. gBrowser.selectedBrowser.loadURI(testPageURL);
  28. yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
  29. registerPopupEventHandler("popupshowing", function () {
  30. ok(true, "prompt showing");
  31. });
  32. registerPopupEventHandler("popupshown", function () {
  33. ok(true, "prompt shown");
  34. triggerSecondaryCommand(this, 0);
  35. });
  36. registerPopupEventHandler("popuphidden", function () {
  37. ok(true, "prompt hidden");
  38. });
  39. yield promiseMessage("InvalidStateError", gBrowser);
  40. is(getPermission(testPageURL, "indexedDB"),
  41. Components.interfaces.nsIPermissionManager.DENY_ACTION,
  42. "Correct permission set");
  43. gBrowser.removeCurrentTab();
  44. });
  45. add_task(function test2() {
  46. info("creating private window");
  47. let win = yield BrowserTestUtils.openNewBrowserWindow({ private : true });
  48. info("creating private tab");
  49. win.gBrowser.selectedTab = win.gBrowser.addTab();
  50. info("loading test page: " + testPageURL);
  51. win.gBrowser.selectedBrowser.loadURI(testPageURL);
  52. yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
  53. registerPopupEventHandler("popupshowing", function () {
  54. ok(false, "prompt showing");
  55. });
  56. registerPopupEventHandler("popupshown", function () {
  57. ok(false, "prompt shown");
  58. });
  59. registerPopupEventHandler("popuphidden", function () {
  60. ok(false, "prompt hidden");
  61. });
  62. yield promiseMessage("InvalidStateError", win.gBrowser);
  63. is(getPermission(testPageURL, "indexedDB"),
  64. Components.interfaces.nsIPermissionManager.DENY_ACTION,
  65. "Correct permission set");
  66. unregisterAllPopupEventHandlers();
  67. win.gBrowser.removeCurrentTab();
  68. win.close();
  69. });
  70. add_task(function test3() {
  71. info("creating tab");
  72. gBrowser.selectedTab = gBrowser.addTab();
  73. info("loading test page: " + testPageURL);
  74. gBrowser.selectedBrowser.loadURI(testPageURL);
  75. yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
  76. registerPopupEventHandler("popupshowing", function () {
  77. ok(false, "Shouldn't show a popup this time");
  78. });
  79. registerPopupEventHandler("popupshown", function () {
  80. ok(false, "Shouldn't show a popup this time");
  81. });
  82. registerPopupEventHandler("popuphidden", function () {
  83. ok(false, "Shouldn't show a popup this time");
  84. });
  85. yield promiseMessage("InvalidStateError", gBrowser);
  86. is(getPermission(testPageURL, "indexedDB"),
  87. Components.interfaces.nsIPermissionManager.DENY_ACTION,
  88. "Correct permission set");
  89. gBrowser.removeCurrentTab();
  90. unregisterAllPopupEventHandlers();
  91. removePermission(testPageURL, "indexedDB");
  92. });