blob: 9de8f7fee8a89e3e6a778bdd16f40606acdbbcac [file] [log] [blame]
<html>
<head>
<link rel="stylesheet" href="resources/styles-history.css">
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="../../http/tests/inspector/resources-test.js"></script>
<script>
function test()
{
InspectorTest.runAfterCachedResourcesProcessed(runTestSuite);
var uiSourceCode;
function runTestSuite()
{
InspectorTest.runTestSuite([
function testSetUp(next)
{
function visitUISourceCodes(currentUISourceCode)
{
if (currentUISourceCode.originURL().indexOf("styles-history.css") === -1)
return;
uiSourceCode = currentUISourceCode;
next();
}
WebInspector.workspace.uiSourceCodes().forEach(visitUISourceCodes);
},
function testSetResourceContentMinor(next)
{
InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMinor);
uiSourceCode.setWorkingCopy("body {\n margin: 15px;\n padding: 10px;\n}");
function styleUpdatedMinor()
{
dumpHistory(next)();
}
},
function testSetResourceContentMajor(next)
{
InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMinor);
uiSourceCode.setWorkingCopy("body {\n margin: 20px;\n padding: 10px;\n}");
function styleUpdatedMinor()
{
InspectorTest.addSniffer(WebInspector.StyleFile.prototype, "_styleContentSet", styleUpdatedMajor);
uiSourceCode.commitWorkingCopy(function() { });
function styleUpdatedMajor()
{
dumpHistory(next)();
}
}
},
function testSetContentViaModelMinor(next)
{
styleSheetForResource(step1);
function step1(styleSheet)
{
var style = styleSheet.rules[0].style;
var property = style.getLiveProperty("margin");
property.setText("margin:25px;", false, true, dumpHistory(next));
}
},
function testSetContentViaModelMajor(next)
{
styleSheetForResource(step1);
function step1(styleSheet)
{
var style = styleSheet.rules[0].style;
var property = style.getLiveProperty("margin");
property.setText("margin:30px;", true, true);
InspectorTest.runAfterPendingDispatches(dumpHistory(next));
}
}
]);
}
function styleSheetForResource(callback)
{
CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
function didGetAllStyleSheets(error, infos)
{
if (error) {
InspectorTest.addResult("Error:" + error);
callback(null);
return;
}
for (var i = 0; i < infos.length; ++i) {
var info = infos[i];
if (info.sourceURL.indexOf("styles-history.css") === -1)
continue;
WebInspector.CSSStyleSheet.createForId(info.styleSheetId, callback);
return;
}
callback(null);
}
}
function dumpHistory(next)
{
function result()
{
InspectorTest.addResult("History length: " + uiSourceCode.history.length);
for (var i = 0; i < uiSourceCode.history.length; ++i) {
InspectorTest.addResult("Item " + i + ":");
InspectorTest.addResult(uiSourceCode.history[i].content);
}
next();
}
return result;
}
}
</script>
</head>
<body onload="runTest()">
<p>
Tests resources panel history.
</p>
</body>
</html>