Title: [208878] trunk
Revision
208878
Author
rn...@webkit.org
Date
2016-11-17 21:30:24 -0800 (Thu, 17 Nov 2016)

Log Message

Add an experimental API to find elements across shadow boundaries
https://bugs.webkit.org/show_bug.cgi?id=164851
<rdar://problem/28220092>

Reviewed by Sam Weinig.

Source/_javascript_Core:

* runtime/CommonIdentifiers.h:

Source/WebCore:

Add window.collectMatchingElementsInFlatTree(Node node, DOMString selectors)
as an experimental API which finds a list of elements that matches the given CSS selectors
and expose it to a JSWorld on which WKBundleScriptWorldMakeAllShadowRootsOpen was called.

No new tests. More test cases are added to WebKit2.InjectedBundleMakeAllShadowRootsOpen.

* bindings/scripts/CodeGeneratorJS.pm:
(NeedsRuntimeCheck): Added. Abstracts checks for EnabledAtRuntime and EnabledForWorld.
(OperationShouldBeOnInstance):
(GeneratePropertiesHashTable):
(GetRuntimeEnableFunctionName): Use worldForDOMObject(this).condition() for EnabledForWorld.
Also split the line for EnabledAtRuntime and EnabledAtRuntime for a better readability.
(GenerateImplementation):
(addIterableProperties):
* bindings/scripts/IDLAttributes.txt:
* bindings/scripts/preprocess-idls.pl:
(GenerateConstructorAttribute):
* bindings/scripts/test/JS/JSTestGlobalObject.cpp:
(WebCore::JSTestGlobalObject::finishCreation):
(WebCore::jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld):
(WebCore::jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldCaller):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::JSTestObjPrototype::finishCreation):
(WebCore::jsTestObjPrototypeFunctionWorldSpecificMethod):
(WebCore::jsTestObjPrototypeFunctionWorldSpecificMethodCaller):
* bindings/scripts/test/TestGlobalObject.idl: Added a test case.
* bindings/scripts/test/TestObj.idl: Ditto.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::collectMatchingElementsInFlatTree): Added. Implements the feature by
calling SelectorQuery's matches on a node yielded by ComposedTreeIterator.
* page/DOMWindow.h:
* page/DOMWindow.idl:

Tools:

Added test cases for window.collectMatchingElementsInFlatTree to WebKit2.InjectedBundleMakeAllShadowRootOpen.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRoot*s*Open_Bundle.cpp: Renamed
from InjectedBundleMakeAllShadowRootOpen_Bundle.cpp.
(TestWebKitAPI::InjectedBundleMakeAllShadowRootOpenTest::initialize): Added test cases for
window.collectMatchingElementsInFlatTree by calling alert() many times.
* TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp:
(TestWebKitAPI::runJavaScriptAlert): Added expectations for multiple test cases. Each test case
finishes with a call to alert, and moves testNumber forward.
(TestWebKitAPI::TEST): Use the newly added closed-shadow-tree-test.html
* TestWebKitAPI/Tests/WebKit2/closed-shadow-tree-test.html: Added. Creates a shadow tree with slots
and tests that window.collectMatchingElementsInFlatTree is not present when
an event named "testnormalworld" is dispatched by the injected bundle.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (208877 => 208878)


--- trunk/Source/_javascript_Core/ChangeLog	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-11-18 05:30:24 UTC (rev 208878)
@@ -1,3 +1,13 @@
+2016-11-17  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add an experimental API to find elements across shadow boundaries
+        https://bugs.webkit.org/show_bug.cgi?id=164851
+        <rdar://problem/28220092>
+
+        Reviewed by Sam Weinig.
+
+        * runtime/CommonIdentifiers.h:
+
 2016-11-17  Yusuke Suzuki  <utatane....@gmail.com>
 
         [JSC] Drop arguments.caller

Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (208877 => 208878)


--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h	2016-11-18 05:30:24 UTC (rev 208878)
@@ -260,6 +260,7 @@
     macro(value) \
     macro(valueOf) \
     macro(webkit) \
+    macro(collectMatchingElementsInFlatTree) \
     macro(webkitIDBCursor) \
     macro(webkitIDBDatabase) \
     macro(webkitIDBFactory) \

