Commit 70783602 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Add a sanity check for detecting incorrect PreRunTestOnMainThread overloading

This CL is adding a sanity dcheck to avoid tests crashing on MAC only when
a chrome developer forgot to call the base function
"ContentBrowserTest::PreRunTestOnMainThread".


  class MyBrowserTest : public ContentBrowserTest {

   public:

    void PreRunTestOnMainThread() override {

      [...]

      ContentBrowserTest::PreRunTestOnMainThread();
  // Required, otherwise crash on MAC.
    }

I recently did that silly mistake and needed time to set up a MAC build to
debug it. I believe this test is cheap enough and worth saving developers time.

R=sky@chromium.org

Change-Id: Iec0ed2e19b216a35c675016ad6ff88dc9e1c86ad
Reviewed-on: https://chromium-review.googlesource.com/c/1407110Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626186}
parent 5a177cf2
......@@ -140,9 +140,16 @@ void ContentBrowserTest::PreRunTestOnMainThread() {
#if defined(OS_MACOSX)
pool_->Recycle();
#endif
pre_run_test_executed_ = true;
}
void ContentBrowserTest::PostRunTestOnMainThread() {
// This code is failing when the test is overriding PreRunTestOnMainThread()
// without the required call to ContentBrowserTest::PreRunTestOnMainThread().
// This is a common error causing a crash on MAC.
DCHECK(pre_run_test_executed_);
#if defined(OS_MACOSX)
pool_->Recycle();
#endif
......
......@@ -48,7 +48,7 @@ class ContentBrowserTest : public BrowserTestBase {
base::FilePath GetTestDataFilePath();
private:
Shell* shell_;
Shell* shell_ = nullptr;
#if defined(OS_MACOSX)
// On Mac, without the following autorelease pool, code which is directly
......@@ -66,6 +66,10 @@ class ContentBrowserTest : public BrowserTestBase {
// ContentMain. For Android we set things up manually.
std::unique_ptr<ShellMainDelegate> shell_main_delegate_;
#endif
// Used to detect incorrect overriding of PreRunTestOnMainThread() with
// missung call to base implementation.
bool pre_run_test_executed_ = false;
};
} // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment