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

Side by Side Diff: chrome/test/base/in_process_browser_test.cc

Issue 1225093003: mac: Flush the autorelease pool after making a browser window in browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_test_base
Patch Set: Add missing include. Created 5 years, 5 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 "chrome/test/base/in_process_browser_test.h" 5 #include "chrome/test/base/in_process_browser_test.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/test/test_file_util.h" 18 #include "base/test/test_file_util.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/non_thread_safe.h" 20 #include "base/threading/non_thread_safe.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h" 22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/devtools/devtools_window.h"
23 #include "chrome/browser/lifetime/application_lifetime.h" 24 #include "chrome/browser/lifetime/application_lifetime.h"
24 #include "chrome/browser/net/net_error_tab_helper.h" 25 #include "chrome/browser/net/net_error_tab_helper.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_list.h" 31 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/browser_list_observer.h" 32 #include "chrome/browser/ui/browser_list_observer.h"
31 #include "chrome/browser/ui/browser_navigator.h" 33 #include "chrome/browser/ui/browser_navigator.h"
32 #include "chrome/browser/ui/browser_tabstrip.h" 34 #include "chrome/browser/ui/browser_tabstrip.h"
33 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
34 #include "chrome/browser/ui/host_desktop.h" 36 #include "chrome/browser/ui/host_desktop.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" 37 #include "chrome/browser/ui/tabs/tab_strip_model.h"
36 #include "chrome/common/chrome_constants.h" 38 #include "chrome/common/chrome_constants.h"
37 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/logging_chrome.h" 41 #include "chrome/common/logging_chrome.h"
40 #include "chrome/common/url_constants.h" 42 #include "chrome/common/url_constants.h"
41 #include "chrome/renderer/chrome_content_renderer_client.h" 43 #include "chrome/renderer/chrome_content_renderer_client.h"
42 #include "chrome/test/base/chrome_test_suite.h" 44 #include "chrome/test/base/chrome_test_suite.h"
43 #include "chrome/test/base/test_launcher_utils.h" 45 #include "chrome/test/base/test_launcher_utils.h"
44 #include "chrome/test/base/test_switches.h" 46 #include "chrome/test/base/test_switches.h"
45 #include "chrome/test/base/testing_browser_process.h" 47 #include "chrome/test/base/testing_browser_process.h"
48 #include "chrome/test/base/ui_test_utils.h"
46 #include "components/google/core/browser/google_util.h" 49 #include "components/google/core/browser/google_util.h"
47 #include "components/os_crypt/os_crypt.h" 50 #include "components/os_crypt/os_crypt.h"
51 #include "content/public/browser/devtools_agent_host.h"
48 #include "content/public/browser/notification_service.h" 52 #include "content/public/browser/notification_service.h"
49 #include "content/public/browser/notification_types.h" 53 #include "content/public/browser/notification_types.h"
50 #include "content/public/test/browser_test_utils.h" 54 #include "content/public/test/browser_test_utils.h"
51 #include "content/public/test/test_launcher.h" 55 #include "content/public/test/test_launcher.h"
52 #include "content/public/test/test_navigation_observer.h" 56 #include "content/public/test/test_navigation_observer.h"
53 #include "net/test/embedded_test_server/embedded_test_server.h" 57 #include "net/test/embedded_test_server/embedded_test_server.h"
54 #include "net/test/spawned_test_server/spawned_test_server.h" 58 #include "net/test/spawned_test_server/spawned_test_server.h"
55 59
56 #if defined(OS_MACOSX) 60 #if defined(OS_MACOSX)
57 #include "base/mac/scoped_nsautorelease_pool.h" 61 #include "base/mac/scoped_nsautorelease_pool.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 406
403 void InProcessBrowserTest::CloseAllBrowsers() { 407 void InProcessBrowserTest::CloseAllBrowsers() {
404 chrome::CloseAllBrowsers(); 408 chrome::CloseAllBrowsers();
405 #if defined(OS_MACOSX) 409 #if defined(OS_MACOSX)
406 // BrowserWindowController depends on the auto release pool being recycled 410 // BrowserWindowController depends on the auto release pool being recycled
407 // in the message loop to delete itself. 411 // in the message loop to delete itself.
408 AutoreleasePool()->Recycle(); 412 AutoreleasePool()->Recycle();
409 #endif 413 #endif
410 } 414 }
411 415
416 void InProcessBrowserTest::OpenDevToolsWindow(
417 content::WebContents* web_contents) {
418 #if defined(OS_MACOSX)
419 // Opening a Devtools Window can cause AppKit to throw objects into the
420 // autorelease pool. Flush the pool when this function returns.
421 base::mac::ScopedNSAutoreleasePool pool;
422 #endif // OS_MACOSX
423 ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents));
424 DevToolsWindow::OpenDevToolsWindow(web_contents);
425 ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents));
426 }
427
428 Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile,
429 const GURL& url) {
430 #if defined(OS_MACOSX)
431 // Opening an incognito window can cause AppKit to throw objects into the
432 // autorelease pool. Flush the pool when this function returns.
433 base::mac::ScopedNSAutoreleasePool pool;
434 #endif
435 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop();
436 chrome::OpenURLOffTheRecord(profile, url, active_desktop);
437 Browser* browser = chrome::FindTabbedBrowser(
438 profile->GetOffTheRecordProfile(), false, active_desktop);
439 content::TestNavigationObserver observer(
440 browser->tab_strip_model()->GetActiveWebContents());
441 observer.Wait();
442 return browser;
443 }
444
412 // TODO(alexmos): This function should expose success of the underlying 445 // TODO(alexmos): This function should expose success of the underlying
413 // navigation to tests, which should make sure navigations succeed when 446 // navigation to tests, which should make sure navigations succeed when
414 // appropriate. See https://crbug.com/425335 447 // appropriate. See https://crbug.com/425335
415 void InProcessBrowserTest::AddTabAtIndexToBrowser( 448 void InProcessBrowserTest::AddTabAtIndexToBrowser(
416 Browser* browser, 449 Browser* browser,
417 int index, 450 int index,
418 const GURL& url, 451 const GURL& url,
419 ui::PageTransition transition, 452 ui::PageTransition transition,
420 bool check_navigation_success) { 453 bool check_navigation_success) {
421 chrome::NavigateParams params(browser, url, transition); 454 chrome::NavigateParams params(browser, url, transition);
(...skipping 14 matching lines...) Expand all
436 AddTabAtIndexToBrowser(browser(), index, url, transition, true); 469 AddTabAtIndexToBrowser(browser(), index, url, transition, true);
437 } 470 }
438 471
439 bool InProcessBrowserTest::SetUpUserDataDirectory() { 472 bool InProcessBrowserTest::SetUpUserDataDirectory() {
440 return true; 473 return true;
441 } 474 }
442 475
443 // Creates a browser with a single tab (about:blank), waits for the tab to 476 // Creates a browser with a single tab (about:blank), waits for the tab to
444 // finish loading and shows the browser. 477 // finish loading and shows the browser.
445 Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) { 478 Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) {
479 #if defined(OS_MACOSX)
James Hawkins 2015/07/13 18:22:23 Something doesn't seem right about this change. I
erikchen 2015/07/13 19:39:21 I agree that this solution isn't ideal, although I
480 // Making a browser window can cause AppKit to throw objects into the
481 // autorelease pool. Flush the pool when this function returns.
482 base::mac::ScopedNSAutoreleasePool pool;
483 #endif
446 Browser* browser = new Browser( 484 Browser* browser = new Browser(
447 Browser::CreateParams(profile, chrome::GetActiveDesktop())); 485 Browser::CreateParams(profile, chrome::GetActiveDesktop()));
448 AddBlankTabAndShow(browser); 486 AddBlankTabAndShow(browser);
449 return browser; 487 return browser;
450 } 488 }
451 489
452 Browser* InProcessBrowserTest::CreateIncognitoBrowser() { 490 Browser* InProcessBrowserTest::CreateIncognitoBrowser() {
491 #if defined(OS_MACOSX)
492 // Making a browser window can cause AppKit to throw objects into the
493 // autorelease pool. Flush the pool when this function returns.
494 base::mac::ScopedNSAutoreleasePool pool;
495 #endif
453 // Create a new browser with using the incognito profile. 496 // Create a new browser with using the incognito profile.
454 Browser* incognito = new Browser( 497 Browser* incognito = new Browser(
455 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(), 498 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(),
456 chrome::GetActiveDesktop())); 499 chrome::GetActiveDesktop()));
457 AddBlankTabAndShow(incognito); 500 AddBlankTabAndShow(incognito);
458 return incognito; 501 return incognito;
459 } 502 }
460 503
461 Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) { 504 Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) {
505 #if defined(OS_MACOSX)
506 // Making a browser window can cause AppKit to throw objects into the
507 // autorelease pool. Flush the pool when this function returns.
508 base::mac::ScopedNSAutoreleasePool pool;
509 #endif
462 Browser* browser = 510 Browser* browser =
463 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, 511 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile,
464 chrome::GetActiveDesktop())); 512 chrome::GetActiveDesktop()));
465 AddBlankTabAndShow(browser); 513 AddBlankTabAndShow(browser);
466 return browser; 514 return browser;
467 } 515 }
468 516
469 Browser* InProcessBrowserTest::CreateBrowserForApp( 517 Browser* InProcessBrowserTest::CreateBrowserForApp(
470 const std::string& app_name, 518 const std::string& app_name,
471 Profile* profile) { 519 Profile* profile) {
520 #if defined(OS_MACOSX)
521 // Making a browser window can cause AppKit to throw objects into the
522 // autorelease pool. Flush the pool when this function returns.
523 base::mac::ScopedNSAutoreleasePool pool;
524 #endif
472 Browser* browser = new Browser( 525 Browser* browser = new Browser(
473 Browser::CreateParams::CreateForApp( 526 Browser::CreateParams::CreateForApp(
474 app_name, false /* trusted_source */, gfx::Rect(), profile, 527 app_name, false /* trusted_source */, gfx::Rect(), profile,
475 chrome::GetActiveDesktop())); 528 chrome::GetActiveDesktop()));
476 AddBlankTabAndShow(browser); 529 AddBlankTabAndShow(browser);
477 return browser; 530 return browser;
478 } 531 }
479 532
480 void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) { 533 void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) {
481 content::WindowedNotificationObserver observer( 534 content::WindowedNotificationObserver observer(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // On the Mac, this eventually reaches 676 // On the Mac, this eventually reaches
624 // -[BrowserWindowController windowWillClose:], which will post a deferred 677 // -[BrowserWindowController windowWillClose:], which will post a deferred
625 // -autorelease on itself to ultimately destroy the Browser object. The line 678 // -autorelease on itself to ultimately destroy the Browser object. The line
626 // below is necessary to pump these pending messages to ensure all Browsers 679 // below is necessary to pump these pending messages to ensure all Browsers
627 // get deleted. 680 // get deleted.
628 content::RunAllPendingInMessageLoop(); 681 content::RunAllPendingInMessageLoop();
629 delete autorelease_pool_; 682 delete autorelease_pool_;
630 autorelease_pool_ = NULL; 683 autorelease_pool_ = NULL;
631 #endif 684 #endif
632 } 685 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698