1 function initialize_cssTest()
4 InspectorTest
.dumpStyleSheetText = function(styleSheetId
, callback
)
6 InspectorTest
.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId
: styleSheetId
}, onStyleSheetText
);
7 function onStyleSheetText(result
)
9 InspectorTest
.log("==== Style sheet text ====");
10 InspectorTest
.log(result
.text
);
15 function updateStyleSheetRange(command
, styleSheetId
, expectError
, options
, callback
)
17 options
.styleSheetId
= styleSheetId
;
19 InspectorTest
.sendCommand(command
, options
, onResponse
);
21 InspectorTest
.sendCommandOrDie(command
, options
, onSuccess
);
25 InspectorTest
.dumpStyleSheetText(styleSheetId
, callback
);
28 function onResponse(message
)
31 InspectorTest
.log("ERROR: protocol method call did not return expected error. Instead, the following message was received: " + JSON
.stringify(message
));
32 InspectorTest
.completeTest();
35 InspectorTest
.log("Expected protocol error: " + message
.error
.message
);
40 InspectorTest
.setPropertyText
= updateStyleSheetRange
.bind(null, "CSS.setPropertyText");
41 InspectorTest
.setRuleSelector
= updateStyleSheetRange
.bind(null, "CSS.setRuleSelector");
42 InspectorTest
.setStyleText
= updateStyleSheetRange
.bind(null, "CSS.setStyleText");
43 InspectorTest
.setMediaText
= updateStyleSheetRange
.bind(null, "CSS.setMediaText");
44 InspectorTest
.addRule
= updateStyleSheetRange
.bind(null, "CSS.addRule");
46 InspectorTest
.requestMainFrameId = function(callback
)
48 InspectorTest
.sendCommandOrDie("Page.enable", {}, pageEnabled
);
50 function pageEnabled()
52 InspectorTest
.sendCommandOrDie("Page.getResourceTree", {}, resourceTreeLoaded
);
55 function resourceTreeLoaded(payload
)
57 callback(payload
.frameTree
.frame
.id
);
61 function indentLog(indent
, string
)
63 var indentString
= Array(indent
+1).join(" ");
64 InspectorTest
.log(indentString
+ string
);
67 InspectorTest
.dumpRuleMatch = function(ruleMatch
)
70 var rule
= ruleMatch
.rule
;
71 var matchingSelectors
= ruleMatch
.matchingSelectors
;
72 var media
= rule
.media
|| [];
74 for (var i
= 0; i
< media
.length
; ++i
)
75 mediaLine
+= (i
> 0 ? " " : "") + media
[i
].text
;
77 if (mediaLine
.length
) {
78 indentLog(baseIndent
, "@media " + mediaLine
);
81 var selectorLine
= "";
82 var selectors
= rule
.selectorList
.selectors
;
83 for (var i
= 0; i
< selectors
.length
; ++i
) {
86 var matching
= matchingSelectors
.indexOf(i
) !== -1;
89 selectorLine
+= selectors
[i
].value
;
94 selectorLine
+= " " + rule
.origin
;
95 if (!rule
.style
.styleSheetId
)
96 selectorLine
+= " readonly";
97 indentLog(baseIndent
, selectorLine
);
98 InspectorTest
.dumpStyle(rule
.style
, baseIndent
);
99 indentLog(baseIndent
, "}");
102 InspectorTest
.dumpStyle = function(style
, baseIndent
)
106 var cssProperties
= style
.cssProperties
;
107 for (var i
= 0; i
< cssProperties
.length
; ++i
) {
108 var cssProperty
= cssProperties
[i
];
109 var propertyLine
= cssProperty
.name
+ ": " + cssProperty
.value
+ ";";
110 indentLog(baseIndent
+ 4, propertyLine
);
114 InspectorTest
.displayName = function(url
)
116 return url
.substr(url
.lastIndexOf("/") + 1);
119 InspectorTest
.loadAndDumpMatchingRulesForNode = function(nodeId
, callback
, omitLog
)
121 InspectorTest
.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId": nodeId
}, matchingRulesLoaded
);
123 function matchingRulesLoaded(result
)
126 InspectorTest
.log("Dumping matched rules: ");
127 dumpRuleMatches(result
.matchedCSSRules
);
129 InspectorTest
.log("Dumping inherited rules: ");
130 for (var inheritedEntry
of result
.inherited
) {
131 InspectorTest
.dumpStyle(inheritedEntry
.inlineStyle
);
132 dumpRuleMatches(inheritedEntry
.matchedCSSRules
);
137 function dumpRuleMatches(ruleMatches
)
139 for (var ruleMatch
of ruleMatches
) {
140 var origin
= ruleMatch
.rule
.origin
;
141 if (origin
!== "inspector" && origin
!== "regular")
143 InspectorTest
.dumpRuleMatch(ruleMatch
);
148 InspectorTest
.loadAndDumpMatchingRules = function(documentNodeId
, selector
, callback
, omitLog
)
150 InspectorTest
.requestNodeId(documentNodeId
, selector
, nodeIdLoaded
);
152 function nodeIdLoaded(nodeId
)
154 InspectorTest
.loadAndDumpMatchingRulesForNode(nodeId
, callback
, omitLog
);
158 InspectorTest
.loadAndDumpInlineAndMatchingRules = function(documentNodeId
, selector
, callback
, omitLog
)
160 InspectorTest
.requestNodeId(documentNodeId
, selector
, nodeIdLoaded
);
162 function nodeIdLoaded(id
)
165 InspectorTest
.sendCommandOrDie("CSS.getInlineStylesForNode", { "nodeId": nodeId
}, onInline
);
168 function onInline(result
)
171 InspectorTest
.log("Dumping inline style: ");
172 InspectorTest
.log("{");
173 InspectorTest
.dumpStyle(result
.inlineStyle
, 0);
174 InspectorTest
.log("}");
175 InspectorTest
.loadAndDumpMatchingRulesForNode(nodeId
, callback
, omitLog
)