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 <WebKit2/WKViewPrivate.h>
33
#include <wtf/RetainPtr.h>
35
namespace TestWebKitAPI {
37
class DeviceScaleFactorOnBack : public WebKitAgnosticTest {
39
RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
41
template <typename View> void runTest(View);
44
virtual NSURL *url() const { return [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; }
45
virtual void didLoadURL(WebView *webView) { runTest(webView); }
46
virtual void didLoadURL(WKView *wkView) { runTest(wkView); }
47
virtual void initializeView(WebView *);
48
virtual void initializeView(WKView *);
51
RetainPtr<SyntheticBackingScaleFactorWindow> DeviceScaleFactorOnBack::createWindow()
53
RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
54
[window.get() setReleasedWhenClosed:NO];
58
void DeviceScaleFactorOnBack::initializeView(WebView *view)
60
// The default cache model has a capacity of 0, so it is necessary to switch to a cache
61
// model that actuall caches things.
62
[[view preferences] setCacheModel:WebCacheModelDocumentBrowser];
65
void DeviceScaleFactorOnBack::initializeView(WKView *view)
67
// The default cache model has a capacity of 0, so it is necessary to switch to a cache
68
// model that actuall caches things.
69
WKContextSetCacheModel(WKPageGetContext([view pageRef]), kWKCacheModelDocumentBrowser);
72
template <typename View>
73
void DeviceScaleFactorOnBack::runTest(View view)
75
EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
76
EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
78
// Navigate to new URL
79
loadURL(view, [NSURL URLWithString:@"about:blank"]);
80
waitForLoadToFinish();
82
// Change the scale factor
83
RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
84
[window1.get() setBackingScaleFactor:3];
86
[[window1.get() contentView] addSubview:view];
88
// Navigate back to the first page
90
waitForLoadToFinish();
92
// Ensure that the cached page has updated its scale factor
93
EXPECT_JS_EQ(view, "window.devicePixelRatio", "3");
94
EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "3");
96
[view removeFromSuperview];
99
TEST_F(DeviceScaleFactorOnBack, WebKit)
104
TEST_F(DeviceScaleFactorOnBack, WebKit2)
109
} // namespace TestWebKitAPI