summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_media-queries_reload.js
blob: 79bc9b9f8f84271cae25026498ef4e56d1a227d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that applicable media queries are updated in the Rule view after reloading
// the page and resizing the window.

const TEST_URI = `
  <style type='text/css'>
    @media all and (max-width: 500px) {
      div {
        color: red;
      }
    }
    @media all and (min-width: 500px) {
      div {
        color: green;
      }
    }
  </style>
  <div></div>
`;

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector, view: ruleView, toolbox } = await openRuleView();
  const hostWindow = toolbox.win.parent;

  const originalWidth = hostWindow.outerWidth;
  const originalHeight = hostWindow.outerHeight;

  await selectNode("div", inspector);

  info("Resize window so the media query for small viewports applies");
  hostWindow.resizeTo(400, 400);

  await waitForMediaRuleColor(ruleView, "red");
  ok(true, "Small viewport media query inspected");

  info("Reload the current page");
  await reloadBrowser();
  await selectNode("div", inspector);

  info("Resize window so the media query for large viewports applies");
  hostWindow.resizeTo(800, 800);

  info("Reselect the rule after page reload.");
  await waitForMediaRuleColor(ruleView, "green");
  ok(true, "Large viewport media query inspected");

  info("Resize window to original dimentions");
  const onResize = once(hostWindow, "resize");
  hostWindow.resizeTo(originalWidth, originalHeight);
  await onResize;
});

function waitForMediaRuleColor(ruleView, color) {
  return waitUntil(() => {
    try {
      const { value } = getTextProperty(ruleView, 1, { color });
      return value === color;
    } catch (e) {
      return false;
    }
  });
}