Title: [239851] trunk
Revision
239851
Author
timo...@apple.com
Date
2019-01-10 17:11:57 -0800 (Thu, 10 Jan 2019)

Log Message

Add WKBundlePage SPI to temporarily force light or dark appearance on a page.
https://bugs.webkit.org/show_bug.cgi?id=193327
rdar://problem/47093222

Reviewed by Tim Horton.

Source/WebKit:

Tests: WebKit.ForceLightAppearanceInBundle API Test

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageSetUseDarkAppearance): Added.
(WKBundlePageIsUsingDarkAppearance): Added.
* WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle.mm: Added.
(TestWebKitAPI::didFinishNavigation):
(TestWebKitAPI::didReceiveMessageFromInjectedBundle):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle_Bundle.mm: Added.
(TestWebKitAPI::ForceLightAppearanceInBundleTest::ForceLightAppearanceInBundleTest):
(TestWebKitAPI::ForceLightAppearanceInBundleTest::didCreatePage):
(TestWebKitAPI::ForceLightAppearanceInBundleTest::didReceiveMessage):
* TestWebKitAPI/Tests/WebKit/mac/dark-mode.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (239850 => 239851)


--- trunk/Source/WebKit/ChangeLog	2019-01-11 00:49:23 UTC (rev 239850)
+++ trunk/Source/WebKit/ChangeLog	2019-01-11 01:11:57 UTC (rev 239851)
@@ -1,3 +1,18 @@
+2019-01-10  Timothy Hatcher  <timo...@apple.com>
+
+        Add WKBundlePage SPI to temporarily force light or dark appearance on a page.
+        https://bugs.webkit.org/show_bug.cgi?id=193327
+        rdar://problem/47093222
+
+        Reviewed by Tim Horton.
+
+        Tests: WebKit.ForceLightAppearanceInBundle API Test
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKBundlePageSetUseDarkAppearance): Added.
+        (WKBundlePageIsUsingDarkAppearance): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h:
+
 2019-01-10  Eric Carlson  <eric.carl...@apple.com>
 
         DeviceID hash salt manager can be NULL

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (239850 => 239851)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2019-01-11 00:49:23 UTC (rev 239850)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp	2019-01-11 01:11:57 UTC (rev 239851)
@@ -589,6 +589,21 @@
     WebKit::toImpl(pageRef)->confirmCompositionForTesting(WebKit::toWTFString(text));
 }
 
+void WKBundlePageSetUseDarkAppearance(WKBundlePageRef pageRef, bool useDarkAppearance)
+{
+    WebKit::WebPage* webPage = WebKit::toImpl(pageRef);
+    if (WebCore::Page* page = webPage ? webPage->corePage() : nullptr)
+        page->setUseDarkAppearance(useDarkAppearance);
+}
+
+bool WKBundlePageIsUsingDarkAppearance(WKBundlePageRef pageRef)
+{
+    WebKit::WebPage* webPage = WebKit::toImpl(pageRef);
+    if (WebCore::Page* page = webPage ? webPage->corePage() : nullptr)
+        return page->useDarkAppearance();
+    return false;
+}
+
 bool WKBundlePageCanShowMIMEType(WKBundlePageRef pageRef, WKStringRef mimeTypeRef)
 {
     return WebKit::toImpl(pageRef)->canShowMIMEType(WebKit::toWTFString(mimeTypeRef));

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h (239850 => 239851)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h	2019-01-11 00:49:23 UTC (rev 239850)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h	2019-01-11 01:11:57 UTC (rev 239851)
@@ -77,6 +77,9 @@
 WK_EXPORT void WKBundlePageConfirmComposition(WKBundlePageRef page);
 WK_EXPORT void WKBundlePageConfirmCompositionWithText(WKBundlePageRef page, WKStringRef text);
 
+WK_EXPORT void WKBundlePageSetUseDarkAppearance(WKBundlePageRef page, bool useDarkAppearance);
+WK_EXPORT bool WKBundlePageIsUsingDarkAppearance(WKBundlePageRef page);
+
 WK_EXPORT bool WKBundlePageCanShowMIMEType(WKBundlePageRef, WKStringRef mimeType);
 
 WK_EXPORT void* WKAccessibilityRootObject(WKBundlePageRef);

Modified: trunk/Tools/ChangeLog (239850 => 239851)


--- trunk/Tools/ChangeLog	2019-01-11 00:49:23 UTC (rev 239850)
+++ trunk/Tools/ChangeLog	2019-01-11 01:11:57 UTC (rev 239851)
@@ -1,3 +1,22 @@
+2019-01-10  Timothy Hatcher  <timo...@apple.com>
+
+        Add WKBundlePage SPI to temporarily force light or dark appearance on a page.
+        https://bugs.webkit.org/show_bug.cgi?id=193327
+        rdar://problem/47093222
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle.mm: Added.
+        (TestWebKitAPI::didFinishNavigation):
+        (TestWebKitAPI::didReceiveMessageFromInjectedBundle):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle_Bundle.mm: Added.
+        (TestWebKitAPI::ForceLightAppearanceInBundleTest::ForceLightAppearanceInBundleTest):
+        (TestWebKitAPI::ForceLightAppearanceInBundleTest::didCreatePage):
+        (TestWebKitAPI::ForceLightAppearanceInBundleTest::didReceiveMessage):
+        * TestWebKitAPI/Tests/WebKit/mac/dark-mode.html: Added.
+
 2019-01-10  Joseph Pecoraro  <pecor...@apple.com>
 
         Leak of WKWebProcessPlugInHitTestResult (160 bytes) in com.apple.WebKit.WebContent running layout tests

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (239850 => 239851)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-01-11 00:49:23 UTC (rev 239850)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-01-11 01:11:57 UTC (rev 239851)
@@ -72,6 +72,9 @@
 		1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */; };
 		1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
 		1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */; };
