Index: content/public/test/content_browser_test.h |
diff --git a/content/public/test/content_browser_test.h b/content/public/test/content_browser_test.h |
index b91b350f9ef4301df4b07dd598687a6eaa06c930..44134f2c0c6373de4f6796311c651a008ee6f733 100644 |
--- a/content/public/test/content_browser_test.h |
+++ b/content/public/test/content_browser_test.h |
@@ -11,6 +11,10 @@ |
#include "content/public/test/browser_test.h" |
#include "content/public/test/browser_test_base.h" |
+#if defined(OS_MACOSX) |
+#include "base/mac/scoped_nsautorelease_pool.h" |
+#endif |
+ |
namespace content { |
class Shell; |
class ShellMainDelegate; |
@@ -26,7 +30,8 @@ class ContentBrowserTest : public BrowserTestBase { |
void TearDown() override; |
// BrowserTestBase: |
- void RunTestOnMainThreadLoop() override; |
+ void PreRunTestOnMainThread() override; |
+ void PostRunTestOnMainThread() override; |
protected: |
// Creates a new window and loads about:blank. |
@@ -41,6 +46,17 @@ class ContentBrowserTest : public BrowserTestBase { |
private: |
Shell* shell_; |
+#if defined(OS_MACOSX) |
+ // On Mac, without the following autorelease pool, code which is directly |
+ // executed (as opposed to executed inside a message loop) would autorelease |
+ // objects into a higher-level pool. This pool is not recycled in-sync with |
+ // the message loops' pools and causes problems with code relying on |
+ // deallocation via an autorelease pool (such as browser window closure and |
+ // browser shutdown). To avoid this, the following pool is recycled after each |
+ // time code is directly executed. |
+ base::mac::ScopedNSAutoreleasePool* pool_ = nullptr; |
+#endif |
+ |
#if defined(OS_ANDROID) |
// For all other platforms, this is done automatically when calling into |
// ContentMain. For Android we set things up manually. |