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

Unified 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: compile fixes Created 5 years, 1 month 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
« media/blink/url_index.cc ('K') | « media/blink/url_index.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/url_index_unittest.cc
diff --git a/media/blink/url_index_unittest.cc b/media/blink/url_index_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..58d34b29206d8f4768431968b37abc8f90d2d9da
--- /dev/null
+++ b/media/blink/url_index_unittest.cc
@@ -0,0 +1,157 @@
+// Copyright 2015 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 <stdint.h>
+
+#include <list>
+#include <string>
+
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+#include "media/blink/url_index.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+class UrlIndexTest : public testing::Test {
+ public:
+ UrlIndexTest() : url_index_(NULL) {}
xhwang 2015/11/19 23:34:19 nit: s/NULL/nullptr
hubbe 2015/11/20 23:24:24 Done.
+
+ scoped_refptr<UrlData> GetByUrl(const GURL& gurl,
+ UrlData::CORSMode cors_mode) {
+ scoped_refptr<UrlData> ret = url_index_.GetByUrl(gurl, cors_mode);
+ EXPECT_EQ(ret->url(), gurl);
+ EXPECT_EQ(ret->cors_mode(), cors_mode);
+ return ret;
+ }
+
+ UrlIndex url_index_;
+};
+
+TEST_F(UrlIndexTest, SimpleTest) {
+ GURL url1("http://foo.bar.com");
+ GURL url2("http://foo.bar.com/urgel");
+ scoped_refptr<UrlData> a = GetByUrl(url1, UrlData::kUnspecified);
+ // Make sure it's valid, we still shouldn't get the same one.
+ a->Use();
+ a->set_range_supported();
+ EXPECT_TRUE(a->Valid());
+ EXPECT_EQ(a, url_index_.TryInsert(a));
+ scoped_refptr<UrlData> b = GetByUrl(url1, UrlData::kAnonymous);
+ b->Use();
+ b->set_range_supported();
+ EXPECT_TRUE(b->Valid());
+ EXPECT_EQ(b, url_index_.TryInsert(b));
+ scoped_refptr<UrlData> c = GetByUrl(url1, UrlData::kUseCredentials);
+ c->Use();
+ c->set_range_supported();
+ EXPECT_TRUE(c->Valid());
+ EXPECT_EQ(c, url_index_.TryInsert(c));
+ scoped_refptr<UrlData> d = GetByUrl(url2, UrlData::kUnspecified);
+ d->Use();
+ d->set_range_supported();
+ EXPECT_TRUE(d->Valid());
+ EXPECT_EQ(d, url_index_.TryInsert(d));
+
+ EXPECT_NE(a, b);
+ EXPECT_NE(a, c);
+ EXPECT_NE(a, d);
+ EXPECT_NE(b, c);
+ EXPECT_NE(b, d);
+ EXPECT_NE(c, d);
+ EXPECT_EQ(a, GetByUrl(url1, UrlData::kUnspecified));
+ EXPECT_EQ(b, GetByUrl(url1, UrlData::kAnonymous));
+ EXPECT_EQ(c, GetByUrl(url1, UrlData::kUseCredentials));
+ EXPECT_EQ(d, GetByUrl(url2, UrlData::kUnspecified));
+}
+
+TEST_F(UrlIndexTest, UrlDataTest) {
+ GURL url("http://foo.bar.com");
+ scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified);
+
+ // Check default values.
+ EXPECT_FALSE(a->range_supported());
+ EXPECT_FALSE(a->cacheable());
+ EXPECT_EQ(a->length(), kPositionNotSpecified);
+ EXPECT_FALSE(a->Valid());
+
+ a->set_length(117);
+ EXPECT_EQ(a->length(), 117);
+
+ a->set_cacheable(true);
+ EXPECT_TRUE(a->cacheable());
+
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeTicks valid_until = now + base::TimeDelta::FromSeconds(500);
+ a->set_valid_until(valid_until);
+ a->set_range_supported();
+ EXPECT_EQ(valid_until, a->valid_until());
+ EXPECT_TRUE(a->Valid());
+
+ base::Time time_now = base::Time::Now();
+ base::Time last_modified = time_now - base::TimeDelta::FromSeconds(500);
+ a->set_last_modified(last_modified);
+ EXPECT_EQ(last_modified, a->last_modified());
+}
+
+TEST_F(UrlIndexTest, UseTest) {
+ GURL url("http://foo.bar.com");
+ scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified);
+ EXPECT_FALSE(a->Valid());
+ a->Use();
+ a->set_range_supported();
+ EXPECT_TRUE(a->Valid());
+}
+
+TEST_F(UrlIndexTest, TryInsert) {
+ GURL url("http://foo.bar.com");
+ scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified);
+ scoped_refptr<UrlData> c = GetByUrl(url, UrlData::kUnspecified);
+ EXPECT_NE(a, c);
+ EXPECT_FALSE(a->Valid());
+ base::Time now_time = base::Time::Now();
+ base::Time last_modified = now_time - base::TimeDelta::FromSeconds(500);
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeTicks valid_until = now + base::TimeDelta::FromSeconds(500);
+
+ // Not sharable yet. (no ranges)
+ EXPECT_EQ(a, url_index_.TryInsert(a));
+ EXPECT_NE(a, GetByUrl(url, UrlData::kUnspecified));
+ a->set_last_modified(last_modified);
+
+ // Not sharable yet. (no ranges)
+ EXPECT_EQ(a, url_index_.TryInsert(a));
+ EXPECT_NE(a, GetByUrl(url, UrlData::kUnspecified));
+
+ // Now we should be able to insert it into the index.
+ a->set_range_supported();
+ a->set_valid_until(valid_until);
+ EXPECT_TRUE(a->Valid());
+ EXPECT_EQ(a, url_index_.TryInsert(a));
+ EXPECT_EQ(a, GetByUrl(url, UrlData::kUnspecified));
+
+ // |a| becomes expired...
+ a->set_valid_until(now - base::TimeDelta::FromSeconds(1));
+ scoped_refptr<UrlData> b = GetByUrl(url, UrlData::kUnspecified);
+ EXPECT_NE(a, b);
+
+ b->set_range_supported();
+ b->set_valid_until(valid_until);
+ b->set_last_modified(last_modified);
+ EXPECT_TRUE(b->Valid());
+
+ EXPECT_EQ(b, url_index_.TryInsert(b));
+ EXPECT_EQ(b, GetByUrl(url, UrlData::kUnspecified));
+
+ c->set_range_supported();
+ c->set_valid_until(valid_until);
+ c->set_last_modified(last_modified);
+ EXPECT_TRUE(c->Valid());
+
+ // B is still valid, so it should be preferred over C.
+ EXPECT_EQ(b, url_index_.TryInsert(c));
+ EXPECT_EQ(b, GetByUrl(url, UrlData::kUnspecified));
+}
+
+} // namespace media
« media/blink/url_index.cc ('K') | « media/blink/url_index.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698