Title: [195686] trunk
Revision
195686
Author
rn...@webkit.org
Date
2016-01-27 12:29:30 -0800 (Wed, 27 Jan 2016)

Log Message

Add API to access closed shadowRoot in InjectedBundle
https://bugs.webkit.org/show_bug.cgi?id=153533

Reviewed by Antti Koivisto.

Source/WebCore:

Always return the shadow root in Element.shadowRootForBindings when the DOM wrapper world has
shadowRootIsAlwaysOpen set to true. Also renamed bindingShadowRoot to shadowRootForBindings
to be consistent.

* bindings/js/DOMWrapperWorld.h:
(WebCore::DOMWrapperWorld::setShadowRootIsAlwaysOpen): Added.
(WebCore::DOMWrapperWorld::shadowRootIsAlwaysOpen): Added.
* dom/Element.cpp:
(WebCore::Element::shadowRootForBindings): Renamed from bindingShadowRoot.
* dom/Element.h:
* dom/Element.idl:

Source/WebKit2:

Added WKBundleScriptWorldMakeAllShadowRootsOpen to make all shadow roots open.
This is needed to keep supporting certain browser-level features such as autofill.

* WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp:
(WKBundleScriptWorldMakeAllShadowRootsOpen): Added.
* WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h:
* WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp:
(WebKit::InjectedBundleScriptWorld::makeAllShadowRootsOpen): Added.
* WebProcess/InjectedBundle/InjectedBundleScriptWorld.h:

Tools:

Added WebKit2 API test for WKBundleScriptWorldMakeAllShadowRootsOpen.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp: Added.
(TestWebKitAPI::runJavaScriptAlert):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2/InjectedBundleMakrAllShadowRootOpen_Bundle.cpp: Added.
(TestWebKitAPI::InjectedBundleMakrAllShadowRootOpenTest::InjectedBundleMakrAllShadowRootOpenTest):
(TestWebKitAPI::InjectedBundleMakrAllShadowRootOpenTest::initialize):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (195685 => 195686)


--- trunk/Source/WebCore/ChangeLog	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebCore/ChangeLog	2016-01-27 20:29:30 UTC (rev 195686)
@@ -1,3 +1,22 @@
+2016-01-27  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add API to access closed shadowRoot in InjectedBundle
+        https://bugs.webkit.org/show_bug.cgi?id=153533
+
+        Reviewed by Antti Koivisto.
+
+        Always return the shadow root in Element.shadowRootForBindings when the DOM wrapper world has
+        shadowRootIsAlwaysOpen set to true. Also renamed bindingShadowRoot to shadowRootForBindings
+        to be consistent.
+
+        * bindings/js/DOMWrapperWorld.h:
+        (WebCore::DOMWrapperWorld::setShadowRootIsAlwaysOpen): Added.
+        (WebCore::DOMWrapperWorld::shadowRootIsAlwaysOpen): Added.
+        * dom/Element.cpp:
+        (WebCore::Element::shadowRootForBindings): Renamed from bindingShadowRoot.
+        * dom/Element.h:
+        * dom/Element.idl:
+
 2016-01-27  Zhuo Li  <zac...@apple.com>
 
         Need ability to specify alternate image for AutoFill button in input fields.

Modified: trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h (195685 => 195686)


--- trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h	2016-01-27 20:29:30 UTC (rev 195686)
@@ -46,6 +46,9 @@
     void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); }
     void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); }
 
+    void setShadowRootIsAlwaysOpen() { m_shadowRootIsAlwaysOpen = true; }
+    bool shadowRootIsAlwaysOpen() const { return m_shadowRootIsAlwaysOpen; }
+
     // FIXME: can we make this private?
     DOMObjectWrapperMap m_wrappers;
     HashMap<CSSValue*, void*> m_cssValueRoots;
@@ -61,6 +64,7 @@
     JSC::VM& m_vm;
     HashSet<ScriptController*> m_scriptControllersWithWindowShells;
     bool m_isNormal;
