| <!doctype html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function test() |
| { |
| const color = undefined; |
| const outlineColor = undefined; |
| const useViewportCoordinates = false; |
| const usePageCoordinates = true; |
| |
| function getHighlightRects(callback) { |
| InspectorTest.evaluateInPage("JSON.stringify(Array.from(window.internals.inspectorHighlightRects()))", (error, value, wasThrown) => { |
| InspectorTest.assert(!error, "Unexpected error dumping highlight: " + error); |
| InspectorTest.assert(!wasThrown, "Unexpected exception when dumping highlight."); |
| callback(JSON.parse(value)); |
| }); |
| } |
| |
| function dumpHighlightRects(callback) { |
| getHighlightRects((highlightRects) => { |
| InspectorTest.expectThat(highlightRects.length === 1, "Should be one highlight rect."); |
| InspectorTest.log("Highlight Rect: " + JSON.stringify(highlightRects[0])); |
| callback(); |
| }); |
| } |
| |
| let suite = InspectorTest.createAsyncSuite("DOM.highlightQuad"); |
| |
| suite.addTestCase({ |
| name: "CheckEmptyHighlight", |
| description: "Should not be a highlight yet.", |
| test(resolve, reject) { |
| getHighlightRects((highlightRects) => { |
| InspectorTest.expectThat(highlightRects.length === 0, "Should not be a highlight yet."); |
| resolve(); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "HighlightSmallRectWithQuad", |
| description: "Should create a highlight using viewport coordinates.", |
| test(resolve, reject) { |
| let quad = new WI.Quad([0, 0, 100, 0, 100, 100, 100, 0]); |
| DOMAgent.highlightQuad(quad.toProtocol(), color, outlineColor, (error) => { |
| dumpHighlightRects(resolve); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "HighlightSmallQuadViewportCoordinates", |
| description: "Should create a highlight using viewport coordinates.", |
| test(resolve, reject) { |
| let quad = new WI.Quad([100, 100, 150, 150, 100, 200, 50, 150]); |
| DOMAgent.highlightQuad(quad.toProtocol(), color, outlineColor, useViewportCoordinates, (error) => { |
| dumpHighlightRects(resolve); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "HighlightSmallQuadPageCoordinates", |
| description: "Should create a highlight using page coordinates.", |
| test(resolve, reject) { |
| let quad = new WI.Quad([100, 100, 150, 150, 100, 200, 50, 150]); |
| DOMAgent.highlightQuad(quad.toProtocol(), color, outlineColor, usePageCoordinates, (error) => { |
| dumpHighlightRects(resolve); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "HighlightSmallUnspecifiedCoordinatesUsesViewportCoordinates", |
| description: "Should create a highlight using page coordinates.", |
| test(resolve, reject) { |
| let quad = new WI.Quad([100, 100, 150, 150, 100, 200, 50, 150]); |
| DOMAgent.highlightQuad(quad.toProtocol(), color, outlineColor, (error) => { |
| dumpHighlightRects(resolve); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "HighlightLargeQuadViewportCoordinates", |
| description: "Should create a highlight using viewport coordinates.", |
| test(resolve, reject) { |
| let quad = new WI.Quad([0, 0, 500, 0, 1000, 1000, 0, 2000]); |
| DOMAgent.highlightQuad(quad.toProtocol(), color, outlineColor, useViewportCoordinates, (error) => { |
| dumpHighlightRects(resolve); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "HighlightLargeQuadPageCoordinates", |
| description: "Should create a highlight using viewport coordinates.", |
| test(resolve, reject) { |
| let quad = new WI.Quad([0, 0, 500, 0, 1000, 1000, 0, 2000]); |
| DOMAgent.highlightQuad(quad.toProtocol(), color, outlineColor, usePageCoordinates, (error) => { |
| dumpHighlightRects(resolve); |
| }); |
| } |
| }); |
| |
| // ------ |
| |
| suite.addTestCase({ |
| name: "BadQuadShouldError", |
| description: "Should get an error when specifying a quad with too few points.", |
| test(resolve, reject) { |
| let badQuadArray = [1, 2, 3, 4]; |
| DOMAgent.highlightQuad(badQuadArray, color, outlineColor, usePageCoordinates, (error) => { |
| InspectorTest.expectThat(error, "Should produce an error."); |
| InspectorTest.log("Error: " + error); |
| resolve(); |
| }); |
| } |
| }); |
| |
| InspectorTest.evaluateInPage("window.scrollTo(10, 10)", () => { |
| suite.runTestCasesAndFinish(); |
| }); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests for the DOM.highlightQuad command.</p> |
| <!-- Ensure the page is scrollable so we can test highlight rects relative to a scroll page --> |
| <div style="height:2000px; width: 2000px; background:blue"></div> |
| </body> |
| </html> |