summaryrefslogtreecommitdiffstats
path: root/media/blink/buffered_data_source_host_impl_unittest.cc
blob: 54ecf75c3b6ea6652d8af115800b0d502a868bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/macros.h"
#include "media/blink/buffered_data_source_host_impl.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {

class BufferedDataSourceHostImplTest : public testing::Test {
 public:
  BufferedDataSourceHostImplTest() {}

  void Add() {
    host_.AddBufferedTimeRanges(&ranges_, base::TimeDelta::FromSeconds(10));
  }

 protected:
  BufferedDataSourceHostImpl host_;
  Ranges<base::TimeDelta> ranges_;

  DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImplTest);
};

TEST_F(BufferedDataSourceHostImplTest, Empty) {
  EXPECT_FALSE(host_.DidLoadingProgress());
  Add();
  EXPECT_EQ(0u, ranges_.size());
}

TEST_F(BufferedDataSourceHostImplTest, AddBufferedTimeRanges) {
  host_.AddBufferedByteRange(10, 20);
  host_.SetTotalBytes(100);
  Add();
  EXPECT_EQ(1u, ranges_.size());
  EXPECT_EQ(base::TimeDelta::FromSeconds(1), ranges_.start(0));
  EXPECT_EQ(base::TimeDelta::FromSeconds(2), ranges_.end(0));
}

TEST_F(BufferedDataSourceHostImplTest, AddBufferedTimeRanges_Merges) {
  ranges_.Add(base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1));
  host_.AddBufferedByteRange(10, 20);
  host_.SetTotalBytes(100);
  Add();
  EXPECT_EQ(1u, ranges_.size());
  EXPECT_EQ(base::TimeDelta::FromSeconds(0), ranges_.start(0));
  EXPECT_EQ(base::TimeDelta::FromSeconds(2), ranges_.end(0));
}

TEST_F(BufferedDataSourceHostImplTest, AddBufferedTimeRanges_Snaps) {
  host_.AddBufferedByteRange(5, 995);
  host_.SetTotalBytes(1000);
  Add();
  EXPECT_EQ(1u, ranges_.size());
  EXPECT_EQ(base::TimeDelta::FromSeconds(0), ranges_.start(0));
  EXPECT_EQ(base::TimeDelta::FromSeconds(10), ranges_.end(0));
}

TEST_F(BufferedDataSourceHostImplTest, SetTotalBytes) {
  host_.AddBufferedByteRange(10, 20);
  Add();
  EXPECT_EQ(0u, ranges_.size());

  host_.SetTotalBytes(100);
  Add();
  EXPECT_EQ(1u, ranges_.size());
}

TEST_F(BufferedDataSourceHostImplTest, DidLoadingProgress) {
  host_.AddBufferedByteRange(10, 20);
  EXPECT_TRUE(host_.DidLoadingProgress());
  EXPECT_FALSE(host_.DidLoadingProgress());
}

}  // namespace media