Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / profiler / cpu-profiler-save-load.html
1 <html>
2 <head>
3   <script src="../../http/tests/inspector/inspector-test.js"></script>
4   <script src="profiler-test.js"></script>
5 <script>
6
7 function pageFunction() {
8     console.profile("manual");
9     console.profileEnd("manual");
10 }
11
12 function test()
13 {
14     MockedFile = function()
15     {
16         this._buffer = "";
17     }
18     MockedFile.prototype = {
19         _appendData: function(data)
20         {
21             this._buffer += data;
22         },
23
24         _data: function()
25         {
26             return this._buffer
27         },
28
29         get size()
30         {
31             return this._buffer.length;
32         },
33
34         slice: function(chunkStart, chunkEnd)
35         {
36             var blob = new Blob([this._buffer], {type: "text\/text"});
37             return blob;
38         }
39     };
40     var file = new MockedFile();
41
42     InspectorTest.runProfilerTestSuite([
43         function testSave(next)
44         {
45             function waitForTempFile(view)
46             {
47                 InspectorTest.addSniffer(view._profileHeader, "_writeToTempFile", saveProfileToFile.bind(this, view._profileHeader));
48             }
49             function saveProfileToFile(profile)
50             {
51                 WebInspector.FileOutputStream = function() { }
52                 WebInspector.FileOutputStream.prototype = {
53                     open: function(fileName, callback)
54                     {
55                         file.name = fileName;
56                         if (fileName.endsWith(".cpuprofile")) {
57                             InspectorTest.addResult("PASS: open was called with extension '.cpuprofile'");
58                             callback(true);
59                         } else {
60                             InspectorTest.addResult("FAILED: open was called with wrong extension. fileName: '" + fileName + "'");
61                             next();
62                         }
63                     },
64
65                     write: function(data, callback)
66                     {
67                         file._appendData(data);
68                         if (data.length) {
69                             InspectorTest.addResult("PASS: write was called with data length more than zero");
70                             callback(this);
71                         } else {
72                             InspectorTest.addResult("FAILED: write was called with zero data length");
73                             next();
74                         }
75                     },
76
77                     close: function()
78                     {
79                         InspectorTest.addResult("PASS: close was called");
80                         next();
81                     }
82                 }
83
84                 profile.saveToFile();
85             }
86             InspectorTest.showProfileWhenAdded("manual");
87             InspectorTest.waitUntilProfileViewIsShown("manual", waitForTempFile.bind(this));
88             InspectorTest.evaluateInConsole("pageFunction()", function done() {});
89         },
90
91         function testLoad(next)
92         {
93             var loadedProfileData;
94             function checkLoadedContent(profileView)
95             {
96                 if (loadedProfileData === file._data())
97                     InspectorTest.addResult("PASS: the content of loaded profile matches with the original profile.");
98                 else {
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);
102                 }
103                 next();
104             }
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()
111             {
112                 loadedProfileData = this._jsonifiedProfile;
113                 onTransferFinished.call(this);
114                 WebInspector.panels.profiles.showProfile(this);
115             }
116         }
117
118     ]);
119 }
120
121 </script>
122 </head>
123 <body onload="runTest()">
124 <p>
125 Tests that CPU profiling is able to save/load.
126
127 </p>
128 </body>
129 </html>