Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / elements / 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.FileSystemWorkspaceBinding.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(WebInspector.targetManager.activeTarget(), InspectorTest.testWorkspace);
65     WebInspector.targetManager.activeTarget().cssModel = cssModel;
66     new WebInspector.CSSStyleSheetMapping(cssModel, InspectorTest.testWorkspace, InspectorTest.testNetworkWorkspaceBinding);
67
68     var resourcesURL = WebInspector.ParsedURL.completeURL(WebInspector.resourceTreeModel.inspectedPageURL(), "resources/");
69     var namePrefix = "update-locations-on-filesystem-scss-load."
70     var cssURL = resourcesURL + namePrefix + "css";
71     var scssURL = resourcesURL + namePrefix + "scss";
72     var cssLocation = new WebInspector.CSSLocation(WebInspector.targetManager.activeTarget(), cssURL, 0, 1);
73     var scssContent =
74         ["a {",
75         "  foo: bar;",
76         "/* COMMENT */",
77         "  font-size: 12px;",
78         "}"].join("\n");
79     var cssContent =
80         ["a {",
81         "  foo: bar;",
82         "  /* COMMENT */",
83         "  font-size: 12px; }"].join("\n");
84
85     var files = {};
86     files["/" + namePrefix + "css"] = cssContent;
87     InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded, 4);
88     InspectorTest.addResult("Adding file system.");
89     manager.addEventListener(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystemAdded, this);
90     manager.addMockFileSystem(fileSystemPath);
91     InspectorTest.testFileSystemMapping.addFileMapping(fileSystemPath, resourcesURL, "/");
92     manager.addFiles(fileSystemPath, files);
93
94     InspectorTest.addSniffer(WebInspector.SASSSourceMapping.prototype, "_bindUISourceCode", afterBind);
95
96     InspectorTest.addResult("Adding stylesheet header.");
97     addMockHeader(cssURL, cssURL + ".map");
98     InspectorTest.addResult("Adding network resource.");
99     InspectorTest.addMockUISourceCodeToWorkspace(cssURL, WebInspector.resourceTypes.Stylesheet, cssContent);
100     liveLocation = cssLocation.createLiveLocation("1", updateDelegate);
101     dumpLiveLocation();
102
103     InspectorTest.addResult("Adding filesystem SCSS.");
104     var scssPath = namePrefix + "scss";
105     fileSystem.setFileContent(scssPath, scssContent, function() {});
106     InspectorTest.addMockUISourceCodeToWorkspace(scssURL, WebInspector.resourceTypes.Stylesheet, scssContent);
107     manager.fileSystemWorkspaceBinding._boundFileSystems.get(fileSystemPath)._addFile(scssPath);
108
109     function afterBind()
110     {
111         dumpLiveLocation();
112         InspectorTest.completeTest();
113     }
114 };
115 </script>
116 </head>
117 <body onload="runTest()">
118 <p>Tests that stylesheet LiveLocations are updated when an SCSS file is added from the filesystem.</p>
119 </body>
120 </html>