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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2229543002: Fix UseCounter for SubframeBeforeUnloadFired. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Now with test Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/events/EventTarget.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3224 EXPECT_FALSE(webView->page()->defersLoading()); 3224 EXPECT_FALSE(webView->page()->defersLoading());
3225 } 3225 }
3226 3226
3227 { 3227 {
3228 ScopedPageLoadDeferrer deferrer; 3228 ScopedPageLoadDeferrer deferrer;
3229 WebViewImpl* webView = m_webViewHelper.initialize(); 3229 WebViewImpl* webView = m_webViewHelper.initialize();
3230 EXPECT_TRUE(webView->page()->defersLoading()); 3230 EXPECT_TRUE(webView->page()->defersLoading());
3231 } 3231 }
3232 } 3232 }
3233 3233
3234 // Make sure the SubframeBeforeUnloadUseCounter is only incremented on subframe
3235 // unloads. crbug.com/635029.
3236 TEST_F(WebViewTest, SubframeBeforeUnloadUseCounter)
3237 {
3238 registerMockedHttpURLLoad("visible_iframe.html");
3239 registerMockedHttpURLLoad("single_iframe.html");
3240 WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "single _iframe.html", true);
3241
3242 WebFrame* frame = m_webViewHelper.webView()->mainFrame();
3243 Document* document =
3244 toLocalFrame(m_webViewHelper.webView()->page()->mainFrame())->document() ;
3245
3246 // Add a beforeunload handler in the main frame. Make sure firing
3247 // beforeunload doesn't increment the subframe use counter.
3248 {
3249 frame->executeScript(WebScriptSource(
3250 "addEventListener('beforeunload', function() {});"));
3251 webView->mainFrame()->toWebLocalFrame()->dispatchBeforeUnloadEvent(false );
3252 EXPECT_FALSE(UseCounter::isCounted(*document, UseCounter::SubFrameBefore UnloadFired));
3253 }
3254
3255 // Add a beforeunload handler in the iframe and dispatch. Make sure we do
3256 // increment the use counter for subframe beforeunloads.
3257 {
3258 frame->executeScript(WebScriptSource(
3259 "document.getElementsByTagName('iframe')[0].contentWindow.addEventLi stener('beforeunload', function() {});"));
3260 webView->mainFrame()->firstChild()->toWebLocalFrame()->dispatchBeforeUnl oadEvent(false);
3261
3262 Document* childDocument = toLocalFrame(m_webViewHelper.webView()->page() ->mainFrame()->tree().firstChild())->document();
3263 EXPECT_TRUE(UseCounter::isCounted(*childDocument, UseCounter::SubFrameBe foreUnloadFired));
3264 }
3265 }
3266
3234 // Verify that page loads are deferred until all ScopedPageLoadDeferrers are 3267 // Verify that page loads are deferred until all ScopedPageLoadDeferrers are
3235 // destroyed. 3268 // destroyed.
3236 TEST_F(WebViewTest, NestedLoadDeferrals) 3269 TEST_F(WebViewTest, NestedLoadDeferrals)
3237 { 3270 {
3238 WebViewImpl* webView = m_webViewHelper.initialize(); 3271 WebViewImpl* webView = m_webViewHelper.initialize();
3239 EXPECT_FALSE(webView->page()->defersLoading()); 3272 EXPECT_FALSE(webView->page()->defersLoading());
3240 3273
3241 { 3274 {
3242 ScopedPageLoadDeferrer deferrer; 3275 ScopedPageLoadDeferrer deferrer;
3243 EXPECT_TRUE(webView->page()->defersLoading()); 3276 EXPECT_TRUE(webView->page()->defersLoading());
3244 3277
3245 { 3278 {
3246 ScopedPageLoadDeferrer deferrer2; 3279 ScopedPageLoadDeferrer deferrer2;
3247 EXPECT_TRUE(webView->page()->defersLoading()); 3280 EXPECT_TRUE(webView->page()->defersLoading());
3248 } 3281 }
3249 3282
3250 EXPECT_TRUE(webView->page()->defersLoading()); 3283 EXPECT_TRUE(webView->page()->defersLoading());
3251 } 3284 }
3252 3285
3253 EXPECT_FALSE(webView->page()->defersLoading()); 3286 EXPECT_FALSE(webView->page()->defersLoading());
3254 } 3287 }
3255 3288
3256 } // namespace blink 3289 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/events/EventTarget.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698