Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / profiler / profiler-test.js
1 var initialize_ProfilerTest = function() {
2
3 InspectorTest.startProfilerTest = function(callback)
4 {
5     WebInspector.showPanel("profiles");
6
7     InspectorTest.addResult("Profiler was enabled.");
8     InspectorTest.addSniffer(WebInspector.panels.profiles, "_addProfileHeader", InspectorTest._profileHeaderAdded, true);
9     InspectorTest.addSniffer(WebInspector.CPUProfileView.prototype, "refresh", InspectorTest._profileViewRefresh, true);
10     InspectorTest.safeWrap(callback)();
11 };
12
13 InspectorTest.completeProfilerTest = function()
14 {
15     InspectorTest.addResult("");
16     InspectorTest.addResult("Profiler was disabled.");
17     InspectorTest.completeTest();
18 };
19
20 InspectorTest.runProfilerTestSuite = function(testSuite)
21 {
22     var testSuiteTests = testSuite.slice();
23
24     function runner()
25     {
26         if (!testSuiteTests.length) {
27             InspectorTest.completeProfilerTest();
28             return;
29         }
30
31         var nextTest = testSuiteTests.shift();
32         InspectorTest.addResult("");
33         InspectorTest.addResult("Running: " + /function\s([^(]*)/.exec(nextTest)[1]);
34         InspectorTest.safeWrap(nextTest)(runner, runner);
35     }
36
37     InspectorTest.startProfilerTest(runner);
38 };
39
40 InspectorTest.showProfileWhenAdded = function(title)
41 {
42     InspectorTest._showProfileWhenAdded = title;
43 };
44
45 InspectorTest._profileHeaderAdded = function(profile)
46 {
47     if (InspectorTest._showProfileWhenAdded === profile.title)
48         WebInspector.panels.profiles.showProfile(profile);
49 };
50
51 InspectorTest.waitUntilProfileViewIsShown = function(title, callback)
52 {
53     callback = InspectorTest.safeWrap(callback);
54
55     var profilesPanel = WebInspector.panels.profiles;
56     if (profilesPanel.visibleView && profilesPanel.visibleView.profile && profilesPanel.visibleView.profile.title === title)
57         callback(profilesPanel.visibleView);
58     else
59         InspectorTest._waitUntilProfileViewIsShownCallback = { title: title, callback: callback };
60 }
61
62 InspectorTest._profileViewRefresh = function()
63 {
64     // Called in the context of ProfileView.
65     if (InspectorTest._waitUntilProfileViewIsShownCallback && InspectorTest._waitUntilProfileViewIsShownCallback.title === this.profile.title) {
66         var callback = InspectorTest._waitUntilProfileViewIsShownCallback;
67         delete InspectorTest._waitUntilProfileViewIsShownCallback;
68         callback.callback(this);
69     }
70 };
71
72 };