Title: [285645] trunk
Revision
285645
Author
[email protected]
Date
2021-11-11 12:14:50 -0800 (Thu, 11 Nov 2021)

Log Message

Add support in WebCore for web app manifest icons
https://bugs.webkit.org/show_bug.cgi?id=231339
Source/WebCore:

rdar://84311306

Patch by Rachel Ginsberg <[email protected]> on 2021-11-11
Reviewed by Brent Fulgham.

Tests are added to OpenSource/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp

* Modules/applicationmanifest/ApplicationManifest.h:
A new enum for the icon purpose (Icon::Purpose) was added to the ApplicationManifest::Icon struct.
A new Icon struct containing variable for the src, sizes,
type, and Icon::Purpose attributes for app manifest icons was added to the ApplicationManifest
struct. A vector of Icon's is added as a variable for
the ApplicationManifest struct.
(WebCore::ApplicationManifest::encode const):
Added icons to encode function
(WebCore::ApplicationManifest::decode):
Added icons to decode function
(WebCore::ApplicationManifest::Icon::encode const):
Create encode function for ApplicationManifest::Icon
(WebCore::ApplicationManifest::Icon::decode):
Create decode function for ApplicationManifest::Icon

* Modules/applicationmanifest/ApplicationManifestParser.cpp:
(WebCore::ApplicationManifestParser::parseManifest):
Added call to parseIcons
(WebCore::ApplicationManifestParser::parseIcons):
parseIcons iterates through the list of icons, performs checks for attribute,
and then, if valid, adds the attribute to an ApplicationManifestIcon struct
that is appended to a new Vector of ApplicationManifestIcons.

* Modules/applicationmanifest/ApplicationManifestParser.h:
Declare functions for ApplicationManifestParser

Source/WebKit:

rdar://84311306

Patch by Rachel Ginsberg <[email protected]> on 2021-11-11
Reviewed by Brent Fulgham.

* UIProcess/API/Cocoa/_WKApplicationManifest.h:
* UIProcess/API/Cocoa/_WKApplicationManifest.mm:
(makeVectorElement):
Used by makeVector in initWithCoder:. Takes a _WKApplicationManifestIcon and returns
a WebCore::ApplicationManifest::Icon.
(-[_WKApplicationManifest initWithCoder:]):
Added icons.
(-[_WKApplicationManifest encodeWithCoder:]):
Added icons.
(-[_WKApplicationManifest icons]):
Should appease build error before full support for icons is built into _WKApplicationManifest

(+[_WKApplicationManifestIcon supportsSecureCoding]):
(-[_WKApplicationManifestIcon initWithCoder:]):
(-[_WKApplicationManifestIcon encodeWithCoder:]):
(-[_WKApplicationManifestIcon dealloc]):
* UIProcess/API/Cocoa/_WKApplicationManifestInternal.h:

Tools:

Patch by Rachel Ginsberg <[email protected]> on 2021-11-11
Reviewed by Brent Fulgham.

* TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
(ApplicationManifestParserTest::parseIconFirstTopLevelProperty):
Function to create JSON for icon attributes. This is
necessary because icons are in a list, whereas all other
attributes in app manifest are not.
(ApplicationManifestParserTest::parseIconFirstTopLevelPropertyForSrc):
Needed to make a slightly different version to add a src URL, since
it is required for a given icon to be added to the vector.

(ApplicationManifestParserTest::testIconsSrc):
(ApplicationManifestParserTest::testIconsType):
(ApplicationManifestParserTest::testIconsSizes):
(ApplicationManifestParserTest::testIconsPurposes):
Functions for each of the icon attributes.

(TEST_F):
Calls the various icon test functions with different input

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (285644 => 285645)


