Changeset 252023 in webkit


Ignore:
Timestamp:
Nov 4, 2019 3:55:15 PM (4 years ago)
Author:
dbates@webkit.org
Message:

Add Googletest assertion support for CGRect and NSRect
https://bugs.webkit.org/show_bug.cgi?id=203817

Reviewed by Myles C. Maxfield.

Add operator== and operator<< overloads for CGRect and NSRect so that these types can be
passed to EXPECT_EQ() and other Googletest assertions.

To make use of these overloads Cocoa tests should include #import "TestCocoa.h" instead of
"Test.h". TestCocoa.h imports Test.h. With these overloads an assertion like this:

EXPECT_EQ(CGRectMake(0, 0, 23, 24), rects[0].CGRectValue);

will produce output like this when it fails:

Expected equality of these values:

CGRectMake(138, 0, 23, 24)

Which is: (origin = (x = 138, y = 0), size = (width = 23, height = 24))

rects.firstObject.CGRectValue

Which is: (origin = (x = 96, y = 0), size = (width = 16, height = 17))

  • TestWebKitAPI/SourcesCocoa.txt:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

Add source files.

  • TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
  • TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm:

Write in terms of EXPECT_EQ() now that it just works when passed CGRects.

  • TestWebKitAPI/cocoa/TestCocoa.h: Added.
  • TestWebKitAPI/cocoa/TestCocoa.mm: Added.

(ostreamRectCommon):
(operator<<):
(operator==):

