OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
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. | |
12 * | |
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. | |
24 */ | |
25 | |
26 #include "config.h" | |
27 #include "WebKitAgnosticTest.h" | |
28 | |
29 #include "JavaScriptTest.h" | |
30 #include "PlatformUtilities.h" | |
31 #include "SyntheticBackingScaleFactorWindow.h" | |
32 #include <wtf/RetainPtr.h> | |
33 | |
34 namespace TestWebKitAPI { | |
35 | |
36 class DynamicDeviceScaleFactor : public WebKitAgnosticTest { | |
37 public: | |
38 RetainPtr<SyntheticBackingScaleFactorWindow> createWindow(); | |
39 | |
40 template <typename View> void runTest(View); | |
41 | |
42 // WebKitAgnosticTest | |
43 virtual NSURL *url() const { return [[NSBundle mainBundle] URLForResource:@"
devicePixelRatio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]
; } | |
44 virtual void didLoadURL(WebView *webView) { runTest(webView); } | |
45 virtual void didLoadURL(WKView *wkView) { runTest(wkView); } | |
46 }; | |
47 | |
48 RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWin
dow() | |
49 { | |
50 RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBack
ingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderless
WindowMask backing:NSBackingStoreBuffered defer:YES]); | |
51 [window.get() setReleasedWhenClosed:NO]; | |
52 return window; | |
53 } | |
54 | |
55 template <typename View> | |
56 void DynamicDeviceScaleFactor::runTest(View view) | |
57 { | |
58 EXPECT_JS_EQ(view, "window.devicePixelRatio", "1"); | |
59 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1"); | |
60 | |
61 RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow(); | |
62 [window1.get() setBackingScaleFactor:3]; | |
63 | |
64 [[window1.get() contentView] addSubview:view]; | |
65 EXPECT_JS_EQ(view, "window.devicePixelRatio", "3"); | |
66 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "3"); | |
67 | |
68 RetainPtr<SyntheticBackingScaleFactorWindow> window2 = createWindow(); | |
69 [window2.get() setBackingScaleFactor:4]; | |
70 | |
71 [[window2.get() contentView] addSubview:view]; | |
72 EXPECT_JS_EQ(view, "window.devicePixelRatio", "4"); | |
73 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "4"); | |
74 | |
75 [view removeFromSuperview]; | |
76 EXPECT_JS_EQ(view, "window.devicePixelRatio", "1"); | |
77 EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1"); | |
78 } | |
79 | |
80 TEST_F(DynamicDeviceScaleFactor, WebKit) | |
81 { | |
82 runWebKit1Test(); | |
83 } | |
84 | |
85 TEST_F(DynamicDeviceScaleFactor, WebKit2) | |
86 { | |
87 runWebKit2Test(); | |
88 } | |
89 | |
90 } // namespace TestWebKitAPI | |
OLD | NEW |