OLD | NEW |
(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 scoped_refptr<UrlData> GetByUrl(const GURL& gurl, |
| 20 UrlData::CORSMode cors_mode) { |
| 21 scoped_refptr<UrlData> ret = url_index_.GetByUrl(gurl, cors_mode); |
| 22 EXPECT_EQ(ret->url(), gurl); |
| 23 EXPECT_EQ(ret->cors_mode(), cors_mode); |
| 24 return ret; |
| 25 } |
| 26 |
| 27 UrlIndex url_index_; |
| 28 }; |
| 29 |
| 30 TEST_F(UrlIndexTest, SimpleTest) { |
| 31 GURL url1("http://foo.bar.com"); |
| 32 GURL url2("http://foo.bar.com/urgel"); |
| 33 scoped_refptr<UrlData> a = GetByUrl(url1, UrlData::kUnspecified); |
| 34 // Make sure it's valid, we still shouldn't get the same one. |
| 35 a->Use(); |
| 36 scoped_refptr<UrlData> b = GetByUrl(url1, UrlData::kAnonymous); |
| 37 b->Use(); |
| 38 scoped_refptr<UrlData> c = GetByUrl(url1, UrlData::kUseCredentials); |
| 39 c->Use(); |
| 40 scoped_refptr<UrlData> d = GetByUrl(url2, UrlData::kUnspecified); |
| 41 d->Use(); |
| 42 EXPECT_NE(a, b); |
| 43 EXPECT_NE(a, c); |
| 44 EXPECT_NE(a, d); |
| 45 EXPECT_NE(b, c); |
| 46 EXPECT_NE(b, d); |
| 47 EXPECT_NE(c, d); |
| 48 EXPECT_EQ(a, GetByUrl(url1, UrlData::kUnspecified)); |
| 49 EXPECT_EQ(b, GetByUrl(url1, UrlData::kAnonymous)); |
| 50 EXPECT_EQ(c, GetByUrl(url1, UrlData::kUseCredentials)); |
| 51 EXPECT_EQ(d, GetByUrl(url2, UrlData::kUnspecified)); |
| 52 } |
| 53 |
| 54 TEST_F(UrlIndexTest, UrlDataTest) { |
| 55 GURL url("http://foo.bar.com"); |
| 56 scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified); |
| 57 |
| 58 // Check default values. |
| 59 EXPECT_TRUE(a->redirects_to().is_empty()); |
| 60 EXPECT_FALSE(a->range_supported()); |
| 61 EXPECT_FALSE(a->cacheable()); |
| 62 EXPECT_EQ(a->length(), kPositionNotSpecified); |
| 63 EXPECT_FALSE(a->Valid()); |
| 64 |
| 65 a->set_length(117); |
| 66 EXPECT_EQ(a->length(), 117); |
| 67 |
| 68 // Redirects to self, bad but not inconceivable. |
| 69 a->set_redirects_to(url); |
| 70 EXPECT_EQ(a->url(), url); |
| 71 |
| 72 a->set_cacheable(true); |
| 73 EXPECT_TRUE(a->cacheable()); |
| 74 |
| 75 base::TimeTicks now = base::TimeTicks::Now(); |
| 76 base::TimeTicks valid_until = now + base::TimeDelta::FromSeconds(500); |
| 77 a->set_valid_until(valid_until); |
| 78 EXPECT_EQ(valid_until, a->valid_until()); |
| 79 EXPECT_TRUE(a->Valid()); |
| 80 |
| 81 base::Time time_now = base::Time::Now(); |
| 82 base::Time last_modified = time_now - base::TimeDelta::FromSeconds(500); |
| 83 a->set_last_modified(last_modified); |
| 84 EXPECT_EQ(last_modified, a->last_modified()); |
| 85 } |
| 86 |
| 87 TEST_F(UrlIndexTest, UseTest) { |
| 88 GURL url("http://foo.bar.com"); |
| 89 scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified); |
| 90 EXPECT_FALSE(a->Valid()); |
| 91 a->Use(); |
| 92 EXPECT_TRUE(a->Valid()); |
| 93 } |
| 94 |
| 95 TEST_F(UrlIndexTest, SetLastModified) { |
| 96 GURL url("http://foo.bar.com"); |
| 97 scoped_refptr<UrlData> a = GetByUrl(url, UrlData::kUnspecified); |
| 98 EXPECT_FALSE(a->Valid()); |
| 99 base::Time time_now = base::Time::Now(); |
| 100 base::Time last_modified = time_now - base::TimeDelta::FromSeconds(500); |
| 101 scoped_refptr<UrlData> b = a->set_last_modified(last_modified); |
| 102 EXPECT_EQ(a, b); |
| 103 scoped_refptr<UrlData> c = GetByUrl(url, UrlData::kUnspecified); |
| 104 EXPECT_NE(b, c); |
| 105 scoped_refptr<UrlData> d = c->set_last_modified(last_modified); |
| 106 EXPECT_EQ(b, d); |
| 107 } |
| 108 |
| 109 } // namespace media |
OLD | NEW |