3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="profiler-test.js"></script>
7 function pageFunction() {
8 console.profile("manual");
9 console.profileEnd("manual");
14 MockedFile = function()
18 MockedFile.prototype = {
19 _appendData: function(data)
31 return this._buffer.length;
34 slice: function(chunkStart, chunkEnd)
36 var blob = new Blob([this._buffer], {type: "text\/text"});
40 var file = new MockedFile();
42 InspectorTest.runProfilerTestSuite([
43 function testSave(next)
45 function waitForTempFile(view)
47 InspectorTest.addSniffer(view._profileHeader, "_writeToTempFile", saveProfileToFile.bind(this, view._profileHeader));
49 function saveProfileToFile(profile)
51 WebInspector.FileOutputStream = function() { }
52 WebInspector.FileOutputStream.prototype = {
53 open: function(fileName, callback)
56 if (fileName.endsWith(".cpuprofile")) {
57 InspectorTest.addResult("PASS: open was called with extension '.cpuprofile'");
60 InspectorTest.addResult("FAILED: open was called with wrong extension. fileName: '" + fileName + "'");
65 write: function(data, callback)
67 file._appendData(data);
69 InspectorTest.addResult("PASS: write was called with data length more than zero");
72 InspectorTest.addResult("FAILED: write was called with zero data length");
79 InspectorTest.addResult("PASS: close was called");
86 InspectorTest.showProfileWhenAdded("manual");
87 InspectorTest.waitUntilProfileViewIsShown("manual", waitForTempFile.bind(this));
88 InspectorTest.evaluateInConsole("pageFunction()", function done() {});
91 function testLoad(next)
93 var loadedProfileData;
94 function checkLoadedContent(profileView)
96 if (loadedProfileData === file._data())
97 InspectorTest.addResult("PASS: the content of loaded profile matches with the original profile.");
99 InspectorTest.addResult("FAIL: the content of loaded profile doesn't match with the original profile.");
100 InspectorTest.addResult("old: " + file._data());
101 InspectorTest.addResult("new: " + loadedProfileData);
105 var profilesPanel = WebInspector.panels.profiles;
106 var profileName = file.name.substr(0, file.name.length - ".cpuprofile".length);
107 InspectorTest.waitUntilProfileViewIsShown(profileName, checkLoadedContent);
108 profilesPanel._loadFromFile(file);
109 var onTransferFinished = WebInspector.CPUProfileHeader.prototype.onTransferFinished;
110 WebInspector.CPUProfileHeader.prototype.onTransferFinished = function()
112 loadedProfileData = this._jsonifiedProfile;
113 onTransferFinished.call(this);
114 WebInspector.panels.profiles.showProfile(this);
123 <body onload="runTest()">
125 Tests that CPU profiling is able to save/load.