Changeset 93405 in webkit


Ignore:
Timestamp:
Aug 19, 2011 7:51:16 AM (13 years ago)
Author:
Adam Roben
Message:

Pull some of DynamicDeviceScaleFactor's code up into a shareable base class

This will make it easier to write other WebKit-agnostic tests

Fixes <http://webkit.org/b/66558> Would like to be able to reuse DynamicDeviceScaleFactor's
code in other WebKit-agnostic tests

Reviewed by Anders Carlsson.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
  • TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm: Fixed copyright. Moved a bunch of

code to WebKitAgnosticTest.h/mm. Changed to inherit from WebKitAgnosticTest.
(TestWebKitAPI::DynamicDeviceScaleFactor::url): Simple getter.
(TestWebKitAPI::DynamicDeviceScaleFactor::didLoadURL): Calls through to runTest.
(TestWebKitAPI::DynamicDeviceScaleFactor::runTest): Removed loading code which
WebKitAgnosticTest handles for us.
(TestWebKitAPI::TEST_F): Removed view-creation code which WebKitAgnosticTest handles for us.

  • TestWebKitAPI/mac/WebKitAgnosticTest.h: Added. Code came from DynamicDeviceScaleFactor.

(TestWebKitAPI::WebKitAgnosticTest::loadSynchronously): Code came from
DynamicDeviceScaleFactor::runTest.

  • TestWebKitAPI/mac/WebKitAgnosticTest.mm: Copied from Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm.

(TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test): Code came from
DynamicDeviceScaleFactor.WebKit.
(TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test): Code came from
DynamicDeviceScaleFactor.WebKit2.

