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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/events/EventTarget.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/web/tests/WebViewTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/WebViewTest.cpp b/third_party/WebKit/Source/web/tests/WebViewTest.cpp
index a1c0366709c8942485b23d30a4b47885368ee333..340521631ad19f081804fb958e67acbb0ae14ad8 100644
--- a/third_party/WebKit/Source/web/tests/WebViewTest.cpp
+++ b/third_party/WebKit/Source/web/tests/WebViewTest.cpp
@@ -3231,6 +3231,39 @@ TEST_F(WebViewTest, CreatedDuringLoadDeferral)
}
}
+// Make sure the SubframeBeforeUnloadUseCounter is only incremented on subframe
+// unloads. crbug.com/635029.
+TEST_F(WebViewTest, SubframeBeforeUnloadUseCounter)
+{
+ registerMockedHttpURLLoad("visible_iframe.html");
+ registerMockedHttpURLLoad("single_iframe.html");
+ WebViewImpl* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "single_iframe.html", true);
+
+ WebFrame* frame = m_webViewHelper.webView()->mainFrame();
+ Document* document =
+ toLocalFrame(m_webViewHelper.webView()->page()->mainFrame())->document();
+
+ // Add a beforeunload handler in the main frame. Make sure firing
+ // beforeunload doesn't increment the subframe use counter.
+ {
+ frame->executeScript(WebScriptSource(
+ "addEventListener('beforeunload', function() {});"));
+ webView->mainFrame()->toWebLocalFrame()->dispatchBeforeUnloadEvent(false);
+ EXPECT_FALSE(UseCounter::isCounted(*document, UseCounter::SubFrameBeforeUnloadFired));
+ }
+
+ // Add a beforeunload handler in the iframe and dispatch. Make sure we do
+ // increment the use counter for subframe beforeunloads.
+ {
+ frame->executeScript(WebScriptSource(
+ "document.getElementsByTagName('iframe')[0].contentWindow.addEventListener('beforeunload', function() {});"));
+ webView->mainFrame()->firstChild()->toWebLocalFrame()->dispatchBeforeUnloadEvent(false);
+
+ Document* childDocument = toLocalFrame(m_webViewHelper.webView()->page()->mainFrame()->tree().firstChild())->document();
+ EXPECT_TRUE(UseCounter::isCounted(*childDocument, UseCounter::SubFrameBeforeUnloadFired));
+ }
+}
+
// Verify that page loads are deferred until all ScopedPageLoadDeferrers are
// destroyed.
TEST_F(WebViewTest, NestedLoadDeferrals)
« 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