1b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// found in the LICENSE file.
4b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/basictypes.h"
6b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/bind.h"
7b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
8ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/message_loop/message_loop.h"
9b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "media/base/decoder_buffer.h"
10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "media/base/demuxer_stream.h"
11b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "media/filters/fake_demuxer_stream.h"
12b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
14b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace media {
15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)const int kNumBuffersInOneConfig = 9;
176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)const int kNumBuffersToReadFirst = 5;
186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)const int kNumConfigs = 3;
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)COMPILE_ASSERT(kNumBuffersToReadFirst < kNumBuffersInOneConfig,
20b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)               do_not_read_too_many_buffers);
21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)COMPILE_ASSERT(kNumConfigs > 0, need_multiple_configs_to_trigger_config_change);
22b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
23b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class FakeDemuxerStreamTest : public testing::Test {
24b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public:
25b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  FakeDemuxerStreamTest()
26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      : status_(DemuxerStream::kAborted),
276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)        read_pending_(false),
286d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)        num_buffers_received_(0) {}
29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual ~FakeDemuxerStreamTest() {}
30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
31b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void BufferReady(DemuxerStream::Status status,
32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                   const scoped_refptr<DecoderBuffer>& buffer) {
33b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    DCHECK(read_pending_);
34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    read_pending_ = false;
35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    status_ = status;
36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    buffer_ = buffer;
376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    if (status == DemuxerStream::kOk && !buffer->end_of_stream())
386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      num_buffers_received_++;
39b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
40b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  enum ReadResult {
42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    OK,
43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    ABORTED,
44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    CONFIG_CHANGED,
45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    EOS,
46b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    PENDING
47b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  };
48b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
49b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void EnterNormalReadState() {
50b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    stream_.reset(
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        new FakeDemuxerStream(kNumConfigs, kNumBuffersInOneConfig, false));
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for (int i = 0; i < kNumBuffersToReadFirst; ++i)
53b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      ReadAndExpect(OK);
546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    DCHECK_EQ(kNumBuffersToReadFirst, num_buffers_received_);
55b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
56b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
57b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void EnterBeforeEOSState() {
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    stream_.reset(new FakeDemuxerStream(1, kNumBuffersInOneConfig, false));
5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for (int i = 0; i < kNumBuffersInOneConfig; ++i)
60b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      ReadAndExpect(OK);
616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    DCHECK_EQ(kNumBuffersInOneConfig, num_buffers_received_);
62b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
63b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
64b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void ExpectReadResult(ReadResult result) {
65b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    switch (result) {
66b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      case OK:
67b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_FALSE(read_pending_);
68b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_EQ(DemuxerStream::kOk, status_);
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ASSERT_TRUE(buffer_.get());
70ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        EXPECT_FALSE(buffer_->end_of_stream());
71b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        break;
72b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
73b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      case ABORTED:
74b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_FALSE(read_pending_);
75b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_EQ(DemuxerStream::kAborted, status_);
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        EXPECT_FALSE(buffer_.get());
77b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        break;
78b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
79b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      case CONFIG_CHANGED:
80effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch        EXPECT_TRUE(stream_->SupportsConfigChanges());
81b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_FALSE(read_pending_);
82b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_EQ(DemuxerStream::kConfigChanged, status_);
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        EXPECT_FALSE(buffer_.get());
84b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        break;
85b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
86b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      case EOS:
87b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_FALSE(read_pending_);
88b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_EQ(DemuxerStream::kOk, status_);
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ASSERT_TRUE(buffer_.get());
90ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        EXPECT_TRUE(buffer_->end_of_stream());
91b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        break;
92b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
93b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      case PENDING:
94b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        EXPECT_TRUE(read_pending_);
95b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        break;
96b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    }
97b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
98b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
99b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void ReadAndExpect(ReadResult result) {
100b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    EXPECT_FALSE(read_pending_);
101b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    read_pending_ = true;
102b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    stream_->Read(base::Bind(&FakeDemuxerStreamTest::BufferReady,
103b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)                             base::Unretained(this)));
104b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    message_loop_.RunUntilIdle();
105b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    ExpectReadResult(result);
106b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
107b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void ReadUntilPending() {
10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    while (1) {
11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      read_pending_ = true;
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      stream_->Read(base::Bind(&FakeDemuxerStreamTest::BufferReady,
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                               base::Unretained(this)));
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      message_loop_.RunUntilIdle();
11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if (read_pending_)
11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        break;
11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    }
11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
119b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void SatisfyReadAndExpect(ReadResult result) {
120b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    EXPECT_TRUE(read_pending_);
121b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    stream_->SatisfyRead();
122b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    message_loop_.RunUntilIdle();
123b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    ExpectReadResult(result);
124b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
125b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
126b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  void Reset() {
127b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    bool had_read_pending = read_pending_;
128b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    stream_->Reset();
129b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    message_loop_.RunUntilIdle();
130b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
131b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    EXPECT_FALSE(read_pending_);
132b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    if (had_read_pending)
133b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      ExpectReadResult(ABORTED);
134b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
135b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
1366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  void ReadAllBuffers(int num_configs, int num_buffers_in_one_config) {
1376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    DCHECK_EQ(0, num_buffers_received_);
138b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    for (int i = 0; i < num_configs; ++i) {
13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      for (int j = 0; j < num_buffers_in_one_config; ++j) {
140b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        ReadAndExpect(OK);
1416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)        EXPECT_EQ(num_buffers_received_, stream_->num_buffers_returned());
14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      }
143b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
144b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      if (i == num_configs - 1)
145b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        ReadAndExpect(EOS);
146b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)      else
147b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)        ReadAndExpect(CONFIG_CHANGED);
148b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    }
149b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
150b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    // Will always get EOS after we hit EOS.
151b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    ReadAndExpect(EOS);
15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    EXPECT_EQ(num_configs * num_buffers_in_one_config, num_buffers_received_);
1546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
1556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  void TestRead(int num_configs,
1576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                int num_buffers_in_one_config,
1586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                bool is_encrypted) {
1596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    stream_.reset(new FakeDemuxerStream(
1606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)        num_configs, num_buffers_in_one_config, is_encrypted));
1616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    const VideoDecoderConfig& config = stream_->video_decoder_config();
1636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    EXPECT_TRUE(config.IsValidConfig());
1646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    EXPECT_EQ(is_encrypted, config.is_encrypted());
1656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    ReadAllBuffers(num_configs, num_buffers_in_one_config);
167b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  }
168b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
169b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  base::MessageLoop message_loop_;
170b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  scoped_ptr<FakeDemuxerStream> stream_;
171b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
172b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  DemuxerStream::Status status_;
173b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  scoped_refptr<DecoderBuffer> buffer_;
174b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  bool read_pending_;
17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  int num_buffers_received_;
176b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
177b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) private:
178b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStreamTest);
179b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)};
180b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
181b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Read_OneConfig) {
182b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  TestRead(1, 5, false);
183b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
184b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
185b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Read_MultipleConfigs) {
186b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  TestRead(3, 5, false);
187b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
188b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Read_OneBufferPerConfig) {
190b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  TestRead(3, 1, false);
191b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
192b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
193b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Read_Encrypted) {
194b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  TestRead(6, 3, true);
195b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
196b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
197b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, HoldRead_Normal) {
198b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EnterNormalReadState();
199b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  stream_->HoldNextRead();
200b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(PENDING);
201b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  SatisfyReadAndExpect(OK);
202b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
203b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
204b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, HoldRead_BeforeConfigChanged) {
20590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EnterNormalReadState();
20690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  stream_->HoldNextConfigChangeRead();
20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ReadUntilPending();
208b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  SatisfyReadAndExpect(CONFIG_CHANGED);
209b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
210b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
211b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, HoldRead_BeforeEOS) {
212b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EnterBeforeEOSState();
213b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  stream_->HoldNextRead();
214b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(PENDING);
215b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  SatisfyReadAndExpect(EOS);
216b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
217b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
218b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Reset_Normal) {
219b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EnterNormalReadState();
220b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  Reset();
221b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(OK);
222b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
223b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
224b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Reset_AfterHoldRead) {
225b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EnterNormalReadState();
226b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  stream_->HoldNextRead();
227b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  Reset();
228b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(OK);
229b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
230b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
231b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Reset_DuringPendingRead) {
232b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EnterNormalReadState();
233b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  stream_->HoldNextRead();
234b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(PENDING);
235b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  Reset();
236b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(OK);
237b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
238b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
239b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Reset_BeforeConfigChanged) {
24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EnterNormalReadState();
24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  stream_->HoldNextConfigChangeRead();
24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ReadUntilPending();
243b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  Reset();
244b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(CONFIG_CHANGED);
245b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
246b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
247b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST_F(FakeDemuxerStreamTest, Reset_BeforeEOS) {
248b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  EnterBeforeEOSState();
249b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  stream_->HoldNextRead();
250b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(PENDING);
251b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  Reset();
252b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ReadAndExpect(EOS);
253b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}
254b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
255effb81e5f8246d0db0270817048dc992db66e9fbBen MurdochTEST_F(FakeDemuxerStreamTest, NoConfigChanges) {
256effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  stream_.reset(
257effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      new FakeDemuxerStream(1, kNumBuffersInOneConfig, false));
258effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  EXPECT_FALSE(stream_->SupportsConfigChanges());
259effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  for (int i = 0; i < kNumBuffersInOneConfig; ++i)
260effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    ReadAndExpect(OK);
261effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ReadAndExpect(EOS);
262effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}
263effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
2646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(FakeDemuxerStreamTest, SeekToStart_Normal) {
2656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EnterNormalReadState();
2666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  stream_->SeekToStart();
2676d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  num_buffers_received_ = 0;
2686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  ReadAllBuffers(kNumConfigs, kNumBuffersInOneConfig);
2696d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(FakeDemuxerStreamTest, SeekToStart_BeforeEOS) {
2726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EnterBeforeEOSState();
2736d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  stream_->SeekToStart();
2746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  num_buffers_received_ = 0;
2756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  ReadAllBuffers(1, kNumBuffersInOneConfig);
2766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2786d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(FakeDemuxerStreamTest, SeekToStart_AfterEOS) {
2796d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  TestRead(3, 5, false);
2806d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  stream_->SeekToStart();
2816d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  num_buffers_received_ = 0;
2826d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  ReadAllBuffers(3, 5);
2836d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
285b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace media
286