+    bool m_shadowRootIsAlwaysOpen { false };
 };
 
 DOMWrapperWorld& normalWorld(JSC::VM&);

Modified: trunk/Source/WebCore/dom/Element.cpp (195685 => 195686)


--- trunk/Source/WebCore/dom/Element.cpp	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-01-27 20:29:30 UTC (rev 195686)
@@ -1713,13 +1713,16 @@
     return shadowRoot();
 }
 
-ShadowRoot* Element::bindingShadowRoot() const
+ShadowRoot* Element::shadowRootForBindings(JSC::ExecState& state) const
 {
     ShadowRoot* root = shadowRoot();
     if (!root)
         return nullptr;
-    if (root->type() != ShadowRoot::Type::Open)
-        return nullptr;
+
+    if (root->type() != ShadowRoot::Type::Open) {
+        if (!JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject())->world().shadowRootIsAlwaysOpen())
+            return nullptr;
+    }
     return root;
 }
 

Modified: trunk/Source/WebCore/dom/Element.h (195685 => 195686)


--- trunk/Source/WebCore/dom/Element.h	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebCore/dom/Element.h	2016-01-27 20:29:30 UTC (rev 195686)
@@ -248,7 +248,7 @@
     WEBCORE_EXPORT ShadowRoot* shadowRoot() const;
     WEBCORE_EXPORT RefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
 
-    ShadowRoot* bindingShadowRoot() const;
+    ShadowRoot* shadowRootForBindings(JSC::ExecState&) const;
     RefPtr<ShadowRoot> attachShadow(const Dictionary&, ExceptionCode&);
 
     ShadowRoot* userAgentShadowRoot() const;

Modified: trunk/Source/WebCore/dom/Element.idl (195685 => 195686)


--- trunk/Source/WebCore/dom/Element.idl	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebCore/dom/Element.idl	2016-01-27 20:29:30 UTC (rev 195686)
@@ -169,7 +169,7 @@
     // Shadow DOM API
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
     [Conditional=SHADOW_DOM, RaisesException] ShadowRoot attachShadow(Dictionary options);
-    [Conditional=SHADOW_DOM, ImplementedAs=bindingShadowRoot] readonly attribute ShadowRoot shadowRoot;
+    [Conditional=SHADOW_DOM, ImplementedAs=shadowRootForBindings, CallWith=ScriptState] readonly attribute ShadowRoot shadowRoot;
     [Conditional=SHADOW_DOM, Reflect] attribute DOMString slot;
 #endif
 

Modified: trunk/Source/WebKit2/ChangeLog (195685 => 195686)


--- trunk/Source/WebKit2/ChangeLog	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebKit2/ChangeLog	2016-01-27 20:29:30 UTC (rev 195686)
@@ -1,3 +1,20 @@
+2016-01-27  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add API to access closed shadowRoot in InjectedBundle
+        https://bugs.webkit.org/show_bug.cgi?id=153533
+
+        Reviewed by Antti Koivisto.
+
+        Added WKBundleScriptWorldMakeAllShadowRootsOpen to make all shadow roots open.
+        This is needed to keep supporting certain browser-level features such as autofill.
+
+        * WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp:
+        (WKBundleScriptWorldMakeAllShadowRootsOpen): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h:
+        * WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp:
+        (WebKit::InjectedBundleScriptWorld::makeAllShadowRootsOpen): Added.
+        * WebProcess/InjectedBundle/InjectedBundleScriptWorld.h:
+
 2016-01-27  Zhuo Li  <zac...@apple.com>
 
         Need ability to specify alternate image for AutoFill button in input fields.

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp (195685 => 195686)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp	2016-01-27 20:29:30 UTC (rev 195686)
@@ -52,3 +52,8 @@
 {
     toImpl(scriptWorldRef)->clearWrappers();
 }