Modified: trunk/Source/WebCore/ChangeLog (208877 => 208878)


--- trunk/Source/WebCore/ChangeLog	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/ChangeLog	2016-11-18 05:30:24 UTC (rev 208878)
@@ -1,3 +1,44 @@
+2016-11-17  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add an experimental API to find elements across shadow boundaries
+        https://bugs.webkit.org/show_bug.cgi?id=164851
+        <rdar://problem/28220092>
+
+        Reviewed by Sam Weinig.
+
+        Add window.collectMatchingElementsInFlatTree(Node node, DOMString selectors)
+        as an experimental API which finds a list of elements that matches the given CSS selectors
+        and expose it to a JSWorld on which WKBundleScriptWorldMakeAllShadowRootsOpen was called.
+
+        No new tests. More test cases are added to WebKit2.InjectedBundleMakeAllShadowRootsOpen.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (NeedsRuntimeCheck): Added. Abstracts checks for EnabledAtRuntime and EnabledForWorld.
+        (OperationShouldBeOnInstance):
+        (GeneratePropertiesHashTable):
+        (GetRuntimeEnableFunctionName): Use worldForDOMObject(this).condition() for EnabledForWorld.
+        Also split the line for EnabledAtRuntime and EnabledAtRuntime for a better readability.
+        (GenerateImplementation):
+        (addIterableProperties):
+        * bindings/scripts/IDLAttributes.txt:
+        * bindings/scripts/preprocess-idls.pl:
+        (GenerateConstructorAttribute):
+        * bindings/scripts/test/JS/JSTestGlobalObject.cpp:
+        (WebCore::JSTestGlobalObject::finishCreation):
+        (WebCore::jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld):
+        (WebCore::jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldCaller):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::JSTestObjPrototype::finishCreation):
+        (WebCore::jsTestObjPrototypeFunctionWorldSpecificMethod):
+        (WebCore::jsTestObjPrototypeFunctionWorldSpecificMethodCaller):
+        * bindings/scripts/test/TestGlobalObject.idl: Added a test case.
+        * bindings/scripts/test/TestObj.idl: Ditto.
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::collectMatchingElementsInFlatTree): Added. Implements the feature by
+        calling SelectorQuery's matches on a node yielded by ComposedTreeIterator.
+        * page/DOMWindow.h:
+        * page/DOMWindow.idl:
+
 2016-11-17  Sam Weinig  <s...@webkit.org>
 
         [WebIDL] Add support for ByteString

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-11-18 05:30:24 UTC (rev 208878)
@@ -693,6 +693,13 @@
     return 0;
 }
 
