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

Side by Side Diff: media/blink/url_index_unittest.cc

Issue 1399603003: Tie multibuffers to URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_cache
Patch Set: formatted Created 5 years 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 unified diff | Download patch
« no previous file with comments | « media/blink/url_index.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6
7 #include <list>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h"
12 #include "media/blink/url_index.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media {
16
17 class UrlIndexTest : public testing::Test {
18 public:
19 UrlIndexTest() : url_index_(nullptr) {}
20
21 scoped_refptr<UrlData> GetByUrl(const GURL& gurl,
22 UrlData::CORSMode cors_mode) {
23 scoped_refptr<UrlData> ret = url_index_.GetByUrl(gurl, cors_mode);
24 EXPECT_EQ(ret->url(), gurl);
25 EXPECT_EQ(ret->cors_mode(), cors_mode);
26 return ret;
27 }
28
29 UrlIndex url_index_;
30 };
31
32 TEST_F(UrlIndexTest, SimpleTest) {
33 GURL url1("http://foo.bar.com");
34 GURL url2("http://foo.bar.com/urgel");
35 scoped_refptr<UrlData> a = GetByUrl(url1, UrlData::CORS_UNSPECIFIED);
36 // Make sure it's valid, we still shouldn't get the same one.
37 a->Use();
38 a->set_range_supported();
39 EXPECT_TRUE(a->Valid());
40 EXPECT_EQ(a, url_index_.TryInsert(a));
41 scoped_refptr<UrlData> b = GetByUrl(url1, UrlData::CORS_ANONYMOUS);
42 b->Use();
43 b->set_range_supported();
44 EXPECT_TRUE(b->Valid());
45 EXPECT_EQ(b, url_index_.TryInsert(b));
46 scoped_refptr<UrlData> c = GetByUrl(url1, UrlData::CORS_USE_CREDENTIALS);
47 c->Use();
48 c->set_range_supported();
49 EXPECT_TRUE(c->Valid());
50 EXPECT_EQ(c, url_index_.TryInsert(c));
51 scoped_refptr<UrlData> d = GetByUrl(url2, UrlData::CORS_UNSPECIFIED);
52 d->Use();
53 d->set_range_supported();
54 EXPECT_TRUE(d->Valid());
55 EXPECT_EQ(d, url_index_.TryInsert(d));
56
57 EXPECT_NE(a, b);
58 EXPECT_NE(a, c);
59 EXPECT_NE(a, d);
60 EXPECT_NE(b, c);
61 EXPECT_NE(b, d);
62 EXPECT_NE(c, d);
63 EXPECT_EQ(a, GetByUrl(url1, UrlData::CORS_UNSPECIFIED));
64 EXPECT_EQ(b, GetByUrl(url1, UrlData::CORS_ANONYMOUS));
65 EXPECT_EQ(c, GetByUrl(url1, UrlData::CORS_USE_CREDENTIALS));
66 EXPECT_EQ(d, GetByUrl(url2, UrlData::CORS_UNSPECIFIED));
67 }
68
69 TEST_F(UrlIndexTest, UrlDataTest) {
70 GURL url("http://foo.bar.com");
71 scoped_refptr<UrlData> a = GetByUrl(url, UrlData::CORS_UNSPECIFIED);
72
73 // Check default values.
74 EXPECT_FALSE(a->range_supported());
75 EXPECT_FALSE(a->cacheable());
76 EXPECT_EQ(a->length(), kPositionNotSpecified);
77 EXPECT_FALSE(a->Valid());
78
79 a->set_length(117);
80 EXPECT_EQ(a->length(), 117);
81
82 a->set_cacheable(true);
83 EXPECT_TRUE(a->cacheable());
84
85 base::Time now = base::Time::Now();
86 base::Time valid_until = now + base::TimeDelta::FromSeconds(500);
87 a->set_valid_until(valid_until);
88 a->set_range_supported();
89 EXPECT_EQ(valid_until, a->valid_until());
90 EXPECT_TRUE(a->Valid());
91
92 base::Time last_modified = now - base::TimeDelta::FromSeconds(500);
93 a->set_last_modified(last_modified);
94 EXPECT_EQ(last_modified, a->last_modified());
95 }
96
97 TEST_F(UrlIndexTest, UseTest) {
98 GURL url("http://foo.bar.com");
99 scoped_refptr<UrlData> a = GetByUrl(url, UrlData::CORS_UNSPECIFIED);
100 EXPECT_FALSE(a->Valid());
101 a->Use();
102 a->set_range_supported();
103 EXPECT_TRUE(a->Valid());
104 }
105
106 TEST_F(UrlIndexTest, TryInsert) {
107 GURL url("http://foo.bar.com");
108 scoped_refptr<UrlData> a = GetByUrl(url, UrlData::CORS_UNSPECIFIED);
109 scoped_refptr<UrlData> c = GetByUrl(url, UrlData::CORS_UNSPECIFIED);
110 EXPECT_NE(a, c);
111 EXPECT_FALSE(a->Valid());
112 base::Time now = base::Time::Now();
113 base::Time last_modified = now - base::TimeDelta::FromSeconds(500);
114 base::Time valid_until = now + base::TimeDelta::FromSeconds(500);
115
116 // Not sharable yet. (no ranges)
117 EXPECT_EQ(a, url_index_.TryInsert(a));
118 EXPECT_NE(a, GetByUrl(url, UrlData::CORS_UNSPECIFIED));
119 a->set_last_modified(last_modified);
120
121 // Not sharable yet. (no ranges)
122 EXPECT_EQ(a, url_index_.TryInsert(a));
123 EXPECT_NE(a, GetByUrl(url, UrlData::CORS_UNSPECIFIED));
124
125 // Now we should be able to insert it into the index.
126 a->set_range_supported();
127 a->set_valid_until(valid_until);
128 EXPECT_TRUE(a->Valid());
129 EXPECT_EQ(a, url_index_.TryInsert(a));
130 EXPECT_EQ(a, GetByUrl(url, UrlData::CORS_UNSPECIFIED));
131
132 // |a| becomes expired...
133 a->set_valid_until(now - base::TimeDelta::FromSeconds(100));
134 EXPECT_FALSE(a->Valid());
135 scoped_refptr<UrlData> b = GetByUrl(url, UrlData::CORS_UNSPECIFIED);
136 EXPECT_NE(a, b);
137
138 b->set_range_supported();
139 b->set_valid_until(valid_until);
140 b->set_last_modified(last_modified);
141 EXPECT_TRUE(b->Valid());
142
143 EXPECT_EQ(b, url_index_.TryInsert(b));
144 EXPECT_EQ(b, GetByUrl(url, UrlData::CORS_UNSPECIFIED));
145
146 c->set_range_supported();
147 c->set_valid_until(valid_until);
148 c->set_last_modified(last_modified);
149 EXPECT_TRUE(c->Valid());
150
151 // B is still valid, so it should be preferred over C.
152 EXPECT_EQ(b, url_index_.TryInsert(c));
153 EXPECT_EQ(b, GetByUrl(url, UrlData::CORS_UNSPECIFIED));
154 }
155
156 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/url_index.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698