+
+void WKBundleScriptWorldMakeAllShadowRootsOpen(WKBundleScriptWorldRef scriptWorldRef)
+{
+    toImpl(scriptWorldRef)->makeAllShadowRootsOpen();
+}

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h (195685 => 195686)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h	2016-01-27 20:29:30 UTC (rev 195686)
@@ -37,6 +37,7 @@
 WK_EXPORT WKBundleScriptWorldRef WKBundleScriptWorldCreateWorld();
 WK_EXPORT WKBundleScriptWorldRef WKBundleScriptWorldNormalWorld();
 WK_EXPORT void WKBundleScriptWorldClearWrappers(WKBundleScriptWorldRef scriptWorld);
+WK_EXPORT void WKBundleScriptWorldMakeAllShadowRootsOpen(WKBundleScriptWorldRef scriptWorld);
 
 #ifdef __cplusplus
 }

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp (195685 => 195686)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp	2016-01-27 20:29:30 UTC (rev 195686)
@@ -88,4 +88,9 @@
     m_world->clearWrappers();
 }
 
+void InjectedBundleScriptWorld::makeAllShadowRootsOpen()
+{
+    m_world->setShadowRootIsAlwaysOpen();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h (195685 => 195686)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h	2016-01-27 20:29:30 UTC (rev 195686)
@@ -45,8 +45,9 @@
     virtual ~InjectedBundleScriptWorld();
 
     WebCore::DOMWrapperWorld& coreWorld() const;
-    
+
     void clearWrappers();
+    void makeAllShadowRootsOpen();
 
 private:
     InjectedBundleScriptWorld(PassRefPtr<WebCore::DOMWrapperWorld>);

Modified: trunk/Tools/ChangeLog (195685 => 195686)


--- trunk/Tools/ChangeLog	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Tools/ChangeLog	2016-01-27 20:29:30 UTC (rev 195686)
@@ -1,3 +1,20 @@
+2016-01-27  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add API to access closed shadowRoot in InjectedBundle
+        https://bugs.webkit.org/show_bug.cgi?id=153533
+
+        Reviewed by Antti Koivisto.
+
+        Added WebKit2 API test for WKBundleScriptWorldMakeAllShadowRootsOpen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp: Added.
+        (TestWebKitAPI::runJavaScriptAlert):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2/InjectedBundleMakrAllShadowRootOpen_Bundle.cpp: Added.
+        (TestWebKitAPI::InjectedBundleMakrAllShadowRootOpenTest::InjectedBundleMakrAllShadowRootOpenTest):
+        (TestWebKitAPI::InjectedBundleMakrAllShadowRootOpenTest::initialize):
+
 2016-01-27  Jason Marcell  <jmarc...@apple.com>
 
         Refactor logic for parsing Trac revisions into its own function and add logic for parsing git hashes.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (195685 => 195686)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-01-27 20:24:37 UTC (rev 195685)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-01-27 20:29:30 UTC (rev 195686)
@@ -268,6 +268,8 @@
 		93F1DB3414DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB3314DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp */; };
 		93F1DB5714DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */; };
 		93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
+		9B0786A31C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A21C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp */; };
+		9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp */; };
 		9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
 		9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; };
 		9B7916501BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */; };
@@ -658,6 +660,8 @@
 		93F1DB5614DB1B840024C362 /* NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFails_Bundle.cpp; sourceTree = "<group>"; };
 		93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames.cpp; sourceTree = "<group>"; };
 		93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp; sourceTree = "<group>"; };
+		9B0786A21C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootsOpen.cpp; sourceTree = "<group>"; };
+		9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootOpen_Bundle.cpp; sourceTree = "<group>"; };
 		9B26FC6B159D061000CC3765 /* HTMLFormCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLFormCollectionNamedItem.mm; sourceTree = "<group>"; };
 		9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLFormCollectionNamedItem.html; sourceTree = "<group>"; };
 		9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; };
@@ -1110,6 +1114,8 @@
 				9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */,
 				BCB6803F126FBFE100642A61 /* DocumentStartUserScriptAlertCrash.cpp */,
 				BCB68041126FBFF100642A61 /* DocumentStartUserScriptAlertCrash_Bundle.cpp */,
