Bug 1218144 - also select image in Page Info window when opened from View Image page. r?florian
MozReview-Commit-ID: DvUVEHBboQ4
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -1063,21 +1063,31 @@ var PageInfoListener = {
// Separate step so page info dialog isn't blank while waiting for this to finish.
this.getMediaInfo(document, window, strings);
},
getImageInfo(imageElement) {
let imageInfo = null;
if (imageElement) {
+ let imageText;
+ /* For the list of all images, the imageText doesn't get set for
+ SVGImageElement and ImageDocument, see serializeElementInfo. The
+ imageText is used to match the image on which "View Image Info" got
+ called for with the list of available images in pageInfo.js'
+ selectImage(), so similar behavior is required here. */
+ if (!(imageElement instanceof content.SVGImageElement) &&
+ !(imageElement.ownerDocument instanceof content.ImageDocument)) {
+ imageText = imageElement.title || imageElement.alt;
+ }
imageInfo = {
currentSrc: imageElement.currentSrc,
width: imageElement.width,
height: imageElement.height,
- imageText: imageElement.title || imageElement.alt
+ imageText: imageText
};
}
return imageInfo;
},
getMetaInfo(document) {
let metaViewRows = [];
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+
+[browser_viewImageInfo_from_viewImagePage.js]
+skip-if = (os == 'linux' && e10s) # bug 1161699
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_viewImageInfo_from_viewImagePage.js
@@ -0,0 +1,58 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(function* () {
+ let pageSource = encodeURI("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 id='showContextMenu' src='about:logo?b' height=200 width=250 alt=1>" +
+ "<img src='about:logo?b' height=100 width=150 alt=2 id='test-image'>");
+
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageSource);
+ info("page with images loaded");
+ let browser = tab.linkedBrowser;
+
+ let contextMenu = document.getElementById("contentAreaContextMenu");
+ let awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu,
+ "popupshown");
+ info("context menu opened on page with images");
+
+ yield BrowserTestUtils.synthesizeMouseAtCenter("#showContextMenu", {
+ type: "contextmenu",
+ button: 2
+ }, browser);
+ yield awaitPopupShown;
+ document.getElementById("context-viewimage").click();
+ info("'View Image' clicked");
+ contextMenu.hidePopup();
+ yield BrowserTestUtils.browserLoaded(browser);
+ info("'View Image' page opened");
+
+ awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu,
+ "popupshown");
+ let awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu,
+ "popuphidden");
+ yield BrowserTestUtils.synthesizeMouseAtCenter("img", {
+ type: "contextmenu",
+ button: 2
+ }, browser);
+ yield awaitPopupShown;
+ document.getElementById("context-viewimageinfo").click();
+ info("'View Image Info' clicked");
+ yield awaitPopupHidden;
+
+ let pageInfoWindow = Services.wm.getMostRecentWindow("Browser:page-info");
+ let imageTree = pageInfoWindow.document.getElementById("imagetree");
+ info("Page Info Window opened");
+ yield BrowserTestUtils.waitForEvent(imageTree, "select");
+ info("image selected in tree");
+ is(imageTree.view.selection.count, 1, "selected images");
+ // 0 is the column with the address in the image list.
+ is(pageInfoWindow.gImageView.data[imageTree.view.selection.currentIndex][0],
+ "about:logo?b", "address of selected image");
+
+ pageInfoWindow.close();
+ gBrowser.removeCurrentTab();
+});
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -14,16 +14,17 @@ MOCHITEST_CHROME_MANIFESTS += [
'content/test/chrome/chrome.ini',
]
BROWSER_CHROME_MANIFESTS += [
'content/test/alerts/browser.ini',
'content/test/captivePortal/browser.ini',
'content/test/general/browser.ini',
'content/test/newtab/browser.ini',
+ 'content/test/pageinfo/browser.ini',
'content/test/plugins/browser.ini',
'content/test/popupNotifications/browser.ini',
'content/test/referrer/browser.ini',
'content/test/siteIdentity/browser.ini',
'content/test/social/browser.ini',
'content/test/tabcrashed/browser.ini',
'content/test/tabPrompts/browser.ini',
'content/test/tabs/browser.ini',