--- trunk/Source/WebCore/ChangeLog	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebCore/ChangeLog	2021-11-11 20:14:50 UTC (rev 285645)
@@ -1,3 +1,39 @@
+2021-11-11  Rachel Ginsberg  <[email protected]>
+
+        Add support in WebCore for web app manifest icons
+        https://bugs.webkit.org/show_bug.cgi?id=231339
+        rdar://84311306
+
+        Reviewed by Brent Fulgham.
+
+        Tests are added to OpenSource/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp
+
+        * Modules/applicationmanifest/ApplicationManifest.h:
+        A new enum for the icon purpose (Icon::Purpose) was added to the ApplicationManifest::Icon struct.
+        A new Icon struct containing variable for the src, sizes,
+        type, and Icon::Purpose attributes for app manifest icons was added to the ApplicationManifest
+        struct. A vector of Icon's is added as a variable for
+        the ApplicationManifest struct.
+        (WebCore::ApplicationManifest::encode const):
+        Added icons to encode function
+        (WebCore::ApplicationManifest::decode):
+        Added icons to decode function
+        (WebCore::ApplicationManifest::Icon::encode const):
+        Create encode function for ApplicationManifest::Icon
+        (WebCore::ApplicationManifest::Icon::decode):
+        Create decode function for ApplicationManifest::Icon
+
+        * Modules/applicationmanifest/ApplicationManifestParser.cpp:
+        (WebCore::ApplicationManifestParser::parseManifest):
+        Added call to parseIcons
+        (WebCore::ApplicationManifestParser::parseIcons):
+        parseIcons iterates through the list of icons, performs checks for attribute,
+        and then, if valid, adds the attribute to an ApplicationManifestIcon struct
+        that is appended to a new Vector of ApplicationManifestIcons.
+
+        * Modules/applicationmanifest/ApplicationManifestParser.h:
+        Declare functions for ApplicationManifestParser
+
 2021-11-11  Kimmo Kinnunen  <[email protected]>
 
         REGRESSION (iOS 15, GPU Process): Fails to load texture map

Modified: trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifest.h (285644 => 285645)


--- trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifest.h	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifest.h	2021-11-11 20:14:50 UTC (rev 285645)
@@ -30,6 +30,7 @@
 #include "Color.h"
 #include <wtf/EnumTraits.h>
 #include <wtf/URL.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -41,6 +42,22 @@
         Fullscreen,
     };
 
+    struct Icon {
+        enum class Purpose : uint8_t  {
+            Any = 1 << 0,
+            Monochrome = 1 << 1,
+            Maskable = 1 << 2,
+        };
+
+        URL src;
+        String sizes;
+        String type;
+        OptionSet<Purpose> purposes;
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static std::optional<ApplicationManifest::Icon> decode(Decoder&);
+    };
+
     String name;
     String shortName;
     String description;
@@ -48,6 +65,7 @@
     Display display;
     URL startURL;
     Color themeColor;
+    Vector<Icon> icons;
 
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<ApplicationManifest> decode(Decoder&);
@@ -56,7 +74,7 @@
 template<class Encoder>
 void ApplicationManifest::encode(Encoder& encoder) const
 {
-    encoder << name << shortName << description << scope << display << startURL << themeColor;
+    encoder << name << shortName << description << scope << display << startURL << themeColor << icons;
 }
 
 template<class Decoder>
@@ -78,10 +96,34 @@
         return std::nullopt;
     if (!decoder.decode(result.themeColor))
         return std::nullopt;
+    if (!decoder.decode(result.icons))
+        return std::nullopt;
 
     return result;
 }
 
+template<class Encoder>
+void ApplicationManifest::Icon::encode(Encoder& encoder) const
+{
+    encoder << src << sizes << type << purposes;
+}
+
+template<class Decoder>
+std::optional<ApplicationManifest::Icon> ApplicationManifest::Icon::decode(Decoder& decoder)
+{
+    ApplicationManifest::Icon result;
+    if (!decoder.decode(result.src))
+        return std::nullopt;
+    if (!decoder.decode(result.sizes))
+        return std::nullopt;
+    if (!decoder.decode(result.type))
+        return std::nullopt;
+    if (!decoder.decode(result.purposes))
+        return std::nullopt;
+
+    return result;
+}
+
 } // namespace WebCore
 
 namespace WTF {
@@ -96,6 +138,15 @@
     >;
 };
 
+template<> struct EnumTraits<WebCore::ApplicationManifest::Icon::Purpose> {
+    using values = EnumValues<
+        WebCore::ApplicationManifest::Icon::Purpose,
+        WebCore::ApplicationManifest::Icon::Purpose::Any,
+        WebCore::ApplicationManifest::Icon::Purpose::Monochrome,
+        WebCore::ApplicationManifest::Icon::Purpose::Maskable
+    >;
+};
+
 } // namespace WTF;
 
 #endif // ENABLE(APPLICATION_MANIFEST)

Modified: trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp (285644 => 285645)


--- trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp	2021-11-11 20:14:50 UTC (rev 285645)
@@ -78,6 +78,7 @@
     parsedManifest.shortName = parseShortName(*manifest);
     parsedManifest.scope = parseScope(*manifest, documentURL, parsedManifest.startURL);
     parsedManifest.themeColor = parseColor(*manifest, "theme_color"_s);
+    parsedManifest.icons = parseIcons(*manifest);
 
     if (m_document)
         m_document->processApplicationManifest(parsedManifest);
@@ -174,6 +175,87 @@
     return parseGenericString(manifest, "short_name"_s);
 }
 
+Vector<ApplicationManifest::Icon> ApplicationManifestParser::parseIcons(const JSON::Object& manifest)
+{
+    auto manifestIcons = manifest.getValue("icons"_s);
+
+    Vector<ApplicationManifest::Icon> imageResources;
+    if (!manifestIcons)
+        return imageResources;
+
+    auto manifestIconsArray = manifestIcons->asArray();
+    if (!manifestIconsArray) {
+        logDeveloperWarning("The value of icons is not a valid array."_s);
+        return imageResources;
+    }
+
+    for (const auto& iconValue : *manifestIconsArray) {
+        ApplicationManifest::Icon currentIcon;
+        auto iconObject = iconValue->asObject();
+        if (!iconObject)
+            continue;
+        const auto& iconJSON = *iconObject;
+
+        auto srcValue = iconJSON.getValue("src"_s);
+        if (!srcValue)
+            continue;
+        auto srcStringValue = srcValue->asString();
+        if (!srcStringValue) {
+            logManifestPropertyNotAString("src"_s);
+            continue;
+        }
+        URL srcURL(m_manifestURL, srcStringValue);
+        if (srcURL.isEmpty())
+            continue;
+        if (!srcURL.isValid()) {
+            logManifestPropertyInvalidURL("src"_s);
+            continue;
+        }
+        currentIcon.src = ""
+
+        currentIcon.sizes = parseGenericString(iconJSON, "sizes"_s);
+
+        currentIcon.type = parseGenericString(iconJSON, "type"_s);
+
+        auto purposeValue = iconJSON.getValue("purpose"_s);
+        OptionSet<ApplicationManifest::Icon::Purpose> purposes;
+
+        if (!purposeValue) {
+            purposes.add(ApplicationManifest::Icon::Purpose::Any);
+            currentIcon.purposes = purposes;
+        } else {
+            auto purposeStringValue = purposeValue->asString();
+            if (!purposeStringValue) {
+                logManifestPropertyNotAString("purpose"_s);
+                purposes.add(ApplicationManifest::Icon::Purpose::Any);
+                currentIcon.purposes = purposes;
+            } else {
+                purposeStringValue = purposeStringValue.stripWhiteSpace().convertToASCIILowercase();
+                Vector<String> keywords = purposeStringValue.splitAllowingEmptyEntries(" ");
+
+                for (const auto& keyword : keywords) {
+                    if (keyword == "monochrome")
+                        purposes.add(ApplicationManifest::Icon::Purpose::Monochrome);
+                    else if (keyword == "maskable")
+                        purposes.add(ApplicationManifest::Icon::Purpose::Maskable);
+                    else if (keyword == "any")
+                        purposes.add(ApplicationManifest::Icon::Purpose::Any);
+                    else
+                        logDeveloperWarning(makeString("\""_s, purposeStringValue, "\" is not a valid purpose."_s));
+                }
+                if (purposes.isEmpty())
+                    continue;
+
+                currentIcon.purposes = purposes;
+            }
+        }
+
+        imageResources.append(WTFMove(currentIcon));
+    }
+
+    return imageResources;
+}
+
 static bool isInScope(const URL& scopeURL, const URL& targetURL)
 {
     // 1. If scopeURL is undefined (i.e., it is unbounded because of an error or it was not declared in the manifest), return true.

Modified: trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.h (285644 => 285645)


--- trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.h	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.h	2021-11-11 20:14:50 UTC (rev 285645)
@@ -50,6 +50,7 @@
     String parseDescription(const JSON::Object&);
     String parseShortName(const JSON::Object&);
     URL parseScope(const JSON::Object&, const URL&, const URL&);
+    Vector<ApplicationManifest::Icon> parseIcons(const JSON::Object&);
 
     Color parseColor(const JSON::Object&, const String& propertyName);
     String parseGenericString(const JSON::Object&, const String&);

Modified: trunk/Source/WebKit/ChangeLog (285644 => 285645)


--- trunk/Source/WebKit/ChangeLog	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebKit/ChangeLog	2021-11-11 20:14:50 UTC (rev 285645)
@@ -1,3 +1,29 @@
+2021-11-11  Rachel Ginsberg  <[email protected]>
+
+        Add support in WebCore for web app manifest icons
+        https://bugs.webkit.org/show_bug.cgi?id=231339
+        rdar://84311306
+
+        Reviewed by Brent Fulgham.
+
+        * UIProcess/API/Cocoa/_WKApplicationManifest.h:
+        * UIProcess/API/Cocoa/_WKApplicationManifest.mm:
+        (makeVectorElement):
+        Used by makeVector in initWithCoder:. Takes a _WKApplicationManifestIcon and returns
+        a WebCore::ApplicationManifest::Icon.
+        (-[_WKApplicationManifest initWithCoder:]):
+        Added icons.
+        (-[_WKApplicationManifest encodeWithCoder:]):
+        Added icons.
+        (-[_WKApplicationManifest icons]):
+        Should appease build error before full support for icons is built into _WKApplicationManifest
+
+        (+[_WKApplicationManifestIcon supportsSecureCoding]):
+        (-[_WKApplicationManifestIcon initWithCoder:]):
+        (-[_WKApplicationManifestIcon encodeWithCoder:]):
+        (-[_WKApplicationManifestIcon dealloc]):
+        * UIProcess/API/Cocoa/_WKApplicationManifestInternal.h:
+
 2021-11-11  Kimmo Kinnunen  <[email protected]>
 
         REGRESSION (iOS 15, GPU Process): Fails to load texture map

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.h (285644 => 285645)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.h	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.h	2021-11-11 20:14:50 UTC (rev 285645)
@@ -31,6 +31,7 @@
 #else
 @class NSColor;
 #endif
+@class _WKApplicationManifestIcon;
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -41,6 +42,12 @@
     _WKApplicationManifestDisplayModeFullScreen,
 } WK_API_AVAILABLE(macos(10.13.4), ios(11.3));
 