+		1CF59AE221E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CF59AE021E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm */; };
+		1CF59AE321E68932006E37EC /* ForceLightAppearanceInBundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CF59ADF21E68925006E37EC /* ForceLightAppearanceInBundle.mm */; };
+		1CF59AE521E6977D006E37EC /* dark-mode.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1CF59AE421E696FB006E37EC /* dark-mode.html */; };
 		1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */; };
 		26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
 		26F52EAD1828827B0023D412 /* geolocationGetCurrentPosition.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26F52EAC1828820E0023D412 /* geolocationGetCurrentPosition.html */; };
@@ -1043,6 +1046,7 @@
 				7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */,
 				F4AB578A1F65165400DB0DA1 /* custom-draggable-div.html in Copy Resources */,
 				290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */,
+				1CF59AE521E6977D006E37EC /* dark-mode.html in Copy Resources */,
 				F47DFB2621A878DF00021FB6 /* data-detectors.html in Copy Resources */,
 				F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */,
 				F457A9D6202D68AF00F7E9D5 /* DataTransfer.html in Copy Resources */,
@@ -1356,6 +1360,9 @@
 		1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCache.cpp; sourceTree = "<group>"; };
 		1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = "<group>"; };
 		1CF0D3781BBF2F3D00B4EF54 /* WKRetainPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRetainPtr.cpp; sourceTree = "<group>"; };
+		1CF59ADF21E68925006E37EC /* ForceLightAppearanceInBundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ForceLightAppearanceInBundle.mm; sourceTree = "<group>"; };
+		1CF59AE021E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ForceLightAppearanceInBundle_Bundle.mm; sourceTree = "<group>"; };
+		1CF59AE421E696FB006E37EC /* dark-mode.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "dark-mode.html"; sourceTree = "<group>"; };
 		1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKBackForwardList.mm; path = Tests/WebKit/WKBackForwardList.mm; sourceTree = SOURCE_ROOT; };
 		260BA5781B1D2E7B004FA07C /* DFACombiner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DFACombiner.cpp; sourceTree = "<group>"; };
 		260BA57A1B1D2EE2004FA07C /* DFAHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DFAHelpers.h; sourceTree = "<group>"; };
@@ -3528,7 +3535,10 @@
 				7AC7B56F20D9BA5B002C09A0 /* CustomBundleObject.mm */,
 				7AC7B56C20D9768F002C09A0 /* CustomBundleParameter.mm */,
 				7AC7B56B20D9768E002C09A0 /* CustomBundleParameter_Bundle.mm */,
+				1CF59AE421E696FB006E37EC /* dark-mode.html */,
 				BCAA485714A044D40088FAC4 /* EditorCommands.mm */,
+				1CF59ADF21E68925006E37EC /* ForceLightAppearanceInBundle.mm */,
+				1CF59AE021E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm */,
 				C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */,
 				C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */,
 				1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */,
@@ -3995,6 +4005,7 @@
 				2E92B8FA2164A0C1005B64F0 /* FontAttributes.mm in Sources */,
 				1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */,
 				F456AB1C213EDBA300CB2CEF /* FontManagerTests.mm in Sources */,
+				1CF59AE321E68932006E37EC /* ForceLightAppearanceInBundle.mm in Sources */,
 				7CCE7EF51A411AE600447C4C /* ForceRepaint.cpp in Sources */,
 				7CCE7EC01A411A7E00447C4C /* FragmentNavigation.mm in Sources */,
 				376C8C061D6E197C007D2BB9 /* FrameHandle.cpp in Sources */,
@@ -4365,6 +4376,7 @@
 				51393E221523952D005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp in Sources */,
 				F6F49C6B15545CA70007F39D /* DOMWindowExtensionNoCache_Bundle.cpp in Sources */,
 				1171B24F219F49CD00CB897D /* FirstMeaningfulPaintMilestone_Bundle.cpp in Sources */,
