browser_responsiveuiaddcustompreset.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. add_task(function* () {
  5. let tab = yield addTab("data:text/html;charset=utf8,Test RDM custom presets");
  6. let { rdm, manager } = yield openRDM(tab);
  7. let oldPrompt = Services.prompt;
  8. Services.prompt = {
  9. value: "",
  10. returnBool: true,
  11. prompt: function (parent, dialogTitle, text, value, checkMsg, checkState) {
  12. value.value = this.value;
  13. return this.returnBool;
  14. }
  15. };
  16. registerCleanupFunction(() => {
  17. Services.prompt = oldPrompt;
  18. });
  19. // Is it open?
  20. let container = gBrowser.getBrowserContainer();
  21. is(container.getAttribute("responsivemode"), "true",
  22. "Should be in responsive mode.");
  23. ok(rdm, "RDM instance should be attached to the tab.");
  24. // Tries to add a custom preset and cancel the prompt
  25. let idx = rdm.menulist.selectedIndex;
  26. let presetCount = rdm.presets.length;
  27. Services.prompt.value = "";
  28. Services.prompt.returnBool = false;
  29. rdm.addbutton.doCommand();
  30. is(idx, rdm.menulist.selectedIndex,
  31. "selected item shouldn't change after add preset and cancel");
  32. is(presetCount, rdm.presets.length,
  33. "number of presets shouldn't change after add preset and cancel");
  34. // Adds the custom preset with "Testing preset"
  35. Services.prompt.value = "Testing preset";
  36. Services.prompt.returnBool = true;
  37. let resized = once(manager, "content-resize");
  38. let customHeight = 123, customWidth = 456;
  39. rdm.startResizing({});
  40. rdm.setViewportSize({
  41. width: customWidth,
  42. height: customHeight,
  43. });
  44. rdm.stopResizing({});
  45. rdm.addbutton.doCommand();
  46. yield resized;
  47. yield closeRDM(rdm);
  48. ({rdm} = yield openRDM(tab));
  49. is(container.getAttribute("responsivemode"), "true",
  50. "Should be in responsive mode.");
  51. let presetLabel = "456" + "\u00D7" + "123 (Testing preset)";
  52. let customPresetIndex = yield getPresetIndex(rdm, manager, presetLabel);
  53. ok(customPresetIndex >= 0, "(idx = " + customPresetIndex + ") should be the" +
  54. " previously added preset in the list of items");
  55. yield setPresetIndex(rdm, manager, customPresetIndex);
  56. let browser = gBrowser.selectedBrowser;
  57. yield ContentTask.spawn(browser, null, function* () {
  58. let {innerWidth, innerHeight} = content;
  59. Assert.equal(innerWidth, 456, "Selecting preset should change the width");
  60. Assert.equal(innerHeight, 123, "Selecting preset should change the height");
  61. });
  62. info(`menulist count: ${rdm.menulist.itemCount}`);
  63. rdm.removebutton.doCommand();
  64. yield setPresetIndex(rdm, manager, 2);
  65. let deletedPresetA = rdm.menulist.selectedItem.getAttribute("label");
  66. rdm.removebutton.doCommand();
  67. yield setPresetIndex(rdm, manager, 2);
  68. let deletedPresetB = rdm.menulist.selectedItem.getAttribute("label");
  69. rdm.removebutton.doCommand();
  70. yield closeRDM(rdm);
  71. ({rdm} = yield openRDM(tab));
  72. customPresetIndex = yield getPresetIndex(rdm, manager, deletedPresetA);
  73. is(customPresetIndex, -1,
  74. "Deleted preset " + deletedPresetA + " should not be in the list anymore");
  75. customPresetIndex = yield getPresetIndex(rdm, manager, deletedPresetB);
  76. is(customPresetIndex, -1,
  77. "Deleted preset " + deletedPresetB + " should not be in the list anymore");
  78. yield closeRDM(rdm);
  79. });
  80. var getPresetIndex = Task.async(function* (rdm, manager, presetLabel) {
  81. var testOnePreset = Task.async(function* (c) {
  82. if (c == 0) {
  83. return -1;
  84. }
  85. yield setPresetIndex(rdm, manager, c);
  86. let item = rdm.menulist.firstChild.childNodes[c];
  87. if (item.getAttribute("label") === presetLabel) {
  88. return c;
  89. }
  90. return testOnePreset(c - 1);
  91. });
  92. return testOnePreset(rdm.menulist.firstChild.childNodes.length - 4);
  93. });