+sub NeedsRuntimeCheck
+{
+    my $interface = shift;
+    return $interface->extendedAttributes->{EnabledAtRuntime}
+        || $interface->extendedAttributes->{EnabledForWorld};
+}
+
 # https://heycam.github.io/webidl/#es-operations
 sub OperationShouldBeOnInstance
 {
@@ -702,7 +709,7 @@
     return 1 if IsGlobalOrPrimaryGlobalInterface($interface);
 
     # FIXME: The bindings generator does not support putting runtime-enabled operations on the instance yet (except for global objects).
-    return 0 if $function->extendedAttributes->{EnabledAtRuntime};
+    return 0 if NeedsRuntimeCheck($function);
 
     # [Unforgeable] operations should be on the instance. https://heycam.github.io/webidl/#Unforgeable
     return 1 if IsUnforgeable($interface, $function);
@@ -1875,7 +1882,7 @@
         next if AttributeShouldBeOnInstance($interface, $attribute) != $isInstance;
 
         # Global objects add RuntimeEnabled attributes after creation so do not add them to the static table.
-        if ($isInstance && $attribute->extendedAttributes->{EnabledAtRuntime}) {
+        if ($isInstance && NeedsRuntimeCheck($attribute)) {
             $propertyCount -= 1;
             next;
         }
@@ -1904,7 +1911,7 @@
         my $conditional = $attribute->extendedAttributes->{Conditional};
         $conditionals->{$name} = $conditional if $conditional;
 
-        if ($attribute->extendedAttributes->{EnabledAtRuntime}) {
+        if (NeedsRuntimeCheck($attribute)) {
             push(@$runtimeEnabledAttributes, $attribute);
         }
     }
@@ -1920,7 +1927,7 @@
         next if $function->name eq "[Symbol.Iterator]";
 
         # Global objects add RuntimeEnabled operations after creation so do not add them to the static table.
-        if ($isInstance && $function->extendedAttributes->{EnabledAtRuntime}) {
+        if ($isInstance && NeedsRuntimeCheck($function)) {
             $propertyCount -= 1;
             next;
         }
@@ -1947,7 +1954,7 @@
         my $conditional = getConditionalForFunctionConsideringOverloads($function);
         $conditionals->{$name} = $conditional if $conditional;
 
-        if ($function->extendedAttributes->{EnabledAtRuntime}) {
+        if (NeedsRuntimeCheck($function)) {
             push(@$runtimeEnabledFunctions, $function);
         }
     }
@@ -2511,8 +2518,16 @@
 {
     my $context = shift;
 
+    AddToImplIncludes("RuntimeEnabledFeatures.h");
+    
+    if ($context->extendedAttributes->{EnabledForWorld}) {
+        return "worldForDOMObject(this)." . ToMethodName($context->extendedAttributes->{EnabledForWorld});
+    }
+
     # If a parameter is given (e.g. "EnabledAtRuntime=FeatureName") return the RuntimeEnabledFeatures::sharedFeatures().{FeatureName}Enabled() method.
-    return "RuntimeEnabledFeatures::sharedFeatures()." . ToMethodName($context->extendedAttributes->{EnabledAtRuntime}) . "Enabled" if ($context->extendedAttributes->{EnabledAtRuntime} && $context->extendedAttributes->{EnabledAtRuntime} ne "VALUE_IS_MISSING");
+    if ($context->extendedAttributes->{EnabledAtRuntime} && $context->extendedAttributes->{EnabledAtRuntime} ne "VALUE_IS_MISSING") {
+        return "RuntimeEnabledFeatures::sharedFeatures()." . ToMethodName($context->extendedAttributes->{EnabledAtRuntime}) . "Enabled";
+    }
 
     # Otherwise return a function named RuntimeEnabledFeatures::sharedFeatures().{methodName}Enabled().
     return "RuntimeEnabledFeatures::sharedFeatures()." . ToMethodName($context->name) . "Enabled";
@@ -3000,10 +3015,9 @@
 
     # Support for RuntimeEnabled attributes on instances.
     foreach my $attribute (@{$interface->attributes}) {
-        next unless $attribute->extendedAttributes->{EnabledAtRuntime};
+        next unless NeedsRuntimeCheck($attribute);
         next unless AttributeShouldBeOnInstance($interface, $attribute);
 
-        AddToImplIncludes("RuntimeEnabledFeatures.h");
         my $conditionalString = $codeGenerator->GenerateConditionalString($attribute);
         push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
         my $enable_function = GetRuntimeEnableFunctionName($attribute);
@@ -3035,11 +3049,10 @@
 
     # Support for RuntimeEnabled operations on instances.
     foreach my $function (@{$interface->functions}) {
-        next unless $function->extendedAttributes->{EnabledAtRuntime};
+        next unless NeedsRuntimeCheck($function);
         next unless OperationShouldBeOnInstance($interface, $function);
         next if $function->{overloadIndex} && $function->{overloadIndex} > 1;
 
-        AddToImplIncludes("RuntimeEnabledFeatures.h");
         my $conditionalString = $codeGenerator->GenerateConditionalString($function);
         push(@implContent, "#if ${conditionalString}\n") if $conditionalString;
         my $enable_function = GetRuntimeEnableFunctionName($function);
@@ -5027,8 +5040,7 @@
     my $interface = shift;
     my $className = shift;
 
-    if ($interface->iterable->extendedAttributes->{EnabledAtRuntime}) {
-        AddToImplIncludes("RuntimeEnabledFeatures.h");
+    if (NeedsRuntimeCheck($interface->iterable)) {
         my $enable_function = GetRuntimeEnableFunctionName($interface->iterable);
         push(@implContent, "    if (${enable_function}())\n    ");
     }

Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2016-11-18 05:30:24 UTC (rev 208878)
@@ -59,6 +59,7 @@
 DocumentEventHandler
 EnabledAtRuntime=*
 EnabledBySetting=*
+EnabledForWorld=*
 EnforceRange
 ExportMacro=WEBCORE_EXPORT|WEBCORE_TESTSUPPORT_EXPORT
 ExportToWrappedFunction

Modified: trunk/Source/WebCore/bindings/scripts/preprocess-idls.pl (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/preprocess-idls.pl	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/preprocess-idls.pl	2016-11-18 05:30:24 UTC (rev 208878)
@@ -246,7 +246,7 @@
     my $code = "    ";
     my @extendedAttributesList;
     foreach my $attributeName (sort keys %{$extendedAttributes}) {
-      next unless ($attributeName eq "Conditional" || $attributeName eq "EnabledAtRuntime" || $attributeName eq "EnabledBySetting" || $attributeName eq "PrivateIdentifier" || $attributeName eq "PublicIdentifier");
+      next unless ($attributeName eq "Conditional" || $attributeName eq "EnabledAtRuntime" || $attributeName eq "EnabledForWorld" || $attributeName eq "EnabledBySetting" || $attributeName eq "PrivateIdentifier" || $attributeName eq "PublicIdentifier");
       my $extendedAttribute = $attributeName;
       $extendedAttribute .= "=" . $extendedAttributes->{$attributeName} unless $extendedAttributes->{$attributeName} eq "VALUE_IS_MISSING";
       push(@extendedAttributesList, $extendedAttribute);

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp	2016-11-18 05:30:24 UTC (rev 208878)
@@ -44,6 +44,7 @@
 #if ENABLE(TEST_FEATURE)
 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation(JSC::ExecState*);
 #endif
+JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld(JSC::ExecState*);
 #if ENABLE(TEST_FEATURE)
 JSC::EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionTestPrivateFunction(JSC::ExecState*);
 #endif
@@ -159,6 +160,8 @@
     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
         putDirectNativeFunction(vm, this, vm.propertyNames->enabledAtRuntimeOperation, 1, jsTestGlobalObjectInstanceFunctionEnabledAtRuntimeOperation, NoIntrinsic, attributesForStructure(JSC::Function));
 #endif
+    if (worldForDOMObject(this).specificWorld())
+        putDirectNativeFunction(vm, this, vm.propertyNames->enabledInSpecificWorld, 1, jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld, NoIntrinsic, attributesForStructure(JSC::Function));
 #if ENABLE(TEST_FEATURE)
     if (RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled())
         putDirectNativeFunction(vm, this, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().testPrivateFunctionPrivateName(), 0, jsTestGlobalObjectInstanceFunctionTestPrivateFunction, NoIntrinsic, attributesForStructure(JSC::Function));
@@ -451,6 +454,26 @@
 }
 #endif
 
+static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldCaller(JSC::ExecState*, JSTestGlobalObject*, JSC::ThrowScope&);
+
+EncodedJSValue JSC_HOST_CALL jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorld(ExecState* state)
+{
+    return BindingCaller<JSTestGlobalObject>::callOperation<jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldCaller>(state, "enabledInSpecificWorld");
+}
+
+static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionEnabledInSpecificWorldCaller(JSC::ExecState* state, JSTestGlobalObject* castedThis, JSC::ThrowScope& throwScope)
+{
+    UNUSED_PARAM(state);
+    UNUSED_PARAM(throwScope);
+    auto& impl = castedThis->wrapped();
+    if (UNLIKELY(state->argumentCount() < 1))
+        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
+    auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0), IntegerConversionConfiguration::Normal);
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    impl.enabledInSpecificWorld(WTFMove(testParam));
+    return JSValue::encode(jsUndefined());
+}
+
 #if ENABLE(TEST_FEATURE)
 static inline JSC::EncodedJSValue jsTestGlobalObjectInstanceFunctionTestPrivateFunctionCaller(JSC::ExecState*, JSTestGlobalObject*, JSC::ThrowScope&);
 

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-11-18 05:30:24 UTC (rev 208878)
@@ -938,6 +938,7 @@
 #if ENABLE(TEST_FEATURE)
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionEnabledAtRuntimeOperation(JSC::ExecState*);
 #endif
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWorldSpecificMethod(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVoidMethod(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVoidMethodWithArgs(JSC::ExecState*);
 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionByteMethod(JSC::ExecState*);
@@ -1545,6 +1546,7 @@
 #else
     { 0, 0, NoIntrinsic, { 0, 0 } },
 #endif
+    { "worldSpecificMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionWorldSpecificMethod), (intptr_t) (1) } },
     { "voidMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionVoidMethod), (intptr_t) (0) } },
     { "voidMethodWithArgs", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionVoidMethodWithArgs), (intptr_t) (3) } },
     { "byteMethod", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionByteMethod), (intptr_t) (0) } },
@@ -1726,6 +1728,11 @@
         JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
     }
 #endif
+    if (!worldForDOMObject(this).someWorld()) {
+        Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("worldSpecificMethod"), strlen("worldSpecificMethod"));
+        VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
+        JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
+    }
 #if ENABLE(TEST_FEATURE)
     if (!RuntimeEnabledFeatures::sharedFeatures().testFeatureEnabled()) {
         Identifier propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("enabledAtRuntimeAttribute"), strlen("enabledAtRuntimeAttribute"));
@@ -4711,6 +4718,26 @@
 }
 #endif
 
+static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionWorldSpecificMethodCaller(JSC::ExecState*, JSTestObj*, JSC::ThrowScope&);
+
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWorldSpecificMethod(ExecState* state)
+{
+    return BindingCaller<JSTestObj>::callOperation<jsTestObjPrototypeFunctionWorldSpecificMethodCaller>(state, "worldSpecificMethod");
+}
+
+static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionWorldSpecificMethodCaller(JSC::ExecState* state, JSTestObj* castedThis, JSC::ThrowScope& throwScope)
+{
+    UNUSED_PARAM(state);
+    UNUSED_PARAM(throwScope);
+    auto& impl = castedThis->wrapped();
+    if (UNLIKELY(state->argumentCount() < 1))
+        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
+    auto testParam = convert<IDLLong>(*state, state->uncheckedArgument(0), IntegerConversionConfiguration::Normal);
+    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+    impl.worldSpecificMethod(WTFMove(testParam));
+    return JSValue::encode(jsUndefined());
+}
+
 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionVoidMethodCaller(JSC::ExecState*, JSTestObj*, JSC::ThrowScope&);
 
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVoidMethod(ExecState* state)

Modified: trunk/Source/WebCore/bindings/scripts/test/TestGlobalObject.idl (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/test/TestGlobalObject.idl	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/test/TestGlobalObject.idl	2016-11-18 05:30:24 UTC (rev 208878)
@@ -35,6 +35,8 @@
     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(DOMString testParam);
     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(long testParam);
 
+    [EnabledForWorld=specificWorld] void enabledInSpecificWorld(long testParam);
+
     [PrivateIdentifier, Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void testPrivateFunction();
     [JSBuiltin, Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void testJSBuiltinFunction();
 };

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (208877 => 208878)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-11-18 05:30:24 UTC (rev 208878)
@@ -109,6 +109,8 @@
     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(DOMString testParam);
     [Conditional=TEST_FEATURE, EnabledAtRuntime=TestFeature] void enabledAtRuntimeOperation(long testParam);
 
+    [EnabledForWorld=someWorld] void worldSpecificMethod(long testParam);
+
     // TypedArray attribute
     attribute Float32Array typedArrayAttr;
 

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (208877 => 208878)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2016-11-18 05:30:24 UTC (rev 208878)
@@ -35,6 +35,7 @@
 #include "CSSRuleList.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
+#include "ComposedTreeIterator.h"
 #include "ContentExtensionActions.h"
 #include "ContentExtensionRule.h"
 #include "Crypto.h"
@@ -89,8 +90,10 @@
 #include "SecurityOrigin.h"
 #include "SecurityOriginData.h"
 #include "SecurityPolicy.h"
+#include "SelectorQuery.h"
 #include "SerializedScriptValue.h"
 #include "Settings.h"
+#include "StaticNodeList.h"
 #include "Storage.h"
 #include "StorageArea.h"
 #include "StorageNamespace.h"
@@ -632,6 +635,33 @@
     return *m_customElementRegistry;
 }
 
+ExceptionOr<Ref<NodeList>> DOMWindow::collectMatchingElementsInFlatTree(Node& scope, const String& selectors)
+{
+    if (!m_frame)
+        return Exception { NOT_SUPPORTED_ERR };
+
+    Document* document = m_frame->document();
+    if (!document)
+        return Exception { NOT_SUPPORTED_ERR };
+
+    auto queryOrException = document->selectorQueryForString(selectors);
+    if (queryOrException.hasException())
+        return queryOrException.releaseException();
+
+    if (!is<ContainerNode>(scope))
+        return Ref<NodeList> { StaticElementList::create() };
+
+    SelectorQuery& query = queryOrException.releaseReturnValue();
+
+    Vector<Ref<Element>> result;
+    for (auto& node : composedTreeDescendants(downcast<ContainerNode>(scope))) {
+        if (is<Element>(node) && query.matches(downcast<Element>(node)))
+            result.append(downcast<Element>(node));
+    }
+
+    return Ref<NodeList> { StaticElementList::create(WTFMove(result)) };
+}
+
 #if ENABLE(ORIENTATION_EVENTS)
 
 int DOMWindow::orientation() const

Modified: trunk/Source/WebCore/page/DOMWindow.h (208877 => 208878)


--- trunk/Source/WebCore/page/DOMWindow.h	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/page/DOMWindow.h	2016-11-18 05:30:24 UTC (rev 208878)
@@ -71,6 +71,7 @@
 class MessagePort;
 class Navigator;
 class Node;
+class NodeList;
 class Page;
 class PageConsoleClient;
 class Performance;
@@ -295,6 +296,8 @@
     CustomElementRegistry* customElementRegistry() { return m_customElementRegistry.get(); }
     CustomElementRegistry& ensureCustomElementRegistry();
 
+    ExceptionOr<Ref<NodeList>> collectMatchingElementsInFlatTree(Node&, const String& selectors);
+
 #if ENABLE(ORIENTATION_EVENTS)
     // This is the interface orientation in degrees. Some examples are:
     //  0 is straight up; -90 is when the device is rotated 90 clockwise;

Modified: trunk/Source/WebCore/page/DOMWindow.idl (208877 => 208878)


--- trunk/Source/WebCore/page/DOMWindow.idl	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Source/WebCore/page/DOMWindow.idl	2016-11-18 05:30:24 UTC (rev 208878)
@@ -173,6 +173,9 @@
 
     [EnabledAtRuntime=CustomElements, ImplementedAs=ensureCustomElementRegistry] readonly attribute CustomElementRegistry customElements;
 
+    [MayThrowException, EnabledForWorld=shadowRootIsAlwaysOpen]
+    NodeList collectMatchingElementsInFlatTree(Node scope, DOMString selectors);
+
     // Event handlers unique to Element and DOMWindow.
     // FIXME: Should these be exposed on Document as well (and therefore moved to GlobalEventHandlers.idl)?
     [NotEnumerable] attribute EventHandler onanimationend;

Modified: trunk/Tools/ChangeLog (208877 => 208878)


--- trunk/Tools/ChangeLog	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Tools/ChangeLog	2016-11-18 05:30:24 UTC (rev 208878)
@@ -1,3 +1,26 @@
+2016-11-17  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add an experimental API to find elements across shadow boundaries
+        https://bugs.webkit.org/show_bug.cgi?id=164851
+        <rdar://problem/28220092>
+
+        Reviewed by Sam Weinig.
+
+        Added test cases for window.collectMatchingElementsInFlatTree to WebKit2.InjectedBundleMakeAllShadowRootOpen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRoot*s*Open_Bundle.cpp: Renamed
+        from InjectedBundleMakeAllShadowRootOpen_Bundle.cpp.
+        (TestWebKitAPI::InjectedBundleMakeAllShadowRootOpenTest::initialize): Added test cases for
+        window.collectMatchingElementsInFlatTree by calling alert() many times.
+        * TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp:
+        (TestWebKitAPI::runJavaScriptAlert): Added expectations for multiple test cases. Each test case
+        finishes with a call to alert, and moves testNumber forward.
+        (TestWebKitAPI::TEST): Use the newly added closed-shadow-tree-test.html
+        * TestWebKitAPI/Tests/WebKit2/closed-shadow-tree-test.html: Added. Creates a shadow tree with slots
+        and tests that window.collectMatchingElementsInFlatTree is not present when
+        an event named "testnormalworld" is dispatched by the injected bundle.
+
 2016-11-17  Brady Eidson  <beid...@apple.com>
 
         Add _WKIconLoadingDelegate SPI.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (208877 => 208878)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-11-18 05:30:24 UTC (rev 208878)
@@ -433,8 +433,9 @@
 		93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
 		9984FACC1CFFAF60008D198C /* WKWebViewTextInput.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */; };
 		9984FACE1CFFB090008D198C /* editable-body.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9984FACD1CFFB038008D198C /* editable-body.html */; };
-		9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp */; };
+		9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */; };
 		9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
