Index: media/blink/url_index_unittests.cc |
diff --git a/media/blink/url_index_unittests.cc b/media/blink/url_index_unittests.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3613eb521885f55dd75459392f901927f0b6fb2c |
--- /dev/null |
+++ b/media/blink/url_index_unittests.cc |
@@ -0,0 +1,109 @@ |
+// 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: |
+ 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(); |
+ scoped_refptr<UrlData> b = GetByUrl(url1, UrlData::kAnonymous); |
+ b->Use(); |
+ scoped_refptr<UrlData> c = GetByUrl(url1, UrlData::kUseCredentials); |
+ c->Use(); |
+ scoped_refptr<UrlData> d = GetByUrl(url2, UrlData::kUnspecified); |
+ d->Use(); |
+ 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_TRUE(a->redirects_to().is_empty()); |
+ 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); |
+ |
+ // Redirects to self, bad but not inconceivable. |
+ a->set_redirects_to(url); |
+ EXPECT_EQ(a->url(), url); |
+ |
+ 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); |
+ 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(); |
+ EXPECT_TRUE(a->Valid()); |
+} |
+ |
+TEST_F(UrlIndexTest, SetLastModified) { |
+ GURL url("http://foo.bar.com"); |
+ scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified); |
+ EXPECT_FALSE(a->Valid()); |
+ base::Time time_now = base::Time::Now(); |
+ base::Time last_modified = time_now - base::TimeDelta::FromSeconds(500); |
+ scoped_refptr<UrlData> b = a->set_last_modified(last_modified); |
+ EXPECT_EQ(a, b); |
+ scoped_refptr<UrlData> c = GetByUrl(url, UrlData::kUnspecified); |
+ EXPECT_NE(b, c); |
+ scoped_refptr<UrlData> d = c->set_last_modified(last_modified); |
+ EXPECT_EQ(b, d); |
+} |
+ |
+} // namespace media |