Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / elements / 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 src="styles-test.js"></script>
10 <script>
11
12 function test()
13 {
14     InspectorTest.runAfterCachedResourcesProcessed(runTestSuite);
15
16     var uiSourceCode;
17
18     function runTestSuite()
19     {
20         InspectorTest.runTestSuite([
21             function testSetUp(next)
22             {
23                 function visitUISourceCodes(currentUISourceCode)
24                 {
25                     if (currentUISourceCode.originURL().indexOf("styles-history.css") === -1)
26                         return;
27                     uiSourceCode = currentUISourceCode;
28                     next();
29                 }
30                 WebInspector.workspace.uiSourceCodes().forEach(visitUISourceCodes);
31             },
32
33             function testSetResourceContentMinor(next)
34             {
35                 InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMinor);
36                 uiSourceCode.setWorkingCopy("body {\n  margin: 15px;\n  padding: 10px;\n}");
37
38                 function styleUpdatedMinor()
39                 {
40                     dumpHistory(next)();
41                 }
42             },
43
44             function testSetResourceContentMajor(next)
45             {
46                 InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMinor);
47                 uiSourceCode.setWorkingCopy("body {\n  margin: 20px;\n  padding: 10px;\n}");
48
49                 function styleUpdatedMinor()
50                 {
51                     InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMajor);
52                     uiSourceCode.commitWorkingCopy(function() { });
53
54                     function styleUpdatedMajor()
55                     {
56                         dumpHistory(next)();
57                     }
58                 }
59             },
60
61             function testSetContentViaModelMinor(next)
62             {
63                 styleSheetForResource(step1);
64
65                 function step1(style)
66                 {
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(style)
77                 {
78                     var property = style.getLiveProperty("margin");
79                     property.setText("margin:30px;", true, true);
80                     InspectorTest.runAfterPendingDispatches(dumpHistory(next));
81                 }
82             }
83         ]);
84     }
85
86     function styleSheetForResource(callback)
87     {
88         InspectorTest.nodeWithId("mainBody", onNodeSelected);
89
90         function onNodeSelected(node)
91         {
92             CSSAgent.getMatchedStylesForNode(node.id, false, false, onMatchedStylesForNode);
93         }
94
95         function onMatchedStylesForNode(error, matchedStyles)
96         {
97             if (error) {
98                 InspectorTest.addResult("error: " + error);
99                 InspectorTest.completeTest();
100                 return;
101             }
102             for (var i = 0; i < matchedStyles.length; ++i) {
103                 var rule = matchedStyles[i].rule;
104                 if (rule.origin !== "regular")
105                     continue;
106                 callback(WebInspector.CSSStyleDeclaration.parsePayload(WebInspector.cssModel, rule.style));
107                 return;
108             }
109             InspectorTest.addResult("error: did not find any regular rule");
110             InspectorTest.completeTest();
111         }
112     }
113
114     function dumpHistory(next)
115     {
116         function result()
117         {
118             InspectorTest.addResult("History length: " + uiSourceCode.history.length);
119             for (var i = 0; i < uiSourceCode.history.length; ++i) {
120                 InspectorTest.addResult("Item " + i + ":");
121                 InspectorTest.addResult(uiSourceCode.history[i].content);
122             }
123             next();
124         }
125         return result;
126     }
127 }
128
129 </script>
130 </head>
131
132 <body id="mainBody" onload="runTest()">
133 <p>
134 Tests resources panel history.
135 </p>
136 </body>
137 </html>