Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / stylesheet-source-mapping.html
1 <html>
2 <head>
3 <script src="inspector-test.js"></script>
4 <script src="debugger-test.js"></script>
5 <script src="workspace-test.js"></script>
6
7 <script>
8
9 function test()
10 {
11     var contentReceived;
12     var finalMappedLocation;
13     InspectorTest.createWorkspace();
14     var target = WebInspector.targetManager.mainTarget();
15     var cssModel = new WebInspector.CSSStyleModel(target);
16     target.cssModel = cssModel;
17     new WebInspector.CSSWorkspaceBinding.TargetInfo(target, InspectorTest.testWorkspace, InspectorTest.testNetworkWorkspaceBinding);
18
19     InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(cssUISourceCodeAdded);
20     const styleSheetURL = "http://localhost:8000/inspector/resources/example.css";
21     const sourceMapURL = "example.css.map";
22     const styleSheetId = 1;
23     InspectorTest.addMockUISourceCodeToWorkspace(styleSheetURL, WebInspector.resourceTypes.Stylesheet, "");
24
25     InspectorTest.addSniffer(WebInspector.CSSWorkspaceBinding.prototype, "updateLocations", locationsUpdated, true);
26     cssModel._styleSheetAdded(createMockStyleSheetHeader(styleSheetURL, sourceMapURL));
27
28     function locationsUpdated()
29     {
30         var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILocation(new WebInspector.CSSLocation(target, styleSheetId, styleSheetURL, 2, 3));
31         if (uiLocation.uiSourceCode.url.indexOf(".scss") === -1)
32             return;
33         finalMappedLocation = uiLocation.uiSourceCode.url + ":" + uiLocation.lineNumber + ":" + uiLocation.columnNumber;
34         join();
35     }
36
37
38     function createMockStyleSheetHeader(url, sourceMapURL)
39     {
40         const frame = WebInspector.resourceTreeModel.mainFrame;
41         return {
42             styleSheetId: styleSheetId,
43             frameId: frame.id,
44             sourceURL: url,
45             sourceMapURL: sourceMapURL,
46             origin: "regular",
47             title: "",
48             disabled: false
49         };
50     }
51
52     function createMockStyleSheetResource(url, mimeType, content)
53     {
54         const documentURL = "http://localhost:8000/inspector/stylesheet-source-mapping.html";
55         const frame = WebInspector.resourceTreeModel.mainFrame;
56         var resource = new WebInspector.Resource(WebInspector.resourceTreeModel.target(), null, url, documentURL, frame.id, frame.loaderId, WebInspector.resourceTypes.Stylesheet, mimeType);
57         resource.requestContent = function(callback)
58         {
59             callback(content, false, mimeType);
60         }
61         return resource;
62     }
63
64
65     function cssUISourceCodeAdded(uiSourceCode)
66     {
67         InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(scssUISourceCodeAdded);
68     }
69
70     function scssUISourceCodeAdded(uiSourceCode)
71     {
72         afterStyleSheetAdded();
73     }
74
75     function rawLocationToUILocation(line, column)
76     {
77         return WebInspector.cssWorkspaceBinding.rawLocationToUILocation(new WebInspector.CSSLocation(target, styleSheetId, styleSheetURL, line, column));
78     }
79
80     function afterStyleSheetAdded()
81     {
82         var cssUISourceCode = InspectorTest.testWorkspace.uiSourceCodeForOriginURL(styleSheetURL);
83         var scssUISourceCode = InspectorTest.testWorkspace.uiSourceCodeForOriginURL("http://localhost:8000/inspector/resources/example.scss");
84
85         InspectorTest.checkUILocation(cssUISourceCode, 0, 3, rawLocationToUILocation(0, 3));
86         InspectorTest.checkUILocation(scssUISourceCode, 1, 0, rawLocationToUILocation(1, 0));
87         InspectorTest.checkUILocation(scssUISourceCode, 2, 2, rawLocationToUILocation(2, 4));
88         InspectorTest.checkUILocation(scssUISourceCode, 2, 5, rawLocationToUILocation(2, 6));
89         InspectorTest.checkUILocation(scssUISourceCode, 2, 7, rawLocationToUILocation(2, 9));
90         InspectorTest.checkUILocation(scssUISourceCode, 2, 10, rawLocationToUILocation(3, 7));
91         InspectorTest.checkUILocation(scssUISourceCode, 4, 2, rawLocationToUILocation(4, 8));
92         InspectorTest.checkUILocation(scssUISourceCode, 4, 2, rawLocationToUILocation(4, 10));
93         InspectorTest.checkUILocation(scssUISourceCode, 4, 11, rawLocationToUILocation(4, 11));
94         InspectorTest.checkUILocation(scssUISourceCode, 4, 13, rawLocationToUILocation(4, 15));
95         InspectorTest.checkUILocation(scssUISourceCode, 4, 17, rawLocationToUILocation(4, 20));
96         scssUISourceCode.requestContent(didRequestContent);
97
98         function didRequestContent(content, contentEncoded, mimeType)
99         {
100             InspectorTest.assertEquals(0, content.indexOf("/* Comment */"));
101             contentReceived = true;
102             join();
103         }
104     }
105
106     function join()
107     {
108         if (!contentReceived || !finalMappedLocation)
109             return;
110         InspectorTest.addResult("UILocation upon LiveLocation update: " + finalMappedLocation);
111         InspectorTest.completeTest();
112     }
113 }
114
115 </script>
116
117 </head>
118
119 <body onload="runTest()">
120 <p>Tests SourceMap and StyleSheetMapping.</p>
121 </body>
122 </html>