diff options
author | robert.bradford <robert.bradford@intel.com> | 2015-07-31 09:28:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-31 16:29:11 +0000 |
commit | 499fc4dc61b6eced9690a92746b78f00e41300bd (patch) | |
tree | 6d662e1ef8ed5502b89545bfa303f32110f9c318 /ash | |
parent | 2b8c9d2366a7480bcd003fcd87e073b6bb89b11b (diff) | |
download | chromium_src-499fc4dc61b6eced9690a92746b78f00e41300bd.zip chromium_src-499fc4dc61b6eced9690a92746b78f00e41300bd.tar.gz chromium_src-499fc4dc61b6eced9690a92746b78f00e41300bd.tar.bz2 |
ash: Add a test to cover AssociateTouchscreens with no internal display
A segfault was happening in AssociateTouchscreens if it found an
internal touchscreen but no internal display. This change introduces a
test to check that AssociateTouchscreens() will not crash when no
internal display is present when an internal touchscreen is identified.
BUG=515201
TEST=ash_unittests crashes before bug fix, and passes after bug fix
lands.
R=oshima@chromium.org
Review URL: https://codereview.chromium.org/1268683003
Cr-Commit-Position: refs/heads/master@{#341344}
Diffstat (limited to 'ash')
-rw-r--r-- | ash/touch/touchscreen_util_unittest.cc | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/ash/touch/touchscreen_util_unittest.cc b/ash/touch/touchscreen_util_unittest.cc index e5bb0b8..d69e405 100644 --- a/ash/touch/touchscreen_util_unittest.cc +++ b/ash/touch/touchscreen_util_unittest.cc @@ -6,18 +6,21 @@ #include <vector> #include "ash/display/display_info.h" +#include "ash/test/ash_test_base.h" +#include "ash/test/display_manager_test_api.h" #include "ash/touch/touchscreen_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/events/devices/input_device.h" namespace ash { -class TouchscreenUtilTest : public testing::Test { +class TouchscreenUtilTest : public test::AshTestBase { public: TouchscreenUtilTest() {} ~TouchscreenUtilTest() override {} void SetUp() override { + test::AshTestBase::SetUp(); // Internal display will always match to internal touchscreen. If internal // touchscreen can't be detected, it is then associated to a touch screen // with matching size. @@ -28,7 +31,6 @@ class TouchscreenUtilTest : public testing::Test { std::vector<DisplayMode> modes(1, mode); display.SetDisplayModes(modes); displays_.push_back(display); - gfx::Display::SetInternalDisplayId(1); } { @@ -56,7 +58,10 @@ class TouchscreenUtilTest : public testing::Test { } } - void TearDown() override { displays_.clear(); } + void TearDown() override { + displays_.clear(); + test::AshTestBase::TearDown(); + } protected: std::vector<DisplayInfo> displays_; @@ -67,6 +72,8 @@ class TouchscreenUtilTest : public testing::Test { TEST_F(TouchscreenUtilTest, NoTouchscreens) { std::vector<ui::TouchscreenDevice> devices; + + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); for (size_t i = 0; i < displays_.size(); ++i) @@ -82,6 +89,7 @@ TEST_F(TouchscreenUtilTest, OneToOneMapping) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", gfx::Size(1024, 768), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); EXPECT_EQ(0u, displays_[0].input_devices().size()); @@ -98,6 +106,7 @@ TEST_F(TouchscreenUtilTest, MapToCorrectDisplaySize) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", gfx::Size(1024, 768), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); EXPECT_EQ(0u, displays_[0].input_devices().size()); @@ -116,6 +125,7 @@ TEST_F(TouchscreenUtilTest, MapWhenSizeDiffersByOne) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", gfx::Size(1023, 768), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); EXPECT_EQ(0u, displays_[0].input_devices().size()); @@ -135,6 +145,7 @@ TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", gfx::Size(802, 600), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); EXPECT_EQ(0u, displays_[0].input_devices().size()); @@ -154,6 +165,7 @@ TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "", gfx::Size(9999, 888), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); // Internal touchscreen is always mapped to internal display. @@ -174,6 +186,7 @@ TEST_F(TouchscreenUtilTest, MultipleInternal) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "", gfx::Size(1920, 1080), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); EXPECT_EQ(2u, displays_[0].input_devices().size()); @@ -194,6 +207,7 @@ TEST_F(TouchscreenUtilTest, MultipleInternalAndExternal) { ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", gfx::Size(1024, 768), 0)); + test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); AssociateTouchscreens(&displays_, devices); EXPECT_EQ(2u, displays_[0].input_devices().size()); @@ -202,4 +216,24 @@ TEST_F(TouchscreenUtilTest, MultipleInternalAndExternal) { EXPECT_EQ(1u, displays_[3].input_devices().size()); } +// crbug.com/515201 +TEST_F(TouchscreenUtilTest, TestWithNoInternalDisplay) { + std::vector<ui::TouchscreenDevice> devices; + devices.push_back( + ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", + gfx::Size(1920, 1080), 0)); + devices.push_back( + ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "", + gfx::Size(9999, 888), 0)); + + AssociateTouchscreens(&displays_, devices); + + EXPECT_EQ(1u, displays_[0].input_devices().size()); + EXPECT_EQ(1, displays_[0].input_devices()[0]); + EXPECT_EQ(1u, displays_[1].input_devices().size()); + EXPECT_EQ(2, displays_[1].input_devices()[0]); + EXPECT_EQ(0u, displays_[2].input_devices().size()); + EXPECT_EQ(0u, displays_[3].input_devices().size()); +} + } // namespace ash |