2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitAgnosticTest.h"
29 #include "JavaScriptTest.h"
30 #include "PlatformUtilities.h"
31 #include "SyntheticBackingScaleFactorWindow.h"
32 #include <wtf/RetainPtr.h>
34 namespace TestWebKitAPI {
36 class DynamicDeviceScaleFactor : public WebKitAgnosticTest {
38 RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
40 template <typename View> void runTest(View);
43 virtual NSURL *url() const { return [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]; }
44 virtual void didLoadURL(WebView *webView) { runTest(webView); }
45 virtual void didLoadURL(WKView *wkView) { runTest(wkView); }
48 RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWindow()
50 RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
51 [window.get() setReleasedWhenClosed:NO];
55 template <typename View>
56 void DynamicDeviceScaleFactor::runTest(View view)
58 EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
59 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
61 RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
62 [window1.get() setBackingScaleFactor:3];
64 [[window1.get() contentView] addSubview:view];
65 EXPECT_JS_EQ(view, "window.devicePixelRatio", "3");
66 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "3");
68 RetainPtr<SyntheticBackingScaleFactorWindow> window2 = createWindow();
69 [window2.get() setBackingScaleFactor:4];
71 [[window2.get() contentView] addSubview:view];
72 EXPECT_JS_EQ(view, "window.devicePixelRatio", "4");
73 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "4");
75 [view removeFromSuperview];
76 EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
77 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
80 TEST_F(DynamicDeviceScaleFactor, WebKit)
85 TEST_F(DynamicDeviceScaleFactor, WebKit2)
90 } // namespace TestWebKitAPI