Index: third_party/WebKit/LayoutTests/inspector/elements/elements-panel-restore-selection-when-node-comes-later.html |
diff --git a/third_party/WebKit/LayoutTests/inspector/elements/elements-panel-restore-selection-when-node-comes-later.html b/third_party/WebKit/LayoutTests/inspector/elements/elements-panel-restore-selection-when-node-comes-later.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3a77fb01612b45b00d14615943e94db465245542 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/inspector/elements/elements-panel-restore-selection-when-node-comes-later.html |
@@ -0,0 +1,112 @@ |
+<html> |
+<head> |
+<script src="../../http/tests/inspector/inspector-test.js"></script> |
+<script src="../../http/tests/inspector/elements-test.js"></script> |
+<script src="./shadow/elements-panel-shadow-selection-on-refresh.js"></script> |
+<script> |
+ |
+function test() |
+{ |
+ var domModel = WebInspector.DOMModel.fromTarget(WebInspector.targetManager.mainTarget()); |
+ var node; |
+ |
+ InspectorTest.runTestSuite([ |
+ function selectNode(next) |
+ { |
+ InspectorTest.nodeWithId("inspected", onNodeFound); |
+ |
+ function onNodeFound(n) |
+ { |
+ node = n; |
+ InspectorTest.selectNode(node).then(onNodeSelected); |
+ } |
+ |
+ function onNodeSelected() |
+ { |
+ dumpSelectedNode(); |
+ next(); |
+ } |
+ }, |
+ |
+ function firstReloadWithoutNodeInDOM(next) |
+ { |
+ InspectorTest.addSniffer(WebInspector.ElementsPanel.prototype, "_lastSelectedNodeSelectedForTest", onNodeRestored); |
+ // Do a reload and pretend page's DOM doesn't have a node to restore. |
+ overridePushNodeForPath(node.path()); |
+ InspectorTest.reloadPage(function() { }); |
+ |
+ function onNodeRestored() |
+ { |
+ dumpSelectedNode(); |
+ next(); |
+ } |
+ }, |
+ |
+ function secondReloadWithNodeInDOM(next) |
+ { |
+ var pageReloaded = false; |
+ var nodeRestored = false; |
+ InspectorTest.addSniffer(WebInspector.ElementsPanel.prototype, "_lastSelectedNodeSelectedForTest", onNodeRestored); |
+ InspectorTest.reloadPage(onPageReloaded); |
+ |
+ function onPageReloaded() |
+ { |
+ pageReloaded = true; |
+ maybeNext(); |
+ } |
+ |
+ function onNodeRestored() |
+ { |
+ nodeRestored = true; |
+ maybeNext(); |
+ } |
+ |
+ function maybeNext() |
+ { |
+ if (!nodeRestored || !pageReloaded) |
+ return; |
+ dumpSelectedNode(); |
+ next(); |
+ } |
+ }, |
+ |
+ ]); |
+ |
+ function dumpSelectedNode() |
+ { |
+ var selectedElement = InspectorTest.firstElementsTreeOutline().selectedTreeElement; |
+ var nodeName = selectedElement ? selectedElement.node().nodeNameInCorrectCase() : "null"; |
+ InspectorTest.addResult("Selected node: '" + nodeName + "'"); |
+ } |
+ |
+ /** |
+ * @param {string} pathToIgnore |
+ */ |
+ function overridePushNodeForPath(pathToIgnore) |
+ { |
+ var original = InspectorTest.override(WebInspector.DOMModel.prototype, "pushNodeByPathToFrontend", override); |
+ |
+ function override(nodePath, callback) |
+ { |
+ if (nodePath === pathToIgnore) { |
+ setTimeout(callback.bind(null), 0); |
+ return; |
+ } |
+ original(nodePath, callback); |
+ } |
+ } |
+} |
+ |
+</script> |
+</head> |
+ |
+<body onload="runTest()"> |
+<p> |
+Verify that last selected element is restored properly later, even if |
+it failed to do so once. |
+</p> |
+<div> |
+ <span id="inspected"></span> |
+</div> |
+</body> |
+</html> |