Bug 1038651 - Prevent inspector from breaking when reloading an SVG file;r=mratcliffe
authorBrian Grinstead <bgrinstead@mozilla.com>
Wed, 16 Jul 2014 08:40:07 -0500
changeset 216265 869f9ac3e3baa18a582d8705fb9a928e674bd429
parent 216264 acf444215f8d167082b6612b6e58667cc6ac0258
child 216266 46acc7f0704bf14d7ad0964ec9666bc39bd91b4d
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmratcliffe
bugs1038651
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1038651 - Prevent inspector from breaking when reloading an SVG file;r=mratcliffe
browser/devtools/inspector/inspector-panel.js
browser/devtools/inspector/test/browser.ini
browser/devtools/inspector/test/browser_inspector_reload-01.js
browser/devtools/inspector/test/browser_inspector_reload-02.js
browser/devtools/inspector/test/browser_inspector_reload.js
toolkit/devtools/server/actors/highlighter.js
--- a/browser/devtools/inspector/inspector-panel.js
+++ b/browser/devtools/inspector/inspector-panel.js
@@ -362,17 +362,17 @@ InspectorPanel.prototype = {
 
   _selectionCssSelector: null,
 
   /**
    * Set the currently selected node unique css selector.
    * Will store the current target url along with it to allow pre-selection at
    * reload
    */
-  set selectionCssSelector(cssSelector) {
+  set selectionCssSelector(cssSelector = null) {
     this._selectionCssSelector = {
       selector: cssSelector,
       url: this._target.url
     };
   },
 
   /**
    * Get the current selection unique css selector if any, that is, if a node
--- a/browser/devtools/inspector/test/browser.ini
+++ b/browser/devtools/inspector/test/browser.ini
@@ -38,17 +38,18 @@ support-files =
 [browser_inspector_invalidate.js]
 [browser_inspector_keyboard-shortcuts.js]
 [browser_inspector_menu.js]
 [browser_inspector_navigation.js]
 [browser_inspector_picker-stop-on-destroy.js]
 [browser_inspector_picker-stop-on-tool-change.js]
 [browser_inspector_pseudoclass-lock.js]
 [browser_inspector_pseudoclass-menu.js]
-[browser_inspector_reload.js]
+[browser_inspector_reload-01.js]
+[browser_inspector_reload-02.js]
 [browser_inspector_remove-iframe-during-load.js]
 [browser_inspector_scrolling.js]
 [browser_inspector_search-01.js]
 [browser_inspector_search-02.js]
 [browser_inspector_search-03.js]
 [browser_inspector_select-last-selected.js]
 [browser_inspector_search-navigation.js]
 [browser_inspector_sidebarstate.js]
rename from browser/devtools/inspector/test/browser_inspector_reload.js
rename to browser/devtools/inspector/test/browser_inspector_reload-01.js
new file mode 100644
--- /dev/null
+++ b/browser/devtools/inspector/test/browser_inspector_reload-02.js
@@ -0,0 +1,46 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+// A test to ensure reloading a page doesn't break the inspector.
+
+// Reload should reselect the currently selected markup view element.
+// This should work even when an element whose selector is inaccessible
+// is selected (bug 1038651).
+const TEST_URI = 'data:text/xml,<?xml version="1.0" standalone="no"?>' +
+'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"' +
+'  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' +
+'<svg width="4cm" height="4cm" viewBox="0 0 400 400"' +
+'     xmlns="http://www.w3.org/2000/svg" version="1.1">' +
+'  <title>Example triangle01- simple example of a path</title>' +
+'  <desc>A path that draws a triangle</desc>' +
+'  <rect x="1" y="1" width="398" height="398"' +
+'        fill="none" stroke="blue" />' +
+'  <path d="M 100 100 L 300 100 L 200 300 z"' +
+'        fill="red" stroke="blue" stroke-width="3" />' +
+'</svg>';
+
+let test = asyncTest(function* () {
+  let { inspector, toolbox } = yield openInspectorForURL(TEST_URI);
+
+  let markupLoaded = inspector.once("markuploaded");
+
+  info("Reloading page.");
+  content.location.reload();
+
+  info("Waiting for markupview to load after reload.");
+  yield markupLoaded;
+
+  is(inspector.selection.node, getNode("svg"), "<svg> selected after reload.");
+
+  info("Selecting a node to see that inspector still works.");
+  yield selectNode("rect", inspector);
+
+  info("Reloading page.");
+  content.location.reload();
+
+  is(inspector.selection.node, getNode("rect"), "<rect> selected after reload.");
+});
--- a/toolkit/devtools/server/actors/highlighter.js
+++ b/toolkit/devtools/server/actors/highlighter.js
@@ -771,18 +771,22 @@ BoxModelHighlighter.prototype = Heritage
    * @return {boolean}
    *         True if the current node has a box model to be highlighted
    */
   _updateBoxModel: function() {
     this.options.region = this.options.region || "content";
 
     if (this._nodeNeedsHighlighting()) {
       for (let boxType in this._boxModelNodes) {
-        let {p1, p2, p3, p4} =
-          this.layoutHelpers.getAdjustedQuads(this.currentNode, boxType);
+
+        let quads = this.layoutHelpers.getAdjustedQuads(this.currentNode, boxType);
+        if (!quads) {
+          continue;
+        }
+        let {p1, p2, p3, p4} = quads;
 
         let boxNode = this._boxModelNodes[boxType];
 
         if (this.regionFill[boxType]) {
           boxNode.setAttribute("style", "fill:" + this.regionFill[boxType]);
         } else {
           boxNode.removeAttribute("style");
         }