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

Side by Side Diff: chrome/browser/devtools/devtools_sanity_browsertest.cc

Issue 2801813005: Only show a beforeunload dialog if a frame has had a user gesture since its load. (Closed)
Patch Set: aw Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 379
380 void CloseInspectedBrowser() { 380 void CloseInspectedBrowser() {
381 chrome::CloseWindow(browser()); 381 chrome::CloseWindow(browser());
382 } 382 }
383 383
384 protected: 384 protected:
385 void InjectBeforeUnloadListener(content::WebContents* web_contents) { 385 void InjectBeforeUnloadListener(content::WebContents* web_contents) {
386 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), 386 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
387 "window.addEventListener('beforeunload'," 387 "window.addEventListener('beforeunload',"
388 "function(event) { event.returnValue = 'Foo'; });")); 388 "function(event) { event.returnValue = 'Foo'; });"));
389 // JavaScript onbeforeunload dialogs require a user gesture.
390 web_contents->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
391 base::string16());
389 // Disable the hang monitor, otherwise there will be a race between the 392 // Disable the hang monitor, otherwise there will be a race between the
390 // beforeunload dialog and the beforeunload hang timer. 393 // beforeunload dialog and the beforeunload hang timer.
391 web_contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting(); 394 web_contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting();
392 } 395 }
393 396
394 void RunBeforeUnloadSanityTest(bool is_docked, 397 void RunBeforeUnloadSanityTest(bool is_docked,
395 base::Callback<void(void)> close_method, 398 base::Callback<void(void)> close_method,
396 bool wait_for_browser_close = true) { 399 bool wait_for_browser_close = true) {
397 OpenDevToolsWindow(kDebuggerTestPage, is_docked); 400 OpenDevToolsWindow(kDebuggerTestPage, is_docked);
398 scoped_refptr<content::MessageLoopRunner> runner = 401 scoped_refptr<content::MessageLoopRunner> runner =
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); 2063 RunTestFunction(window, "testWindowInitializedOnNavigateBack");
2061 2064
2062 DevToolsWindowTesting::CloseDevToolsWindowSync(window); 2065 DevToolsWindowTesting::CloseDevToolsWindowSync(window);
2063 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); 2066 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory);
2064 } 2067 }
2065 2068
2066 // Tests scripts panel showing. 2069 // Tests scripts panel showing.
2067 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { 2070 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) {
2068 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); 2071 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL);
2069 } 2072 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698