Diff
Modified: trunk/Tools/ChangeLog (93404 => 93405)
--- trunk/Tools/ChangeLog 2011-08-19 14:50:05 UTC (rev 93404)
+++ trunk/Tools/ChangeLog 2011-08-19 14:51:16 UTC (rev 93405)
@@ -1,5 +1,36 @@
2011-08-19 Adam Roben <[email protected]>
+ 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::loadAndWaitUntilDone): 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.
+
+2011-08-19 Adam Roben <[email protected]>
+
Clean up #includes in TestWebKitAPI
Fixes <http://webkit.org/b/66556> TestWebKitAPI's prefix header isn't very helpful
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (93404 => 93405)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2011-08-19 14:50:05 UTC (rev 93404)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2011-08-19 14:51:16 UTC (rev 93405)
@@ -65,6 +65,7 @@
C081224213FC172400DC39AE /* _javascript_TestMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C081224013FC172400DC39AE /* _javascript_TestMac.mm */; };
C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */; };
C081224913FC1B0300DC39AE /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C081224813FC1B0300DC39AE /* WebKit.framework */; };
+ C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */; };
C0ADBE7C12FCA4D000D2C129 /* _javascript_Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE7A12FCA4D000D2C129 /* _javascript_Test.cpp */; };
C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */; };
C0ADBE9612FCA79B00D2C129 /* simple-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C0ADBE8412FCA6B600D2C129 /* simple-form.html */; };
@@ -186,6 +187,8 @@
C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SyntheticBackingScaleFactorWindow.h; sourceTree = "<group>"; };
C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SyntheticBackingScaleFactorWindow.m; sourceTree = "<group>"; };
C081224813FC1B0300DC39AE /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitAgnosticTest.mm; sourceTree = "<group>"; };
+ C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAgnosticTest.h; sourceTree = "<group>"; };
C0ADBE7A12FCA4D000D2C129 /* _javascript_Test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = _javascript_Test.cpp; sourceTree = "<group>"; };
C0ADBE7B12FCA4D000D2C129 /* _javascript_Test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _javascript_Test.h; sourceTree = "<group>"; };
C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RestoreSessionStateContainingFormData.cpp; sourceTree = "<group>"; };
@@ -372,6 +375,8 @@
BC90955C125548AA00083756 /* PlatformWebViewMac.mm */,
C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */,
C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */,
+ C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */,
+ C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */,
);
path = mac;
sourceTree = "<group>";
@@ -518,6 +523,7 @@
C081224213FC172400DC39AE /* _javascript_TestMac.mm in Sources */,
C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */,
C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */,
+ C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm (93404 => 93405)
--- trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm 2011-08-19 14:50:05 UTC (rev 93404)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm 2011-08-19 14:51:16 UTC (rev 93405)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,79 +23,27 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "WebKitAgnosticTest.h"
+
#include "_javascript_Test.h"
#include "PlatformUtilities.h"
#include "SyntheticBackingScaleFactorWindow.h"
-#include <WebKit2/WKURLCF.h>
#include <wtf/RetainPtr.h>
-@interface FrameLoadDelegate : NSObject {
- bool* _didFinishLoad;
-}
-
-- (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad;
-
-@end
-
-@implementation FrameLoadDelegate
-
-- (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad
-{
- self = [super init];
- if (!self)
- return nil;
-
- _didFinishLoad = didFinishLoad;
- return self;
-}
-
-- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame
-{
- *_didFinishLoad = true;
-}
-
-@end
-
namespace TestWebKitAPI {
-static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* context)
-{
- *static_cast<bool*>(const_cast<void*>(context)) = true;
-}
-
-static void setPageLoaderClient(WKPageRef page, bool* didFinishLoad)
-{
- WKPageLoaderClient loaderClient;
- memset(&loaderClient, 0, sizeof(loaderClient));
- loaderClient.version = 0;
- loaderClient.clientInfo = didFinishLoad;
- loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
-
- WKPageSetPageLoaderClient(page, &loaderClient);
-}
-
-class DynamicDeviceScaleFactor : public ::testing::Test {
+class DynamicDeviceScaleFactor : public WebKitAgnosticTest {
public:
- DynamicDeviceScaleFactor();
+ RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
template <typename View> void runTest(View);
- bool didFinishLoad;
- NSRect viewFrame;
-
-private:
- RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
-
- void loadURL(WebView *, NSURL *);
- void loadURL(WKView *, NSURL *);
+ // WebKitAgnosticTest
+ virtual NSURL *url() const { return [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]; }
+ virtual void didLoadURL(WebView *webView) { runTest(webView); }
+ virtual void didLoadURL(WKView *wkView) { runTest(wkView); }
};
-DynamicDeviceScaleFactor::DynamicDeviceScaleFactor()
- : didFinishLoad(false)
- , viewFrame(NSMakeRect(0, 0, 800, 600))
-{
-}
-
RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWindow()
{
RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
@@ -106,11 +54,6 @@
template <typename View>
void DynamicDeviceScaleFactor::runTest(View view)
{
- EXPECT_FALSE(didFinishLoad);
- loadURL(view, [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]);
- Util::run(&didFinishLoad);
- didFinishLoad = false;
-
EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
@@ -133,32 +76,14 @@
EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
}
-void DynamicDeviceScaleFactor::loadURL(WebView *webView, NSURL *url)
-{
- [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
-}
-
-void DynamicDeviceScaleFactor::loadURL(WKView *view, NSURL *url)
-{
- WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
-}
-
TEST_F(DynamicDeviceScaleFactor, WebKit)
{
- RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
- RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] initWithDidFinishLoadBoolean:&didFinishLoad]);
- [webView.get() setFrameLoadDelegate:delegate.get()];
-
- runTest(webView.get());
+ runWebKit1Test();
}
TEST_F(DynamicDeviceScaleFactor, WebKit2)
{
- WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
- RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame contextRef:context.get()]);
- setPageLoaderClient([view.get() pageRef], &didFinishLoad);
-
- runTest(view.get());
+ runWebKit2Test();
}
} // namespace TestWebKitAPI
Added: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h (0 => 93405)
--- trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h 2011-08-19 14:51:16 UTC (rev 93405)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebKitAgnosticTest_h
+#define WebKitAgnosticTest_h
+
+#include "PlatformUtilities.h"
+
+namespace TestWebKitAPI {
+
+// This test fixture can be used to write test that work with both WebKit1 and WebKit2. Calling
+// runWebKit1Test or runWebKit2Test will create a WebView or WKView (respectively), load the URL
+// specified by url(), and then call didLoadURL. Your test's logic should go in didLoadURL.
+class WebKitAgnosticTest : public ::testing::Test {
+public:
+ WebKitAgnosticTest();
+
+ void runWebKit1Test();
+ void runWebKit2Test();
+
+ void loadURL(WebView *, NSURL *);
+ void loadURL(WKView *, NSURL *);
+ template <typename View> void loadAndWaitUntilFinished(View, NSURL *);
+
+ bool didFinishLoad;
+ NSRect viewFrame;
+
+ virtual NSURL *url() const = 0;
+ virtual void didLoadURL(WebView *) = 0;
+ virtual void didLoadURL(WKView *) = 0;
+};
+
+template <typename View>
+void WebKitAgnosticTest::loadAndWaitUntilFinished(View view, NSURL *url)
+{
+ EXPECT_FALSE(didFinishLoad);
+ loadURL(view, url);
+ Util::run(&didFinishLoad);
+ didFinishLoad = false;
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WebKitAgnosticTest_h
Property changes on: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h
___________________________________________________________________
Added: svn:eol-style
Copied: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm (from rev 93404, trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm) (0 => 93405)
--- trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm 2011-08-19 14:51:16 UTC (rev 93405)
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "WebKitAgnosticTest.h"
+
+#include <WebKit2/WKURLCF.h>
+#include <wtf/RetainPtr.h>
+
+@interface FrameLoadDelegate : NSObject {
+ bool* _didFinishLoad;
+}
+
+- (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad;
+
+@end
+
+@implementation FrameLoadDelegate
+
+- (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ _didFinishLoad = didFinishLoad;
+ return self;
+}
+
+- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame
+{
+ *_didFinishLoad = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* context)
+{
+ *static_cast<bool*>(const_cast<void*>(context)) = true;
+}
+
+static void setPageLoaderClient(WKPageRef page, bool* didFinishLoad)
+{
+ WKPageLoaderClient loaderClient;
+ memset(&loaderClient, 0, sizeof(loaderClient));
+ loaderClient.version = 0;
+ loaderClient.clientInfo = didFinishLoad;
+ loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+ WKPageSetPageLoaderClient(page, &loaderClient);
+}
+
+WebKitAgnosticTest::WebKitAgnosticTest()
+ : didFinishLoad(false)
+ , viewFrame(NSMakeRect(0, 0, 800, 600))
+{
+}
+
+void WebKitAgnosticTest::runWebKit1Test()
+{
+ RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
+ RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] initWithDidFinishLoadBoolean:&didFinishLoad]);
+ [webView.get() setFrameLoadDelegate:delegate.get()];
+
+ loadAndWaitUntilFinished(webView.get(), url());
+ didLoadURL(webView.get());
+}
+
+void WebKitAgnosticTest::runWebKit2Test()
+{
+ WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+ RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame contextRef:context.get()]);
+ setPageLoaderClient([view.get() pageRef], &didFinishLoad);
+
+ loadAndWaitUntilFinished(view.get(), url());
+ didLoadURL(view.get());
+}
+
+void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url)
+{
+ [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
+}
+
+void WebKitAgnosticTest::loadURL(WKView *view, NSURL *url)
+{
+ WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
+}
+
+} // namespace TestWebKitAPI