Title: [277030] trunk
Revision
277030
Author
[email protected]
Date
2021-05-05 11:17:53 -0700 (Wed, 05 May 2021)

Log Message

Sampled Page Top Color: take additional snapshots further down the page to see if the sampled top color is more than just a tiny strip
https://bugs.webkit.org/show_bug.cgi?id=225323

Reviewed by Beth Dakin.

Source/WebCore:

Add a `SampledPageTopColorMinHeight` setting that controls how far down the sampled page top
color needs to extend in order for us to not bail. If the value > 0, we take an additional
snapshot at (0, SampledPageTopColorMinHeight) and (width, SampledPageTopColorMinHeight),
comparing each to the snapshot directly above (e.g. (0, SampledPageTopColorMinHeight) is
compared to (0, 0)) using the `SampledPageTopColorMaxDifference`. Depending on the value, if
the color across the top of the page is only a small strip, these extra snapshot comparisons
will prevent a resulting color from being derived.

Tests: SampledPageTopColor.VerticalGradientBelowMaxDifference
       SampledPageTopColor.VerticalGradientAboveMaxDifference

* dom/Document.cpp:
(WebCore::Document::determineSampledPageTopColor):

Source/WebKit:

Add a `SampledPageTopColorMinHeight` setting that controls how far down the sampled page top
color needs to extend in order for us to not bail. If the value > 0, we take an additional
snapshot at (0, SampledPageTopColorMinHeight) and (width, SampledPageTopColorMinHeight),
comparing each to the snapshot directly above (e.g. (0, SampledPageTopColorMinHeight) is
compared to (0, 0)) using the `SampledPageTopColorMaxDifference`. Depending on the value, if
the color across the top of the page is only a small strip, these extra snapshot comparisons
will prevent a resulting color from being derived.

* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]):
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _setSampledPageTopColorMinHeight:]): Added.
(-[WKWebViewConfiguration _sampledPageTopColorMinHeight]): Added.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setupPageConfiguration:]):
Provide SPI to configure the `SampledPageTopColorMinHeight` preference when creating the `WKWebView`.

Source/WTF:

Add a `SampledPageTopColorMinHeight` setting that controls how far down the sampled page top
color needs to extend in order for us to not bail. If the value > 0, we take an additional
snapshot at (0, SampledPageTopColorMinHeight) and (width, SampledPageTopColorMinHeight),
comparing each to the snapshot directly above (e.g. (0, SampledPageTopColorMinHeight) is
compared to (0, 0)) using the `SampledPageTopColorMaxDifference`. Depending on the value, if
the color across the top of the page is only a small strip, these extra snapshot comparisons
will prevent a resulting color from being derived.

* Scripts/Preferences/WebPreferences.yaml:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm:
(createWebViewWithSampledPageTopColorMaxDifference):
(createHTMLGradientWithColorStops):
(TEST.SampledPageTopColor.ZeroMaxDifference):
(TEST.SampledPageTopColor.NegativeMaxDifference):
(TEST.SampledPageTopColor.SolidColor):
(TEST.SampledPageTopColor.DifferentColorsWithoutOutlierBelowMaxDifference):
(TEST.SampledPageTopColor.DifferentColorsWithLeftOutlierAboveMaxDifference):
(TEST.SampledPageTopColor.DifferentColorsWithMiddleOutlierAboveMaxDifference):
(TEST.SampledPageTopColor.DifferentColorsWithRightOutlierAboveMaxDifference):
(TEST.SampledPageTopColor.DifferentColorsIndividuallyAboveMaxDifference):
(TEST.SampledPageTopColor.DifferentColorsCumulativelyAboveMaxDifference):
(TEST.SampledPageTopColor.VerticalGradientBelowMaxDifference): Added.
(TEST.SampledPageTopColor.VerticalGradientAboveMaxDifference): Added.
(TEST.SampledPageTopColor.DISABLED_DisplayP3):
(TEST.SampledPageTopColor.ExperimentalUseSampledPageTopColorForScrollAreaBackgroundColor):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (277029 => 277030)


