Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / styles / update-locations-on-filesystem-scss-load.html
1 <html>
2 <head>
3 <script src="../inspector-test.js"></script>
4 <script src="../isolated-filesystem-test.js"></script>
5 <script src="../workspace-test.js"></script>
6 <script>
7 function test()
8 {
9     var manager;
10     var fileSystem;
11     var cssModel;
12     var liveLocation;
13     var fileSystemPath = "/var/www";
14     var fileSystemProjectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystemPath);
15
16     function addMockHeader(sourceURL, sourceMapURL)
17     {
18         cssModel._styleSheetAdded({
19             styleSheetId: 1,
20             frameId: 1000,
21             sourceURL: sourceURL,
22             sourceMapURL: sourceMapURL,
23             origin: "regular",
24             title: "",
25             disabled: false,
26             isInline: false,
27             startLine: 0,
28             startColumn: 0
29         });
30     }
31
32     function uiSourceCodeAdded(uiSourceCode) { }
33
34     function dumpFileSystemUISourceCodesMappings()
35     {
36         var uiSourceCodes = InspectorTest.testWorkspace.project(fileSystemProjectId).uiSourceCodes();
37         InspectorTest.addResult("UISourceCode uri to url mappings:");
38         for (var i = 0; i < uiSourceCodes.length; ++i)
39             InspectorTest.addResult("    " + uiSourceCodes[i].uri() + " -> " + uiSourceCodes[i].url);
40     }
41
42     function fileSystemAdded(event)
43     {
44         fileSystem = event.data;
45     }
46
47     function updateDelegate()
48     {
49         InspectorTest.addResult("LiveLocation updated:");
50     }
51
52     function dumpLiveLocation()
53     {
54         var uiLocation = liveLocation.uiLocation();
55         if (!uiLocation) {
56             InspectorTest.addResult("Null uiLocation");
57             return;
58         }
59         InspectorTest.addResult(uiLocation.uiSourceCode.url + ":" + uiLocation.lineNumber + ":" + uiLocation.columnNumber);
60     }
61
62     InspectorTest.createWorkspace();
63     manager = InspectorTest.createIsolatedFileSystemManager(InspectorTest.testWorkspace, InspectorTest.testFileSystemMapping);
64     cssModel = new WebInspector.CSSStyleModel(InspectorTest.testWorkspace);
65     new WebInspector.CSSStyleSheetMapping(cssModel, InspectorTest.testWorkspace, InspectorTest.testNetworkWorkspaceProvider);
66
67     var resourcesURL = WebInspector.ParsedURL.completeURL(WebInspector.inspectedPageURL, "resources/");
68     var namePrefix = "update-locations-on-filesystem-scss-load."
69     var cssURL = resourcesURL + namePrefix + "css";
70     var scssURL = resourcesURL + namePrefix + "scss";
71     var cssLocation = new WebInspector.CSSLocation(cssURL, 0, 1);
72     var scssContent =
73         ["a {",
74         "  foo: bar;",
75         "/* COMMENT */",
76         "  font-size: 12px;",
77         "}"].join("\n");
78     var cssContent =
79         ["a {",
80         "  foo: bar;",
81         "  /* COMMENT */",
82         "  font-size: 12px; }"].join("\n");
83
84     var files = {};
85     files["/" + namePrefix + "css"] = cssContent;
86     InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 4);
87     InspectorTest.addResult("Adding file system.");
88     manager.addEventListener(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystemAdded, this);
89     manager.addMockFileSystem(fileSystemPath);
90     InspectorTest.testFileSystemMapping.addFileMapping(fileSystemPath, resourcesURL, "/");
91     manager.addFiles(fileSystemPath, files);
92
93     InspectorTest.addSniffer(WebInspector.SASSSourceMapping.prototype, "_bindUISourceCode", afterBind);
94
95     InspectorTest.addResult("Adding stylesheet header.");
96     addMockHeader(cssURL, cssURL + ".map");
97     InspectorTest.addResult("Adding network resource.");
98     InspectorTest.addMockUISourceCodeToWorkspace(cssURL, WebInspector.resourceTypes.Stylesheet, cssContent);
99     liveLocation = cssModel.createLiveLocation("1", cssLocation, updateDelegate);
100     dumpLiveLocation();
101
102     InspectorTest.addResult("Adding filesystem SCSS.");
103     var scssPath = namePrefix + "scss";
104     fileSystem.setFileContent(scssPath, scssContent, function() {});
105     InspectorTest.addMockUISourceCodeToWorkspace(scssURL, WebInspector.resourceTypes.Stylesheet, scssContent);
106     manager.fileSystemWorkspaceProvider._projectDelegates[fileSystemProjectId]._addFile(scssPath);
107
108     function afterBind()
109     {
110         dumpLiveLocation();
111         InspectorTest.completeTest();
112     }
113 };
114 </script>
115 </head>
116 <body onload="runTest()">
117 <p>Tests that stylesheet LiveLocations are updated when an SCSS file is added from the filesystem.</p>
118 </body>
119 </html>