Title: [94437] trunk/Tools
Revision
94437
Author
bda...@apple.com
Date
2011-09-02 11:55:16 -0700 (Fri, 02 Sep 2011)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=67451
Add a test for going back to a cached page after changing the device scale factor

Reviewed by Adam Roben.

New test DeviceScaleFactorOnBack.mm inherits from WebKitAgnosticTest.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/DeviceScaleFactorOnBack.mm: Added.
(TestWebKitAPI::DeviceScaleFactorOnBack::url):
(TestWebKitAPI::DeviceScaleFactorOnBack::didLoadURL):
(TestWebKitAPI::DeviceScaleFactorOnBack::createWindow):
(TestWebKitAPI::DeviceScaleFactorOnBack::initializeView):
(TestWebKitAPI::DeviceScaleFactorOnBack::runTest):
(TestWebKitAPI::TEST_F):

Added new function to WebKitAgnosticTest to goBack. Separated 
waitForLoadToFinish() into its own function (instead of being a part of 
loadAndWaitUntilFinished()) so that it can be called from goBack as 
well. Also added initializeView() so we can set the cache model.
* TestWebKitAPI/mac/WebKitAgnosticTest.h:
(TestWebKitAPI::WebKitAgnosticTest::initializeView):
* TestWebKitAPI/mac/WebKitAgnosticTest.mm:
(TestWebKitAPI::WebKitAgnosticTest::WebKitAgnosticTest):
(TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test):
(TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test):
(TestWebKitAPI::WebKitAgnosticTest::loadURL):
(TestWebKitAPI::WebKitAgnosticTest::goBack):
(TestWebKitAPI::WebKitAgnosticTest::waitForLoadToFinish):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (94436 => 94437)


--- trunk/Tools/ChangeLog	2011-09-02 18:35:18 UTC (rev 94436)
+++ trunk/Tools/ChangeLog	2011-09-02 18:55:16 UTC (rev 94437)
@@ -1,3 +1,34 @@
+2011-09-01  Beth Dakin  <bda...@apple.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=67451
+        Add a test for going back to a cached page after changing the device scale factor
+
+        Reviewed by Adam Roben.
+
+        New test DeviceScaleFactorOnBack.mm inherits from WebKitAgnosticTest.
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/DeviceScaleFactorOnBack.mm: Added.
+        (TestWebKitAPI::DeviceScaleFactorOnBack::url):
+        (TestWebKitAPI::DeviceScaleFactorOnBack::didLoadURL):
+        (TestWebKitAPI::DeviceScaleFactorOnBack::createWindow):
+        (TestWebKitAPI::DeviceScaleFactorOnBack::initializeView):
+        (TestWebKitAPI::DeviceScaleFactorOnBack::runTest):
+        (TestWebKitAPI::TEST_F):
+
+        Added new function to WebKitAgnosticTest to goBack. Separated 
+        waitForLoadToFinish() into its own function (instead of being a part of 
+        loadAndWaitUntilFinished()) so that it can be called from goBack as 
+        well. Also added initializeView() so we can set the cache model.
+        * TestWebKitAPI/mac/WebKitAgnosticTest.h:
+        (TestWebKitAPI::WebKitAgnosticTest::initializeView):
+        * TestWebKitAPI/mac/WebKitAgnosticTest.mm:
+        (TestWebKitAPI::WebKitAgnosticTest::WebKitAgnosticTest):
+        (TestWebKitAPI::WebKitAgnosticTest::runWebKit1Test):
+        (TestWebKitAPI::WebKitAgnosticTest::runWebKit2Test):
+        (TestWebKitAPI::WebKitAgnosticTest::loadURL):
+        (TestWebKitAPI::WebKitAgnosticTest::goBack):
+        (TestWebKitAPI::WebKitAgnosticTest::waitForLoadToFinish):
+
 2011-09-02  Anders Carlsson  <ander...@apple.com>
 
         Build fix.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (94436 => 94437)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-09-02 18:35:18 UTC (rev 94436)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-09-02 18:55:16 UTC (rev 94437)
@@ -23,6 +23,7 @@
 		37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */; };
 		4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
 		4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */; };
+		939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */; };
 		A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
 		BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */; };
 		BC131A9B1171316900B69727 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131A9A1171316900B69727 /* main.mm */; };
@@ -140,6 +141,7 @@
 		4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle_Bundle.cpp; sourceTree = "<group>"; };
 		4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle.cpp; sourceTree = "<group>"; };
 		8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; };
+		939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; };
 		A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedArithmeticOperations.cpp; path = WTF/CheckedArithmeticOperations.cpp; sourceTree = "<group>"; };
 		BC131883117114A800B69727 /* PlatformUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformUtilities.h; sourceTree = "<group>"; };
 		BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformUtilitiesMac.mm; sourceTree = "<group>"; };
@@ -413,6 +415,7 @@
 				C07E6CB013FD737C0038B22B /* Resources */,
 				37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */,
 				C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
+				939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -562,6 +565,7 @@
 				C085880013FEC3A6001EF4E5 /* InstanceMethodSwizzler.mm in Sources */,
 				37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
 				A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
+				939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Tools/TestWebKitAPI/Tests/mac/DeviceScaleFactorOnBack.mm (0 => 94437)


