summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js
blob: 374cd5f0321cbe6bdd92d5d21e6304133d844431 (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/
 **/

const URI =
  "data:text/html," +
  "<style type='text/css'>%23test-image,%23not-test-image {background-image: url('about:logo?c');}</style>" +
  "<img src='about:logo?b' height=300 width=350 alt=2 id='not-test-image'>" +
  "<img src='about:logo?b' height=300 width=350 alt=2>" +
  "<img src='about:logo?a' height=200 width=250>" +
  "<img src='about:logo?b' height=200 width=250 alt=1>" +
  "<img src='about:logo?b' height=100 width=150 alt=2 id='test-image'>";

add_task(async function () {
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URI);
  let browser = tab.linkedBrowser;

  let imageInfo = await SpecialPowers.spawn(browser, [], async () => {
    let testImg = content.document.getElementById("test-image");

    return {
      src: testImg.src,
      currentSrc: testImg.currentSrc,
      width: testImg.width,
      height: testImg.height,
      imageText: testImg.title || testImg.alt,
    };
  });

  let pageInfo = BrowserPageInfo(
    browser.currentURI.spec,
    "mediaTab",
    imageInfo
  );
  await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");

  let pageInfoImg = pageInfo.document.getElementById("thepreviewimage");
  await BrowserTestUtils.waitForEvent(pageInfoImg, "load");
  Assert.equal(
    pageInfoImg.src,
    imageInfo.src,
    "selected image has the correct source"
  );
  Assert.equal(
    pageInfoImg.width,
    imageInfo.width,
    "selected image has the correct width"
  );
  Assert.equal(
    pageInfoImg.height,
    imageInfo.height,
    "selected image has the correct height"
  );
  pageInfo.close();
  BrowserTestUtils.removeTab(tab);
});