3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script type=
"text/javascript">
6 function initialize_ProgressBarTest()
9 InspectorTest
.MockProgressIndicator = function()
13 InspectorTest
.MockProgressIndicator
.prototype = {
14 // Implementation of WebInspector.Progress interface.
15 isCanceled: function()
17 return this._isCanceled
;
22 InspectorTest
.addResult("progress indicator: done");
25 setTotalWork: function(totalWork
)
27 this._totalWork
= totalWork
;
30 setWorked: function(worked
, title
)
32 this._worked
= worked
;
33 if (typeof title
!== "undefined")
37 setTitle: function(title
)
45 this._isCanceled
= true;
50 const roundFactor
= 10000;
52 var worked
= this._worked
;
53 var totalWork
= this._totalWork
;
55 if (typeof worked
=== "number")
56 worked
= Math
.round(worked
* roundFactor
) / roundFactor
;
57 if (typeof totalWork
=== "number")
58 totalWork
= Math
.round(totalWork
* roundFactor
) / roundFactor
;
60 InspectorTest
.addResult("progress: `" + this._title
+ "' " + worked
+ " out of " + totalWork
+ " done.");
68 InspectorTest
.runTestSuite([
69 function testOneSubProgress(next
)
71 var indicator
= new InspectorTest
.MockProgressIndicator();
72 var composite
= new WebInspector
.CompositeProgress(indicator
);
73 var subProgress
= composite
.createSubProgress();
75 InspectorTest
.addResult("Testing CompositeProgress with a single subprogress:");
77 subProgress
.setTitle("cuckooing");
78 subProgress
.setWorked(10);
80 subProgress
.setTotalWork(100);
82 subProgress
.setWorked(20, "meowing");
89 function testMultipleSubProgresses(next
)
91 var indicator
= new InspectorTest
.MockProgressIndicator();
92 var composite
= new WebInspector
.CompositeProgress(indicator
);
93 var subProgress1
= composite
.createSubProgress();
94 var subProgress2
= composite
.createSubProgress(3);
96 InspectorTest
.addResult("Testing CompositeProgress with multiple subprogresses:");
99 subProgress1
.setTitle("cuckooing");
100 subProgress1
.setTotalWork(100);
101 subProgress1
.setWorked(20);
104 subProgress2
.setWorked(10);
107 subProgress2
.setTotalWork(10);
108 subProgress2
.setWorked(3, "barking");
111 subProgress1
.setWorked(50, "meowing");
112 subProgress2
.setWorked(5);
123 function testCancel(next
)
125 var indicator
= new InspectorTest
.MockProgressIndicator();
126 var composite
= new WebInspector
.CompositeProgress(indicator
);
127 var subProgress
= composite
.createSubProgress();
129 InspectorTest
.addResult("Testing isCanceled:");
130 InspectorTest
.assertTrue(!subProgress
.isCanceled(), "progress should not be canceled");
132 InspectorTest
.assertTrue(subProgress
.isCanceled(), "progress should be canceled");
136 function testNested(next
)
138 var indicator
= new InspectorTest
.MockProgressIndicator();
139 var composite0
= new WebInspector
.CompositeProgress(indicator
);
140 var subProgress01
= composite0
.createSubProgress();
141 var composite1
= new WebInspector
.CompositeProgress(subProgress01
);
142 var subProgress11
= composite1
.createSubProgress(10); // Weight should have no effect.
144 InspectorTest
.addResult("Testing nested subprogresses:");
147 subProgress11
.setWorked(10);
150 subProgress11
.setTotalWork(100);
153 subProgress11
.setWorked(50, "meowing");
156 InspectorTest
.assertTrue(!subProgress11
.isCanceled());
158 InspectorTest
.assertTrue(subProgress11
.isCanceled());
160 subProgress11
.done();
169 <body onload=
"runTest()">
170 <p>Tests inspector's composite progress bar.
</p>