--- trunk/Tools/TestWebKitAPI/Tests/mac/DeviceScaleFactorOnBack.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/DeviceScaleFactorOnBack.mm	2011-09-02 18:55:16 UTC (rev 94437)
@@ -0,0 +1,107 @@
+/*
+ * 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 "_javascript_Test.h"
+#include "PlatformUtilities.h"
+#include "SyntheticBackingScaleFactorWindow.h"
+#include <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+class DeviceScaleFactorOnBack : public WebKitAgnosticTest {
+public:
+    RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
+
+    template <typename View> void runTest(View);
+
+    // 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); }
+    virtual void initializeView(WebView *);
+    virtual void initializeView(WKView *);
+};
+
+RetainPtr<SyntheticBackingScaleFactorWindow> DeviceScaleFactorOnBack::createWindow()
+{
+    RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+    [window.get() setReleasedWhenClosed:NO];
+    return window;
+}
+
+void DeviceScaleFactorOnBack::initializeView(WebView *view)
+{
+    // The default cache model has a capacity of 0, so it is necessary to switch to a cache
+    // model that actuall caches things.
+    [[view preferences] setCacheModel:WebCacheModelDocumentBrowser];
+}
+
+void DeviceScaleFactorOnBack::initializeView(WKView *view)
+{
+    // The default cache model has a capacity of 0, so it is necessary to switch to a cache
+    // model that actuall caches things.
+    WKContextSetCacheModel(WKPageGetContext([view pageRef]), kWKCacheModelDocumentBrowser);
+}
+
+template <typename View>
+void DeviceScaleFactorOnBack::runTest(View view)
+{
+    EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
+    EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
+
+    // Navigate to new URL
+    loadURL(view, [NSURL URLWithString:@"about:blank"]);
+    waitForLoadToFinish();
+
+    // Change the scale factor
+    RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
+    [window1.get() setBackingScaleFactor:3];
+
+    [[window1.get() contentView] addSubview:view];
+
+    // Navigate back to the first page
+    goBack(view);
+    waitForLoadToFinish();
+
+    // Ensure that the cached page has updated its scale factor
+    EXPECT_JS_EQ(view, "window.devicePixelRatio", "3");
+    EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "3");
+
+    [view removeFromSuperview];
+}
+
+TEST_F(DeviceScaleFactorOnBack, WebKit)
+{
+    runWebKit1Test();
+}
+
+TEST_F(DeviceScaleFactorOnBack, WebKit2)
+{
+    runWebKit2Test();
+}
+
+} // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h (94436 => 94437)


--- trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h	2011-09-02 18:35:18 UTC (rev 94436)
+++ trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.h	2011-09-02 18:55:16 UTC (rev 94437)
@@ -42,25 +42,25 @@
 
     void loadURL(WebView *, NSURL *);
     void loadURL(WKView *, NSURL *);
-    template <typename View> void loadAndWaitUntilFinished(View, NSURL *);
 
-    bool didFinishLoad;
+    void goBack(WebView *);
+    void goBack(WKView *);
+
+    void waitForLoadToFinish();
+
     NSRect viewFrame;
 
+private:
     virtual NSURL *url() const = 0;
     virtual void didLoadURL(WebView *) = 0;
     virtual void didLoadURL(WKView *) = 0;
+
+    virtual void initializeView(WebView *) { }
+    virtual void initializeView(WKView *) { }
+
+    bool didFinishLoad;
 };
 
-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

Modified: trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm (94436 => 94437)


--- trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm	2011-09-02 18:35:18 UTC (rev 94436)
+++ trunk/Tools/TestWebKitAPI/mac/WebKitAgnosticTest.mm	2011-09-02 18:55:16 UTC (rev 94437)
@@ -74,8 +74,8 @@
 }
 
 WebKitAgnosticTest::WebKitAgnosticTest()
-    : didFinishLoad(false)
-    , viewFrame(NSMakeRect(0, 0, 800, 600))
+    : viewFrame(NSMakeRect(0, 0, 800, 600))
+    , didFinishLoad(false)
 {
 }
 
@@ -84,8 +84,10 @@
     RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
     RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] initWithDidFinishLoadBoolean:&didFinishLoad]);
     [webView.get() setFrameLoadDelegate:delegate.get()];
+    initializeView(webView.get());
 
-    loadAndWaitUntilFinished(webView.get(), url());
+    loadURL(webView.get(), url());
+    waitForLoadToFinish();
     didLoadURL(webView.get());
 }
 
@@ -94,19 +96,41 @@
     WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
     RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame contextRef:context.get()]);
     setPageLoaderClient([view.get() pageRef], &didFinishLoad);
+    initializeView(view.get());
 
-    loadAndWaitUntilFinished(view.get(), url());
+    loadURL(view.get(), url());
+    waitForLoadToFinish();
     didLoadURL(view.get());
 }
 
 void WebKitAgnosticTest::loadURL(WebView *webView, NSURL *url)
 {
+    EXPECT_FALSE(didFinishLoad);
     [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
 }
 
 void WebKitAgnosticTest::loadURL(WKView *view, NSURL *url)
 {
+    EXPECT_FALSE(didFinishLoad);
     WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
 }
 
+void WebKitAgnosticTest::goBack(WebView *webView)
+{
+    EXPECT_FALSE(didFinishLoad);
+    [webView goBack];
+}
+
+void WebKitAgnosticTest::goBack(WKView *view)
+{
+    EXPECT_FALSE(didFinishLoad);
+    WKPageGoBack([view pageRef]);
+}
+
+void WebKitAgnosticTest::waitForLoadToFinish()
+{
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to