Skip to content

Commit

Permalink
ozone/wayland: set OsExchangeDataProvider factory.
Browse files Browse the repository at this point in the history
Enabling ozone_unittests on linux bots revealed some problems
with downcasting. In particular, linux-ubsan-vptr bot started to
fail with the following error message -

./../ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc:515:10: runtime error: downcast of address 0x2ccc00349e00 which does not point to an object of type 'const WaylandExchangeDataProvider'
0x2ccc00349e00: note: object is of type 'ui::OSExchangeDataProviderNonBacked'
 00 00 00 00  28 3b f6 e3 f0 55 00 00  01 00 00 00 00 00 00 00  20 b1 26 00 cc 2c 00 00  28 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'ui::OSExchangeDataProviderNonBacked'
    #0 0x55f0e331831c in GetOfferedExchangeDataProvider ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc:515:10
    #1 0x55f0e331831c in ui::WaylandDataDragController::StartSession(ui::OSExchangeData const&, int, ui::mojom::DragEventSource) ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc:133:23
    #2 0x55f0e3366bbc in ui::WaylandWindow::StartDrag(ui::OSExchangeData const&, int, ui::mojom::DragEventSource, ui::Cursor, bool, base::OnceCallback<void (ui::mojom::DragOperation)>, ui::WmDragHandler::LocationDelegate*) ui/ozone/platform/wayland/host/wayland_window.cc:227:45
    #3 0x55f0e2b28c32 in ui::WaylandDataDragControllerTest_AsyncNoopStartDrag_Test::TestBody() ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc:973:28
    #4 0x55f0e2e26ab1 in testing::Test::Run() third_party/googletest/src/googletest/src/gtest.cc:2670:5
    #5 0x55f0e2e28046 in testing::TestInfo::Run() third_party/googletest/src/googletest/src/gtest.cc:2849:11
    #6 0x55f0e2e29beb in testing::TestSuite::Run() third_party/googletest/src/googletest/src/gtest.cc:3008:30
    #7 0x55f0e2e3fafe in testing::internal::UnitTestImpl::RunAllTests() third_party/googletest/src/googletest/src/gtest.cc:5866:44
    #8 0x55f0e2e3e604 in testing::UnitTest::Run() third_party/googletest/src/googletest/src/gtest.cc:5440:10
    #9 0x55f0e34276d1 in RUN_ALL_TESTS third_party/googletest/src/googletest/include/gtest/gtest.h:2284:73
    #10 0x55f0e34276d1 in base::TestSuite::Run() base/test/test_suite.cc:463:16
    #11 0x55f0e342b9dc in Run base/callback.h:145:12
    #12 0x55f0e342b9dc in base::(anonymous namespace)::LaunchUnitTestsInternal(base::OnceCallback<int ()>, unsigned long, int, unsigned long, bool, base::RepeatingCallback<void ()>, base::OnceCallback<void ()>) base/test/launcher/unit_test_launcher.cc:181:38
    #13 0x55f0e342b877 in base::LaunchUnitTests(int, char**, base::OnceCallback<int ()>, unsigned long) base/test/launcher/unit_test_launcher.cc:272:10
    #14 0x55f0e2acc2cc in main mojo/core/test/run_all_unittests.cc:69:10
    #15 0x7ff7560d4082 in __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
    #16 0x55f0e2ab4169 in _start (/home/msisov/code/chromium/src/out/asan/ozone_unittests+0xb13169) (BuildId: 77bfee5b71bd92da)

It turned out that WaylandDataDragController was getting a non-backed provider
as a Wayland one wasn't set (it's set during OzonePlatformWayland initialization
in production). As a result, downcasting to WaylandExchangeDataProvider
was illegal in tests. It's unknown why tests didn't fail. Probably,
the result of the WaylandDataDragController::GetOfferedExchangeDataProvider
was never used. And the problem with downcasting was only caught with
this new bot.

Bug: 1358123
Change-Id: I4c8deb16a57b485de1fabd91fdcaab136d5da639
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3865512
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1041976}
  • Loading branch information
msisov authored and Chromium LUCI CQ committed Sep 1, 2022
1 parent 68495d3 commit f08c58a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ui/ozone/platform/wayland/test/wayland_drag_drop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ using testing::_;

namespace ui {

TestWaylandOSExchangeDataProvideFactory::
TestWaylandOSExchangeDataProvideFactory() {
SetInstance(this);
}

TestWaylandOSExchangeDataProvideFactory::
~TestWaylandOSExchangeDataProvideFactory() {
SetInstance(nullptr);
}

std::unique_ptr<OSExchangeDataProvider>
TestWaylandOSExchangeDataProvideFactory::CreateProvider() {
return std::make_unique<WaylandExchangeDataProvider>();
}

WaylandDragDropTest::WaylandDragDropTest() = default;

WaylandDragDropTest::~WaylandDragDropTest() = default;
Expand Down
13 changes: 13 additions & 0 deletions ui/ozone/platform/wayland/test/wayland_drag_drop_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h"
#include "ui/ozone/platform/wayland/test/test_data_device.h"
#include "ui/ozone/platform/wayland/test/test_data_source.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
Expand All @@ -27,6 +28,15 @@ namespace ui {

class WaylandWindow;

class TestWaylandOSExchangeDataProvideFactory
: public OSExchangeDataProviderFactoryOzone {
public:
TestWaylandOSExchangeDataProvideFactory();
~TestWaylandOSExchangeDataProvideFactory() override;

std::unique_ptr<OSExchangeDataProvider> CreateProvider() override;
};

// Base class for Wayland drag-and-drop tests. Public methods allow test code to
// emulate dnd-related events from the test compositor and can be used in both
// data and window dragging test cases.
Expand Down Expand Up @@ -100,6 +110,9 @@ class WaylandDragDropTest : public WaylandTest,
raw_ptr<wl::TestTouch> touch_;

uint32_t current_serial_;

private:
TestWaylandOSExchangeDataProvideFactory os_exchange_factory_;
};

} // namespace ui
Expand Down

0 comments on commit f08c58a

Please sign in to comment.