Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / modify-cross-domain-rule.html
1 <html>
2 <head>
3 <link rel="stylesheet" href="http://localhost:8000/inspector/elements/styles/modify-cross-domain-rule.css">
4 <script src="inspector-test.js"></script>
5 <script src="elements-test.js"></script>
6 <script>
7
8 function test()
9 {
10     var nodeId;
11     var allRules;
12     var rule;
13     var matchedRules;
14
15     InspectorTest.runTestSuite([
16         function testSetUp(next) {
17             InspectorTest.selectNodeAndWaitForStyles("inspected", selectCallback);
18
19             function selectCallback()
20             {
21                 var idToDOMNode = WebInspector.domModel._idToDOMNode;
22                 for (var id in idToDOMNode) {
23                     node = idToDOMNode[id];
24                     if (node.getAttribute && node.getAttribute("id") === "inspected") {
25                         nodeId = parseInt(id, 10);
26                         break;
27                     }
28                 }
29
30                 if (!nodeId) {
31                     InspectorTest.completeTest();
32                     return;
33                 }
34
35                 WebInspector.cssModel.getMatchedStylesAsync(nodeId, false, false, callback);
36             }
37
38             function callback(rules)
39             {
40                 if (!rules || !rules.matchedCSSRules || !rules.matchedCSSRules.length) {
41                     InspectorTest.addResult("[!] No rules found");
42                     InspectorTest.completeTest();
43                     return;
44                 }
45
46                 allRules = rules.matchedCSSRules;
47                 next();
48             }
49         },
50
51         function testAddProperty(next)
52         {
53             for (var i = 0; i < allRules.length; ++i) {
54                 if (allRules[i].isRegular) {
55                     rule = allRules[i];
56                     break;
57                 }
58             }
59             rule.style.appendProperty("width", "100%", callback);
60             function callback(newStyle)
61             {
62                 InspectorTest.addResult("=== Rule modified ===");
63                 if (!newStyle) {
64                     InspectorTest.addResult("[!] No valid rule style received");
65                     InspectorTest.completeTest();
66                 } else {
67                     dumpProperties(newStyle);
68                     WebInspector.cssModel.setRuleSelector(rule, nodeId, "body", successCallback, failureCallback);
69                 }
70             }
71
72             function successCallback(rule, doesAffectSelectedNode)
73             {
74                 InspectorTest.addResult("=== Selector changed ===");
75                 InspectorTest.addResult(rule.selectorText + " {" + rule.style.cssText + "}");
76                 InspectorTest.addResult("Selectors matching the (#inspected) node: " + InspectorTest.matchingSelectors(rule));
77                 next();
78             }
79
80             function failureCallback()
81             {
82                 InspectorTest.addResult("[!] Failed to change selector");
83                 InspectorTest.completeTest();
84             }
85         }
86     ]);
87
88     function dumpProperties(style)
89     {
90        if (!style)
91            return;
92        var allProperties = style.allProperties;
93        for (var i = 0; i < allProperties.length; ++i)
94            InspectorTest.addResult(allProperties[i].text);
95     }
96 }
97 </script>
98 </head>
99
100 <body onload="runTest()">
101 <p>
102 Tests that modifying a rule in a stylesheet loaded from a different domain does not crash the renderer.
103 </p>
104
105 <div id="inspected">Text</div>
106
107 </body>
108 </html>