+		9B270FEE1DDC2C0B002D53F3 /* closed-shadow-tree-test.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */; };
 		9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; };
 		9C64DC321D76198A004B598E /* YouTubePluginReplacement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */; };
 		A1146A8D1D2D7115000FE710 /* ContentFiltering.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1146A8A1D2D704F000FE710 /* ContentFiltering.mm */; };
@@ -579,6 +580,7 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				9B270FEE1DDC2C0B002D53F3 /* closed-shadow-tree-test.html in Copy Resources */,
 				F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */,
 				8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */,
 				AD57AC221DA7466E00FF1BDE /* many-iframes.html in Copy Resources */,
@@ -1077,9 +1079,10 @@
 		9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewTextInput.mm; sourceTree = "<group>"; };
 		9984FACD1CFFB038008D198C /* editable-body.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "editable-body.html"; 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>"; };
+		9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootsOpen_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>"; };
+		9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "closed-shadow-tree-test.html"; sourceTree = "<group>"; };
 		9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; };
 		9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLCollectionNamedItem.html; sourceTree = "<group>"; };
 		9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderScrollingPosition.mm; sourceTree = "<group>"; };
@@ -1727,7 +1730,7 @@
 				378E64751632655D00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp */,
 				F660AA1215A619C8003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp */,
 				F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */,
