browser_responsivecomputedview.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 computed-view refreshes.
  5. const TEST_URI = "data:text/html;charset=utf-8,<html><style>" +
  6. "div {" +
  7. " width: 500px;" +
  8. " height: 10px;" +
  9. " background: purple;" +
  10. "} " +
  11. "@media screen and (max-width: 200px) {" +
  12. " div { " +
  13. " width: 100px;" +
  14. " }" +
  15. "};" +
  16. "</style><div></div></html>";
  17. add_task(function* () {
  18. yield addTab(TEST_URI);
  19. info("Open the responsive design mode and set its size to 500x500 to start");
  20. let { rdm, manager } = yield openRDM();
  21. yield setSize(rdm, manager, 500, 500);
  22. info("Open the inspector, computed-view and select the test node");
  23. let {inspector, view} = yield openComputedView();
  24. yield selectNode("div", inspector);
  25. info("Try shrinking the viewport and checking the applied styles");
  26. yield testShrink(view, inspector, rdm, manager);
  27. info("Try growing the viewport and checking the applied styles");
  28. yield testGrow(view, inspector, rdm, manager);
  29. yield closeRDM(rdm);
  30. yield closeToolbox();
  31. });
  32. function* testShrink(computedView, inspector, rdm, manager) {
  33. is(computedWidth(computedView), "500px", "Should show 500px initially.");
  34. let onRefresh = inspector.once("computed-view-refreshed");
  35. yield setSize(rdm, manager, 100, 100);
  36. yield onRefresh;
  37. is(computedWidth(computedView), "100px", "Should be 100px after shrinking.");
  38. }
  39. function* testGrow(computedView, inspector, rdm, manager) {
  40. let onRefresh = inspector.once("computed-view-refreshed");
  41. yield setSize(rdm, manager, 500, 500);
  42. yield onRefresh;
  43. is(computedWidth(computedView), "500px", "Should be 500px after growing.");
  44. }
  45. function computedWidth(computedView) {
  46. for (let prop of computedView.propertyViews) {
  47. if (prop.name === "width") {
  48. return prop.valueNode.textContent;
  49. }
  50. }
  51. return null;
  52. }