Bug 1218144 - also select image in Page Info window when opened from View Image page. r?florian draft
authorSebastian Hengst <archaeopteryx@coole-files.de>
Tue, 07 Mar 2017 15:46:54 +0100
changeset 494599 63f78ce52e18fb88df51f950a2849118260be569
parent 493537 eb23648534779c110f3a1f2baae1849ae4a9c570
child 548147 b9bf6f7eb6f59e6a6126ec1437add7860494642b
push id48079
push userarchaeopteryx@coole-files.de
push dateTue, 07 Mar 2017 14:50:34 +0000
reviewersflorian
bugs1218144
milestone54.0a1
Bug 1218144 - also select image in Page Info window when opened from View Image page. r?florian MozReview-Commit-ID: DvUVEHBboQ4
browser/base/content/content.js
browser/base/content/test/pageinfo/browser.ini
browser/base/content/test/pageinfo/browser_viewImageInfo_from_viewImagePage.js
browser/base/moz.build
--- 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',