Commit c8a95bb8 authored by Sven Zheng's avatar Sven Zheng Committed by Commit Bot

Fix flakiness pixeltests on bots

On bot, often we can only catch black screen for dialog. I found a similar
bug crbug.com/687387 related to gpu. To repro the same result locally,
pass in --disable-gpu when running test locally.
To fix the flakiness, we don't catch the screen from HDC. Instead, we
catch from Layer::RequestCopyOfOutput.
This change also refactor some code to reuse some existing lib.

browser_tests.exe
  --build-revision=fd1bb443
  --test-launcher-filter-file=testing/buildbot/filters/pixel_browser_tests.filter
  --browser-ui-tests-verify-pixels
  --enable-pixel-output-in-tests
  --disable-gpu
  --no-luci-auth
can pass.

TEST: tested multiple times the tests won't catch black screen anymore.
Bug: 958242
Change-Id: Ie7df0e304fb74eb1d2b6c013612529dcdf549605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879506
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709634}
parent 1092a8c0
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/views/test/widget_test.h" #include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget_observer.h"
#endif #endif
namespace { namespace {
...@@ -56,18 +56,6 @@ class WidgetCloser { ...@@ -56,18 +56,6 @@ class WidgetCloser {
DISALLOW_COPY_AND_ASSIGN(WidgetCloser); DISALLOW_COPY_AND_ASSIGN(WidgetCloser);
}; };
class CompositorObserverEnd : public ui::CompositorObserver {
public:
void OnCompositingEnded(ui::Compositor* compositor) override {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
run_loop_.QuitClosure());
}
void WaitForComplete() { run_loop_.Run(); }
private:
base::RunLoop run_loop_;
};
#endif // defined(TOOLKIT_VIEWS) #endif // defined(TOOLKIT_VIEWS)
} // namespace } // namespace
...@@ -85,13 +73,6 @@ void TestBrowserDialog::PreShow() { ...@@ -85,13 +73,6 @@ void TestBrowserDialog::PreShow() {
UpdateWidgets(); UpdateWidgets();
} }
void CompareAsync(const BrowserSkiaGoldPixelDiff* pixel_diff,
const std::string& name,
const views::View* view,
bool* result) {
*result = pixel_diff->CompareScreenshot(name, view);
}
// This returns true if exactly one views widget was shown that is a dialog or // This returns true if exactly one views widget was shown that is a dialog or
// has a name matching the test-specified name, and if that window is in the // has a name matching the test-specified name, and if that window is in the
// work area (if |should_verify_dialog_bounds_| is true). // work area (if |should_verify_dialog_bounds_| is true).
...@@ -120,26 +101,15 @@ bool TestBrowserDialog::VerifyUi() { ...@@ -120,26 +101,15 @@ bool TestBrowserDialog::VerifyUi() {
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (pixel_diff_) { if (pixel_diff_) {
// Wait for painting complete. // Wait for painting complete.
auto* compositor = dialog_widget->GetNativeView()->layer()->GetCompositor(); auto* compositor = dialog_widget->GetCompositor();
CompositorObserverEnd obend; ui::DrawWaiterForTest::WaitForCompositingEnded(compositor);
compositor->AddObserver(&obend);
obend.WaitForComplete();
compositor->RemoveObserver(&obend);
base::ScopedAllowBlockingForTesting allow_blocking;
pixel_diff_->Init(dialog_widget, "BrowserUiDialog"); pixel_diff_->Init(dialog_widget, "BrowserUiDialog");
auto* test_info = testing::UnitTest::GetInstance()->current_test_info(); auto* test_info = testing::UnitTest::GetInstance()->current_test_info();
const std::string test_name = const std::string test_name =
base::StrCat({test_info->test_case_name(), "_", test_info->name()}); base::StrCat({test_info->test_case_name(), "_", test_info->name()});
bool result = false; if (!pixel_diff_->CompareScreenshot(test_name,
base::RunLoop run_loop; dialog_widget->GetContentsView()))
base::ThreadTaskRunnerHandle::Get()->PostTaskAndReply(
FROM_HERE,
base::BindOnce(CompareAsync, pixel_diff_.get(), test_name,
dialog_widget->GetContentsView(), &result),
run_loop.QuitClosure());
run_loop.Run();
if (!result)
return false; return false;
} }
#endif // OS_MACOSX #endif // OS_MACOSX
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/test/pixel/browser_skia_gold_pixel_diff.h" #include "chrome/test/pixel/browser_skia_gold_pixel_diff.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -13,6 +14,18 @@ ...@@ -13,6 +14,18 @@
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#if defined(USE_AURA)
#include "ui/snapshot/snapshot_aura.h"
#endif
void SnapshotCallback(base::RunLoop* run_loop,
gfx::Image* ret_image,
gfx::Image image) {
*ret_image = image;
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
run_loop->QuitClosure());
}
BrowserSkiaGoldPixelDiff::BrowserSkiaGoldPixelDiff() = default; BrowserSkiaGoldPixelDiff::BrowserSkiaGoldPixelDiff() = default;
BrowserSkiaGoldPixelDiff::~BrowserSkiaGoldPixelDiff() = default; BrowserSkiaGoldPixelDiff::~BrowserSkiaGoldPixelDiff() = default;
...@@ -28,12 +41,16 @@ bool BrowserSkiaGoldPixelDiff::GrabWindowSnapshotInternal( ...@@ -28,12 +41,16 @@ bool BrowserSkiaGoldPixelDiff::GrabWindowSnapshotInternal(
gfx::NativeWindow window, gfx::NativeWindow window,
const gfx::Rect& snapshot_bounds, const gfx::Rect& snapshot_bounds,
gfx::Image* image) const { gfx::Image* image) const {
bool ret = ui::GrabWindowSnapshot(window, snapshot_bounds, image); base::RunLoop run_loop;
if (!ret) { #if defined(USE_AURA)
LOG(WARNING) << "Grab snapshot failed"; ui::GrabWindowSnapshotAsyncAura(
return false; #else
} ui::GrabWindowSnapshotAsync(
return true; #endif
window, snapshot_bounds,
base::BindOnce(&SnapshotCallback, &run_loop, image));
run_loop.Run();
return !image->IsEmpty();
} }
bool BrowserSkiaGoldPixelDiff::CompareScreenshot( bool BrowserSkiaGoldPixelDiff::CompareScreenshot(
...@@ -48,6 +65,7 @@ bool BrowserSkiaGoldPixelDiff::CompareScreenshot( ...@@ -48,6 +65,7 @@ bool BrowserSkiaGoldPixelDiff::CompareScreenshot(
gfx::Image image; gfx::Image image;
bool ret = GrabWindowSnapshotInternal(widget_->GetNativeWindow(), rc, &image); bool ret = GrabWindowSnapshotInternal(widget_->GetNativeWindow(), rc, &image);
if (!ret) { if (!ret) {
LOG(ERROR) << "Grab screenshot failed.";
return false; return false;
} }
return SkiaGoldPixelDiff::CompareScreenshot(screenshot_name, return SkiaGoldPixelDiff::CompareScreenshot(screenshot_name,
......
...@@ -25,3 +25,6 @@ ProfileSigninConfirmationDialogTest.* ...@@ -25,3 +25,6 @@ ProfileSigninConfirmationDialogTest.*
TabGroupEditorBubbleViewDialogBrowserTest.* TabGroupEditorBubbleViewDialogBrowserTest.*
TabHoverCardBubbleViewBrowserTest.* TabHoverCardBubbleViewBrowserTest.*
OutdatedUpgradeBubbleTest.* OutdatedUpgradeBubbleTest.*
# This test uses random network port and shows it on ui.
-ContentSettingBubbleDialogTest.InvokeUi_popups
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