~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/TestWebKitAPI/Tests/mac/DeviceScaleFactorOnBack.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <WebKit2/WKViewPrivate.h>
 
33
#include <wtf/RetainPtr.h>
 
34
 
 
35
namespace TestWebKitAPI {
 
36
 
 
37
class DeviceScaleFactorOnBack : public WebKitAgnosticTest {
 
38
public:
 
39
    RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
 
40
 
 
41
    template <typename View> void runTest(View);
 
42
 
 
43
    // WebKitAgnosticTest
 
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 *);
 
49
};
 
50
 
 
51
RetainPtr<SyntheticBackingScaleFactorWindow> DeviceScaleFactorOnBack::createWindow()
 
52
{
 
53
    RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
 
54
    [window.get() setReleasedWhenClosed:NO];
 
55
    return window;
 
56
}
 
57
 
 
58
void DeviceScaleFactorOnBack::initializeView(WebView *view)
 
59
{
 
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];
 
63
}
 
64
 
 
65
void DeviceScaleFactorOnBack::initializeView(WKView *view)
 
66
{
 
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);
 
70
}
 
71
 
 
72
template <typename View>
 
73
void DeviceScaleFactorOnBack::runTest(View view)
 
74
{
 
75
    EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
 
76
    EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
 
77
 
 
78
    // Navigate to new URL
 
79
    loadURL(view, [NSURL URLWithString:@"about:blank"]);
 
80
    waitForLoadToFinish();
 
81
 
 
82
    // Change the scale factor
 
83
    RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
 
84
    [window1.get() setBackingScaleFactor:3];
 
85
 
 
86
    [[window1.get() contentView] addSubview:view];
 
87
 
 
88
    // Navigate back to the first page
 
89
    goBack(view);
 
90
    waitForLoadToFinish();
 
91
 
 
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");
 
95
 
 
96
    [view removeFromSuperview];
 
97
}
 
98
 
 
99
TEST_F(DeviceScaleFactorOnBack, WebKit)
 
100
{
 
101
    runWebKit1Test();
 
102
}
 
103
 
 
104
TEST_F(DeviceScaleFactorOnBack, WebKit2)
 
105
{
 
106
    runWebKit2Test();
 
107
}
 
108
 
 
109
} // namespace TestWebKitAPI