Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / styles / add-new-rule-inline-style-csp.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Security-Policy" content="style-src https://*:443">
4 <script src="../../http/tests/inspector/inspector-test.js"></script>
5 <script src="../../http/tests/inspector/elements-test.js"></script>
6 <script>
7
8 function test()
9 {
10     var nodeId;
11     var rule;
12
13     WebInspector.showPanel("elements");
14
15     InspectorTest.runTestSuite([
16         function testSetUp(next) {
17             InspectorTest.selectNodeAndWaitForStyles("inspected", next);
18         },
19
20         function testAddRule(next)
21         {
22             InspectorTest.nodeWithId("inspected", nodeCallback);
23
24             function nodeCallback(node)
25             {
26                 nodeId = node.id;
27                 WebInspector.cssModel.addRule(nodeId, "#inspected", successCallback, failureCallback);
28             }
29
30             function successCallback(newRule, doesAffectSelectedNode)
31             {
32                 rule = newRule;
33                 InspectorTest.addResult("=== Rule added ===");
34                 InspectorTest.addResult(rule.selectorText + " {" + rule.style.cssText + "}");
35                 InspectorTest.addResult("Selectors matching the (#inspected) node: " + InspectorTest.matchingSelectors(rule));
36                 next();
37             }
38
39             function failureCallback()
40             {
41                 InspectorTest.addResult("[!] Failed to add rule.");
42                 InspectorTest.completeTest();
43             }
44         },
45
46         function testAddProperty(next)
47         {
48             rule.style.appendProperty("width", "100%", callback);
49
50             function callback(newStyle)
51             {
52                 InspectorTest.addResult("=== Added rule modified ===");
53                 if (!newStyle) {
54                     InspectorTest.addResult("[!] No valid rule style received");
55                     InspectorTest.completeTest();
56                 } else {
57                     dumpProperties(newStyle);
58                     WebInspector.cssModel.setRuleSelector(rule.id, nodeId, "body", successCallback, failureCallback);
59                 }
60             }
61
62             function successCallback(rule)
63             {
64                 var doesAffectSelectedNode = rule.matchingSelectors.length > 0;
65                 InspectorTest.addResult("=== Selector changed ===");
66                 InspectorTest.addResult(rule.selectorText + " {" + rule.style.cssText + "}");
67                 InspectorTest.addResult("Selectors matching the (#inspected) node: " + InspectorTest.matchingSelectors(rule));
68
69                 next();
70             }
71
72             function failureCallback()
73             {
74                 InspectorTest.addResult("[!] Failed to change selector");
75                 InspectorTest.completeTest();
76             }
77         },
78
79         function testModifyInlineStyle(next)
80         {
81             WebInspector.cssModel.getInlineStylesAsync(nodeId, stylesCallback);
82
83             function stylesCallback(inlineStyle)
84             {
85                 if (!inlineStyle) {
86                     InspectorTest.completeTest();
87                     return;
88                 }
89                 inlineStyle.appendProperty("font-size", "14px", appendCallback);
90             }
91
92             function appendCallback(newStyle)
93             {
94                 InspectorTest.addResult("=== Inline style modified ===");
95                 if (!newStyle) {
96                     InspectorTest.addResult("No valid inline style received");
97                     InspectorTest.completeTest();
98                     return;
99                 }
100
101                 dumpProperties(newStyle);
102                 next();
103             }
104         }
105     ]);
106
107     function dumpProperties(style)
108     {
109        if (!style)
110            return;
111        var allProperties = style.allProperties;
112        for (var i = 0; i < allProperties.length; ++i)
113            InspectorTest.addResult(allProperties[i].text);
114     }
115 }
116 </script>
117 </head>
118
119 <body onload="runTest()">
120 <p>
121 Tests that adding a new rule does not crash the renderer and modifying an inline style does not report errors when forbidden by Content-Security-Policy.
122 </p>
123
124 <div id="inspected">Text</div>
125
126 </body>
127 </html>