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

Side by Side Diff: content/browser/shared_worker/shared_worker_instance_unittest.cc

Issue 2881073003: Support DataSaver for SharedWorker (Closed)
Patch Set: fix #include "public/web/WebDataSaverFlag.h" Created 3 years, 7 months 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
OLDNEW
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 "content/browser/shared_worker/shared_worker_instance.h" 5 #include "content/browser/shared_worker/shared_worker_instance.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/shared_worker/worker_storage_partition.h" 12 #include "content/browser/shared_worker/worker_storage_partition.h"
13 #include "content/public/browser/storage_partition.h" 13 #include "content/public/browser/storage_partition.h"
14 #include "content/public/test/test_browser_context.h" 14 #include "content/public/test/test_browser_context.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/web/WebDataSaverFlag.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 class SharedWorkerInstanceTest : public testing::Test { 21 class SharedWorkerInstanceTest : public testing::Test {
21 protected: 22 protected:
22 SharedWorkerInstanceTest() 23 SharedWorkerInstanceTest()
23 : browser_context_(new TestBrowserContext()), 24 : browser_context_(new TestBrowserContext()),
24 partition_(new WorkerStoragePartition( 25 partition_(new WorkerStoragePartition(
25 BrowserContext::GetDefaultStoragePartition(browser_context_.get()) 26 BrowserContext::GetDefaultStoragePartition(browser_context_.get())
26 ->GetURLRequestContext(), 27 ->GetURLRequestContext(),
(...skipping 22 matching lines...) Expand all
49 50
50 private: 51 private:
51 DISALLOW_COPY_AND_ASSIGN(SharedWorkerInstanceTest); 52 DISALLOW_COPY_AND_ASSIGN(SharedWorkerInstanceTest);
52 }; 53 };
53 54
54 TEST_F(SharedWorkerInstanceTest, MatchesTest) { 55 TEST_F(SharedWorkerInstanceTest, MatchesTest) {
55 SharedWorkerInstance instance1( 56 SharedWorkerInstance instance1(
56 GURL("http://example.com/w.js"), base::string16(), base::string16(), 57 GURL("http://example.com/w.js"), base::string16(), base::string16(),
57 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic, 58 blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
58 browser_context_->GetResourceContext(), partition_id_, 59 browser_context_->GetResourceContext(), partition_id_,
59 blink::kWebSharedWorkerCreationContextTypeNonsecure); 60 blink::kWebSharedWorkerCreationContextTypeNonsecure,
61 blink::WebDataSaverFlag::kDisabled);
60 EXPECT_TRUE(Matches(instance1, "http://example.com/w.js", "")); 62 EXPECT_TRUE(Matches(instance1, "http://example.com/w.js", ""));
61 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "")); 63 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", ""));
62 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "")); 64 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", ""));
63 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "")); 65 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", ""));
64 EXPECT_FALSE(Matches(instance1, "http://example.com/w.js", "name")); 66 EXPECT_FALSE(Matches(instance1, "http://example.com/w.js", "name"));
65 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "name")); 67 EXPECT_FALSE(Matches(instance1, "http://example.com/w2.js", "name"));
66 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "name")); 68 EXPECT_FALSE(Matches(instance1, "http://example.net/w.js", "name"));
67 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "name")); 69 EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "name"));
68 70
69 SharedWorkerInstance instance2( 71 SharedWorkerInstance instance2(
70 GURL("http://example.com/w.js"), base::ASCIIToUTF16("name"), 72 GURL("http://example.com/w.js"), base::ASCIIToUTF16("name"),
71 base::string16(), blink::kWebContentSecurityPolicyTypeReport, 73 base::string16(), blink::kWebContentSecurityPolicyTypeReport,
72 blink::kWebAddressSpacePublic, browser_context_->GetResourceContext(), 74 blink::kWebAddressSpacePublic, browser_context_->GetResourceContext(),
73 partition_id_, blink::kWebSharedWorkerCreationContextTypeNonsecure); 75 partition_id_, blink::kWebSharedWorkerCreationContextTypeNonsecure,
76 blink::WebDataSaverFlag::kDisabled);
74 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "")); 77 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", ""));
75 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "")); 78 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", ""));
76 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "")); 79 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", ""));
77 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "")); 80 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", ""));
78 EXPECT_TRUE(Matches(instance2, "http://example.com/w.js", "name")); 81 EXPECT_TRUE(Matches(instance2, "http://example.com/w.js", "name"));
79 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "name")); 82 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "name"));
80 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name")); 83 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name"));
81 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name")); 84 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name"));
82 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "name2")); 85 EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", "name2"));
83 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "name2")); 86 EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", "name2"));
84 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name2")); 87 EXPECT_FALSE(Matches(instance2, "http://example.net/w.js", "name2"));
85 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name2")); 88 EXPECT_FALSE(Matches(instance2, "http://example.net/w2.js", "name2"));
86 } 89 }
87 90
88 TEST_F(SharedWorkerInstanceTest, AddressSpace) { 91 TEST_F(SharedWorkerInstanceTest, AddressSpace) {
89 for (int i = 0; i < static_cast<int>(blink::kWebAddressSpaceLast); i++) { 92 for (int i = 0; i < static_cast<int>(blink::kWebAddressSpaceLast); i++) {
90 SharedWorkerInstance instance( 93 SharedWorkerInstance instance(
91 GURL("http://example.com/w.js"), base::ASCIIToUTF16("name"), 94 GURL("http://example.com/w.js"), base::ASCIIToUTF16("name"),
92 base::string16(), blink::kWebContentSecurityPolicyTypeReport, 95 base::string16(), blink::kWebContentSecurityPolicyTypeReport,
93 static_cast<blink::WebAddressSpace>(i), 96 static_cast<blink::WebAddressSpace>(i),
94 browser_context_->GetResourceContext(), partition_id_, 97 browser_context_->GetResourceContext(), partition_id_,
95 blink::kWebSharedWorkerCreationContextTypeNonsecure); 98 blink::kWebSharedWorkerCreationContextTypeNonsecure,
99 blink::WebDataSaverFlag::kDisabled);
96 EXPECT_EQ(static_cast<blink::WebAddressSpace>(i), 100 EXPECT_EQ(static_cast<blink::WebAddressSpace>(i),
97 instance.creation_address_space()); 101 instance.creation_address_space());
98 } 102 }
99 } 103 }
100 104
101 } // namespace content 105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698