--- trunk/Source/WTF/ChangeLog	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WTF/ChangeLog	2021-05-05 18:17:53 UTC (rev 277030)
@@ -1,3 +1,20 @@
+2021-05-05  Devin Rousso  <[email protected]>
+
+        Sampled Page Top Color: take additional snapshots further down the page to see if the sampled top color is more than just a tiny strip
+        https://bugs.webkit.org/show_bug.cgi?id=225323
+
+        Reviewed by Beth Dakin.
+
+        Add a `SampledPageTopColorMinHeight` setting that controls how far down the sampled page top
+        color needs to extend in order for us to not bail. If the value > 0, we take an additional
+        snapshot at (0, SampledPageTopColorMinHeight) and (width, SampledPageTopColorMinHeight),
+        comparing each to the snapshot directly above (e.g. (0, SampledPageTopColorMinHeight) is
+        compared to (0, 0)) using the `SampledPageTopColorMaxDifference`. Depending on the value, if
+        the color across the top of the page is only a small strip, these extra snapshot comparisons
+        will prevent a resulting color from being derived.
+
+        * Scripts/Preferences/WebPreferences.yaml:
+
 2021-05-05  Sam Weinig  <[email protected]>
 
         Add preliminary support for specifying a color space for 2D canvas

Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferences.yaml (277029 => 277030)


--- trunk/Source/WTF/Scripts/Preferences/WebPreferences.yaml	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferences.yaml	2021-05-05 18:17:53 UTC (rev 277030)
@@ -1833,6 +1833,16 @@
     WebCore:
       default: 0
 
+SampledPageTopColorMinHeight:
+  type: double
+  defaultValue:
+    WebKitLegacy:
+      default: 0
+    WebKit:
+      default: 0
+    WebCore:
+      default: 0
+
 SansSerifFontFamily:
   type: String
   webKitLegacyPreferenceKey: WebKitSansSerifFont

Modified: trunk/Source/WebCore/ChangeLog (277029 => 277030)


--- trunk/Source/WebCore/ChangeLog	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WebCore/ChangeLog	2021-05-05 18:17:53 UTC (rev 277030)
@@ -1,3 +1,24 @@
+2021-05-05  Devin Rousso  <[email protected]>
+
+        Sampled Page Top Color: take additional snapshots further down the page to see if the sampled top color is more than just a tiny strip
+        https://bugs.webkit.org/show_bug.cgi?id=225323
+
+        Reviewed by Beth Dakin.
+
+        Add a `SampledPageTopColorMinHeight` setting that controls how far down the sampled page top
+        color needs to extend in order for us to not bail. If the value > 0, we take an additional
+        snapshot at (0, SampledPageTopColorMinHeight) and (width, SampledPageTopColorMinHeight),
+        comparing each to the snapshot directly above (e.g. (0, SampledPageTopColorMinHeight) is
+        compared to (0, 0)) using the `SampledPageTopColorMaxDifference`. Depending on the value, if
+        the color across the top of the page is only a small strip, these extra snapshot comparisons
+        will prevent a resulting color from being derived.
+
+        Tests: SampledPageTopColor.VerticalGradientBelowMaxDifference
+               SampledPageTopColor.VerticalGradientAboveMaxDifference
+
+        * dom/Document.cpp:
+        (WebCore::Document::determineSampledPageTopColor):
+
 2021-05-05  Youenn Fablet  <[email protected]>
 
         No need to error a fetch body stream if its request or response is stopped

Modified: trunk/Source/WebCore/dom/Document.cpp (277029 => 277030)


--- trunk/Source/WebCore/dom/Document.cpp	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-05-05 18:17:53 UTC (rev 277030)
@@ -3914,8 +3914,7 @@
     });
 
     // FIXME: <https://webkit.org/b/225167> (Sampled Page Top Color: hook into painting logic instead of taking snapshots)
