summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js
blob: eee72f696cd053854fae6f2612f0f3f8b6a9e5cc (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that the box model view for elements within iframes also updates when they
// change

add_task(async function () {
  const tab = await addTab(URL_ROOT + "doc_boxmodel_iframe1.html");
  const browser = tab.linkedBrowser;
  const { inspector, boxmodel } = await openLayoutView();

  await testResizingInIframe(inspector, boxmodel, browser);
  await testReflowsAfterIframeDeletion(inspector, boxmodel, browser);
});

async function testResizingInIframe(inspector, boxmodel, browser) {
  info("Test that resizing an element in an iframe updates its box model");

  info("Selecting the nested test node");
  await selectNodeInFrames(["iframe", "iframe", "div"], inspector);

  info("Checking that the box model view shows the right value");
  const sizeElt = boxmodel.document.querySelector(".boxmodel-size > span");
  is(sizeElt.textContent, "400\u00D7200");

  info("Listening for box model view changes and modifying its size");
  const onUpdated = waitForUpdate(inspector);
  await setStyleInNestedIframe(browser, "div", "width", "200px");
  await onUpdated;
  ok(true, "Box model view got updated");

  info("Checking that the box model view shows the right value after update");
  is(sizeElt.textContent, "200\u00D7200");
}

async function testReflowsAfterIframeDeletion(inspector, boxmodel, browser) {
  info(
    "Test reflows are still sent to the box model view after deleting an " +
      "iframe"
  );

  info("Deleting the iframe2");
  const onInspectorUpdated = inspector.once("inspector-updated");
  await removeNestedIframe(browser);
  await onInspectorUpdated;

  info("Selecting the test node in iframe1");
  await selectNodeInFrames(["iframe", "p"], inspector);

  info("Checking that the box model view shows the right value");
  const sizeElt = boxmodel.document.querySelector(".boxmodel-size > span");
  is(sizeElt.textContent, "100\u00D7100");

  info("Listening for box model view changes and modifying its size");
  const onUpdated = waitForUpdate(inspector);
  await setStyleInIframe(browser, "p", "width", "200px");
  await onUpdated;
  ok(true, "Box model view got updated");

  info("Checking that the box model view shows the right value after update");
  is(sizeElt.textContent, "200\u00D7100");
}

async function setStyleInIframe(browser, selector, propertyName, value) {
  const context = await getBrowsingContextInFrames(browser, ["iframe"]);
  return setStyle(context, selector, propertyName, value);
}

async function setStyleInNestedIframe(browser, selector, propertyName, value) {
  const context = await getBrowsingContextInFrames(browser, [
    "iframe",
    "iframe",
  ]);
  return setStyle(context, selector, propertyName, value);
}

async function removeNestedIframe(browser) {
  const context = await getBrowsingContextInFrames(browser, ["iframe"]);
  await SpecialPowers.spawn(context, [], () =>
    content.document.querySelector("iframe").remove()
  );
}