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