2007-11-21 Eric Seidel <eric@webkit.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Nov 2007 19:29:08 +0000 (19:29 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Nov 2007 19:29:08 +0000 (19:29 +0000)
        Reviewed by Tim Hatcher.

        Abstract more of DRT into static methods

        * DumpRenderTree/mac/DumpRenderTree.mm:
        (setDefaultsToConsistentValuesForTesting):
        (setupSignalHandlers):
        (allocateGlobalControllers):
        (releaseAndZero):
        (releaseGlobalControllers):
        (dumpRenderTree):
        (shouldLogFrameLoadDelegates):
        (createCFURLFromPathOrURL):
        (resetWebViewToConsistentStateBeforeTesting):
        (runTest):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27942 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm

index 7ba5bcd1abe474b8dc090e5177c81399f14a870d..c1671d3e5f1ecdd6b7f0c72cdcb160ca8f8aea6c 100644 (file)
@@ -1,3 +1,21 @@
+2007-11-21  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by Tim Hatcher.
+
+        Abstract more of DRT into static methods
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (setDefaultsToConsistentValuesForTesting):
+        (setupSignalHandlers):
+        (allocateGlobalControllers):
+        (releaseAndZero):
+        (releaseGlobalControllers):
+        (dumpRenderTree):
+        (shouldLogFrameLoadDelegates):
+        (createCFURLFromPathOrURL):
+        (resetWebViewToConsistentStateBeforeTesting):
+        (runTest):
+
 2007-11-21  Eric Seidel  <eric@webkit.org>
 
         Reviewed by Tim Hatcher.
index 2b7cb1811fd69dbcebd2eb21472be9376654bd77..e6ab3ddbc6775624d28966fcbfa05d9f833f7256 100644 (file)
@@ -411,38 +411,23 @@ void testStringByEvaluatingJavaScriptFromString()
     [pool release];
 }
 
-void dumpRenderTree(int argc, const char *argv[])
-{    
-    [NSApplication sharedApplication];
-
-    class_poseAs(objc_getClass("DumpRenderTreePasteboard"), objc_getClass("NSPasteboard"));
-    class_poseAs(objc_getClass("DumpRenderTreeEvent"), objc_getClass("NSEvent"));
-
-    struct option options[] = {
-        {"dump-all-pixels", no_argument, &dumpAllPixels, YES},
-        {"horizontal-sweep", no_argument, &repaintSweepHorizontallyDefault, YES},
-        {"notree", no_argument, &dumpTree, NO},
-        {"pixel-tests", no_argument, &dumpPixels, YES},
-        {"repaint", no_argument, &testRepaintDefault, YES},
-        {"tree", no_argument, &dumpTree, YES},
-        {"threaded", no_argument, &threaded, YES},
-        {NULL, 0, NULL, 0}
-    };
+static void setDefaultsToConsistentValuesForTesting()
+{
+    // Give some clear to undocumented defaults values
+    static const int MediumFontSmoothing = 2;
+    static const int BlueTintedAppearance = 1;
 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     [defaults setObject:@"DoubleMax" forKey:@"AppleScrollBarVariant"];
-    [defaults setInteger:4 forKey:@"AppleAntiAliasingThreshold"];
-    // 2 is the "Medium" font smoothing mode
-    [defaults setInteger:2 forKey:@"AppleFontSmoothing"];
-
-    [defaults setInteger:1 forKey:@"AppleAquaColorVariant"];
+    [defaults setInteger:4 forKey:@"AppleAntiAliasingThreshold"]; // smallest font size to CG should perform antialiasing on
+    [defaults setInteger:MediumFontSmoothing forKey:@"AppleFontSmoothing"];
+    [defaults setInteger:BlueTintedAppearance forKey:@"AppleAquaColorVariant"];
     [defaults setObject:@"0.709800 0.835300 1.000000" forKey:@"AppleHighlightColor"];
     [defaults setObject:@"0.500000 0.500000 0.500000" forKey:@"AppleOtherHighlightColor"];
-    
     [defaults setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
-    
+
     WebPreferences *preferences = [WebPreferences standardPreferences];
-    
+
     [preferences setStandardFontFamily:@"Times"];
     [preferences setFixedFontFamily:@"Courier"];
     [preferences setSerifFontFamily:@"Times"];
@@ -457,6 +442,69 @@ void dumpRenderTree(int argc, const char *argv[])
     [preferences setEditableLinkBehavior:WebKitEditableLinkOnlyLiveWithShiftKey];
     [preferences setTabsToLinks:NO];
     [preferences setDOMPasteAllowed:YES];
+}
+
+static void setupSignalHandlers()
+{
+    signal(SIGILL, crashHandler);    /* 4:   illegal instruction (not reset when caught) */
+    signal(SIGTRAP, crashHandler);   /* 5:   trace trap (not reset when caught) */
+    signal(SIGEMT, crashHandler);    /* 7:   EMT instruction */
+    signal(SIGFPE, crashHandler);    /* 8:   floating point exception */
+    signal(SIGBUS, crashHandler);    /* 10:  bus error */
+    signal(SIGSEGV, crashHandler);   /* 11:  segmentation violation */
+    signal(SIGSYS, crashHandler);    /* 12:  bad argument to system call */
+    signal(SIGPIPE, crashHandler);   /* 13:  write on a pipe with no reader */
+    signal(SIGXCPU, crashHandler);   /* 24:  exceeded CPU time limit */
+    signal(SIGXFSZ, crashHandler);   /* 25:  exceeded file size limit */
+}
+
+static void allocateGlobalControllers()
+{
+    // FIXME: We should remove these and move to the ObjC standard [Foo sharedInstance] model
+    navigationController = [[NavigationController alloc] init];
+    frameLoadDelegate = [[FrameLoadDelegate alloc] init];
+    uiDelegate = [[UIDelegate alloc] init];
+    editingDelegate = [[EditingDelegate alloc] init];
+    resourceLoadDelegate = [[ResourceLoadDelegate alloc] init];
+    policyDelegate = [[PolicyDelegate alloc] init];
+}
+
+// ObjC++ doens't seem to let me pass NSObject*& sadly.
+static inline void releaseAndZero(NSObject** object)
+{
+    [*object release];
+    *object = nil;
+}
+
+static void releaseGlobalControllers()
+{
+    releaseAndZero(&navigationController);
+    releaseAndZero(&frameLoadDelegate);
+    releaseAndZero(&editingDelegate);
+    releaseAndZero(&resourceLoadDelegate);
+    releaseAndZero(&uiDelegate);
+    releaseAndZero(&policyDelegate);
+}
+
+void dumpRenderTree(int argc, const char *argv[])
+{    
+    [NSApplication sharedApplication];
+
+    class_poseAs(objc_getClass("DumpRenderTreePasteboard"), objc_getClass("NSPasteboard"));
+    class_poseAs(objc_getClass("DumpRenderTreeEvent"), objc_getClass("NSEvent"));
+
+    struct option options[] = {
+        {"dump-all-pixels", no_argument, &dumpAllPixels, YES},
+        {"horizontal-sweep", no_argument, &repaintSweepHorizontallyDefault, YES},
+        {"notree", no_argument, &dumpTree, NO},
+        {"pixel-tests", no_argument, &dumpPixels, YES},
+        {"repaint", no_argument, &testRepaintDefault, YES},
+        {"tree", no_argument, &dumpTree, YES},
+        {"threaded", no_argument, &threaded, YES},
+        {NULL, 0, NULL, 0}
+    };
+
+    setDefaultsToConsistentValuesForTesting();
     
     int option;
     while ((option = getopt_long(argc, (char * const *)argv, "", options, NULL)) != -1)
@@ -475,12 +523,7 @@ void dumpRenderTree(int argc, const char *argv[])
         sharedColorSpace = CGColorSpaceCreateDeviceRGB();
     }
     
-    navigationController = [[NavigationController alloc] init];
-    frameLoadDelegate = [[FrameLoadDelegate alloc] init];
-    uiDelegate = [[UIDelegate alloc] init];
-    editingDelegate = [[EditingDelegate alloc] init];    
-    resourceLoadDelegate = [[ResourceLoadDelegate alloc] init];
-    policyDelegate = [[PolicyDelegate alloc] init];
+    allocateGlobalControllers();
     
     NSString *pwd = [[NSString stringWithUTF8String:argv[0]] stringByDeletingLastPathComponent];
     [WebPluginDatabase setAdditionalWebPlugInPaths:[NSArray arrayWithObject:pwd]];
@@ -492,16 +535,7 @@ void dumpRenderTree(int argc, const char *argv[])
 
     makeLargeMallocFailSilently();
 
-    signal(SIGILL, crashHandler);    /* 4:   illegal instruction (not reset when caught) */
-    signal(SIGTRAP, crashHandler);   /* 5:   trace trap (not reset when caught) */
-    signal(SIGEMT, crashHandler);    /* 7:   EMT instruction */
-    signal(SIGFPE, crashHandler);    /* 8:   floating point exception */
-    signal(SIGBUS, crashHandler);    /* 10:  bus error */
-    signal(SIGSEGV, crashHandler);   /* 11:  segmentation violation */
-    signal(SIGSYS, crashHandler);    /* 12:  bad argument to system call */
-    signal(SIGPIPE, crashHandler);   /* 13:  write on a pipe with no reader */
-    signal(SIGXCPU, crashHandler);   /* 24:  exceeded CPU time limit */
-    signal(SIGXFSZ, crashHandler);   /* 25:  exceeded file size limit */
+    setupSignalHandlers();
     
     [[NSURLCache sharedURLCache] removeAllCachedResponses];
     
@@ -545,16 +579,10 @@ void dumpRenderTree(int argc, const char *argv[])
     
     [window close]; // releases when closed
     [webView release];
-    [frameLoadDelegate release];
-    [editingDelegate release];
-    [resourceLoadDelegate release];
-    [uiDelegate release];
-    [policyDelegate release];
     
-    [DumpRenderTreePasteboard releaseLocalPasteboards];
+    releaseGlobalControllers();
     
-    [navigationController release];
-    navigationController = nil;
+    [DumpRenderTreePasteboard releaseLocalPasteboards];
 
     if (disallowedURLs) {
         CFRelease(disallowedURLs);
@@ -963,30 +991,20 @@ void dump()
 static bool shouldLogFrameLoadDelegates(const char *pathOrURL)
 {
     return strstr(pathOrURL, "loading/");
-}    
+}
 
-static void runTest(const char *pathOrURL)
+static CFURLRef createCFURLFromPathOrURL(CFStringRef pathOrURLString)
 {
-    CFStringRef pathOrURLString = CFStringCreateWithCString(NULL, pathOrURL, kCFStringEncodingUTF8);
-    if (!pathOrURLString) {
-        fprintf(stderr, "can't parse filename as UTF-8\n");
-        return;
-    }
-    
     CFURLRef URL;
     if (CFStringHasPrefix(pathOrURLString, CFSTR("http://")) || CFStringHasPrefix(pathOrURLString, CFSTR("https://")))
         URL = CFURLCreateWithString(NULL, pathOrURLString, NULL);
     else
         URL = CFURLCreateWithFileSystemPath(NULL, pathOrURLString, kCFURLPOSIXPathStyle, FALSE);
-    
-    if (!URL) {
-        CFRelease(pathOrURLString);
-        fprintf(stderr, "can't turn %s into a CFURL\n", pathOrURL);
-        return;
-    }
-
-    layoutTestController = new LayoutTestController(testRepaintDefault, repaintSweepHorizontallyDefault);
+    return URL;
+}
 
+static void resetWebViewToConsistentStateBeforeTesting()
+{
     [(EditingDelegate *)[[mainFrame webView] editingDelegate] setAcceptsEditing:YES];
     [[mainFrame webView] makeTextStandardSize:nil];
     [[mainFrame webView] setTabKeyCyclesThroughElements: YES];
@@ -994,9 +1012,27 @@ static void runTest(const char *pathOrURL)
     [[mainFrame webView] _setDashboardBehavior:WebDashboardBehaviorUseBackwardCompatibilityMode to:NO];
     [[[mainFrame webView] preferences] setPrivateBrowsingEnabled:NO];
     [WebView _setUsesTestModeFocusRingColor:YES];
+}
 
-    topLoadingFrame = nil;
+static void runTest(const char *pathOrURL)
+{
+    CFStringRef pathOrURLString = CFStringCreateWithCString(NULL, pathOrURL, kCFStringEncodingUTF8);
+    if (!pathOrURLString) {
+        fprintf(stderr, "Failed to parse filename as UTF-8: %s\n", pathOrURL);
+        return;
+    }
 
+    CFURLRef URL = createCFURLFromPathOrURL(pathOrURLString);
+    if (!URL) {
+        CFRelease(pathOrURLString);
+        fprintf(stderr, "Can't turn %s into a CFURL\n", pathOrURL);
+        return;
+    }
+
+    resetWebViewToConsistentStateBeforeTesting();
+
+    layoutTestController = new LayoutTestController(testRepaintDefault, repaintSweepHorizontallyDefault);
+    topLoadingFrame = nil;
     done = NO;
 
     if (disallowedURLs)