| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/browser/shared_worker/shared_worker_instance.h" | 9 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 10 #include "content/browser/worker_host/worker_storage_partition.h" | 10 #include "content/browser/worker_host/worker_storage_partition.h" |
| 11 #include "content/public/test/test_browser_context.h" | 11 #include "content/public/test/test_browser_context.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class SharedWorkerInstanceTest : public testing::Test { | 16 class SharedWorkerInstanceTest : public testing::Test { |
| 17 protected: | 17 protected: |
| 18 SharedWorkerInstanceTest() | 18 SharedWorkerInstanceTest() |
| 19 : browser_context_(new TestBrowserContext()), | 19 : browser_context_(new TestBrowserContext()), |
| 20 partition_(new WorkerStoragePartition( | 20 partition_( |
| 21 browser_context_->GetRequestContext(), | 21 new WorkerStoragePartition(browser_context_->GetRequestContext(), |
| 22 NULL, NULL, NULL, NULL, NULL, NULL, NULL)) { | 22 NULL, |
| 23 } | 23 NULL, |
| 24 NULL, |
| 25 NULL, |
| 26 NULL, |
| 27 NULL, |
| 28 NULL)), |
| 29 partition_id_(*partition_.get()) {} |
| 24 | 30 |
| 25 bool Matches(const SharedWorkerInstance& instance, | 31 bool Matches(const SharedWorkerInstance& instance, |
| 26 const std::string& url, | 32 const std::string& url, |
| 27 const base::StringPiece& name) { | 33 const base::StringPiece& name) { |
| 28 return instance.Matches(GURL(url), | 34 return instance.Matches(GURL(url), |
| 29 base::ASCIIToUTF16(name), | 35 base::ASCIIToUTF16(name), |
| 30 *partition_.get(), | 36 partition_id_, |
| 31 browser_context_->GetResourceContext()); | 37 browser_context_->GetResourceContext()); |
| 32 } | 38 } |
| 33 | 39 |
| 34 scoped_ptr<TestBrowserContext> browser_context_; | 40 scoped_ptr<TestBrowserContext> browser_context_; |
| 35 scoped_ptr<WorkerStoragePartition> partition_; | 41 scoped_ptr<WorkerStoragePartition> partition_; |
| 42 const WorkerStoragePartitionId partition_id_; |
| 36 | 43 |
| 37 DISALLOW_COPY_AND_ASSIGN(SharedWorkerInstanceTest); | 44 DISALLOW_COPY_AND_ASSIGN(SharedWorkerInstanceTest); |
| 38 }; | 45 }; |
| 39 | 46 |
| 40 TEST_F(SharedWorkerInstanceTest, MatchesTest) { | 47 TEST_F(SharedWorkerInstanceTest, MatchesTest) { |
| 41 SharedWorkerInstance instance1(GURL("http://example.com/w.js"), | 48 SharedWorkerInstance instance1(GURL("http://example.com/w.js"), |
| 42 base::string16(), | 49 base::string16(), |
| 43 base::string16(), | 50 base::string16(), |
| 44 blink::WebContentSecurityPolicyTypeReport, | 51 blink::WebContentSecurityPolicyTypeReport, |
| 45 browser_context_->GetResourceContext(), | 52 browser_context_->GetResourceContext(), |
| 46 *partition_.get()); | 53 partition_id_); |
| 47 EXPECT_TRUE(Matches(instance1, "http://example.com/w.js", "")); | 54 EXPECT_TRUE(Matches(instance1, "http://example.com/w.js", "")); |
| 48 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "")); | 55 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "")); |
| 49 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "")); | 56 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "")); |
| 50 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "")); | 57 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "")); |
| 51 EXPECT_FALSE(Matches(instance1, "http://example.com/w.js", "name")); | 58 EXPECT_FALSE(Matches(instance1, "http://example.com/w.js", "name")); |
| 52 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "name")); | 59 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "name")); |
| 53 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "name")); | 60 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "name")); |
| 54 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "name")); | 61 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "name")); |
| 55 | 62 |
| 56 SharedWorkerInstance instance2(GURL("http://example.com/w.js"), | 63 SharedWorkerInstance instance2(GURL("http://example.com/w.js"), |
| 57 base::ASCIIToUTF16("name"), | 64 base::ASCIIToUTF16("name"), |
| 58 base::string16(), | 65 base::string16(), |
| 59 blink::WebContentSecurityPolicyTypeReport, | 66 blink::WebContentSecurityPolicyTypeReport, |
| 60 browser_context_->GetResourceContext(), | 67 browser_context_->GetResourceContext(), |
| 61 *partition_.get()); | 68 partition_id_); |
| 62 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "")); | 69 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "")); |
| 63 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "")); | 70 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "")); |
| 64 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "")); | 71 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "")); |
| 65 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "")); | 72 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "")); |
| 66 EXPECT_TRUE(Matches(instance2, "http://example.com/w.js", "name")); | 73 EXPECT_TRUE(Matches(instance2, "http://example.com/w.js", "name")); |
| 67 EXPECT_TRUE(Matches(instance2, "http://example.com/w2.js", "name")); | 74 EXPECT_TRUE(Matches(instance2, "http://example.com/w2.js", "name")); |
| 68 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name")); | 75 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name")); |
| 69 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name")); | 76 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name")); |
| 70 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "name2")); | 77 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "name2")); |
| 71 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "name2")); | 78 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "name2")); |
| 72 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name2")); | 79 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name2")); |
| 73 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name2")); | 80 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name2")); |
| 74 } | 81 } |
| 75 | 82 |
| 76 } // namespace content | 83 } // namespace content |
| OLD | NEW |