Location:
trunk/Tools
Files:
1 added
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r93404 r93405  
     12011-08-19  Adam Roben  <aroben@apple.com>
     2
     3        Pull some of DynamicDeviceScaleFactor's code up into a shareable base class
     4
     5        This will make it easier to write other WebKit-agnostic tests
     6
     7        Fixes <http://webkit.org/b/66558> Would like to be able to reuse DynamicDeviceScaleFactor's
     8        code in other WebKit-agnostic tests
     9
     10        Reviewed by Anders Carlsson.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
     13
     14        * TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm: Fixed copyright. Moved a bunch of
     15        code to WebKitAgnosticTest.h/mm. Changed to inherit from WebKitAgnosticTest.
     16        (TestWebKitAPI::DynamicDeviceScaleFactor::url): Simple getter.
     17        (TestWebKitAPI::DynamicDeviceScaleFactor::didLoadURL): Calls through to runTest.
     18        (TestWebKitAPI::DynamicDeviceScaleFactor::runTest): Removed loading code which
     19        WebKitAgnosticTest handles for us.
     20        (TestWebKitAPI::TEST_F): Removed view-creation code which WebKitAgnosticTest handles for us.
     21
     22        * TestWebKitAPI/mac/WebKitAgnosticTest.h: Added. Code came from DynamicDeviceScaleFactor.
     23        (TestWebKitAPI::WebKitAgnosticTest::loadAndWaitUntilDone): Code came from
     24        DynamicDeviceScaleFactor::runTest.
     25
     26        * TestWebKitAPI/mac/WebKitAgnosticTest.mm: Copied from Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm.
     27        (TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test): Code came from
     28        DynamicDeviceScaleFactor.WebKit.
     29        (TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test): Code came from
     30        DynamicDeviceScaleFactor.WebKit2.
     31
    1322011-08-19  Adam Roben  <aroben@apple.com>
    233
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r93315 r93405  
    6666                C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */; };
    6767                C081224913FC1B0300DC39AE /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C081224813FC1B0300DC39AE /* WebKit.framework */; };
     68                C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */; };
    6869                C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */; };
    6970                C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */; };
     
    187188                C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SyntheticBackingScaleFactorWindow.m; sourceTree = "<group>"; };
    188189                C081224813FC1B0300DC39AE /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
     190                C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitAgnosticTest.mm; sourceTree = "<group>"; };
     191                C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAgnosticTest.h; sourceTree = "<group>"; };
    189192                C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptTest.cpp; sourceTree = "<group>"; };
    190193                C0ADBE7B12FCA4D000D2C129 /* JavaScriptTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptTest.h; sourceTree = "<group>"; };
     
    373376                                C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */,
    374377                                C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */,
     378                                C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */,
     379                                C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */,
    375380                        );
    376381                        path = mac;
     
    519524                                C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */,
    520525                                C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */,
     526                                C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */,
    521527                        );
    522528                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm

    r93404 r93405  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
     26#include "WebKitAgnosticTest.h"
     27
    2628#include "JavaScriptTest.h"
    2729#include "PlatformUtilities.h"
    2830#include "SyntheticBackingScaleFactorWindow.h"
    29 #include <WebKit2/WKURLCF.h>
    3031#include <wtf/RetainPtr.h>
    31 
    32 @interface FrameLoadDelegate : NSObject {
    33     bool* _didFinishLoad;
    34 }
    35 
    36 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad;
    37 
    38 @end
    39 
    40 @implementation FrameLoadDelegate
    41 
    42 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad
    43 {
    44     self = [super init];
    45     if (!self)
    46         return nil;
    47 
    48     _didFinishLoad = didFinishLoad;
    49     return self;
    50 }
    51 
    52 - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame
    53 {
    54     *_didFinishLoad = true;
    55 }
    56 
    57 @end
    5832
    5933namespace TestWebKitAPI {
    6034
    61 static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* context)
    62 {
    63     *static_cast<bool*>(const_cast<void*>(context)) = true;
    64 }
    65 
    66 static void setPageLoaderClient(WKPageRef page, bool* didFinishLoad)
    67 {
    68     WKPageLoaderClient loaderClient;
    69     memset(&loaderClient, 0, sizeof(loaderClient));
    70     loaderClient.version = 0;
    71     loaderClient.clientInfo = didFinishLoad;
    72     loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    73 
    74     WKPageSetPageLoaderClient(page, &loaderClient);
    75 }
    76 
    77 class DynamicDeviceScaleFactor : public ::testing::Test {
     35class DynamicDeviceScaleFactor : public WebKitAgnosticTest {
    7836public:
    79     DynamicDeviceScaleFactor();
     37    RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
    8038
    8139    template <typename View> void runTest(View);
    8240
    83     bool didFinishLoad;
    84     NSRect viewFrame;
    85 
    86 private:
    87     RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
    88 
    89     void loadURL(WebView *, NSURL *);
    90     void loadURL(WKView *, NSURL *);
     41    // WebKitAgnosticTest
     42    virtual NSURL *url() const { return [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]; }
     43    virtual void didLoadURL(WebView *webView) { runTest(webView); }
     44    virtual void didLoadURL(WKView *wkView) { runTest(wkView); }
    9145};
    92 
    93 DynamicDeviceScaleFactor::DynamicDeviceScaleFactor()
    94     : didFinishLoad(false)
    95     , viewFrame(NSMakeRect(0, 0, 800, 600))
    96 {
    97 }
    9846
    9947RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWindow()
     
    10755void DynamicDeviceScaleFactor::runTest(View view)
    10856{
    109     EXPECT_FALSE(didFinishLoad);
    110     loadURL(view, [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]);
    111     Util::run(&didFinishLoad);
    112     didFinishLoad = false;
    113 
    11457    EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
    11558    EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
     
    13477}
    13578
    136 void DynamicDeviceScaleFactor::loadURL(WebView *webView, NSURL *url)
    137 {
    138     [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
    139 }
    140 
    141 void DynamicDeviceScaleFactor::loadURL(WKView *view, NSURL *url)
    142 {
    143     WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
    144 }
    145 
    14679TEST_F(DynamicDeviceScaleFactor, WebKit)
    14780{
    148     RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
    149     RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] initWithDidFinishLoadBoolean:&didFinishLoad]);
    150     [webView.get() setFrameLoadDelegate:delegate.get()];
    151 
    152     runTest(webView.get());
     81    runWebKit1Test();
    15382}
    15483
    15584TEST_F(DynamicDeviceScaleFactor, WebKit2)
    15685{
    157     WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
    158     RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame contextRef:context.get()]);
    159     setPageLoaderClient([view.get() pageRef], &didFinishLoad);
    160 
    161     runTest(view.get());
     86    runWebKit2Test();
    16287}
    16388
  • trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm

    r93404 r93405  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #include "JavaScriptTest.h"
    27 #include "PlatformUtilities.h"
    28 #include "SyntheticBackingScaleFactorWindow.h"
     26#include "WebKitAgnosticTest.h"
     27
    2928#include <WebKit2/WKURLCF.h>
    3029#include <wtf/RetainPtr.h>
     
    7574}
    7675
    77 class DynamicDeviceScaleFactor : public ::testing::Test {
    78 public:
    79     DynamicDeviceScaleFactor();
    80 
    81     template <typename View> void runTest(View);
    82 
    83     bool didFinishLoad;
    84     NSRect viewFrame;
    85 
    86 private:
    87     RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
    88 
    89     void loadURL(WebView *, NSURL *);
    90     void loadURL(WKView *, NSURL *);
    91 };
    92 
    93 DynamicDeviceScaleFactor::DynamicDeviceScaleFactor()
     76WebKitAgnosticTest::WebKitAgnosticTest()
    9477    : didFinishLoad(false)
    9578    , viewFrame(NSMakeRect(0, 0, 800, 600))
     
    9780}
    9881
    99 RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWindow()
    100 {
    101     RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
    102     [window.get() setReleasedWhenClosed:NO];
    103     return window;
    104 }
    105 
    106 template <typename View>
    107 void DynamicDeviceScaleFactor::runTest(View view)
    108 {
    109     EXPECT_FALSE(didFinishLoad);
    110     loadURL(view, [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]);
    111     Util::run(&didFinishLoad);
    112     didFinishLoad = false;
    113 
    114     EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
    115     EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
    116 
    117     RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
    118     [window1.get() setBackingScaleFactor:3];
    119 
    120     [[window1.get() contentView] addSubview:view];
    121     EXPECT_JS_EQ(view, "window.devicePixelRatio", "3");
    122     EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "3");
    123 
    124     RetainPtr<SyntheticBackingScaleFactorWindow> window2 = createWindow();
    125     [window2.get() setBackingScaleFactor:4];
    126 
    127     [[window2.get() contentView] addSubview:view];
    128     EXPECT_JS_EQ(view, "window.devicePixelRatio", "4");
    129     EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "4");
    130 
    131     [view removeFromSuperview];
    132     EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
    133     EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
    134 }
    135 
    136 void DynamicDeviceScaleFactor::loadURL(WebView *webView, NSURL *url)
    137 {
    138     [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
    139 }
    140 
    141 void DynamicDeviceScaleFactor::loadURL(WKView *view, NSURL *url)
    142 {
    143     WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
    144 }
    145 
    146 TEST_F(DynamicDeviceScaleFactor, WebKit)
     82void WebKitAgnosticTest::runWebKit1Test()
    14783{
    14884    RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
     
    15086    [webView.get() setFrameLoadDelegate:delegate.get()];
    15187
    152     runTest(webView.get());
     88    loadAndWaitUntilFinished(webView.get(), url());
     89    didLoadURL(webView.get());
    15390}
    15491
    155 TEST_F(DynamicDeviceScaleFactor, WebKit2)
     92void WebKitAgnosticTest::runWebKit2Test()
    15693{
    15794    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
     
    15996    setPageLoaderClient([view.get() pageRef], &didFinishLoad);
    16097
    161     runTest(view.get());
     98    loadAndWaitUntilFinished(view.get(), url());
     99    didLoadURL(view.get());
     100}
     101
     102void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url)
     103{
     104    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
     105}
     106
     107void WebKitAgnosticTest::loadURL(WKView *view, NSURL *url)
     108{
     109    WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
    162110}
    163111
Note: See TracChangeset for help on using the changeset viewer.