browser_responsiveruleview.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Check that when the viewport is resized, the rule-view refreshes.
  5. // Also test that ESC does open the split-console, and that the RDM menu item
  6. // gets updated correctly when needed.
  7. // TODO: split this test.
  8. const TEST_URI = "data:text/html;charset=utf-8,<html><style>" +
  9. "div {" +
  10. " width: 500px;" +
  11. " height: 10px;" +
  12. " background: purple;" +
  13. "} " +
  14. "@media screen and (max-width: 200px) {" +
  15. " div { " +
  16. " width: 100px;" +
  17. " }" +
  18. "};" +
  19. "</style><div></div></html>";
  20. add_task(function* () {
  21. yield addTab(TEST_URI);
  22. info("Open the responsive design mode and set its size to 500x500 to start");
  23. let { rdm, manager } = yield openRDM();
  24. yield setSize(rdm, manager, 500, 500);
  25. info("Open the inspector, rule-view and select the test node");
  26. let {inspector, view} = yield openRuleView();
  27. yield selectNode("div", inspector);
  28. info("Try shrinking the viewport and checking the applied styles");
  29. yield testShrink(view, rdm, manager);
  30. info("Try growing the viewport and checking the applied styles");
  31. yield testGrow(view, rdm, manager);
  32. info("Check that ESC still opens the split console");
  33. yield testEscapeOpensSplitConsole(inspector);
  34. yield closeToolbox();
  35. info("Test the state of the RDM menu item");
  36. yield testMenuItem(rdm);
  37. Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
  38. });
  39. function* testShrink(ruleView, rdm, manager) {
  40. is(numberOfRules(ruleView), 2, "Should have two rules initially.");
  41. info("Resize to 100x100 and wait for the rule-view to update");
  42. let onRefresh = ruleView.once("ruleview-refreshed");
  43. yield setSize(rdm, manager, 100, 100);
  44. yield onRefresh;
  45. is(numberOfRules(ruleView), 3, "Should have three rules after shrinking.");
  46. }
  47. function* testGrow(ruleView, rdm, manager) {
  48. info("Resize to 500x500 and wait for the rule-view to update");
  49. let onRefresh = ruleView.once("ruleview-refreshed");
  50. yield setSize(rdm, manager, 500, 500);
  51. yield onRefresh;
  52. is(numberOfRules(ruleView), 2, "Should have two rules after growing.");
  53. }
  54. function* testEscapeOpensSplitConsole(inspector) {
  55. ok(!inspector._toolbox._splitConsole, "Console is not split.");
  56. info("Press escape");
  57. let onSplit = inspector._toolbox.once("split-console");
  58. EventUtils.synthesizeKey("VK_ESCAPE", {});
  59. yield onSplit;
  60. ok(inspector._toolbox._splitConsole, "Console is split after pressing ESC.");
  61. }
  62. function* testMenuItem(rdm) {
  63. is(document.getElementById("menu_responsiveUI").getAttribute("checked"),
  64. "true", "The menu item is checked");
  65. yield closeRDM(rdm);
  66. is(document.getElementById("menu_responsiveUI").getAttribute("checked"),
  67. "false", "The menu item is unchecked");
  68. }
  69. function numberOfRules(ruleView) {
  70. return ruleView.element.querySelectorAll(".ruleview-code").length;
  71. }