3 <script src=
"inspector-test.js"></script>
4 <script src=
"debugger-test.js"></script>
5 <script src=
"workspace-test.js"></script>
12 var finalMappedLocation
;
13 var target
= InspectorTest
.createWorkspaceWithTarget();
14 var cssModel
= WebInspector
.CSSStyleModel
.fromTarget(target
);
15 WebInspector
.cssWorkspaceBinding
= InspectorTest
.testCSSWorkspaceBinding
;
17 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(cssUISourceCodeAdded
);
18 const styleSheetURL
= "http://localhost:8000/inspector/resources/example.css";
19 const sourceMapURL
= "example.css.map";
20 const styleSheetId
= 1;
21 InspectorTest
.addMockUISourceCodeToWorkspace(styleSheetURL
, WebInspector
.resourceTypes
.Stylesheet
, "");
23 InspectorTest
.addSniffer(WebInspector
.CSSWorkspaceBinding
.prototype, "updateLocations", locationsUpdated
, true);
24 cssModel
._styleSheetAdded(createMockStyleSheetHeader(styleSheetURL
, sourceMapURL
));
26 function locationsUpdated()
28 var uiLocation
= InspectorTest
.testCSSWorkspaceBinding
.rawLocationToUILocation(new WebInspector
.CSSLocation(cssModel
, styleSheetId
, styleSheetURL
, 2, 3));
29 var networkURL
= InspectorTest
.testNetworkMapping
.networkURL(uiLocation
.uiSourceCode
);
30 if (networkURL
.indexOf(".scss") === -1)
32 finalMappedLocation
= networkURL
+ ":" + uiLocation
.lineNumber
+ ":" + uiLocation
.columnNumber
;
37 function createMockStyleSheetHeader(url
, sourceMapURL
)
39 const frame
= InspectorTest
.resourceTreeModel
.mainFrame
;
41 styleSheetId
: styleSheetId
,
44 sourceMapURL
: sourceMapURL
,
51 function createMockStyleSheetResource(url
, mimeType
, content
)
53 const documentURL
= "http://localhost:8000/inspector/stylesheet-source-mapping.html";
54 const frame
= InspectorTest
.resourceTreeModel
.mainFrame
;
55 var resource
= new WebInspector
.Resource(target
, null, url
, documentURL
, frame
.id
, frame
.loaderId
, WebInspector
.resourceTypes
.Stylesheet
, mimeType
);
56 resource
.requestContent = function(callback
)
58 callback(content
, false, mimeType
);
64 function cssUISourceCodeAdded(uiSourceCode
)
66 InspectorTest
.addResult("Added CSS uiSourceCode: " + uiSourceCode
.uri());
67 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(scssUISourceCodeAdded
);
70 function scssUISourceCodeAdded(uiSourceCode
)
72 InspectorTest
.addResult("Added SCSS uiSourceCode: " + uiSourceCode
.uri());
73 afterStyleSheetAdded();
76 function rawLocationToUILocation(line
, column
)
78 return InspectorTest
.testCSSWorkspaceBinding
.rawLocationToUILocation(new WebInspector
.CSSLocation(cssModel
, styleSheetId
, styleSheetURL
, line
, column
));
81 function afterStyleSheetAdded()
83 var cssUISourceCode
= InspectorTest
.testWorkspace
.uiSourceCodeForOriginURL(styleSheetURL
);
84 var scssUISourceCode
= InspectorTest
.testWorkspace
.uiSourceCodeForOriginURL("http://localhost:8000/inspector/resources/example.scss");
86 InspectorTest
.checkUILocation(cssUISourceCode
, 0, 3, rawLocationToUILocation(0, 3));
87 InspectorTest
.checkUILocation(scssUISourceCode
, 1, 0, rawLocationToUILocation(1, 0));
88 InspectorTest
.checkUILocation(scssUISourceCode
, 2, 2, rawLocationToUILocation(2, 4));
89 InspectorTest
.checkUILocation(scssUISourceCode
, 2, 5, rawLocationToUILocation(2, 6));
90 InspectorTest
.checkUILocation(scssUISourceCode
, 2, 7, rawLocationToUILocation(2, 9));
91 InspectorTest
.checkUILocation(scssUISourceCode
, 2, 10, rawLocationToUILocation(3, 7));
92 InspectorTest
.checkUILocation(scssUISourceCode
, 4, 2, rawLocationToUILocation(4, 8));
93 InspectorTest
.checkUILocation(scssUISourceCode
, 4, 2, rawLocationToUILocation(4, 10));
94 InspectorTest
.checkUILocation(scssUISourceCode
, 4, 11, rawLocationToUILocation(4, 11));
95 InspectorTest
.checkUILocation(scssUISourceCode
, 4, 13, rawLocationToUILocation(4, 15));
96 InspectorTest
.checkUILocation(scssUISourceCode
, 4, 17, rawLocationToUILocation(4, 20));
97 scssUISourceCode
.requestContent(didRequestContent
);
99 function didRequestContent(content
, contentEncoded
, mimeType
)
101 InspectorTest
.assertEquals(0, content
.indexOf("/* Comment */"));
102 contentReceived
= true;
109 if (!contentReceived
|| !finalMappedLocation
)
111 InspectorTest
.addResult("UILocation upon LiveLocation update: " + finalMappedLocation
);
112 InspectorTest
.completeTest();
120 <body onload=
"runTest()">
121 <p>Tests SourceMap and StyleSheetMapping.
</p>