-				9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp */,
+				9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */,
 				9B0786A21C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp */,
 				93D3D19D17B1A84200C7C415 /* LayoutMilestonesWithAllContentInFrame.cpp */,
 				52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */,
@@ -1870,6 +1873,7 @@
 				76E182DE15475A8300F1FADD /* auto-submitting-form.html */,
 				7C486BA01AA1254B003F6F9B /* bundle-file.html */,
 				1A50AA1F1A2A4EA500F4C345 /* close-from-within-create-page.html */,
+				9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */,
 				290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */,
 				C5E1AFFD16B22179006CC1F2 /* execCopy.html */,
 				BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */,
@@ -2669,7 +2673,7 @@
 				378E64771632655E00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp in Sources */,
 				F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */,
 				BC575A97126E74F1006F0F12 /* InjectedBundleMain.cpp in Sources */,
-				9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp in Sources */,
+				9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp in Sources */,
 				33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */,
 				33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */,
 				93F1DB3414DA20870024C362 /* NewFirstVisuallyNonEmptyLayout_Bundle.cpp in Sources */,

Deleted: trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp (208877 => 208878)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp	2016-11-18 05:30:24 UTC (rev 208878)
@@ -1,65 +0,0 @@
-/*
- * 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

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp (208877 => 208878)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp	2016-11-18 05:11:18 UTC (rev 208877)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen.cpp	2016-11-18 05:30:24 UTC (rev 208878)
@@ -34,6 +34,7 @@
 
 namespace TestWebKitAPI {
 
+static unsigned testNumber = 0;
 static bool done;
 
 static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
@@ -41,9 +42,27 @@
     ASSERT_NOT_NULL(frame);
 
     EXPECT_EQ(page, WKFrameGetPage(frame));
-    EXPECT_WK_STREQ("PASS", alertText);
-
-    done = true;
+    switch (++testNumber) {
+    case 1:
+        EXPECT_WK_STREQ("PASS: shadowRoot created in injected bundle", alertText);
+        break;
+    case 2:
+        EXPECT_WK_STREQ("PASS: shadowRoot created by normal world", alertText);
+        break;
+    case 3:
+        EXPECT_WK_STREQ("PASS: query method exists", alertText);
+        break;
+    case 4:
+        EXPECT_WK_STREQ("PASS: query method was not present in the normal world", alertText);
+        break;
+    case 5:
+        EXPECT_WK_STREQ("Found:1,2,3,4,5,6", alertText);
+        break;
+    case 6:
+        EXPECT_WK_STREQ("Found:2,3,4", alertText);
+        done = true;
+        break;
+    }
 }
 
 TEST(WebKit2, InjectedBundleMakeAllShadowRootOpenTest)
@@ -61,7 +80,7 @@
 
     WKPageSetPageUIClient(webView.page(), &uiClient.base);
 
-    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("closed-shadow-tree-test", "html"));
     WKPageLoadURL(webView.page(), url.get());
 
     Util::run(&done);

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp (from rev 208877, trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootOpen_Bundle.cpp) (0 => 208878)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp	2016-11-18 05:30:24 UTC (rev 208878)
@@ -0,0 +1,83 @@
+/*
+ * 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(
+            "window._onload_ = function () {\n"
+            "    const element = document.createElement('div');\n"
+            "    const queryMethodName = 'collectMatchingElementsInFlatTree';\n"
+            "    element.attachShadow({mode: 'closed'});\n"
+            // Test 1
+            "    alert(element.shadowRoot ? 'PASS: shadowRoot created in injected bundle' : 'FAIL');\n"
+            // Test 2
+            "    alert(document.querySelector('shadow-host').shadowRoot ? 'PASS: shadowRoot created by normal world' : 'FAIL');\n"
+            // Test 3
+            "    alert(window[queryMethodName] ? 'PASS: query method exists' : 'FAIL');\n"
+            // Test 4
+            "    document.dispatchEvent(new Event('testnormalworld'));\n"
+            // Test 5
+            "    const queryMethod = window[queryMethodName];\n"
+            "    let queryResult = Array.from(queryMethod(document, 'span'));\n"
+            "    alert('Found:' + queryResult.map((span) => span.textContent).join(','));\n"
+            // Test 6
+            "    const innerHost = queryMethod(document, 'inner-host')[0];\n"
+            "    queryResult = Array.from(queryMethod(innerHost, 'span'));\n"
+            "    alert('Found:' + queryResult.map((span) => span.textContent).join(','));\n"
+            "}\n"));
+        WKBundleAddUserScript(bundle, pageGroup, world, source.get(), 0, 0, 0, kWKInjectAtDocumentStart, kWKInjectInAllFrames);
+    }
+};
+
+static InjectedBundleTest::Register<InjectedBundleMakeAllShadowRootOpenTest> registrar("InjectedBundleMakeAllShadowRootOpenTest");
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/closed-shadow-tree-test.html (0 => 208878)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/closed-shadow-tree-test.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/closed-shadow-tree-test.html	2016-11-18 05:30:24 UTC (rev 208878)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<shadow-host><span>5</span><span slot="bar">2</span></shadow-host>
+<script>
+const shadowRoot = document.querySelector('shadow-host').attachShadow({mode: 'closed'});
+shadowRoot.innerHTML = `
+    <span>1</span>
+    <inner-host>
+        <slot name="bar" slot="foo"><span>FAIL - named slot fallback</span></slot>
+        <span>FAIL - unassigned content</span>
+        <span slot="foo">3</span>
+    </inner-host>
+    <slot><span>FAIL - default slot fallback</span></slot>
+    <span>6</span>`;
+const innerHost = shadowRoot.querySelector('inner-host');
+innerHost.attachShadow({mode: 'closed'}).innerHTML = `
+    <slot name="foo"></slot>
+    <span>4</span>`;
+
+document.addEventListener('testnormalworld', function () {
+    alert(window.collectMatchingElementsInFlatTree ?
+        'FAIL' : 'PASS: query method was not present in the normal world');
+});
+
+</script>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to