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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp

Issue 783663002: Implement ServiceWorkerClient attributes [1/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/ServiceWorkerContainer.h" 6 #include "modules/serviceworkers/ServiceWorkerContainer.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/ScriptFunction.h" 9 #include "bindings/core/v8/ScriptFunction.h"
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
11 #include "bindings/core/v8/ScriptState.h" 11 #include "bindings/core/v8/ScriptState.h"
12 #include "bindings/core/v8/V8DOMException.h" 12 #include "bindings/core/v8/V8DOMException.h"
13 #include "bindings/core/v8/V8GCController.h" 13 #include "bindings/core/v8/V8GCController.h"
14 #include "core/dom/DOMException.h" 14 #include "core/dom/DOMException.h"
15 #include "core/dom/Document.h" 15 #include "core/dom/Document.h"
16 #include "core/dom/ExecutionContext.h" 16 #include "core/dom/ExecutionContext.h"
17 #include "core/page/FocusController.h"
17 #include "core/testing/DummyPageHolder.h" 18 #include "core/testing/DummyPageHolder.h"
18 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" 19 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
19 #include "platform/weborigin/KURL.h" 20 #include "platform/weborigin/KURL.h"
20 #include "platform/weborigin/SecurityOrigin.h" 21 #include "platform/weborigin/SecurityOrigin.h"
22 #include "public/platform/WebServiceWorkerClientsInfo.h"
21 #include "public/platform/WebServiceWorkerProvider.h" 23 #include "public/platform/WebServiceWorkerProvider.h"
22 #include "public/platform/WebURL.h" 24 #include "public/platform/WebURL.h"
23 #include "wtf/OwnPtr.h" 25 #include "wtf/OwnPtr.h"
24 #include "wtf/PassOwnPtr.h" 26 #include "wtf/PassOwnPtr.h"
25 #include "wtf/text/WTFString.h" 27 #include "wtf/text/WTFString.h"
26 #include <gtest/gtest.h> 28 #include <gtest/gtest.h>
27 #include <v8.h> 29 #include <v8.h>
28 30
29 namespace blink { 31 namespace blink {
30 namespace { 32 namespace {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume nt().frame()); } 158 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume nt().frame()); }
157 159
158 void provide(PassOwnPtr<WebServiceWorkerProvider> provider) 160 void provide(PassOwnPtr<WebServiceWorkerProvider> provider)
159 { 161 {
160 m_page->document().DocumentSupplementable::provideSupplement(ServiceWork erContainerClient::supplementName(), ServiceWorkerContainerClient::create(provid er)); 162 m_page->document().DocumentSupplementable::provideSupplement(ServiceWork erContainerClient::supplementName(), ServiceWorkerContainerClient::create(provid er));
161 } 163 }
162 164
163 void setPageURL(const String& url) 165 void setPageURL(const String& url)
164 { 166 {
165 // For URL completion. 167 // For URL completion.
166 m_page->document().setBaseURLOverride(KURL(KURL(), url)); 168 m_page->document().setURL(KURL(KURL(), url));
167 169
168 // The basis for security checks. 170 // The basis for security checks.
169 m_page->document().setSecurityOrigin(SecurityOrigin::createFromString(ur l)); 171 m_page->document().setSecurityOrigin(SecurityOrigin::createFromString(ur l));
170 } 172 }
171 173
174 void setVisibilityState(PageVisibilityState visibilityState)
175 {
176 m_page->page().setVisibilityState(visibilityState, true); // Set as init ial state
177 }
178
179 void setFocused(bool focused)
180 {
181 m_page->page().focusController().setActive(focused);
182 m_page->page().focusController().setFocused(focused);
183 }
184
172 void testRegisterRejected(const String& scriptURL, const String& scope, cons t ScriptValueTest& valueTest) 185 void testRegisterRejected(const String& scriptURL, const String& scope, cons t ScriptValueTest& valueTest)
173 { 186 {
174 // When the registration is rejected, a register call must not reach 187 // When the registration is rejected, a register call must not reach
175 // the provider. 188 // the provider.
176 provide(adoptPtr(new NotReachedWebServiceWorkerProvider())); 189 provide(adoptPtr(new NotReachedWebServiceWorkerProvider()));
177 190
178 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu tionContext()); 191 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execu tionContext());
179 ScriptState::Scope scriptScope(scriptState()); 192 ScriptState::Scope scriptScope(scriptState());
180 RegistrationOptions options; 193 RegistrationOptions options;
181 options.setScope(scope); 194 options.setScope(scope);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 { 364 {
352 ScriptState::Scope scriptScope(scriptState()); 365 ScriptState::Scope scriptScope(scriptState());
353 container->getRegistration(scriptState(), ""); 366 container->getRegistration(scriptState(), "");
354 EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount()); 367 EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount());
355 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), stubPro vider.getRegistrationURL()); 368 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), stubPro vider.getRegistrationURL());
356 } 369 }
357 370
358 container->willBeDetachedFromFrame(); 371 container->willBeDetachedFromFrame();
359 } 372 }
360 373
374 TEST_F(ServiceWorkerContainerTest, GetClientInfo)
375 {
376 setVisibilityState(PageVisibilityStateVisible);
377 setFocused(true);
378 setPageURL("http://localhost/x/index.html");
379
380 ServiceWorkerContainer* container = ServiceWorkerContainer::create(execution Context());
381
382 WebServiceWorkerClientInfo info;
383 ASSERT_TRUE(container->getClientInfo(&info));
384 EXPECT_EQ(WebString("visible"), info.visibilityState);
385 EXPECT_TRUE(info.isFocused);
386 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), info.url);
387 EXPECT_EQ(WebURLRequest::FrameTypeTopLevel, info.frameType);
388 }
389
361 } // namespace 390 } // namespace
362 } // namespace blink 391 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.cpp ('k') | public/platform/WebServiceWorkerClientsInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698