Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / styles / styles-history.html
1 <html>
2 <head>
3
4 <link rel="stylesheet" href="resources/styles-history.css">
5
6 <script src="../../http/tests/inspector/inspector-test.js"></script>
7 <script src="../../http/tests/inspector/elements-test.js"></script>
8 <script src="../../http/tests/inspector/resources-test.js"></script>
9 <script>
10
11 function test()
12 {
13     InspectorTest.runAfterCachedResourcesProcessed(runTestSuite);
14
15     var uiSourceCode;
16
17     function runTestSuite()
18     {
19         InspectorTest.runTestSuite([
20             function testSetUp(next)
21             {
22                 function visitUISourceCodes(currentUISourceCode)
23                 {
24                     if (currentUISourceCode.originURL().indexOf("styles-history.css") === -1)
25                         return;
26                     uiSourceCode = currentUISourceCode;
27                     next();
28                 }
29                 WebInspector.workspace.uiSourceCodes().forEach(visitUISourceCodes);
30             },
31
32             function testSetResourceContentMinor(next)
33             {
34                 InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMinor);
35                 uiSourceCode.setWorkingCopy("body {\n  margin: 15px;\n  padding: 10px;\n}");
36
37                 function styleUpdatedMinor()
38                 {
39                     dumpHistory(next)();
40                 }
41             },
42
43             function testSetResourceContentMajor(next)
44             {
45                 InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMinor);
46                 uiSourceCode.setWorkingCopy("body {\n  margin: 20px;\n  padding: 10px;\n}");
47
48                 function styleUpdatedMinor()
49                 {
50                     InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMajor);
51                     uiSourceCode.commitWorkingCopy(function() { });
52
53                     function styleUpdatedMajor()
54                     {
55                         dumpHistory(next)();
56                     }
57                 }
58             },
59
60             function testSetContentViaModelMinor(next)
61             {
62                 styleSheetForResource(step1);
63
64                 function step1(styleSheet)
65                 {
66                     var style = styleSheet.rules[0].style;
67                     var property = style.getLiveProperty("margin");
68                     property.setText("margin:25px;", false, true, dumpHistory(next));
69                 }
70             },
71
72             function testSetContentViaModelMajor(next)
73             {
74                 styleSheetForResource(step1);
75
76                 function step1(styleSheet)
77                 {
78                     var style = styleSheet.rules[0].style;
79                     var property = style.getLiveProperty("margin");
80                     property.setText("margin:30px;", true, true);
81                     InspectorTest.runAfterPendingDispatches(dumpHistory(next));
82                 }
83             }
84         ]);
85     }
86
87     function styleSheetForResource(callback)
88     {
89         CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
90
91         function didGetAllStyleSheets(error, infos)
92         {
93             if (error) {
94                 InspectorTest.addResult("Error:" + error);
95                 callback(null);
96                 return;
97             }
98
99             for (var i = 0; i < infos.length; ++i) {
100                 var info = infos[i];
101                 if (info.sourceURL.indexOf("styles-history.css") === -1)
102                     continue;
103                 WebInspector.CSSStyleSheet.createForId(info.styleSheetId, callback);
104                 return;
105             }
106             callback(null);
107         }
108     }
109
110     function dumpHistory(next)
111     {
112         function result()
113         {
114             InspectorTest.addResult("History length: " + uiSourceCode.history.length);
115             for (var i = 0; i < uiSourceCode.history.length; ++i) {
116                 InspectorTest.addResult("Item " + i + ":");
117                 InspectorTest.addResult(uiSourceCode.history[i].content);
118             }
119             next();
120         }
121         return result;
122     }
123 }
124
125 </script>
126 </head>
127
128 <body onload="runTest()">
129 <p>
130 Tests resources panel history.
131 </p>
132 </body>
133 </html>