From 2504216bac154b7e1c0161abfb8dc54af812c34e Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Tue, 5 May 2015 11:47:33 -0700 Subject: [PATCH] Bug 1145784 - Use testX/testY for coordinates during tests for the Graph and FlameGraph;r=vporof --- browser/devtools/performance/test/head.js | 8 ++--- .../browser_profiler_tabbed-browser-03.js | 8 ++--- .../shared/test/browser_flame-graph-03a.js | 14 ++++---- .../shared/test/browser_flame-graph-03b.js | 4 +-- .../shared/test/browser_flame-graph-03c.js | 10 +++--- .../devtools/shared/test/browser_graphs-06.js | 6 ++-- .../shared/test/browser_graphs-07a.js | 24 +++++++------- .../shared/test/browser_graphs-07b.js | 10 +++--- .../devtools/shared/test/browser_graphs-08.js | 14 ++++---- .../shared/test/browser_graphs-10a.js | 10 +++--- .../devtools/shared/test/browser_graphs-12.js | 10 +++--- .../devtools/shared/test/browser_graphs-14.js | 12 +++---- browser/devtools/shared/widgets/FlameGraph.js | 32 ++++++++++++++----- browser/devtools/shared/widgets/Graphs.jsm | 6 ++-- 14 files changed, 92 insertions(+), 76 deletions(-) diff --git a/browser/devtools/performance/test/head.js b/browser/devtools/performance/test/head.js index 900308ee1bcc..ebee22b96fed 100644 --- a/browser/devtools/performance/test/head.js +++ b/browser/devtools/performance/test/head.js @@ -476,15 +476,15 @@ function waitUntil(predicate, interval = 10) { function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } function dropSelection(graph) { diff --git a/browser/devtools/profiler/test/browser_profiler_tabbed-browser-03.js b/browser/devtools/profiler/test/browser_profiler_tabbed-browser-03.js index a788ed639a3a..3a2827c28d8f 100644 --- a/browser/devtools/profiler/test/browser_profiler_tabbed-browser-03.js +++ b/browser/devtools/profiler/test/browser_profiler_tabbed-browser-03.js @@ -76,13 +76,13 @@ registerCleanupFunction(() => { function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_flame-graph-03a.js b/browser/devtools/shared/test/browser_flame-graph-03a.js index 1eab1260d681..9a8b92b92e29 100644 --- a/browser/devtools/shared/test/browser_flame-graph-03a.js +++ b/browser/devtools/shared/test/browser_flame-graph-03a.js @@ -91,21 +91,21 @@ function testGraph(graph) { function hover(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } let HORIZONTAL_AXIS = 1; @@ -114,8 +114,8 @@ let VERTICAL_AXIS = 2; function scroll(graph, wheel, axis, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseWheel({ clientX: x, clientY: y, axis, detail: wheel, axis, + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseWheel({ testX: x, testY: y, axis, detail: wheel, axis, HORIZONTAL_AXIS, VERTICAL_AXIS }); diff --git a/browser/devtools/shared/test/browser_flame-graph-03b.js b/browser/devtools/shared/test/browser_flame-graph-03b.js index e1ccffdafbc0..1f17a43910cf 100644 --- a/browser/devtools/shared/test/browser_flame-graph-03b.js +++ b/browser/devtools/shared/test/browser_flame-graph-03b.js @@ -68,8 +68,8 @@ let VERTICAL_AXIS = 2; function scroll(graph, wheel, axis, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseWheel({ clientX: x, clientY: y, axis, detail: wheel, axis, + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseWheel({ testX: x, testY: y, axis, detail: wheel, axis, HORIZONTAL_AXIS, VERTICAL_AXIS }); diff --git a/browser/devtools/shared/test/browser_flame-graph-03c.js b/browser/devtools/shared/test/browser_flame-graph-03c.js index 68f726781dc1..d2fc99d80319 100644 --- a/browser/devtools/shared/test/browser_flame-graph-03c.js +++ b/browser/devtools/shared/test/browser_flame-graph-03c.js @@ -121,19 +121,19 @@ function testGraph(graph) { function hover(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_graphs-06.js b/browser/devtools/shared/test/browser_graphs-06.js index fee5a14b8d96..f102b6b3e5d7 100644 --- a/browser/devtools/shared/test/browser_graphs-06.js +++ b/browser/devtools/shared/test/browser_graphs-06.js @@ -84,7 +84,7 @@ function map(value, istart, istop, ostart, ostop) { function click(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_graphs-07a.js b/browser/devtools/shared/test/browser_graphs-07a.js index 2b641190aad1..0bb082d381f7 100644 --- a/browser/devtools/shared/test/browser_graphs-07a.js +++ b/browser/devtools/shared/test/browser_graphs-07a.js @@ -172,29 +172,29 @@ function testGraph(graph, dragStop) { function hover(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); } function click(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function normalDragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } function buggyDragStop(graph, x, y = 1) { @@ -204,13 +204,13 @@ function buggyDragStop(graph, x, y = 1) { // Only fire a mousemove instead of a mouseup. // This happens when the mouseup happens outside of the toolbox, // see Bug 1066504. - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseMove({ clientX: x, clientY: y, buttons: 0 }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseMove({ testX: x, testY: y, buttons: 0 }); } function scroll(graph, wheel, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseWheel({ clientX: x, clientY: y, detail: wheel }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseWheel({ testX: x, testY: y, detail: wheel }); } diff --git a/browser/devtools/shared/test/browser_graphs-07b.js b/browser/devtools/shared/test/browser_graphs-07b.js index b5beb8fbd6a1..1af18be88e02 100644 --- a/browser/devtools/shared/test/browser_graphs-07b.js +++ b/browser/devtools/shared/test/browser_graphs-07b.js @@ -48,19 +48,19 @@ function testGraph(graph) { function hover(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_graphs-08.js b/browser/devtools/shared/test/browser_graphs-08.js index eae8fa1da0fd..43c79061647c 100644 --- a/browser/devtools/shared/test/browser_graphs-08.js +++ b/browser/devtools/shared/test/browser_graphs-08.js @@ -46,21 +46,21 @@ function testGraph(graph) { function click(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_graphs-10a.js b/browser/devtools/shared/test/browser_graphs-10a.js index bd4a61a0d23a..d371ea8d2fda 100644 --- a/browser/devtools/shared/test/browser_graphs-10a.js +++ b/browser/devtools/shared/test/browser_graphs-10a.js @@ -121,19 +121,19 @@ function* testGraph(host, graph) { function hover(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_graphs-12.js b/browser/devtools/shared/test/browser_graphs-12.js index 8cab4fb34c86..5cbd73aeb6d2 100644 --- a/browser/devtools/shared/test/browser_graphs-12.js +++ b/browser/devtools/shared/test/browser_graphs-12.js @@ -135,19 +135,19 @@ function testGraphs(graph1, graph2) { function hover(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); } function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } diff --git a/browser/devtools/shared/test/browser_graphs-14.js b/browser/devtools/shared/test/browser_graphs-14.js index 4f3123618a6a..613ee2a9af0e 100644 --- a/browser/devtools/shared/test/browser_graphs-14.js +++ b/browser/devtools/shared/test/browser_graphs-14.js @@ -70,20 +70,20 @@ function* testGraph(graph) { function dragStart(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseDown({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseDown({ testX: x, testY: y }); } function dragStop(graph, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseUp({ clientX: x, clientY: y }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseUp({ testX: x, testY: y }); } function scroll(graph, wheel, x, y = 1) { x /= window.devicePixelRatio; y /= window.devicePixelRatio; - graph._onMouseMove({ clientX: x, clientY: y }); - graph._onMouseWheel({ clientX: x, clientY: y, detail: wheel }); + graph._onMouseMove({ testX: x, testY: y }); + graph._onMouseWheel({ testX: x, testY: y, detail: wheel }); } diff --git a/browser/devtools/shared/widgets/FlameGraph.js b/browser/devtools/shared/widgets/FlameGraph.js index ede7852f6d04..df6859bb2c1f 100644 --- a/browser/devtools/shared/widgets/FlameGraph.js +++ b/browser/devtools/shared/widgets/FlameGraph.js @@ -731,9 +731,7 @@ FlameGraph.prototype = { * Listener for the "mousemove" event on the graph's container. */ _onMouseMove: function(e) { - let offset = this._getContainerOffset(); - let mouseX = (e.clientX - offset.left) * this._pixelRatio; - let mouseY = (e.clientY - offset.top) * this._pixelRatio; + let {mouseX, mouseY} = this._getRelativeEventCoordinates(e); let canvasWidth = this._width; let canvasHeight = this._height; @@ -783,9 +781,7 @@ FlameGraph.prototype = { * Listener for the "mousedown" event on the graph's container. */ _onMouseDown: function(e) { - let offset = this._getContainerOffset(); - let mouseX = (e.clientX - offset.left) * this._pixelRatio; - let mouseY = (e.clientY - offset.top) * this._pixelRatio; + let {mouseX, mouseY} = this._getRelativeEventCoordinates(e); this._selectionDragger.origin = mouseX; this._selectionDragger.anchor.start = this._selection.start; @@ -817,8 +813,7 @@ FlameGraph.prototype = { * Listener for the "wheel" event on the graph's container. */ _onMouseWheel: function(e) { - let offset = this._getContainerOffset(); - let mouseX = (e.clientX - offset.left) * this._pixelRatio; + let {mouseX} = this._getRelativeEventCoordinates(e); let canvasWidth = this._width; let canvasHeight = this._height; @@ -941,6 +936,27 @@ FlameGraph.prototype = { return { left: x, top: y }; }, + /** + * Given a MouseEvent, make it relative to this._canvas. + * @return object {mouseX,mouseY} + */ + _getRelativeEventCoordinates: function(e) { + // For ease of testing, testX and testY can be passed in as the event + // object. + if ("testX" in e && "testY" in e) { + return { + mouseX: e.testX * this._pixelRatio, + mouseY: e.testY * this._pixelRatio + }; + } + + let offset = this._getContainerOffset(); + let mouseX = (e.clientX - offset.left) * this._pixelRatio; + let mouseY = (e.clientY - offset.top) * this._pixelRatio; + + return {mouseX,mouseY}; + }, + /** * Listener for the "resize" event on the graph's parent node. */ diff --git a/browser/devtools/shared/widgets/Graphs.jsm b/browser/devtools/shared/widgets/Graphs.jsm index 5bfe3ef6343c..7c5aefee87c8 100644 --- a/browser/devtools/shared/widgets/Graphs.jsm +++ b/browser/devtools/shared/widgets/Graphs.jsm @@ -946,10 +946,10 @@ AbstractCanvasGraph.prototype = { _getRelativeEventCoordinates: function(e) { // For ease of testing, testX and testY can be passed in as the event // object. If so, just return this. - if (e.screenX === undefined) { + if ("testX" in e && "testY" in e) { return { - mouseX: e.clientX * this._pixelRatio, - mouseY: e.clientY * this._pixelRatio + mouseX: e.testX * this._pixelRatio, + mouseY: e.testY * this._pixelRatio }; }