Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7098)

Unified Diff: chrome/test/data/media/html/benchmark.js

Issue 9960063: CNS seek tests for <video>. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/media/html/benchmark.js
diff --git a/chrome/test/data/media/html/benchmark.js b/chrome/test/data/media/html/benchmark.js
new file mode 100644
index 0000000000000000000000000000000000000000..7a0e9d436d5045e46690a7ba1a72c37639bd2770
--- /dev/null
+++ b/chrome/test/data/media/html/benchmark.js
@@ -0,0 +1,130 @@
+
DaleCurtis 2012/04/10 23:00:06 Header w/ details on where this is from? Will thi
+// The purpose of generateSrc() is to return a URL that is not cached.
+function generateSrc(src) {
+ return src;
DaleCurtis 2012/04/10 23:00:06 Dead code?
+ var ch = src.indexOf('?') >= 0 ? '&' : '?';
+ return src + ch + 't=' + (new Date()).getTime();
+}
+
+function Timer() {
+ this.start_ = 0;
+ this.times_ = [];
+ new Date().getTime();
DaleCurtis 2012/04/10 23:00:06 Why?
+}
+
+Timer.prototype = {
+ start: function() {
+ this.start_ = new Date().getTime();
+ },
+
+ stop: function() {
+ this.times_.push((new Date().getTime()) - this.start_);
DaleCurtis 2012/04/10 23:00:06 Extra parens seem unnecessary?
+ // console.log(this.times_[this.times_.length - 1]);
DaleCurtis 2012/04/10 23:00:06 Comment?
+ },
+
+ average: function() {
+ var sum = 0;
+ for (var i in this.times_) {
DaleCurtis 2012/04/10 23:00:06 In w/ arrays can get messy. http://stackoverflow.
+ sum += this.times_[i];
+ }
+ return sum / this.times_.length;
+ },
+
+ reset: function() {
+ this.start_ = 0;
+ this.times_ = [];
+ }
+}
+
+function Benchmark(video, src) {
+ this.video_ = video;
+ this.src_ = src;
+ this.cached_src_ = generateSrc(src);
+ this.timer_ = new Timer;
DaleCurtis 2012/04/10 23:00:06 Timer() ?
+
+ var me = this;
+ this.video_.addEventListener('playing', function() { me.playing(); });
+ this.video_.addEventListener('seeked', function() { me.seeked(); });
+ this.video_.addEventListener('suspend', function() { me.suspend(); });
+ this.video_.addEventListener('error', function() { me.error(); });
+};
+
+Benchmark.prototype = {
+ reset: function() {
+ this.playing = function() {};
+ this.seeked = function() {};
+ this.suspend = function() {};
+ this.error = function() {};
+
+ this.video_.src = '';
+ this.video_.load();
+ },
+
+ testShortSeek: function(iterations, done_cb) {
+ console.log('Starting short seek tests...');
+ this.reset();
+ this.error = function() { done_cb(false, "Error loading media"); }
DaleCurtis 2012/04/10 23:00:06 s/"/'/
+
+ var times = 0;
+ var timer = new Timer;
+ var firstPlaying = function() {
+ this.playing = function() {}
+
+ timer.start();
+ this.video_.currentTime = 1;
+ };
+
+ this.seeked = function() {
+ timer.stop();
+ times++;
+
+ if (times == iterations) {
+ this.reset();
+ done_cb(true, timer.times_);
+ return;
+ }
+
+ this.playing = firstPlaying;
+ this.video_.src = generateSrc(this.src_);
+ this.video_.load();
+ };
+
+ this.playing = firstPlaying;
+ this.video_.src = generateSrc(this.src_);
+ this.video_.load();
+ },
+
+ testLongSeek: function(iterations, done_cb) {
DaleCurtis 2012/04/10 23:00:06 Both these functions seem do exactly the same thin
+ console.log('Starting long seek tests...');
+ this.reset();
+ this.error = function() { done_cb(false, "Error loading media"); }
+ var times = 0;
+ var timer = new Timer;
+
+ var firstPlaying = function() {
+ this.playing = function() {}
+
+ timer.start();
+ this.video_.currentTime = this.video_.duration - 1;
+ };
+
+ this.seeked = function() {
+ timer.stop();
+ times++;
+
+ if (times == iterations) {
+ this.reset();
+ done_cb(true, timer.times_);
+ return;
+ }
+
+ this.playing = firstPlaying;
+ this.video_.src = generateSrc(this.src_);
+ this.video_.load();
+ };
+
+ this.playing = firstPlaying;
+ this.video_.src = generateSrc(this.src_);
+ this.video_.load();
+ }
+};
« no previous file with comments | « no previous file | chrome/test/data/media/html/media_seek.html » ('j') | chrome/test/data/media/html/media_seek.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698