Location:
trunk/Tools
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r252017 r252023  
     12019-11-04  Daniel Bates  <dabates@apple.com>
     2
     3        Add Googletest assertion support for CGRect and NSRect
     4        https://bugs.webkit.org/show_bug.cgi?id=203817
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Add operator== and operator<< overloads for CGRect and NSRect so that these types can be
     9        passed to EXPECT_EQ() and other Googletest assertions.
     10
     11        To make use of these overloads Cocoa tests should include #import "TestCocoa.h" instead of
     12        "Test.h". TestCocoa.h imports Test.h. With these overloads an assertion like this:
     13
     14            EXPECT_EQ(CGRectMake(0, 0, 23, 24), rects[0].CGRectValue);
     15
     16        will produce output like this when it fails:
     17
     18            Expected equality of these values:
     19              CGRectMake(138, 0, 23, 24)
     20                Which is: (origin = (x = 138, y = 0), size = (width = 23, height = 24))
     21              rects.firstObject.CGRectValue
     22                Which is: (origin = (x = 96, y = 0), size = (width = 16, height = 17))
     23
     24        * TestWebKitAPI/SourcesCocoa.txt:
     25        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     26        Add source files.
     27
     28        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
     29        * TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm:
     30        Write in terms of EXPECT_EQ() now that it just works when passed CGRects.
     31
     32        * TestWebKitAPI/cocoa/TestCocoa.h: Added.
     33        * TestWebKitAPI/cocoa/TestCocoa.mm: Added.
     34        (ostreamRectCommon):
     35        (operator<<):
     36        (operator==):
     37
    1382019-11-04  Aakash Jain  <aakash_jain@apple.com>
    239
  • trunk/Tools/TestWebKitAPI/SourcesCocoa.txt

    r249684 r252023  
    2626
    2727cocoa/PlatformUtilitiesCocoa.mm
     28cocoa/TestCocoa.mm
    2829cocoa/TestNavigationDelegate.mm
    2930cocoa/TestProtocol.mm
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r251976 r252023  
    24342434                CE4D5DE51F6743BA0072CFC6 /* StringWithDirection.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StringWithDirection.cpp; sourceTree = "<group>"; };
    24352435                CE50D8C81C8665CE0072EA5A /* OptionSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OptionSet.cpp; sourceTree = "<group>"; };
     2436                CE640CA52370A4F300C5CAA4 /* TestCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TestCocoa.h; path = cocoa/TestCocoa.h; sourceTree = "<group>"; };
     2437                CE640CA62370A4F300C5CAA4 /* TestCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = TestCocoa.mm; path = cocoa/TestCocoa.mm; sourceTree = "<group>"; };
    24362438                CE6E819F20A6935F00E2C80F /* SetTimeoutFunction.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SetTimeoutFunction.mm; sourceTree = "<group>"; };
    24372439                CE6E81A320A933B800E2C80F /* set-timeout-function.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "set-timeout-function.html"; path = "ios/set-timeout-function.html"; sourceTree = SOURCE_ROOT; };
     
    27302732                                F44A531021B8976900DBB99C /* InstanceMethodSwizzler.mm */,
    27312733                                0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */,
     2734                                CE640CA52370A4F300C5CAA4 /* TestCocoa.h */,
     2735                                CE640CA62370A4F300C5CAA4 /* TestCocoa.mm */,
    27322736                                5CE7594822A883A500C12409 /* TestContextMenuDriver.h */,
    27332737                                5CE7594722A883A500C12409 /* TestContextMenuDriver.mm */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm

    r244955 r252023  
    2929
    3030#import "PlatformUtilities.h"
    31 #import "Test.h"
     31#import "TestCocoa.h"
    3232#import "TestNavigationDelegate.h"
    3333#import "TestWKWebView.h"
     
    4747    EXPECT_WK_STREQ(expected, [(NSAttributedString *)actual string]);
    4848
    49 #define EXPECT_RECT_EQ(xExpected, yExpected, widthExpected, heightExpected, rect) \
    50     EXPECT_DOUBLE_EQ(xExpected, rect.origin.x); \
    51     EXPECT_DOUBLE_EQ(yExpected, rect.origin.y); \
    52     EXPECT_DOUBLE_EQ(widthExpected, rect.size.width); \
    53     EXPECT_DOUBLE_EQ(heightExpected, rect.size.height);
    54 
    5549@interface WKContentView ()
    5650- (void)requestDocumentContext:(UIWKDocumentRequest *)request completionHandler:(void (^)(UIWKDocumentContext *))completionHandler;
     
    211205    }];
    212206    EXPECT_EQ(4UL, rects.count);
    213     EXPECT_RECT_EQ(0, 0, 23, 24, rects[0].CGRectValue);
    214     EXPECT_RECT_EQ(23, 0, 23, 24, rects[1].CGRectValue);
    215     EXPECT_RECT_EQ(46, 0, 23, 24, rects[2].CGRectValue);
    216     EXPECT_RECT_EQ(69, 0, 23, 24, rects[3].CGRectValue);
     207    EXPECT_EQ(CGRectMake(0, 0, 23, 24), rects[0].CGRectValue);
     208    EXPECT_EQ(CGRectMake(23, 0, 23, 24), rects[1].CGRectValue);
     209    EXPECT_EQ(CGRectMake(46, 0, 23, 24), rects[2].CGRectValue);
     210    EXPECT_EQ(CGRectMake(69, 0, 23, 24), rects[3].CGRectValue);
    217211    rects = [context characterRectsForCharacterRange:NSMakeRange(5, 1)];
    218212    EXPECT_EQ(0UL, rects.count);
     
    222216    rects = [context characterRectsForCharacterRange:NSMakeRange(0, 1)];
    223217    EXPECT_EQ(1UL, rects.count);
    224     EXPECT_RECT_EQ(0, 0, 23, 24, rects.firstObject.CGRectValue);
     218    EXPECT_EQ(CGRectMake(0, 0, 23, 24), rects.firstObject.CGRectValue);
    225219    rects = [context characterRectsForCharacterRange:NSMakeRange(6, 1)];
    226220    EXPECT_EQ(1UL, rects.count);
    227     EXPECT_RECT_EQ(138, 0, 23, 24, rects.firstObject.CGRectValue);
     221    EXPECT_EQ(CGRectMake(138, 0, 23, 24), rects.firstObject.CGRectValue);
    228222
    229223    // Text Input Context
     
    231225    NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    232226    EXPECT_EQ(1UL, textInputContexts.count);
    233     EXPECT_RECT_EQ(0, 0, 50, 50, textInputContexts[0].boundingRect);
     227    EXPECT_EQ(CGRectMake(0, 0, 50, 50), textInputContexts[0].boundingRect);
    234228
    235229    context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityWord, 0, CGRectZero, textInputContexts[0])];
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm

    r243915 r252023  
    2727
    2828#import "PlatformUtilities.h"
    29 #import "Test.h"
     29#import "TestCocoa.h"
    3030#import "TestNavigationDelegate.h"
    3131#import "TestWKWebView.h"
     
    3535#import <WebKit/_WKTextInputContext.h>
    3636#import <wtf/RetainPtr.h>
    37 
    38 #define EXPECT_RECT_EQ(xExpected, yExpected, widthExpected, heightExpected, rect) \
    39     EXPECT_DOUBLE_EQ(xExpected, rect.origin.x); \
    40     EXPECT_DOUBLE_EQ(yExpected, rect.origin.y); \
    41     EXPECT_DOUBLE_EQ(widthExpected, rect.size.width); \
    42     EXPECT_DOUBLE_EQ(heightExpected, rect.size.height);
    4337
    4438@implementation WKWebView (SynchronousTextInputContext)
     
    9387    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    9488    EXPECT_EQ(1UL, contexts.count);
    95     EXPECT_RECT_EQ(0, 0, 50, 50, contexts[0].boundingRect);
     89    EXPECT_EQ(CGRectMake(0, 0, 50, 50), contexts[0].boundingRect);
    9690
    9791    [webView synchronouslyLoadHTMLString:applyStyle(@"<textarea style='width: 100px; height: 100px;'></textarea>")];
    9892    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    9993    EXPECT_EQ(1UL, contexts.count);
    100     EXPECT_RECT_EQ(0, 0, 100, 100, contexts[0].boundingRect);
     94    EXPECT_EQ(CGRectMake(0, 0, 100, 100), contexts[0].boundingRect);
    10195
    10296    [webView synchronouslyLoadHTMLString:applyStyle(@"<div contenteditable style='width: 100px; height: 100px;'></div>")];
    10397    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    10498    EXPECT_EQ(1UL, contexts.count);
    105     EXPECT_RECT_EQ(0, 0, 100, 100, contexts[0].boundingRect);
     99    EXPECT_EQ(CGRectMake(0, 0, 100, 100), contexts[0].boundingRect);
    106100
    107101    // Basic inputs inside subframe.
     
    110104    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    111105    EXPECT_EQ(1UL, contexts.count);
    112     EXPECT_RECT_EQ(0, 200, 50, 50, contexts[0].boundingRect);
     106    EXPECT_EQ(CGRectMake(0, 200, 50, 50), contexts[0].boundingRect);
    113107
    114108    [webView synchronouslyLoadHTMLString:applyIframe(@"<textarea style='width: 100px; height: 100px;'></textarea>")];
    115109    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    116110    EXPECT_EQ(1UL, contexts.count);
    117     EXPECT_RECT_EQ(0, 200, 100, 100, contexts[0].boundingRect);
     111    EXPECT_EQ(CGRectMake(0, 200, 100, 100), contexts[0].boundingRect);
    118112
    119113    [webView synchronouslyLoadHTMLString:applyIframe(@"<div contenteditable style='width: 100px; height: 100px;'></div>")];
    120114    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    121115    EXPECT_EQ(1UL, contexts.count);
    122     EXPECT_RECT_EQ(0, 200, 100, 100, contexts[0].boundingRect);
     116    EXPECT_EQ(CGRectMake(0, 200, 100, 100), contexts[0].boundingRect);
    123117
    124118    // Read only inputs; should not be included.
     
    159153    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    160154    EXPECT_EQ(1UL, contexts.count);
    161     EXPECT_RECT_EQ(0, 0, 50, 50, contexts[0].boundingRect);
     155    EXPECT_EQ(CGRectMake(0, 0, 50, 50), contexts[0].boundingRect);
    162156
    163157    // Multiple inputs.
     
    166160    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    167161    EXPECT_EQ(3UL, contexts.count);
    168     EXPECT_RECT_EQ(0, 0, 50, 50, contexts[0].boundingRect);
    169     EXPECT_RECT_EQ(0, 50, 50, 50, contexts[1].boundingRect);
    170     EXPECT_RECT_EQ(0, 100, 50, 50, contexts[2].boundingRect);
     162    EXPECT_EQ(CGRectMake(0, 0, 50, 50), contexts[0].boundingRect);
     163    EXPECT_EQ(CGRectMake(0, 50, 50, 50), contexts[1].boundingRect);
     164    EXPECT_EQ(CGRectMake(0, 100, 50, 50), contexts[2].boundingRect);
    171165
    172166    // Nested <input>-inside-contenteditable. Only the contenteditable is considered.
     
    175169    contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]];
    176170    EXPECT_EQ(1UL, contexts.count);
    177     EXPECT_RECT_EQ(0, 0, 100, 100, contexts[0].boundingRect);
     171    EXPECT_EQ(CGRectMake(0, 0, 100, 100), contexts[0].boundingRect);
    178172}
    179173
Note: See TracChangeset for help on using the changeset viewer.