summaryrefslogtreecommitdiffstats
path: root/media/base/mock_pipeline.h
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 02:05:51 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 02:05:51 +0000
commit8e0476c65cc2eb9d84a62d484c0358f9a0e325b0 (patch)
treeb24b3ec35e0c42ced3e2020c5501b280f6f7bd6d /media/base/mock_pipeline.h
parent22b23cd21840b9a148857c60a7f6ca8b0417e190 (diff)
downloadchromium_src-8e0476c65cc2eb9d84a62d484c0358f9a0e325b0.zip
chromium_src-8e0476c65cc2eb9d84a62d484c0358f9a0e325b0.tar.gz
chromium_src-8e0476c65cc2eb9d84a62d484c0358f9a0e325b0.tar.bz2
Fixed up MockFilterHost and MockPipeline to support tasks and callbacks.
I changed the constructor to MockFilterHost to *not* create and initialize filters to allow for testing for conditions where create/initialize would fail. Also multiple MockFilterHosts can now share a common MockPipeline, which simulates how it is supposed to work. Finally, updated the VideoRendererBase tests to be deterministic and completely mocked and fixing failing unittests. BUG=8379 Review URL: http://codereview.chromium.org/39234 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/mock_pipeline.h')
-rw-r--r--media/base/mock_pipeline.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/media/base/mock_pipeline.h b/media/base/mock_pipeline.h
index d353c41..8741cc2 100644
--- a/media/base/mock_pipeline.h
+++ b/media/base/mock_pipeline.h
@@ -2,9 +2,16 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
+// Mock implementation of Pipeline. Simply provides getters/setters for every
+// pipeline state variable and queues all tasks posted to the "pipeline thread."
+// Since there actually isn't a separate thread unit tests can control when
+// they want to execute queued tasks by calling RunAllTasks(), which helps to
+// assert pre- and post-conditions.
+
#ifndef MEDIA_BASE_MOCK_PIPELINE_H_
#define MEDIA_BASE_MOCK_PIPELINE_H_
+#include <deque>
#include <string>
#include "media/base/media_format.h"
@@ -117,8 +124,24 @@ class MockPipeline : public media::Pipeline {
total_bytes_ = 0;
}
- void SetInitialized(bool init_value) {
- initialized_ = init_value;
+ // Runs all queued tasks until there are no more.
+ //
+ // Although it is possible for tasks to run indefinitely (executing tasks post
+ // additional tasks), such situations should be treated as a bug. Since the
+ // pipeline is request/pull-based, only enough tasks to satisfy the request
+ // should ever be executed.
+ void RunAllTasks() {
+ while (!task_queue_.empty()) {
+ Task* task = task_queue_.front();
+ task_queue_.pop_front();
+ task->Run();
+ delete task;
+ }
+ }
+
+ void PostTask(Task* task) {
+ EXPECT_TRUE(task);
+ task_queue_.push_back(task);
}
void Error(media::PipelineError error) {
@@ -146,7 +169,6 @@ class MockPipeline : public media::Pipeline {
buffered_bytes_ = buffered_bytes;
}
- // Sets the size of the video output in pixel units.
virtual void SetVideoSize(size_t width, size_t height) {
width_ = width;
height_ = height;
@@ -165,6 +187,9 @@ class MockPipeline : public media::Pipeline {
int64 buffered_bytes_;
int64 total_bytes_;
+ typedef std::deque<Task*> TaskQueue;
+ TaskQueue task_queue_;
+
DISALLOW_COPY_AND_ASSIGN(MockPipeline);
};