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

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

Issue 2780343002: Always disable the beforeunload timer when injecting the beforeunload method. (Closed)
Patch Set: fix 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
« no previous file with comments | « no previous file | 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 // 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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/cancelable_callback.h" 10 #include "base/cancelable_callback.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 void CloseInspectedBrowser() { 376 void CloseInspectedBrowser() {
377 chrome::CloseWindow(browser()); 377 chrome::CloseWindow(browser());
378 } 378 }
379 379
380 protected: 380 protected:
381 void InjectBeforeUnloadListener(content::WebContents* web_contents) { 381 void InjectBeforeUnloadListener(content::WebContents* web_contents) {
382 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), 382 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
383 "window.addEventListener('beforeunload'," 383 "window.addEventListener('beforeunload',"
384 "function(event) { event.returnValue = 'Foo'; });")); 384 "function(event) { event.returnValue = 'Foo'; });"));
385 // Disable the hang monitor, otherwise there will be a race between the
386 // beforeunload dialog and the beforeunload hang timer.
387 web_contents->GetMainFrame()->DisableBeforeUnloadHangMonitorForTesting();
385 } 388 }
386 389
387 void RunBeforeUnloadSanityTest(bool is_docked, 390 void RunBeforeUnloadSanityTest(bool is_docked,
388 base::Callback<void(void)> close_method, 391 base::Callback<void(void)> close_method,
389 bool wait_for_browser_close = true) { 392 bool wait_for_browser_close = true) {
390 OpenDevToolsWindow(kDebuggerTestPage, is_docked); 393 OpenDevToolsWindow(kDebuggerTestPage, is_docked);
391 scoped_refptr<content::MessageLoopRunner> runner = 394 scoped_refptr<content::MessageLoopRunner> runner =
392 new content::MessageLoopRunner; 395 new content::MessageLoopRunner;
393 DevToolsWindowTesting::Get(window_)-> 396 DevToolsWindowTesting::Get(window_)->
394 SetCloseCallback(runner->QuitClosure()); 397 SetCloseCallback(runner->QuitClosure());
395 InjectBeforeUnloadListener(main_web_contents()); 398 InjectBeforeUnloadListener(main_web_contents());
396 main_web_contents()
397 ->GetMainFrame()
398 ->DisableBeforeUnloadHangMonitorForTesting();
399 { 399 {
400 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_); 400 DevToolsWindowBeforeUnloadObserver before_unload_observer(window_);
401 close_method.Run(); 401 close_method.Run();
402 CancelModalDialog(); 402 CancelModalDialog();
403 before_unload_observer.Wait(); 403 before_unload_observer.Wait();
404 } 404 }
405 { 405 {
406 content::WindowedNotificationObserver close_observer( 406 content::WindowedNotificationObserver close_observer(
407 chrome::NOTIFICATION_BROWSER_CLOSED, 407 chrome::NOTIFICATION_BROWSER_CLOSED,
408 content::Source<Browser>(browser())); 408 content::Source<Browser>(browser()));
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 DevToolsWindowTesting::Get(devtools_window)-> 814 DevToolsWindowTesting::Get(devtools_window)->
815 main_web_contents())); 815 main_web_contents()));
816 close_observers.push_back(close_observer); 816 close_observers.push_back(close_observer);
817 inspected_web_contents = 817 inspected_web_contents =
818 DevToolsWindowTesting::Get(devtools_window)->main_web_contents(); 818 DevToolsWindowTesting::Get(devtools_window)->main_web_contents();
819 } 819 }
820 820
821 InjectBeforeUnloadListener( 821 InjectBeforeUnloadListener(
822 DevToolsWindowTesting::Get(windows[0])->main_web_contents()); 822 DevToolsWindowTesting::Get(windows[0])->main_web_contents());
823 InjectBeforeUnloadListener( 823 InjectBeforeUnloadListener(
824 DevToolsWindowTesting::Get(windows[2])->main_web_contents()); 824 DevToolsWindowTesting::Get(windows[2])->main_web_contents());
Avi (use Gerrit) 2017/03/30 15:29:58 This is the second spot where InjectBeforeUnloadLi
825 // Try to close second devtools. 825 // Try to close second devtools.
826 { 826 {
827 content::WindowedNotificationObserver cancel_browser( 827 content::WindowedNotificationObserver cancel_browser(
828 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, 828 chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
829 content::NotificationService::AllSources()); 829 content::NotificationService::AllSources());
830 chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser()); 830 chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser());
831 CancelModalDialog(); 831 CancelModalDialog();
832 cancel_browser.Wait(); 832 cancel_browser.Wait();
833 } 833 }
834 // Try to close browser window. 834 // Try to close browser window.
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); 1541 RunTestFunction(window, "testWindowInitializedOnNavigateBack");
1542 1542
1543 DevToolsWindowTesting::CloseDevToolsWindowSync(window); 1543 DevToolsWindowTesting::CloseDevToolsWindowSync(window);
1544 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); 1544 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory);
1545 } 1545 }
1546 1546
1547 // Tests scripts panel showing. 1547 // Tests scripts panel showing.
1548 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { 1548 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) {
1549 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); 1549 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL);
1550 } 1550 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698