+typedef NS_ENUM(NSInteger, _WKApplicationManifestIconPurpose) {
+    _WKApplicationManifestIconPurposeAny,
+    _WKApplicationManifestIconPurposeMonochrome,
+    _WKApplicationManifestIconPurposeMaskable,
+} WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 WK_CLASS_AVAILABLE(macos(10.13.4), ios(11.3))
 @interface _WKApplicationManifest : NSObject <NSSecureCoding>
 
@@ -50,6 +57,7 @@
 @property (nonatomic, readonly, nullable, copy) NSURL *scope;
 @property (nonatomic, readonly, copy) NSURL *startURL;
 @property (nonatomic, readonly) _WKApplicationManifestDisplayMode displayMode;
+@property (nonatomic, readonly) NSArray<_WKApplicationManifestIcon *> *icons WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if TARGET_OS_IPHONE
 @property (nonatomic, readonly, nullable, copy) UIColor *themeColor WK_API_AVAILABLE(ios(15.0));
@@ -61,4 +69,9 @@
 
 @end
 
+WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA))
+@interface _WKApplicationManifestIcon : NSObject <NSSecureCoding>
+// FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959
+@end
+
 NS_ASSUME_NONNULL_END

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.mm (285644 => 285645)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.mm	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.mm	2021-11-11 20:14:50 UTC (rev 285645)
@@ -41,6 +41,17 @@
 #import "AppKitSPI.h"
 #endif
 
+static std::optional<WebCore::ApplicationManifest::Icon> makeVectorElement(const WebCore::ApplicationManifest::Icon*, id arrayElement)
+{
+
+    if (![arrayElement isKindOfClass: _WKApplicationManifestIcon.class])
+        return std::nullopt;
+
+    return WebCore::ApplicationManifest::Icon {
+        // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959
+    };
+}
+
 @implementation _WKApplicationManifest
 
 #if ENABLE(APPLICATION_MANIFEST)
@@ -59,6 +70,7 @@
     NSInteger display = [aDecoder decodeIntegerForKey:@"display"];
     NSURL *startURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"start_url"];
     CocoaColor *themeColor = [aDecoder decodeObjectOfClass:[CocoaColor class] forKey:@"theme_color"];
