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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/in_process_browser_test.cc
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index 96f521b12bfb8a73f2b18e500d480eca98ad2eb3..83f3a2181c8fbd27ec84135968f3e3fbbda5a3a8 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -20,11 +20,13 @@
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/net/net_error_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
@@ -43,8 +45,10 @@
#include "chrome/test/base/test_launcher_utils.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "components/google/core/browser/google_util.h"
#include "components/os_crypt/os_crypt.h"
+#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/test/browser_test_utils.h"
@@ -409,6 +413,35 @@ void InProcessBrowserTest::CloseAllBrowsers() {
#endif
}
+void InProcessBrowserTest::OpenDevToolsWindow(
+ content::WebContents* web_contents) {
+#if defined(OS_MACOSX)
+ // Opening a Devtools Window can cause AppKit to throw objects into the
+ // autorelease pool. Flush the pool when this function returns.
+ base::mac::ScopedNSAutoreleasePool pool;
+#endif // OS_MACOSX
+ ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents));
+ DevToolsWindow::OpenDevToolsWindow(web_contents);
+ ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents));
+}
+
+Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile,
+ const GURL& url) {
+#if defined(OS_MACOSX)
+ // Opening an incognito window can cause AppKit to throw objects into the
+ // autorelease pool. Flush the pool when this function returns.
+ base::mac::ScopedNSAutoreleasePool pool;
+#endif
+ chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop();
+ chrome::OpenURLOffTheRecord(profile, url, active_desktop);
+ Browser* browser = chrome::FindTabbedBrowser(
+ profile->GetOffTheRecordProfile(), false, active_desktop);
+ content::TestNavigationObserver observer(
+ browser->tab_strip_model()->GetActiveWebContents());
+ observer.Wait();
+ return browser;
+}
+
// TODO(alexmos): This function should expose success of the underlying
// navigation to tests, which should make sure navigations succeed when
// appropriate. See https://crbug.com/425335
@@ -443,6 +476,11 @@ bool InProcessBrowserTest::SetUpUserDataDirectory() {
// Creates a browser with a single tab (about:blank), waits for the tab to
// finish loading and shows the browser.
Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) {
+#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
+ // Making a browser window can cause AppKit to throw objects into the
+ // autorelease pool. Flush the pool when this function returns.
+ base::mac::ScopedNSAutoreleasePool pool;
+#endif
Browser* browser = new Browser(
Browser::CreateParams(profile, chrome::GetActiveDesktop()));
AddBlankTabAndShow(browser);
@@ -450,6 +488,11 @@ Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) {
}
Browser* InProcessBrowserTest::CreateIncognitoBrowser() {
+#if defined(OS_MACOSX)
+ // Making a browser window can cause AppKit to throw objects into the
+ // autorelease pool. Flush the pool when this function returns.
+ base::mac::ScopedNSAutoreleasePool pool;
+#endif
// Create a new browser with using the incognito profile.
Browser* incognito = new Browser(
Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(),
@@ -459,6 +502,11 @@ Browser* InProcessBrowserTest::CreateIncognitoBrowser() {
}
Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) {
+#if defined(OS_MACOSX)
+ // Making a browser window can cause AppKit to throw objects into the
+ // autorelease pool. Flush the pool when this function returns.
+ base::mac::ScopedNSAutoreleasePool pool;
+#endif
Browser* browser =
new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile,
chrome::GetActiveDesktop()));
@@ -469,6 +517,11 @@ Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) {
Browser* InProcessBrowserTest::CreateBrowserForApp(
const std::string& app_name,
Profile* profile) {
+#if defined(OS_MACOSX)
+ // Making a browser window can cause AppKit to throw objects into the
+ // autorelease pool. Flush the pool when this function returns.
+ base::mac::ScopedNSAutoreleasePool pool;
+#endif
Browser* browser = new Browser(
Browser::CreateParams::CreateForApp(
app_name, false /* trusted_source */, gfx::Rect(), profile,

Powered by Google App Engine
This is Rietveld 408576698