Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / progress-bar.html
blob4513a126c5eabd834b040be363e1af33939029ea
1 <html>
2 <head>
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;
20 done: function()
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")
34 this._title = title;
37 setTitle: function(title)
39 this._title = title;
42 // Test methods.
43 cancel: function()
45 this._isCanceled = true;
48 dump: function()
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.");
66 var test = function()
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:");
76 indicator.dump();
77 subProgress.setTitle("cuckooing");
78 subProgress.setWorked(10);
79 indicator.dump();
80 subProgress.setTotalWork(100);
81 indicator.dump();
82 subProgress.setWorked(20, "meowing");
83 indicator.dump();
84 subProgress.done();
85 indicator.dump();
86 next();
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:");
97 indicator.dump();
99 subProgress1.setTitle("cuckooing");
100 subProgress1.setTotalWork(100);
101 subProgress1.setWorked(20);
102 indicator.dump();
104 subProgress2.setWorked(10);
105 indicator.dump();
107 subProgress2.setTotalWork(10);
108 subProgress2.setWorked(3, "barking");
109 indicator.dump();
111 subProgress1.setWorked(50, "meowing");
112 subProgress2.setWorked(5);
113 indicator.dump();
115 subProgress2.done();
116 indicator.dump();
118 subProgress1.done();
119 indicator.dump();
120 next();
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");
131 indicator.cancel();
132 InspectorTest.assertTrue(subProgress.isCanceled(), "progress should be canceled");
133 next();
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:");
145 indicator.dump();
147 subProgress11.setWorked(10);
148 indicator.dump();
150 subProgress11.setTotalWork(100);
151 indicator.dump();
153 subProgress11.setWorked(50, "meowing");
154 indicator.dump();
156 InspectorTest.assertTrue(!subProgress11.isCanceled());
157 indicator.cancel();
158 InspectorTest.assertTrue(subProgress11.isCanceled());
160 subProgress11.done();
161 indicator.dump();
162 next();
167 </script>
168 </head>
169 <body onload="runTest()">
170 <p>Tests inspector's composite progress bar.</p>
171 </body>
172 </html>