Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector-protocol / css / css-setStyleText.html
1 <html>
2 <head>
3 <style>
4 body {
5   color: green;
6 }
7 </style>
8 <script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
9 <script>
10 function test()
11 {
12     InspectorTest.sendCommand("CSS.getAllStyleSheets", {}, onGotStyleSheets);
13     var styleId;
14
15     function onGotStyleSheets(msg) {
16         if (msg.error) {
17             InspectorTest.log(msg.error.message);
18             InspectorTest.completeTest();
19             return;
20         }
21         var headers = msg.result.headers;
22         for (var i = 0; i < headers.length; ++i) {
23             if (headers[i].origin === "regular") {
24                 styleId = { "styleSheetId": headers[i].styleSheetId, "ordinal": 0 };
25                 InspectorTest.sendCommand("CSS.setStyleText", { "styleId": styleId, "text": "color: red;" }, onTextSet);
26                 return;
27             }
28         }
29         InspectorTest.log("Regular stylesheet not found");
30         InspectorTest.completeTest();
31     }
32
33     function onTextSet(msg) {
34         if (msg.error) {
35             InspectorTest.log(JSON.stringify(msg.error));
36             InspectorTest.completeTest();
37             return;
38         }
39         InspectorTest.log("New cssText:");
40         InspectorTest.log(msg.result.style.cssText);
41         InspectorTest.sendCommand("DOM.undo", {}, onUndo);
42     }
43
44     function onUndo() {
45         InspectorTest.sendCommand("CSS.getStyleSheetText", { "styleSheetId": styleId.styleSheetId }, onUndoneText);
46         function onUndoneText(msg)
47         {
48             if (msg.error) {
49                 InspectorTest.log(msg.error.message);
50                 InspectorTest.completeTest();
51                 return;
52             }
53             InspectorTest.log("StyleSheetText after undo:");
54             InspectorTest.log(msg.result.text);
55             InspectorTest.sendCommand("DOM.redo", {}, onRedo);
56         }
57     }
58
59     function onRedo() {
60         InspectorTest.sendCommand("CSS.getStyleSheetText", { "styleSheetId": styleId.styleSheetId }, onRedoneText);
61         function onRedoneText(msg)
62         {
63             if (msg.error) {
64                 InspectorTest.log(msg.error.message);
65                 InspectorTest.completeTest();
66                 return;
67             }
68             InspectorTest.log("StyleSheetText after redo:");
69             InspectorTest.log(msg.result.text);
70             InspectorTest.completeTest();
71         }
72     }
73 }
74 </script>
75 </head>
76 <body onLoad="runTest();">
77 </body>
78 </html>