+    NSArray<_WKApplicationManifestIcon *> *icons = [aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [_WKApplicationManifestIcon class]]] forKey:@"icons"];
 
     WebCore::ApplicationManifest coreApplicationManifest {
         WTF::String(name),
@@ -68,6 +80,7 @@
         static_cast<WebCore::ApplicationManifest::Display>(display),
         URL(startURL),
         WebCore::roundAndClampToSRGBALossy(themeColor.CGColor),
+        Vector<WebCore::ApplicationManifest::Icon>(makeVector<WebCore::ApplicationManifest::Icon>(icons)),
     };
 
     API::Object::constructInWrapper<API::ApplicationManifest>(self, WTFMove(coreApplicationManifest));
@@ -94,6 +107,7 @@
     [aCoder encodeInteger:static_cast<NSInteger>(_applicationManifest->applicationManifest().display) forKey:@"display"];
     [aCoder encodeObject:self.startURL forKey:@"start_url"];
     [aCoder encodeObject:self.themeColor forKey:@"theme_color"];
+    [aCoder encodeObject:self.icons forKey:@"icons"];
 }
 
 + (_WKApplicationManifest *)applicationManifestFromJSON:(NSString *)json manifestURL:(NSURL *)manifestURL documentURL:(NSURL *)documentURL
@@ -158,6 +172,12 @@
     ASSERT_NOT_REACHED();
 }
 
+- (NSArray<_WKApplicationManifestIcon *> *)icons
+{
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959
+    return nil;
+}
+
 #else // ENABLE(APPLICATION_MANIFEST)
 
 + (_WKApplicationManifest *)applicationManifestFromJSON:(NSString *)json manifestURL:(NSURL *)manifestURL documentURL:(NSURL *)documentURL
@@ -215,6 +235,42 @@
     return _WKApplicationManifestDisplayModeBrowser;
 }
 
+- (NSArray<_WKApplicationManifestIcon *> *)icons
+{
+    return nil;
+}
+
 #endif // ENABLE(APPLICATION_MANIFEST)
 
 @end
+
+@implementation _WKApplicationManifestIcon
+
++ (BOOL)supportsSecureCoding
+{
+    return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)aDecoder
+{
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959
+    UNUSED_PARAM(aDecoder);
+    [self release];
+    return nil;
+}
+
+- (void)encodeWithCoder:(NSCoder *)aCoder
+{
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959
+    UNUSED_PARAM(aCoder);
+}
+
+- (void)dealloc
+{
+    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959
+    if (WebCoreObjCScheduleDeallocateOnMainRunLoop(_WKApplicationManifestIcon.class, self))
+        return;
+    [super dealloc];
+}
+
+@end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifestInternal.h (285644 => 285645)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifestInternal.h	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifestInternal.h	2021-11-11 20:14:50 UTC (rev 285645)
@@ -27,6 +27,7 @@
 
 #import "APIApplicationManifest.h"
 #import "_WKApplicationManifest.h"
+#import <wtf/cocoa/VectorCocoa.h>
 
 #if ENABLE(APPLICATION_MANIFEST)
 

Modified: trunk/Tools/ChangeLog (285644 => 285645)


--- trunk/Tools/ChangeLog	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Tools/ChangeLog	2021-11-11 20:14:50 UTC (rev 285645)
@@ -1,3 +1,28 @@
+2021-11-11 Rachel Ginsberg <[email protected]>
+
+        Add support in WebCore for web app manifest icons
+        https://bugs.webkit.org/show_bug.cgi?id=231339
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp:
+        (ApplicationManifestParserTest::parseIconFirstTopLevelProperty):
+        Function to create JSON for icon attributes. This is
+        necessary because icons are in a list, whereas all other
+        attributes in app manifest are not.
+        (ApplicationManifestParserTest::parseIconFirstTopLevelPropertyForSrc):
+        Needed to make a slightly different version to add a src URL, since
+        it is required for a given icon to be added to the vector.
+
+        (ApplicationManifestParserTest::testIconsSrc):
+        (ApplicationManifestParserTest::testIconsType):
+        (ApplicationManifestParserTest::testIconsSizes):
+        (ApplicationManifestParserTest::testIconsPurposes):
+        Functions for each of the icon attributes.
+
+        (TEST_F):
+        Calls the various icon test functions with different input
+
 2021-11-11  Kimmo Kinnunen  <[email protected]>
 
         REGRESSION (iOS 15, GPU Process): Fails to load texture map

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp (285644 => 285645)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp	2021-11-11 19:46:00 UTC (rev 285644)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp	2021-11-11 20:14:50 UTC (rev 285645)
@@ -74,6 +74,18 @@
         return parseString(manifestContent);
     }
 
