• Etienne Bergeron's avatar
    Fix SystemFont flaky tests · 30137020
    Etienne Bergeron authored
    This CL is fixing a cause of flaky tests when re-ordering tests execution.
    
    SystemFont is keeping two static callbacks that modify metrics of the
    system fonts. Typically, these callbacks are set up before the SystemFont
    class is instantiated. A DCHECK was ensuring this.
    
    We are able to repro flaky test by changing tests order or
    by specifying test filters (see below).
    
    A DCHECK fails because it is possible in unittests to set the
    callbacks after the SystemFont is instantiated. The problem is
    that callbacks are static variables that keep states
    between two tests.
    
    I believe other fancy bugs may be hidden by this bug since system fonts
    may be scaled based on the callback left by a previous test.
    
    This CL is adding the required logic to reset the system fonts.
    
    
    R=robliao@chromium.org,asvitkine@chromium.org
    CC=​benck@google.com
    Bug: 944227
    
    C:\src\chromium\src>out\build\gfx_unittests --gtest_filter=FontListTest.Fonts_DeriveWithHeightUpperBound:RenderTextTest.HarfBuzz_FallbackFontsSupportGlyphs:SystemFontsWinTest.AdjustFontSize
    IMPORTANT DEBUGGING NOTE: batches of tests are run inside their
    own process. For debugging a test inside a debugger, use the
    --gtest_filter=<your_test_name> flag along with
    --single-process-tests.
    Using sharding settings from environment. This is shard 0/1
    Using 1 parallel jobs.
    Note: Google Test filter = FontListTest.Fonts_DeriveWithHeightUpperBound:RenderTextTest.HarfBuzz_FallbackFontsSupportGlyphs:SystemFontsWinTest.AdjustFontSize
    [==========] Running 3 tests from 3 test suites.
    [----------] Global test environment set-up.
    [----------] 1 test from FontListTest
    [ RUN      ] FontListTest.Fonts_DeriveWithHeightUpperBound
    [       OK ] FontListTest.Fonts_DeriveWithHeightUpperBound (13 ms)
    [----------] 1 test from FontListTest (14 ms total)
    
    [----------] 1 test from RenderTextTest
    [ RUN      ] RenderTextTest.HarfBuzz_FallbackFontsSupportGlyphs
    [       OK ] RenderTextTest.HarfBuzz_FallbackFontsSupportGlyphs (32 ms)
    [----------] 1 test from RenderTextTest (34 ms total)
    
    [----------] 1 test from SystemFontsWinTest
    [ RUN      ] SystemFontsWinTest.AdjustFontSize
    [26180:21012:0605/182005.067:1151493921:FATAL:system_fonts_win.cc(100)] Check failed: !SystemFonts::IsInitialized().
    
            base::debug::CollectStackTrace [0x00007FFB78F6D7E0+48] (C:\src\chromium\src\base\debug\stack_trace_win.cc:284)
            base::debug::StackTrace::StackTrace [0x00007FFB78F6C950+80] (C:\src\chromium\src\base\debug\stack_trace.cc:206)
            base::debug::StackTrace::StackTrace [0x00007FFB78F6C8D8+40] (C:\src\chromium\src\base\debug\stack_trace.cc:203)
            logging::LogMessage::~LogMessage [0x00007FFB78FBC78F+143] (C:\src\chromium\src\base\logging.cc:613)
            gfx::win::`anonymous namespace'::SystemFonts::SetGetMinimumFontSizeCallback [0x00007FFB834E3E41+161] (C:\src\chromium\src\ui\gfx\system_fonts_win.cc:101)
            gfx::win::SetGetMinimumFontSizeCallback [0x00007FFB834E3D93+19] (C:\src\chromium\src\ui\gfx\system_fonts_win.cc:222)
            gfx::win::SystemFontsWinTest_AdjustFontSize_Test::TestBody [0x00007FF7F312886E+46] (C:\src\chromium\src\ui\gfx\system_fonts_win_unittest.cc:30)
            testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,void> [0x00007FF7F31A50DF+79] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:2507)
            testing::Test::Run [0x00007FF7F31A5049+185] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:2529)
            testing::TestInfo::Run [0x00007FF7F31A5D11+225] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:2701)
            testing::TestSuite::Run [0x00007FF7F31A69D6+278] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:2827)
            testing::internal::UnitTestImpl::RunAllTests [0x00007FF7F31B0EE9+1113] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:5284)
            testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,bool> [0x00007FF7F31B0A75+85] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:2505)
            testing::UnitTest::Run [0x00007FF7F31B08BC+300] (C:\src\chromium\src\third_party\googletest\src\googletest\src\gtest.cc:4873)
            RUN_ALL_TESTS [0x00007FF7F32463F1+17] (C:\src\chromium\src\third_party\googletest\src\googletest\include\gtest\gtest.h:2453)
            base::TestSuite::Run [0x00007FF7F32459D4+164] (C:\src\chromium\src\base\test\test_suite.cc:316)
            base::internal::FunctorTraits<int (base::TestSuite::*)(),void>::Invoke<int (base::TestSuite::*)(),(anonymous namespace)::GfxTestSuite *> [0x00007FF7F2E1516D+29] (C:\src\chromium\src\base\bind_internal.h:499)
            base::internal::InvokeHelper<0,int>::MakeItSo<int (base::TestSuite::*)(),(anonymous namespace)::GfxTestSuite *> [0x00007FF7F2E150E4+52] (C:\src\chromium\src\base\bind_internal.h:599)
            base::internal::Invoker<base::internal::BindState<int (base::TestSuite::*)(),base::internal::UnretainedWrapper<(anonymous namespace)::GfxTestSuite> >,int ()>::RunImpl<int (base::TestSuite::*)(),std::__1::tuple<base::internal::UnretainedWrapper<(anonymous  [0x00007FF7F2E15068+88] (C:\src\chromium\src\base\bind_internal.h:672)
            base::internal::Invoker<base::internal::BindState<int (base::TestSuite::*)(),base::internal::UnretainedWrapper<(anonymous namespace)::GfxTestSuite> >,int ()>::RunOnce [0x00007FF7F2E14F3E+78] (C:\src\chromium\src\base\bind_internal.h:641)
            base::OnceCallback<int ()>::Run [0x00007FF7F324E611+97] (C:\src\chromium\src\base\callback.h:98)
            base::`anonymous namespace'::LaunchUnitTestsInternal [0x00007FF7F324BCE2+418] (C:\src\chromium\src\base\test\launcher\unit_test_launcher.cc:158)
            base::LaunchUnitTests [0x00007FF7F324BAFD+253] (C:\src\chromium\src\base\test\launcher\unit_test_launcher.cc:492)
            main [0x00007FF7F2E14AAA+138] (C:\src\chromium\src\ui\gfx\test\run_all_unittests.cc:81)
            invoke_main [0x00007FF7F33739E4+52] (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79)
            __scrt_common_main_seh [0x00007FF7F3373B1E+302] (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
            __scrt_common_main [0x00007FF7F3373B9E+14] (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
            mainCRTStartup [0x00007FF7F3373BB9+9] (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17)
            BaseThreadInitThunk [0x00007FFBB44837E4+20]
    
    Backtrace: 
    Change-Id: I23109356db89c48c89c51b1db78cbb0c04367e8a
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1647192
    Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
    Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
    Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#667235}
    30137020
font_unittest.cc 5.37 KB