Changeset 93405 in webkit
- Timestamp:
- Aug 19, 2011 7:51:16 AM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 1 added
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r93404 r93405 1 2011-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 1 32 2011-08-19 Adam Roben <aroben@apple.com> 2 33 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r93315 r93405 66 66 C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */; }; 67 67 C081224913FC1B0300DC39AE /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C081224813FC1B0300DC39AE /* WebKit.framework */; }; 68 C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */; }; 68 69 C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */; }; 69 70 C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */; }; … … 187 188 C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SyntheticBackingScaleFactorWindow.m; sourceTree = "<group>"; }; 188 189 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>"; }; 189 192 C0ADBE7A12FCA4D000D2C129 /* JavaScriptTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptTest.cpp; sourceTree = "<group>"; }; 190 193 C0ADBE7B12FCA4D000D2C129 /* JavaScriptTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptTest.h; sourceTree = "<group>"; }; … … 373 376 C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */, 374 377 C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */, 378 C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */, 379 C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */, 375 380 ); 376 381 path = mac; … … 519 524 C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */, 520 525 C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */, 526 C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */, 521 527 ); 522 528 runOnlyForDeploymentPostprocessing = 0; -
trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm
r93404 r93405 1 1 /* 2 * Copyright (C) 201 0Apple Inc. All rights reserved.2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #include "WebKitAgnosticTest.h" 27 26 28 #include "JavaScriptTest.h" 27 29 #include "PlatformUtilities.h" 28 30 #include "SyntheticBackingScaleFactorWindow.h" 29 #include <WebKit2/WKURLCF.h>30 31 #include <wtf/RetainPtr.h> 31 32 @interface FrameLoadDelegate : NSObject {33 bool* _didFinishLoad;34 }35 36 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad;37 38 @end39 40 @implementation FrameLoadDelegate41 42 - (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad43 {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 *)webFrame53 {54 *_didFinishLoad = true;55 }56 57 @end58 32 59 33 namespace TestWebKitAPI { 60 34 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 { 35 class DynamicDeviceScaleFactor : public WebKitAgnosticTest { 78 36 public: 79 DynamicDeviceScaleFactor();37 RetainPtr<SyntheticBackingScaleFactorWindow> createWindow(); 80 38 81 39 template <typename View> void runTest(View); 82 40 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); } 91 45 }; 92 93 DynamicDeviceScaleFactor::DynamicDeviceScaleFactor()94 : didFinishLoad(false)95 , viewFrame(NSMakeRect(0, 0, 800, 600))96 {97 }98 46 99 47 RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWindow() … … 107 55 void DynamicDeviceScaleFactor::runTest(View view) 108 56 { 109 EXPECT_FALSE(didFinishLoad);110 loadURL(view, [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]);111 Util::run(&didFinishLoad);112 didFinishLoad = false;113 114 57 EXPECT_JS_EQ(view, "window.devicePixelRatio", "1"); 115 58 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1"); … … 134 77 } 135 78 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 79 TEST_F(DynamicDeviceScaleFactor, WebKit) 147 80 { 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(); 153 82 } 154 83 155 84 TEST_F(DynamicDeviceScaleFactor, WebKit2) 156 85 { 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(); 162 87 } 163 88 -
trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm
r93404 r93405 1 1 /* 2 * Copyright (C) 201 0Apple Inc. All rights reserved.2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #include "JavaScriptTest.h" 27 #include "PlatformUtilities.h" 28 #include "SyntheticBackingScaleFactorWindow.h" 26 #include "WebKitAgnosticTest.h" 27 29 28 #include <WebKit2/WKURLCF.h> 30 29 #include <wtf/RetainPtr.h> … … 75 74 } 76 75 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() 76 WebKitAgnosticTest::WebKitAgnosticTest() 94 77 : didFinishLoad(false) 95 78 , viewFrame(NSMakeRect(0, 0, 800, 600)) … … 97 80 } 98 81 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) 82 void WebKitAgnosticTest::runWebKit1Test() 147 83 { 148 84 RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]); … … 150 86 [webView.get() setFrameLoadDelegate:delegate.get()]; 151 87 152 runTest(webView.get()); 88 loadAndWaitUntilFinished(webView.get(), url()); 89 didLoadURL(webView.get()); 153 90 } 154 91 155 TEST_F(DynamicDeviceScaleFactor, WebKit2)92 void WebKitAgnosticTest::runWebKit2Test() 156 93 { 157 94 WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); … … 159 96 setPageLoaderClient([view.get() pageRef], &didFinishLoad); 160 97 161 runTest(view.get()); 98 loadAndWaitUntilFinished(view.get(), url()); 99 didLoadURL(view.get()); 100 } 101 102 void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url) 103 { 104 [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]]; 105 } 106 107 void WebKitAgnosticTest::loadURL(WKView *view, NSURL *url) 108 { 109 WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get()); 162 110 } 163 111
Note: See TracChangeset
for help on using the changeset viewer.