+				1CF59AE221E68925006E37EC /* ForceLightAppearanceInBundle_Bundle.mm in Sources */,
 				C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */,
 				F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */,
 				4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle.mm (0 => 239851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle.mm	2019-01-11 01:11:57 UTC (rev 239851)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2019 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 ENABLE(DARK_MODE_CSS) && WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKContextPrivate.h>
+
+namespace TestWebKitAPI {
+
+static bool didFinishLoad;
+static bool messageReceived;
+
+static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void*)
+{
+    messageReceived = true;
+
+    ASSERT_NOT_NULL(messageBody);
+    EXPECT_EQ(WKStringGetTypeID(), WKGetTypeID(messageBody));
+
+    WKStringRef messageBodyString = static_cast<WKStringRef>(messageBody);
+
+    EXPECT_WK_STREQ("TestDone", messageName);
+    EXPECT_WK_STREQ("rgb(0, 0, 0)", messageBodyString);
+}
+
+TEST(WebKit, ForceLightAppearanceInBundle)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("ForceLightAppearanceInBundleTest"));
+
+    PlatformWebView webView(context.get());
+
+    [webView.platformView() setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
+
+    WKPageNavigationClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+
+    loaderClient.base.version = 0;
+    loaderClient.didFinishNavigation = didFinishNavigation;
+
+    WKPageSetPageNavigationClient(webView.page(), &loaderClient.base);
+
+    WKContextInjectedBundleClientV0 injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+
+    injectedBundleClient.base.version = 0;
+    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+
+    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("dark-mode", "html")).get());
+    Util::run(&didFinishLoad);
+
+    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("RunTest").get(), nullptr);
+    Util::run(&messageReceived);
+    messageReceived = false;
+}
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle_Bundle.mm (0 => 239851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle_Bundle.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ForceLightAppearanceInBundle_Bundle.mm	2019-01-11 01:11:57 UTC (rev 239851)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2019 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 ENABLE(DARK_MODE_CSS) && WK_HAVE_C_SPI
+
+#include "InjectedBundleTest.h"
+
+#include "PlatformUtilities.h"
+#include <_javascript_Core/JSRetainPtr.h>
+#include <WebKit/WKBundleFrame.h>
+#include <WebKit/WKBundlePage.h>
+#include <WebKit/WKBundlePagePrivate.h>
+
+namespace TestWebKitAPI {
+
+class ForceLightAppearanceInBundleTest : public InjectedBundleTest {
+public:
+    ForceLightAppearanceInBundleTest(const std::string& identifier)
+        : InjectedBundleTest(identifier)
+    {
+    }
+
+    virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page)
+    {
+        m_page = page;
+    }
+
+    virtual void didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody)
+    {
+        if (!WKStringIsEqualToUTF8CString(messageName, "RunTest"))
+            return;
+
+        if (!WKBundlePageIsUsingDarkAppearance(m_page))
+            WKBundlePostMessage(bundle, Util::toWK("TestFailed").get(), Util::toWK("Page isn't in dark mode at start of test.").get());
+
+        WKBundlePageSetUseDarkAppearance(m_page, false);
+
+        if (WKBundlePageIsUsingDarkAppearance(m_page))
+            WKBundlePostMessage(bundle, Util::toWK("TestFailed").get(), Util::toWK("Switching to light mode failed.").get());
+
+        auto mainFrame = WKBundlePageGetMainFrame(m_page);
+        auto scriptContext = WKBundleFrameGetJavaScriptContext(mainFrame);
+        auto script = adopt(JSStringCreateWithUTF8CString("window.getComputedStyle(document.body).getPropertyValue('color')"));
+
+        auto result = JSEvaluateScript(scriptContext, script.get(), nullptr, nullptr, 0, nullptr);
+        auto resultString = adopt(JSValueToStringCopy(scriptContext, result, nullptr));
+
+        auto bufferSize = JSStringGetMaximumUTF8CStringSize(resultString.get());
+        auto buffer = std::make_unique<char[]>(bufferSize);
+        JSStringGetUTF8CString(resultString.get(), buffer.get(), bufferSize);
+
+        WKBundlePageSetUseDarkAppearance(m_page, true);
+
+        if (!WKBundlePageIsUsingDarkAppearance(m_page))
+            WKBundlePostMessage(bundle, Util::toWK("TestFailed").get(), Util::toWK("Switching back to dark mode failed.").get());
+
+        WKBundlePostMessage(bundle, Util::toWK("TestDone").get(), Util::toWK(buffer.get()).get());
+    }
+
+private:
+    WKBundlePageRef m_page { nullptr };
+};
+
+static InjectedBundleTest::Register<ForceLightAppearanceInBundleTest> registrar("ForceLightAppearanceInBundleTest");
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/dark-mode.html (0 => 239851)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/dark-mode.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/dark-mode.html	2019-01-11 01:11:57 UTC (rev 239851)
@@ -0,0 +1,5 @@
+<style>
+:root {
+    supported-color-schemes: light dark;
+}
+</style>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to