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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host_unittest.cc

Issue 2627543002: ServiceWorker: Returns true for IsMojoForServiceWorkerEnabled (Closed)
Patch Set: Created 3 years, 11 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/service_worker/service_worker_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_; 95 base::WeakPtr<ServiceWorkerProviderHost> provider_host2_;
96 GURL script_url_; 96 GURL script_url_;
97 ServiceWorkerTestContentClient test_content_client_; 97 ServiceWorkerTestContentClient test_content_client_;
98 TestContentBrowserClient test_content_browser_client_; 98 TestContentBrowserClient test_content_browser_client_;
99 ContentBrowserClient* old_content_browser_client_; 99 ContentBrowserClient* old_content_browser_client_;
100 100
101 private: 101 private:
102 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostTest); 102 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHostTest);
103 }; 103 };
104 104
105 class ServiceWorkerProviderHostTestP 105 TEST_F(ServiceWorkerProviderHostTest, PotentialRegistration_ProcessStatus) {
106 : public MojoServiceWorkerTestP<ServiceWorkerProviderHostTest> {};
107
108 TEST_P(ServiceWorkerProviderHostTestP, PotentialRegistration_ProcessStatus) {
109 // Matching registrations have already been set by SetDocumentUrl. 106 // Matching registrations have already been set by SetDocumentUrl.
110 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern())); 107 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern()));
111 108
112 // Different matching registrations have already been added. 109 // Different matching registrations have already been added.
113 ASSERT_TRUE(PatternHasProcessToRun(registration2_->pattern())); 110 ASSERT_TRUE(PatternHasProcessToRun(registration2_->pattern()));
114 111
115 // Adding the same registration twice has no effect. 112 // Adding the same registration twice has no effect.
116 provider_host1_->AddMatchingRegistration(registration1_.get()); 113 provider_host1_->AddMatchingRegistration(registration1_.get());
117 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern())); 114 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern()));
118 115
119 // Removing a matching registration will decrease the process refs for its 116 // Removing a matching registration will decrease the process refs for its
120 // pattern. 117 // pattern.
121 provider_host1_->RemoveMatchingRegistration(registration1_.get()); 118 provider_host1_->RemoveMatchingRegistration(registration1_.get());
122 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern())); 119 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern()));
123 provider_host2_->RemoveMatchingRegistration(registration1_.get()); 120 provider_host2_->RemoveMatchingRegistration(registration1_.get());
124 ASSERT_FALSE(PatternHasProcessToRun(registration1_->pattern())); 121 ASSERT_FALSE(PatternHasProcessToRun(registration1_->pattern()));
125 122
126 // Matching registration will be removed when moving out of scope 123 // Matching registration will be removed when moving out of scope
127 ASSERT_TRUE(PatternHasProcessToRun(registration2_->pattern())); // host1,2 124 ASSERT_TRUE(PatternHasProcessToRun(registration2_->pattern())); // host1,2
128 ASSERT_FALSE(PatternHasProcessToRun(registration3_->pattern())); // no host 125 ASSERT_FALSE(PatternHasProcessToRun(registration3_->pattern())); // no host
129 provider_host1_->SetDocumentUrl(GURL("https://other.example.com/")); 126 provider_host1_->SetDocumentUrl(GURL("https://other.example.com/"));
130 ASSERT_TRUE(PatternHasProcessToRun(registration2_->pattern())); // host2 127 ASSERT_TRUE(PatternHasProcessToRun(registration2_->pattern())); // host2
131 ASSERT_TRUE(PatternHasProcessToRun(registration3_->pattern())); // host1 128 ASSERT_TRUE(PatternHasProcessToRun(registration3_->pattern())); // host1
132 provider_host2_->SetDocumentUrl(GURL("https://other.example.com/")); 129 provider_host2_->SetDocumentUrl(GURL("https://other.example.com/"));
133 ASSERT_FALSE(PatternHasProcessToRun(registration2_->pattern())); // no host 130 ASSERT_FALSE(PatternHasProcessToRun(registration2_->pattern())); // no host
134 ASSERT_TRUE(PatternHasProcessToRun(registration3_->pattern())); // host1,2 131 ASSERT_TRUE(PatternHasProcessToRun(registration3_->pattern())); // host1,2
135 } 132 }
136 133
137 TEST_P(ServiceWorkerProviderHostTestP, AssociatedRegistration_ProcessStatus) { 134 TEST_F(ServiceWorkerProviderHostTest, AssociatedRegistration_ProcessStatus) {
138 // Associating the registration will also increase the process refs for 135 // Associating the registration will also increase the process refs for
139 // the registration's pattern. 136 // the registration's pattern.
140 provider_host1_->AssociateRegistration(registration1_.get(), 137 provider_host1_->AssociateRegistration(registration1_.get(),
141 false /* notify_controllerchange */); 138 false /* notify_controllerchange */);
142 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern())); 139 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern()));
143 140
144 // Disassociating the registration shouldn't affect the process refs for 141 // Disassociating the registration shouldn't affect the process refs for
145 // the registration's pattern. 142 // the registration's pattern.
146 provider_host1_->DisassociateRegistration(); 143 provider_host1_->DisassociateRegistration();
147 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern())); 144 ASSERT_TRUE(PatternHasProcessToRun(registration1_->pattern()));
148 } 145 }
149 146
150 TEST_P(ServiceWorkerProviderHostTestP, MatchRegistration) { 147 TEST_F(ServiceWorkerProviderHostTest, MatchRegistration) {
151 // Match registration should return the longest matching one. 148 // Match registration should return the longest matching one.
152 ASSERT_EQ(registration2_, provider_host1_->MatchRegistration()); 149 ASSERT_EQ(registration2_, provider_host1_->MatchRegistration());
153 provider_host1_->RemoveMatchingRegistration(registration2_.get()); 150 provider_host1_->RemoveMatchingRegistration(registration2_.get());
154 ASSERT_EQ(registration1_, provider_host1_->MatchRegistration()); 151 ASSERT_EQ(registration1_, provider_host1_->MatchRegistration());
155 152
156 // Should return nullptr after removing all matching registrations. 153 // Should return nullptr after removing all matching registrations.
157 provider_host1_->RemoveMatchingRegistration(registration1_.get()); 154 provider_host1_->RemoveMatchingRegistration(registration1_.get());
158 ASSERT_EQ(nullptr, provider_host1_->MatchRegistration()); 155 ASSERT_EQ(nullptr, provider_host1_->MatchRegistration());
159 156
160 // SetDocumentUrl sets all of matching registrations 157 // SetDocumentUrl sets all of matching registrations
161 provider_host1_->SetDocumentUrl(GURL("https://www.example.com/example1")); 158 provider_host1_->SetDocumentUrl(GURL("https://www.example.com/example1"));
162 ASSERT_EQ(registration2_, provider_host1_->MatchRegistration()); 159 ASSERT_EQ(registration2_, provider_host1_->MatchRegistration());
163 provider_host1_->RemoveMatchingRegistration(registration2_.get()); 160 provider_host1_->RemoveMatchingRegistration(registration2_.get());
164 ASSERT_EQ(registration1_, provider_host1_->MatchRegistration()); 161 ASSERT_EQ(registration1_, provider_host1_->MatchRegistration());
165 162
166 // SetDocumentUrl with another origin also updates matching registrations 163 // SetDocumentUrl with another origin also updates matching registrations
167 provider_host1_->SetDocumentUrl(GURL("https://other.example.com/example")); 164 provider_host1_->SetDocumentUrl(GURL("https://other.example.com/example"));
168 ASSERT_EQ(registration3_, provider_host1_->MatchRegistration()); 165 ASSERT_EQ(registration3_, provider_host1_->MatchRegistration());
169 provider_host1_->RemoveMatchingRegistration(registration3_.get()); 166 provider_host1_->RemoveMatchingRegistration(registration3_.get());
170 ASSERT_EQ(nullptr, provider_host1_->MatchRegistration()); 167 ASSERT_EQ(nullptr, provider_host1_->MatchRegistration());
171 } 168 }
172 169
173 TEST_P(ServiceWorkerProviderHostTestP, ContextSecurity) { 170 TEST_F(ServiceWorkerProviderHostTest, ContextSecurity) {
174 using FrameSecurityLevel = ServiceWorkerProviderHost::FrameSecurityLevel; 171 using FrameSecurityLevel = ServiceWorkerProviderHost::FrameSecurityLevel;
175 content::ResetSchemesAndOriginsWhitelistForTesting(); 172 content::ResetSchemesAndOriginsWhitelistForTesting();
176 173
177 // Insecure document URL. 174 // Insecure document URL.
178 provider_host1_->SetDocumentUrl(GURL("http://host")); 175 provider_host1_->SetDocumentUrl(GURL("http://host"));
179 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::SECURE; 176 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::SECURE;
180 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker()); 177 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker());
181 178
182 // Insecure parent frame. 179 // Insecure parent frame.
183 provider_host1_->SetDocumentUrl(GURL("https://host")); 180 provider_host1_->SetDocumentUrl(GURL("https://host"));
(...skipping 12 matching lines...) Expand all
196 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::SECURE; 193 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::SECURE;
197 EXPECT_FALSE(IsOriginSecure(url)); 194 EXPECT_FALSE(IsOriginSecure(url));
198 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); 195 EXPECT_TRUE(OriginCanAccessServiceWorkers(url));
199 EXPECT_TRUE(provider_host1_->IsContextSecureForServiceWorker()); 196 EXPECT_TRUE(provider_host1_->IsContextSecureForServiceWorker());
200 197
201 // Exceptional service worker scheme with insecure parent frame. 198 // Exceptional service worker scheme with insecure parent frame.
202 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::INSECURE; 199 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::INSECURE;
203 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker()); 200 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker());
204 } 201 }
205 202
206 INSTANTIATE_TEST_CASE_P(ServiceWorkerProviderHostTest,
207 ServiceWorkerProviderHostTestP,
208 ::testing::Values(false, true));
209
210 } // namespace content 203 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698