-    auto pixelColorAtTopX = [&] (int x) -> Optional<Lab<float>> {
-        IntPoint location(x, 0);
+    auto pixelColor = [&] (IntPoint&& location) -> Optional<Lab<float>> {
         IntSize size(1, 1);
 
         if (isHitTestLocationThirdPartyFrame(LayoutPoint(location)))
@@ -3948,7 +3947,7 @@
     };
 
     for (size_t i = 0; i < numSnapshots; ++i) {
-        auto snapshot = pixelColorAtTopX(frameWidth * i / (numSnapshots - 1));
+        auto snapshot = pixelColor(IntPoint(frameWidth * i / (numSnapshots - 1), 0));
         if (!snapshot) {
             if (shouldStopAfterFindingNonMatchingColor(i))
                 return;
@@ -3992,6 +3991,24 @@
         }
     }
 
+    // Decrease the height by one pixel so that the last snapshot is within bounds and not off-by-one.
+    auto minHeight = settings().sampledPageTopColorMinHeight() - 1;
+    if (minHeight > 0) {
+        if (nonMatchingColorIndex) {
+            if (auto leftMiddleSnapshot = pixelColor(IntPoint(0, minHeight))) {
+                if (colorDifference(*leftMiddleSnapshot, snapshots[0]) > maxDifference)
+                    return;
+            }
+        }
+
+        if (nonMatchingColorIndex != numSnapshots - 1) {
+            if (auto rightMiddleSnapshot = pixelColor(IntPoint(frameWidth, minHeight))) {
+                if (colorDifference(*rightMiddleSnapshot, snapshots[numSnapshots - 1]) > maxDifference)
+                    return;
+            }
+        }
+    }
+
     auto snapshotsToAverage = snapshots;
     auto validSnapshotCount = numSnapshots;
     if (!nonMatchingColorIndex) {

Modified: trunk/Source/WebKit/ChangeLog (277029 => 277030)


--- trunk/Source/WebKit/ChangeLog	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WebKit/ChangeLog	2021-05-05 18:17:53 UTC (rev 277030)
@@ -1,3 +1,28 @@
+2021-05-05  Devin Rousso  <[email protected]>
+
+        Sampled Page Top Color: take additional snapshots further down the page to see if the sampled top color is more than just a tiny strip
+        https://bugs.webkit.org/show_bug.cgi?id=225323
+
+        Reviewed by Beth Dakin.
+
+        Add a `SampledPageTopColorMinHeight` setting that controls how far down the sampled page top
+        color needs to extend in order for us to not bail. If the value > 0, we take an additional
+        snapshot at (0, SampledPageTopColorMinHeight) and (width, SampledPageTopColorMinHeight),
+        comparing each to the snapshot directly above (e.g. (0, SampledPageTopColorMinHeight) is
+        compared to (0, 0)) using the `SampledPageTopColorMaxDifference`. Depending on the value, if
+        the color across the top of the page is only a small strip, these extra snapshot comparisons
+        will prevent a resulting color from being derived.
+
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration init]):
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _setSampledPageTopColorMinHeight:]): Added.
+        (-[WKWebViewConfiguration _sampledPageTopColorMinHeight]): Added.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setupPageConfiguration:]):
+        Provide SPI to configure the `SampledPageTopColorMinHeight` preference when creating the `WKWebView`.
+
 2021-05-05  Youenn Fablet  <[email protected]>
 
         REGRESSION (r276633): ASSERTION FAILED: !forbidMallocUseScopeCount || disableMallocRestrictionScopeCount

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (277029 => 277030)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2021-05-05 18:17:53 UTC (rev 277030)
@@ -561,6 +561,7 @@
 #endif
 
     pageConfiguration->preferences()->setSampledPageTopColorMaxDifference([_configuration _sampledPageTopColorMaxDifference]);
+    pageConfiguration->preferences()->setSampledPageTopColorMinHeight([_configuration _sampledPageTopColorMinHeight]);
 
     if (!linkedOnOrAfter(WebCore::SDKVersion::FirstWhereSiteSpecificQuirksAreEnabledByDefault))
         pageConfiguration->preferences()->setNeedsSiteSpecificQuirks(false);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (277029 => 277030)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2021-05-05 18:17:53 UTC (rev 277030)
@@ -178,6 +178,7 @@
     BOOL _appHighlightsEnabled;
 #endif
     double _sampledPageTopColorMaxDifference;
+    double _sampledPageTopColorMinHeight;
 
     RetainPtr<NSString> _mediaContentTypesRequiringHardwareSupport;
     RetainPtr<NSArray<NSString *>> _additionalSupportedImageTypes;
@@ -277,6 +278,7 @@
 #endif
 
     _sampledPageTopColorMaxDifference = DEFAULT_VALUE_FOR_SampledPageTopColorMaxDifference;
+    _sampledPageTopColorMinHeight = DEFAULT_VALUE_FOR_SampledPageTopColorMinHeight;
 
     return self;
 }
@@ -457,6 +459,7 @@
 #endif
 
     configuration->_sampledPageTopColorMaxDifference = self->_sampledPageTopColorMaxDifference;
+    configuration->_sampledPageTopColorMinHeight = self->_sampledPageTopColorMinHeight;
 
     return configuration;
 }
