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