| OLD | NEW |
| 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 #ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_H_ |
| 6 #define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_H_ | 6 #define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "content/public/test/browser_test.h" | 11 #include "content/public/test/browser_test.h" |
| 12 #include "content/public/test/browser_test_base.h" | 12 #include "content/public/test/browser_test_base.h" |
| 13 | 13 |
| 14 #if defined(OS_MACOSX) |
| 15 #include "base/mac/scoped_nsautorelease_pool.h" |
| 16 #endif |
| 17 |
| 14 namespace content { | 18 namespace content { |
| 15 class Shell; | 19 class Shell; |
| 16 class ShellMainDelegate; | 20 class ShellMainDelegate; |
| 17 | 21 |
| 18 // Base class for browser tests which use content_shell. | 22 // Base class for browser tests which use content_shell. |
| 19 class ContentBrowserTest : public BrowserTestBase { | 23 class ContentBrowserTest : public BrowserTestBase { |
| 20 protected: | 24 protected: |
| 21 ContentBrowserTest(); | 25 ContentBrowserTest(); |
| 22 ~ContentBrowserTest() override; | 26 ~ContentBrowserTest() override; |
| 23 | 27 |
| 24 // testing::Test: | 28 // testing::Test: |
| 25 void SetUp() override; | 29 void SetUp() override; |
| 26 void TearDown() override; | 30 void TearDown() override; |
| 27 | 31 |
| 28 // BrowserTestBase: | 32 // BrowserTestBase: |
| 29 void RunTestOnMainThreadLoop() override; | 33 void PreRunTestOnMainThread() override; |
| 34 void PostRunTestOnMainThread() override; |
| 30 | 35 |
| 31 protected: | 36 protected: |
| 32 // Creates a new window and loads about:blank. | 37 // Creates a new window and loads about:blank. |
| 33 Shell* CreateBrowser(); | 38 Shell* CreateBrowser(); |
| 34 | 39 |
| 35 // Creates an off-the-record window and loads about:blank. | 40 // Creates an off-the-record window and loads about:blank. |
| 36 Shell* CreateOffTheRecordBrowser(); | 41 Shell* CreateOffTheRecordBrowser(); |
| 37 | 42 |
| 38 // Returns the window for the test. | 43 // Returns the window for the test. |
| 39 Shell* shell() const { return shell_; } | 44 Shell* shell() const { return shell_; } |
| 40 | 45 |
| 41 private: | 46 private: |
| 42 Shell* shell_; | 47 Shell* shell_; |
| 43 | 48 |
| 49 #if defined(OS_MACOSX) |
| 50 // On Mac, without the following autorelease pool, code which is directly |
| 51 // executed (as opposed to executed inside a message loop) would autorelease |
| 52 // objects into a higher-level pool. This pool is not recycled in-sync with |
| 53 // the message loops' pools and causes problems with code relying on |
| 54 // deallocation via an autorelease pool (such as browser window closure and |
| 55 // browser shutdown). To avoid this, the following pool is recycled after each |
| 56 // time code is directly executed. |
| 57 base::mac::ScopedNSAutoreleasePool* pool_ = nullptr; |
| 58 #endif |
| 59 |
| 44 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
| 45 // For all other platforms, this is done automatically when calling into | 61 // For all other platforms, this is done automatically when calling into |
| 46 // ContentMain. For Android we set things up manually. | 62 // ContentMain. For Android we set things up manually. |
| 47 std::unique_ptr<ShellMainDelegate> shell_main_delegate_; | 63 std::unique_ptr<ShellMainDelegate> shell_main_delegate_; |
| 48 #endif | 64 #endif |
| 49 }; | 65 }; |
| 50 | 66 |
| 51 } // namespace content | 67 } // namespace content |
| 52 | 68 |
| 53 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_H_ | 69 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_H_ |
| OLD | NEW |