@@ -1288,6 +1291,16 @@
     return _sampledPageTopColorMaxDifference;
 }
 
+- (void)_setSampledPageTopColorMinHeight:(double)value
+{
+    _sampledPageTopColorMinHeight = value;
+}
+
+- (double)_sampledPageTopColorMinHeight
+{
+    return _sampledPageTopColorMinHeight;
+}
+
 @end
 
 @implementation WKWebViewConfiguration (WKDeprecated)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h (277029 => 277030)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2021-05-05 18:17:53 UTC (rev 277030)
@@ -127,6 +127,10 @@
 // Expects 0 (disables page top color sampling entirely) or any positive number.
 @property (nonatomic, setter=_setSampledPageTopColorMaxDifference:) double _sampledPageTopColorMaxDifference WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+// How far down the page the sampled page top color needs to extend in order to be considered valid.
+// Expects 0 (the color doesn't need to continue into the page at all) or any positive number.
+@property (nonatomic, setter=_setSampledPageTopColorMinHeight:) double _sampledPageTopColorMinHeight WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #if TARGET_OS_IPHONE

Modified: trunk/Tools/ChangeLog (277029 => 277030)


--- trunk/Tools/ChangeLog	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Tools/ChangeLog	2021-05-05 18:17:53 UTC (rev 277030)
@@ -1,3 +1,27 @@
+2021-05-05  Devin Rousso  <[email protected]>
+
+        Sampled Page Top Color: take additional snapshots further down the page to see if the sampled top color is more than just a tiny strip
+        https://bugs.webkit.org/show_bug.cgi?id=225323
+
+        Reviewed by Beth Dakin.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm:
+        (createWebViewWithSampledPageTopColorMaxDifference):
+        (createHTMLGradientWithColorStops):
+        (TEST.SampledPageTopColor.ZeroMaxDifference):
+        (TEST.SampledPageTopColor.NegativeMaxDifference):
+        (TEST.SampledPageTopColor.SolidColor):
+        (TEST.SampledPageTopColor.DifferentColorsWithoutOutlierBelowMaxDifference):
+        (TEST.SampledPageTopColor.DifferentColorsWithLeftOutlierAboveMaxDifference):
+        (TEST.SampledPageTopColor.DifferentColorsWithMiddleOutlierAboveMaxDifference):
+        (TEST.SampledPageTopColor.DifferentColorsWithRightOutlierAboveMaxDifference):
+        (TEST.SampledPageTopColor.DifferentColorsIndividuallyAboveMaxDifference):
+        (TEST.SampledPageTopColor.DifferentColorsCumulativelyAboveMaxDifference):
+        (TEST.SampledPageTopColor.VerticalGradientBelowMaxDifference): Added.
+        (TEST.SampledPageTopColor.VerticalGradientAboveMaxDifference): Added.
+        (TEST.SampledPageTopColor.DISABLED_DisplayP3):
+        (TEST.SampledPageTopColor.ExperimentalUseSampledPageTopColorForScrollAreaBackgroundColor):
+
 2021-05-05  Sam Weinig  <[email protected]>
 
         Add preliminary support for specifying a color space for 2D canvas

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm (277029 => 277030)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm	2021-05-05 18:12:25 UTC (rev 277029)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SampledPageTopColor.mm	2021-05-05 18:17:53 UTC (rev 277030)
@@ -82,10 +82,11 @@
 @end
 
 enum class UseSampledPageTopColorForScrollAreaBackgroundColor : bool { Yes, No };
-static RetainPtr<TestWKWebView> createWebViewWithSampledPageTopColorMaxDifference(double sampledPageTopColorMaxDifference, UseSampledPageTopColorForScrollAreaBackgroundColor useSampledPageTopColorForScrollAreaBackgroundColor = UseSampledPageTopColorForScrollAreaBackgroundColor::No)
+static RetainPtr<TestWKWebView> createWebViewWithSampledPageTopColorMaxDifference(double sampledPageTopColorMaxDifference, double sampledPageTopColorMinHeight = 0, UseSampledPageTopColorForScrollAreaBackgroundColor useSampledPageTopColorForScrollAreaBackgroundColor = UseSampledPageTopColorForScrollAreaBackgroundColor::No)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [configuration _setSampledPageTopColorMaxDifference:sampledPageTopColorMaxDifference];
+    [configuration _setSampledPageTopColorMinHeight:sampledPageTopColorMinHeight];
 
     for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
         if ([feature.key isEqualToString:@"UseSampledPageTopColorForScrollAreaBackgroundColor"]) {
@@ -107,12 +108,13 @@
     TestWebKitAPI::Util::run(&done);
 }
 
