blob: f7da92eae8a2b1cbd0d681b05ecfc9a5101aef51 [file] [log] [blame]
<html>
<head>
<script src="../http/tests/inspector/inspector-test.js"></script>
<script src="../http/tests/inspector/sources-test.js"></script>
<script>
function test()
{
function createMockProject()
{
var workspace = new WebInspector.Workspace();
var project = new WebInspector.ContentProviderBasedProject(workspace, "");
workspace.addProject(project);
project.requestFileContent = function(uri, callback)
{
callback("<script content>");
}
project.setFileContent = function(uri, newContent, callback)
{
}
return project;
}
function dumpUISourceCodeWithRevisions(uiSourceCode)
{
var content = uiSourceCode._content;
var revisionsString = "";
for (var i = 0; i < uiSourceCode.history.length; ++i) {
var revision = uiSourceCode.history[i];
if (i !== 0)
revisionsString += ", ";
revisionsString += "'" + revision.content + "'";
}
InspectorTest.addResult("UISourceCode content: " + content);
InspectorTest.addResult(" revisions: " + revisionsString);
}
InspectorTest.runTestSuite([
function testAddRevisionsRevertToOriginal(next)
{
var uiSourceCode = new WebInspector.UISourceCode(createMockProject(), "url", WebInspector.resourceTypes.Script);
uiSourceCode.setWorkingCopy("content1");
uiSourceCode.setWorkingCopy("content2");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("First revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content3");
uiSourceCode.setWorkingCopy("content4");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("Second revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.revertToOriginal().then(onReverted);
function onReverted()
{
InspectorTest.addResult("Reverted to original.");
dumpUISourceCodeWithRevisions(uiSourceCode);
next();
}
},
function testAddRevisionsRevertAndClearHistory(next)
{
var uiSourceCode = new WebInspector.UISourceCode(createMockProject(), "url2", WebInspector.resourceTypes.Script);
uiSourceCode.setWorkingCopy("content1");
uiSourceCode.setWorkingCopy("content2");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("First revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content3");
uiSourceCode.setWorkingCopy("content4");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("Second revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.revertAndClearHistory(revertedAndClearedHistory);
function revertedAndClearedHistory()
{
InspectorTest.addResult("Reverted and cleared history.");
dumpUISourceCodeWithRevisions(uiSourceCode);
next();
}
},
function testAddRevisionsRevertToPrevious(next)
{
var uiSourceCode = new WebInspector.UISourceCode(createMockProject(), "url3", WebInspector.resourceTypes.Script);
uiSourceCode.setWorkingCopy("content1");
uiSourceCode.setWorkingCopy("content2");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("First revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content3");
uiSourceCode.setWorkingCopy("content4");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("Second revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.history[0].revertToThis().then(onReverted);
function onReverted()
{
InspectorTest.addResult("Reverted to previous revision.");
dumpUISourceCodeWithRevisions(uiSourceCode);
next();
}
},
function testRequestContentAddRevisionsRevertToOriginal(next)
{
var uiSourceCode = new WebInspector.UISourceCode(createMockProject(), "url4", WebInspector.resourceTypes.Script);
uiSourceCode.requestContent().then(contentReceived);
function contentReceived()
{
InspectorTest.addResult("Content requested.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content1");
uiSourceCode.setWorkingCopy("content2");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("First revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content3");
uiSourceCode.setWorkingCopy("content4");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("Second revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.revertToOriginal().then(onReverted);
function onReverted()
{
InspectorTest.addResult("Reverted to original.");
dumpUISourceCodeWithRevisions(uiSourceCode);
next();
}
}
},
function testRequestContentAddRevisionsRevertAndClearHistory(next)
{
var uiSourceCode = new WebInspector.UISourceCode(createMockProject(), "url5", WebInspector.resourceTypes.Script);
uiSourceCode.requestContent().then(contentReceived);
function contentReceived()
{
InspectorTest.addResult("Content requested.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content1");
uiSourceCode.setWorkingCopy("content2");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("First revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content3");
uiSourceCode.setWorkingCopy("content4");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("Second revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.revertAndClearHistory(revertedAndClearedHistory);
function revertedAndClearedHistory()
{
InspectorTest.addResult("Reverted and cleared history.");
dumpUISourceCodeWithRevisions(uiSourceCode);
next();
}
}
},
function testRequestContentAddRevisionsRevertToPrevious(next)
{
var uiSourceCode = new WebInspector.UISourceCode(createMockProject(), "url6", WebInspector.resourceTypes.Script);
uiSourceCode.requestContent().then(contentReceived);
function contentReceived()
{
InspectorTest.addResult("Content requested.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content1");
uiSourceCode.setWorkingCopy("content2");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("First revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.setWorkingCopy("content3");
uiSourceCode.setWorkingCopy("content4");
uiSourceCode.commitWorkingCopy(function() { });
InspectorTest.addResult("Second revision added.");
dumpUISourceCodeWithRevisions(uiSourceCode);
uiSourceCode.history[0].revertToThis().then(onReverted);
function onReverted()
{
InspectorTest.addResult("Reverted to previous revision.");
dumpUISourceCodeWithRevisions(uiSourceCode);
next();
}
}
},
]);
}
</script>
</head>
<body onload="runTest()">
<p>Tests revision support in UISourceCode.</p>
<a href="https://bugs.webkit.org/show_bug.cgi?id=97669">Bug 97669</a>
</body>
</html>