summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/grids/test/browser_grids_grid-list-on-iframe-reloaded.js
blob: b5871414f8866469a75ecc984a090ca44c5f2324 (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that the list of grids does refresh when an iframe containing a grid is removed
// and re-created.
// See bug 1378306 where this happened with jsfiddle.

const TEST_URI = URL_ROOT + "doc_iframe_reloaded.html";

add_task(async function () {
  await addTab(TEST_URI);
  const { gridInspector, inspector } = await openLayoutView();
  const { document: doc } = gridInspector;
  const { highlighters, store } = inspector;
  const gridList = doc.getElementById("grid-list");
  const checkbox = gridList.children[0].querySelector("input");

  info("Clicking on the first checkbox to highlight the grid");
  const onHighlighterShown = highlighters.once("grid-highlighter-shown");
  const onCheckboxChange = waitUntilState(
    store,
    state => state.grids.length == 1 && state.grids[0].highlighted
  );
  checkbox.click();
  await onHighlighterShown;
  await onCheckboxChange;

  ok(checkbox.checked, "The checkbox is checked");
  is(gridList.childNodes.length, 1, "There's one grid in the list");
  is(highlighters.gridHighlighters.size, 1, "There's a highlighter shown");
  is(
    highlighters.state.grids.size,
    1,
    "There's a saved grid state to be restored."
  );

  info("Reload the iframe in content and expect the grid list to update");
  const oldGrid = store.getState().grids[0];
  const onNewListUnchecked = waitUntilState(
    store,
    state =>
      state.grids.length == 1 &&
      state.grids[0].actorID !== oldGrid.actorID &&
      !state.grids[0].highlighted
  );
  const onHighlighterHidden = highlighters.once("grid-highlighter-hidden");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], () =>
    content.wrappedJSObject.reloadIFrame()
  );
  await onNewListUnchecked;
  await onHighlighterHidden;

  is(gridList.childNodes.length, 1, "There's still one grid in the list");
  ok(!highlighters.state.grids.size, "No grids to be restored on page reload.");
});