-static String createHTMLGradientWithColorStops(Vector<String>&& colorStops)
+static String createHTMLGradientWithColorStops(String&& direction, Vector<String>&& colorStops)
 {
     EXPECT_GE(colorStops.size(), 2UL);
 
     StringBuilder gradientBuilder;
-    gradientBuilder.append("<body style=\"background-image: linear-gradient(to right"_s);
+    gradientBuilder.append("<body style=\"background-image: linear-gradient(to "_s);
+    gradientBuilder.append(WTFMove(direction));
     for (auto&& colorStop : WTFMove(colorStops)) {
         gradientBuilder.append(", "_s);
         gradientBuilder.append(WTFMove(colorStop));
@@ -126,7 +128,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(0);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({ "red", "red" })];
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, { "red"_s, "red"_s })];
     EXPECT_NULL([webView _sampledPageTopColor]);
 }
 
@@ -135,7 +137,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(-5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({ "red", "red" })];
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, { "red"_s, "red"_s })];
     EXPECT_NULL([webView _sampledPageTopColor]);
 }
 
@@ -144,7 +146,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops({ "red", "red" }));
+    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops("right"_s, { "red"_s, "red"_s }));
     EXPECT_EQ(WebCore::Color([webView _sampledPageTopColor].CGColor), WebCore::Color::red);
 }
 
