summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/browser/browser_findbar_hiddenframes.js
blob: f0f41314646ae62652607b664870112d66262dba (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
const TEST_PAGE = "https://example.com/document-builder.sjs?html=";

let content =
  "<html><body><iframe id='a' src='data:text/html,This is the first page'></iframe><iframe id='b' src='data:text/html,That is another page'></iframe></body></html>";

async function doAndCheckFind(bc, text) {
  await promiseFindFinished(gBrowser, text, false);

  let foundText = await SpecialPowers.spawn(bc, [], () => {
    return content.getSelection().toString();
  });
  is(foundText, text, text + " is found");
}

// This test verifies that find continues to work when a find begins and the frame
// is hidden during the next find step.
add_task(async function test_frame() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TEST_PAGE + content
  );
  let browser = gBrowser.getBrowserForTab(tab);

  let findbar = await gBrowser.getFindBar();

  await doAndCheckFind(browser.browsingContext.children[0], "This");

  await SpecialPowers.spawn(browser, [], () => {
    content.document.getElementById("a").style.display = "none";
    content.document.getElementById("a").getBoundingClientRect(); // flush
  });

  await doAndCheckFind(browser.browsingContext.children[1], "another");

  await SpecialPowers.spawn(browser, [], () => {
    content.document.getElementById("a").style.display = "";
    content.document.getElementById("a").getBoundingClientRect();
  });

  await doAndCheckFind(browser.browsingContext.children[0], "first");

  await SpecialPowers.spawn(browser, [], () => {
    content.document.getElementById("a").style.visibility = "hidden";
    content.document.getElementById("a").getBoundingClientRect();
  });

  await doAndCheckFind(browser.browsingContext.children[1], "That");

  await SpecialPowers.spawn(browser, [], () => {
    content.document.getElementById("a").style.visibility = "";
    content.document.getElementById("a").getBoundingClientRect();
  });

  await doAndCheckFind(browser.browsingContext.children[0], "This");

  await closeFindbarAndWait(findbar);

  gBrowser.removeTab(tab);
});