+				9B0786A21C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp */,
+				9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp */,
 				51393E1E1523944A005F39C5 /* DOMWindowExtensionBasic.cpp */,
 				51393E1D1523944A005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp */,
 				F6F49C6715545C8D0007F39D /* DOMWindowExtensionNoCache.cpp */,
@@ -1836,6 +1842,7 @@
 				41973B5B1AF2286A006C7B36 /* FileSystem.cpp in Sources */,
 				A1C4FB6E1BACCE50003742D0 /* QuickLook.mm in Sources */,
 				7A5623111AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp in Sources */,
+				9B0786A31C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp in Sources */,
 				1A4F81CC1BDFFD37004E672E /* RemoteObjectRegistry.mm in Sources */,
 				51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */,
 				9B7916501BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm in Sources */,
@@ -1894,6 +1901,7 @@
 				C0BD669F131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp in Sources */,
 				51FCF7A11534B2A000104491 /* ShouldGoToBackForwardListItem_Bundle.cpp in Sources */,
 				7673499D1930C5BB00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp in Sources */,
+				9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp in Sources */,
 				CE3524F81B1431F60028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp in Sources */,
 				BC22D31914DC68B900FFB1DD /* UserMessage_Bundle.cpp in Sources */,
 				520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp (0 => 195686)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp	2016-01-27 20:29:30 UTC (rev 195686)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2010, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "InjectedBundleTest.h"
+#include <WebKit/WKBundlePageGroup.h>
+#include <WebKit/WKBundlePrivate.h>
+#include <WebKit/WKBundleScriptWorld.h>
+#include <WebKit/WKRetainPtr.h>
+#include <assert.h>
+
+namespace TestWebKitAPI {
+
+class InjectedBundleMakeAllShadowRootOpenTest : public InjectedBundleTest {
+public:
+    InjectedBundleMakeAllShadowRootOpenTest(const std::string& identifier)
+        : InjectedBundleTest(identifier)
+    { }
+
+    virtual void initialize(WKBundleRef bundle, WKTypeRef userData)
+    {
+        assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID());
+        WKBundlePageGroupRef pageGroup = static_cast<WKBundlePageGroupRef>(userData);
+
+        auto world = WKBundleScriptWorldCreateWorld();
+        WKBundleScriptWorldMakeAllShadowRootsOpen(world);
+
+        WKRetainPtr<WKStringRef> source(AdoptWK, WKStringCreateWithUTF8CString(
+            "var element = document.createElement('div');"
+            "element.attachShadow({mode: 'closed'});"
+            "alert(element.shadowRoot ? 'PASS' : 'FAIL');"));
+        WKBundleAddUserScript(bundle, pageGroup, world, source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames);
+    }
+};
+
+static InjectedBundleTest::Register<InjectedBundleMakeAllShadowRootOpenTest> registrar("InjectedBundleMakeAllShadowRootOpenTest");
+
+} // namespace TestWebKitAPI
+
+#endif

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp (from rev 195685, trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp) (0 => 195686)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp	2016-01-27 20:29:30 UTC (rev 195686)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2010, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static bool done;
+
+static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
+{
+    ASSERT_NOT_NULL(frame);
+
+    EXPECT_EQ(page, WKFrameGetPage(frame));
+    EXPECT_WK_STREQ("PASS", alertText);
+
+    done = true;
+}
+
+TEST(WebKit2, InjectedBundleMakeAllShadowRootOpenTest)
+{
+    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("InjectedBundleMakeAllShadowRootOpenTestPageGroup")));
+
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleMakeAllShadowRootOpenTest", pageGroup.get()));
+    PlatformWebView webView(context.get(), pageGroup.get());
+
+    WKPageUIClientV0 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 0;
+    uiClient.runJavaScriptAlert = runJavaScriptAlert;
+
+    WKPageSetPageUIClient(webView.page(), &uiClient.base);
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    Util::run(&done);
+}
+    
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to