@@ -153,7 +155,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops({
+    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops("right"_s, {
         "lab(1% 0 0)"_s,
         "lab(2% 0 0)"_s,
         "lab(3% 0 0)"_s,
@@ -173,7 +175,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops({
+    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops("right"_s, {
         "lab(100% 0 0)"_s, // outlier
         "lab(1% 0 0)"_s,
         "lab(2% 0 0)"_s,
@@ -193,7 +195,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, {
         "lab(1% 0 0)"_s,
         "lab(2% 0 0)"_s,
         "lab(100% 0 0)"_s, // outlier
@@ -208,7 +210,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops({
+    waitForSampledPageTopColorToChangeForHTML(webView.get(), createHTMLGradientWithColorStops("right"_s, {
         "lab(1% 0 0)"_s,
         "lab(2% 0 0)"_s,
         "lab(3% 0 0)"_s,
@@ -228,7 +230,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, {
         "lab(10% 0 0)"_s,
         "lab(20% 0 0)"_s,
         "lab(30% 0 0)"_s,
@@ -243,7 +245,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, {
         "lab(1% 0 0)"_s,
         "lab(3% 0 0)"_s,
         "lab(5% 0 0)"_s,
@@ -253,6 +255,35 @@
     EXPECT_NULL([webView _sampledPageTopColor]);
 }
 
+TEST(SampledPageTopColor, VerticalGradientBelowMaxDifference)
+{
+    auto webView = createWebViewWithSampledPageTopColorMaxDifference(5, 100);
+    EXPECT_NULL([webView _sampledPageTopColor]);
+
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("bottom"_s, {
+        "lab(1% 0 0)"_s,
+        "lab(2% 0 0)"_s,
+        "lab(3% 0 0)"_s,
+        "lab(4% 0 0)"_s,
+        "lab(5% 0 0)"_s,
+        "lab(6% 0 0)"_s,
+    })];
+    auto components = CGColorGetComponents([webView _sampledPageTopColor].CGColor);
+    EXPECT_IN_RANGE(components[0], 0.01, 0.02);
+    EXPECT_IN_RANGE(components[1], 0.01, 0.02);
+    EXPECT_IN_RANGE(components[2], 0.01, 0.02);
+    EXPECT_EQ(components[3], 1);
+}
+
+TEST(SampledPageTopColor, VerticalGradientAboveMaxDifference)
+{
+    auto webView = createWebViewWithSampledPageTopColorMaxDifference(5, 100);
+    EXPECT_NULL([webView _sampledPageTopColor]);
+
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("bottom"_s, { "red"_s, "blue"_s })];
+    EXPECT_NULL([webView _sampledPageTopColor]);
+}
+
 // FIXME: <https://webkit.org/b/225167> (Sampled Page Top Color: hook into painting logic instead of taking snapshots)
 TEST(SampledPageTopColor, DISABLED_DisplayP3)
 {
@@ -259,7 +290,7 @@
     auto webView = createWebViewWithSampledPageTopColorMaxDifference(5);
     EXPECT_NULL([webView _sampledPageTopColor]);
 
-    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({
+    [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, {
         "color(display-p3 0.99 0 0)"_s,
         "color(display-p3 0.98 0 0)"_s,
         "color(display-p3 0.97 0 0)"_s,
@@ -280,25 +311,25 @@
 
 TEST(SampledPageTopColor, ExperimentalUseSampledPageTopColorForScrollAreaBackgroundColor)
 {
-    auto webViewWithoutThemeColorForScrollAreaBackgroundColor = createWebViewWithSampledPageTopColorMaxDifference(5, UseSampledPageTopColorForScrollAreaBackgroundColor::No);
+    auto webViewWithoutThemeColorForScrollAreaBackgroundColor = createWebViewWithSampledPageTopColorMaxDifference(5, 0, UseSampledPageTopColorForScrollAreaBackgroundColor::No);
     EXPECT_NULL([webViewWithoutThemeColorForScrollAreaBackgroundColor _sampledPageTopColor]);
 
-    [webViewWithoutThemeColorForScrollAreaBackgroundColor synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({ "red", "blue" })];
+    [webViewWithoutThemeColorForScrollAreaBackgroundColor synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, { "red"_s, "blue"_s })];
     EXPECT_NULL([webViewWithoutThemeColorForScrollAreaBackgroundColor _sampledPageTopColor]);
     EXPECT_EQ(WebCore::Color([webViewWithoutThemeColorForScrollAreaBackgroundColor scrollView].backgroundColor.CGColor), WebCore::Color::white);
 
-    waitForSampledPageTopColorToChangeForHTML(webViewWithoutThemeColorForScrollAreaBackgroundColor.get(), createHTMLGradientWithColorStops({ "red", "red" }));
+    waitForSampledPageTopColorToChangeForHTML(webViewWithoutThemeColorForScrollAreaBackgroundColor.get(), createHTMLGradientWithColorStops("right"_s, { "red"_s, "red"_s }));
     EXPECT_EQ(WebCore::Color([webViewWithoutThemeColorForScrollAreaBackgroundColor _sampledPageTopColor].CGColor), WebCore::Color::red);
     EXPECT_EQ(WebCore::Color([webViewWithoutThemeColorForScrollAreaBackgroundColor scrollView].backgroundColor.CGColor), WebCore::Color::white);
 
-    auto webViewWithThemeColorForScrollAreaBackgroundColor = createWebViewWithSampledPageTopColorMaxDifference(5, UseSampledPageTopColorForScrollAreaBackgroundColor::Yes);
+    auto webViewWithThemeColorForScrollAreaBackgroundColor = createWebViewWithSampledPageTopColorMaxDifference(5, 0, UseSampledPageTopColorForScrollAreaBackgroundColor::Yes);
     EXPECT_NULL([webViewWithThemeColorForScrollAreaBackgroundColor _sampledPageTopColor]);
 
-    [webViewWithThemeColorForScrollAreaBackgroundColor synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops({ "red", "blue" })];
+    [webViewWithThemeColorForScrollAreaBackgroundColor synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:createHTMLGradientWithColorStops("right"_s, { "red"_s, "blue"_s })];
     EXPECT_NULL([webViewWithThemeColorForScrollAreaBackgroundColor _sampledPageTopColor]);
     EXPECT_EQ(WebCore::Color([webViewWithThemeColorForScrollAreaBackgroundColor scrollView].backgroundColor.CGColor), WebCore::Color::white);
 
-    waitForSampledPageTopColorToChangeForHTML(webViewWithThemeColorForScrollAreaBackgroundColor.get(), createHTMLGradientWithColorStops({ "red", "red" }));
+    waitForSampledPageTopColorToChangeForHTML(webViewWithThemeColorForScrollAreaBackgroundColor.get(), createHTMLGradientWithColorStops("right"_s, { "red"_s, "red"_s }));
     EXPECT_EQ(WebCore::Color([webViewWithThemeColorForScrollAreaBackgroundColor _sampledPageTopColor].CGColor), WebCore::Color::red);
     EXPECT_EQ(WebCore::Color([webViewWithThemeColorForScrollAreaBackgroundColor scrollView].backgroundColor.CGColor), WebCore::Color::red);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to