Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm

Issue 13602008: Remove non-chromium code from TestWebKitAPI (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 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 #import "config.h"
27 #import "JavaScriptTest.h"
28 #import "Test.h"
29 #import "WebKitAgnosticTest.h"
30 #import <WebKit/WebView.h>
31 #import <WebKit2/WKViewPrivate.h>
32 #import <wtf/RetainPtr.h>
33
34 static bool didGetPageSignalToContinue;
35
36 // WebKit1 WebUIDelegate
37
38 @interface PageVisibilityStateDelegate : NSObject
39 @end
40
41 @implementation PageVisibilityStateDelegate
42
43 - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString * )message initiatedByFrame:(WebFrame *)frame
44 {
45 didGetPageSignalToContinue = true;
46 }
47
48 @end
49
50 // WebKit2 WKPageUIClient
51
52 static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
53 {
54 didGetPageSignalToContinue = true;
55 }
56
57 // WebKitAgnosticTest
58
59 namespace TestWebKitAPI {
60
61 class PageVisibilityStateWithWindowChanges : public WebKitAgnosticTest {
62 public:
63 template <typename View> void runTest(View);
64
65 // WebKitAgnosticTest
66 virtual NSURL *url() const OVERRIDE { return [[NSBundle mainBundle] URLForRe source:@"PageVisibilityStateWithWindowChanges" withExtension:@"html" subdirector y:@"TestWebKitAPI.resources"]; }
67 virtual void didLoadURL(WebView *webView) OVERRIDE { runTest(webView); }
68 virtual void didLoadURL(WKView *wkView) OVERRIDE { runTest(wkView); }
69
70 // Setup and teardown the UIDelegate which gets alert() signals from the pag e.
71 virtual void initializeView(WebView *) OVERRIDE;
72 virtual void initializeView(WKView *) OVERRIDE;
73 virtual void teardownView(WebView *) OVERRIDE;
74 virtual void teardownView(WKView *) OVERRIDE;
75 };
76
77 void PageVisibilityStateWithWindowChanges::initializeView(WebView *webView)
78 {
79 // Released in teardownView.
80 webView.UIDelegate = [[PageVisibilityStateDelegate alloc] init];
81 }
82
83 void PageVisibilityStateWithWindowChanges::teardownView(WebView *webView)
84 {
85 id uiDelegate = webView.UIDelegate;
86 webView.UIDelegate = nil;
87 [uiDelegate release];
88 }
89
90 void PageVisibilityStateWithWindowChanges::initializeView(WKView *wkView)
91 {
92 WKPageUIClient uiClient;
93 memset(&uiClient, 0, sizeof(uiClient));
94 uiClient.version = 0;
95 uiClient.clientInfo = 0;
96 uiClient.runJavaScriptAlert = runJavaScriptAlert;
97 WKPageSetPageUIClient(wkView.pageRef, &uiClient);
98 }
99
100 void PageVisibilityStateWithWindowChanges::teardownView(WKView *wkView)
101 {
102 // We do not need to teardown the WKPageUIClient.
103 }
104
105 template <typename View>
106 void PageVisibilityStateWithWindowChanges::runTest(View view)
107 {
108 // This WebView does not have a window and superview. PageVisibility should be "hidden".
109 EXPECT_NULL([view window]);
110 EXPECT_NULL([view superview]);
111 EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden");
112
113 // Add it to a non-visible window. PageVisibility should still be "hidden".
114 RetainPtr<NSWindow> window(AdoptNS, [[NSWindow alloc] initWithContentRect:vi ew.frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:N O]);
115 [window.get().contentView addSubview:view];
116 EXPECT_NOT_NULL([view window]);
117 EXPECT_NOT_NULL([view superview]);
118 EXPECT_FALSE([window.get() isVisible]);
119 EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden");
120
121 // Make the window visible. PageVisibility should become "visible".
122 didGetPageSignalToContinue = false;
123 [window.get() makeKeyAndOrderFront:nil];
124 EXPECT_TRUE([window.get() isVisible]);
125 Util::run(&didGetPageSignalToContinue);
126 EXPECT_JS_EQ(view, "document.webkitVisibilityState", "visible");
127
128 // Minimize the window. PageVisibility should become "hidden".
129 didGetPageSignalToContinue = false;
130 [window.get() miniaturize:nil];
131 Util::run(&didGetPageSignalToContinue);
132 EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden");
133
134 // Deminimize the window. PageVisibility should become "visible".
135 didGetPageSignalToContinue = false;
136 [window.get() deminiaturize:nil];
137 Util::run(&didGetPageSignalToContinue);
138 EXPECT_JS_EQ(view, "document.webkitVisibilityState", "visible");
139
140 // Remove the WebView from its superview. PageVisibility should become "hidd en".
141 didGetPageSignalToContinue = false;
142 [view removeFromSuperview];
143 EXPECT_NULL([view window]);
144 EXPECT_NULL([view superview]);
145 EXPECT_TRUE([window.get() isVisible]);
146 Util::run(&didGetPageSignalToContinue);
147 EXPECT_JS_EQ(view, "document.webkitVisibilityState", "hidden");
148 }
149
150 TEST_F(PageVisibilityStateWithWindowChanges, WebKit)
151 {
152 runWebKit1Test();
153 }
154
155 TEST_F(PageVisibilityStateWithWindowChanges, WebKit2)
156 {
157 runWebKit1Test();
158 }
159
160 } // namespace TestWebKitAPI
OLDNEW
« no previous file with comments | « Tools/TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.html ('k') | Tools/TestWebKitAPI/Tests/mac/PublicSuffix.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698