+    ApplicationManifest parseIconFirstTopLevelProperty(const String& key, const String& value)
+    {
+        String manifestContent = "{ \"icons\": [{\"" + key + "\": " + value + ", \"src\": \"icon/example.png\" }]}";
+        return parseString(manifestContent);
+    }
+
+    ApplicationManifest parseIconFirstTopLevelPropertyForSrc(const String& key, const String& value)
+    {
+        String manifestContent = "{ \"icons\": [{\"" + key + "\": " + value + " }]}";
+        return parseString(manifestContent);
+    }
+
     void testStartURL(const String& rawJSON, const String& expectedValue)
     {
         testStartURL(rawJSON, { { }, expectedValue });
@@ -134,6 +146,34 @@
         EXPECT_EQ(expectedValue, value);
     }
 
+    void testIconsSrc(const String& rawJSON, const URL& expectedValue)
+    {
+        auto manifest = parseIconFirstTopLevelPropertyForSrc("src", rawJSON);
+        auto value = manifest.icons[0].src;
+        EXPECT_STREQ(expectedValue.string().utf8().data(), value.string().utf8().data());
+    }
+
+    void testIconsType(const String &rawJSON, const String& expectedValue)
+    {
+        auto manifest = parseIconFirstTopLevelProperty("type", rawJSON);
+        auto value = manifest.icons[0].type;
+        EXPECT_STREQ(expectedValue.utf8().data(), value.utf8().data());
+    }
+
+    void testIconsSizes(const String &rawJSON, const String& expectedValue)
+    {
+        auto manifest = parseIconFirstTopLevelProperty("sizes", rawJSON);
+        auto value = manifest.icons[0].sizes;
+        EXPECT_STREQ(expectedValue.utf8().data(), value.utf8().data());
+    }
+
+    void testIconsPurposes(const String &rawJSON, OptionSet<ApplicationManifest::Icon::Purpose> expectedValues)
+    {
+        auto manifest = parseIconFirstTopLevelProperty("purpose", rawJSON);
+        auto value = manifest.icons[0].purposes;
+        EXPECT_EQ(expectedValues, value);
+    }
+
 };
 
 static void assertManifestHasDefaultValues(const URL& manifestURL, const URL& documentURL, const ApplicationManifest& manifest)
@@ -323,4 +363,33 @@
     EXPECT_STREQ("PASS", manifest.name.utf8().data());
 }
 
+TEST_F(ApplicationManifestParserTest, Icons)
+{
+    URL srcURL = { { }, "https://example.com/icon.jpg" };
+    testIconsSrc("\"icon.jpg\"", srcURL);
+    testIconsType("\"image/webp\"", "image/webp");
+    testIconsSizes("\"256x256\"", "256x256");
+    testIconsSizes("\"72x72 96x96\"", "72x72 96x96");
+
+    OptionSet<ApplicationManifest::Icon::Purpose> purposeAny { ApplicationManifest::Icon::Purpose::Any };
+    OptionSet<ApplicationManifest::Icon::Purpose> purposeMonochrome { ApplicationManifest::Icon::Purpose::Monochrome };
+    OptionSet<ApplicationManifest::Icon::Purpose> purposeMaskable { ApplicationManifest::Icon::Purpose::Maskable };
+
+    testIconsPurposes("\"monochrome\"", purposeMonochrome);
+    testIconsPurposes("\"maskable\"", purposeMaskable);
+    testIconsPurposes("\"any\"", purposeAny);
+    testIconsPurposes("\"\tMONOCHROME\"", purposeMonochrome);
+
+    testIconsPurposes("123", purposeAny);
+    testIconsPurposes("null", purposeAny);
+    testIconsPurposes("true", purposeAny);
+    testIconsPurposes("{ }", purposeAny);
+    testIconsPurposes("[ ]", purposeAny);
+
+    OptionSet<ApplicationManifest::Icon::Purpose> purposeMonochromeAny { ApplicationManifest::Icon::Purpose::Monochrome, ApplicationManifest::Icon::Purpose::Any };
+
+    testIconsPurposes("\"monochrome any\"", purposeMonochromeAny);
+
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to