summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-03 01:32:23 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-03 01:32:23 +0000
commit0f5377e0ff51f7938d0efcb1defed8aff16d7ef5 (patch)
treed452ae32ef5d7e2dff5c06b5bdeff405113d7f1d
parent356a2f6dc658f1117fe40053d61050a2664d066d (diff)
downloadchromium_src-0f5377e0ff51f7938d0efcb1defed8aff16d7ef5.zip
chromium_src-0f5377e0ff51f7938d0efcb1defed8aff16d7ef5.tar.gz
chromium_src-0f5377e0ff51f7938d0efcb1defed8aff16d7ef5.tar.bz2
x11: Cleanup how valuators are set for X events in tests.
BUG=none R=derat@chromium.org Review URL: https://codereview.chromium.org/95403006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238264 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/root_window_host_x11_unittest.cc4
-rw-r--r--ui/events/test/events_test_utils_x11.cc100
-rw-r--r--ui/events/test/events_test_utils_x11.h4
-rw-r--r--ui/events/x/device_data_manager.cc76
-rw-r--r--ui/events/x/device_data_manager.h30
-rw-r--r--ui/events/x/events_x_unittest.cc2
6 files changed, 96 insertions, 120 deletions
diff --git a/ui/aura/root_window_host_x11_unittest.cc b/ui/aura/root_window_host_x11_unittest.cc
index 871ca68..77e62fe 100644
--- a/ui/aura/root_window_host_x11_unittest.cc
+++ b/ui/aura/root_window_host_x11_unittest.cc
@@ -110,7 +110,7 @@ TEST_F(RootWindowHostX11Test, DispatchTouchEventToOneRootWindow) {
std::vector<unsigned int> devices;
devices.push_back(0);
- ui::SetupTouchDevicesForTest(devices);
+ ui::SetUpTouchDevicesForTest(devices);
std::vector<ui::Valuator> valuators;
EXPECT_EQ(ui::ET_UNKNOWN, delegate->last_touch_type());
@@ -182,7 +182,7 @@ TEST_F(RootWindowHostX11Test, DispatchTouchEventToTwoRootWindow) {
std::vector<unsigned int> devices;
devices.push_back(0);
- ui::SetupTouchDevicesForTest(devices);
+ ui::SetUpTouchDevicesForTest(devices);
std::vector<ui::Valuator> valuators;
EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type());
diff --git a/ui/events/test/events_test_utils_x11.cc b/ui/events/test/events_test_utils_x11.cc
index 9b2cc5b..e647f21 100644
--- a/ui/events/test/events_test_utils_x11.cc
+++ b/ui/events/test/events_test_utils_x11.cc
@@ -16,24 +16,6 @@
namespace {
-const int kScrollValuatorNum = 5;
-const int kScrollValuatorMap[kScrollValuatorNum][4] = {
- // { valuator_index, valuator_type, min_val, max_val }
- { 0, ui::DeviceDataManager::DT_CMT_SCROLL_X, -100, 100 },
- { 1, ui::DeviceDataManager::DT_CMT_SCROLL_Y, -100, 100 },
- { 2, ui::DeviceDataManager::DT_CMT_ORDINAL_X, -100, 100 },
- { 3, ui::DeviceDataManager::DT_CMT_ORDINAL_Y, -100, 100 },
- { 4, ui::DeviceDataManager::DT_CMT_FINGER_COUNT, 0, 3},
-};
-
-const int kTouchValuatorNum = 3;
-const int kTouchValuatorMap[kTouchValuatorNum][4] = {
- // { valuator_index, valuator_type, min_val, max_val }
- { 0, ui::DeviceDataManager::DT_TOUCH_MAJOR, 0, 1000},
- { 1, ui::DeviceDataManager::DT_TOUCH_ORIENTATION, 0, 1},
- { 2, ui::DeviceDataManager::DT_TOUCH_PRESSURE, 0, 1000},
-};
-
// Converts ui::EventType to state for X*Events.
unsigned int XEventState(int flags) {
return
@@ -104,7 +86,8 @@ unsigned int XButtonEventButton(ui::EventType type,
return 0;
}
-void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev, int valuator_count) {
+void InitValuatorsForXIDeviceEvent(XIDeviceEvent* xiev) {
+ int valuator_count = ui::DeviceDataManager::DT_LAST_ENTRY;
xiev->valuators.mask_len = (valuator_count / 8) + 1;
xiev->valuators.mask = new unsigned char[xiev->valuators.mask_len];
memset(xiev->valuators.mask, 0, xiev->valuators.mask_len);
@@ -204,18 +187,17 @@ void ScopedXI2Event::InitScrollEvent(int deviceid,
int y_offset_ordinal,
int finger_count) {
Cleanup();
- event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point()));
+ event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point()));
- int valuator_data[kScrollValuatorNum] =
- { x_offset, y_offset, x_offset_ordinal, y_offset_ordinal, finger_count};
- XIDeviceEvent* xiev =
- static_cast<XIDeviceEvent*>(event_->xcookie.data);
-
- InitValuatorsForXIDeviceEvent(xiev, kScrollValuatorNum);
- for(int i = 0; i < kScrollValuatorNum; i++) {
- XISetMask(xiev->valuators.mask, i);
- xiev->valuators.values[i] = valuator_data[i];
- }
+ Valuator valuators[] = {
+ Valuator(DeviceDataManager::DT_CMT_SCROLL_X, x_offset),
+ Valuator(DeviceDataManager::DT_CMT_SCROLL_Y, y_offset),
+ Valuator(DeviceDataManager::DT_CMT_ORDINAL_X, x_offset_ordinal),
+ Valuator(DeviceDataManager::DT_CMT_ORDINAL_Y, y_offset_ordinal),
+ Valuator(DeviceDataManager::DT_CMT_FINGER_COUNT, finger_count)
+ };
+ SetUpValuators(
+ std::vector<Valuator>(valuators, valuators + arraysize(valuators)));
}
void ScopedXI2Event::InitTouchEvent(int deviceid,
@@ -224,22 +206,8 @@ void ScopedXI2Event::InitTouchEvent(int deviceid,
const gfx::Point& location,
const std::vector<Valuator>& valuators) {
Cleanup();
- event_.reset(CreateXInput2Event(
- deviceid, evtype, tracking_id, location));
-
- XIDeviceEvent* xiev =
- static_cast<XIDeviceEvent*>(event_->xcookie.data);
- InitValuatorsForXIDeviceEvent(xiev, valuators.size());
- int val_count = 0;
- for (int i = 0; i < kTouchValuatorNum; i++) {
- for (size_t j = 0; j < valuators.size(); j++) {
- if (valuators[j].data_type == kTouchValuatorMap[i][1]) {
- XISetMask(xiev->valuators.mask, kTouchValuatorMap[i][0]);
- xiev->valuators.values[val_count++] = valuators[j].value;
- }
- }
- }
-
+ event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location));
+ SetUpValuators(valuators);
}
void ScopedXI2Event::Cleanup() {
@@ -255,39 +223,31 @@ void ScopedXI2Event::Cleanup() {
event_.reset();
}
- void SetUpScrollDeviceForTest(unsigned int deviceid) {
+void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
+ CHECK(event_.get());
+ CHECK_EQ(GenericEvent, event_->type);
+ XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(event_->xcookie.data);
+ InitValuatorsForXIDeviceEvent(xiev);
+ ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
+ for (size_t i = 0; i < valuators.size(); ++i) {
+ manager->SetValuatorDataForTest(xiev, valuators[i].data_type,
+ valuators[i].value);
+ }
+}
+
+void SetUpScrollDeviceForTest(unsigned int deviceid) {
std::vector<unsigned int> device_list;
device_list.push_back(deviceid);
TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
- manager->SetDeviceListForTest(device_list, device_list, device_list);
-
- for (int i = 0; i < kScrollValuatorNum; i++) {
- manager->SetDeviceValuatorForTest(
- deviceid,
- kScrollValuatorMap[i][0],
- static_cast<DeviceDataManager::DataType>(kScrollValuatorMap[i][1]),
- kScrollValuatorMap[i][2],
- kScrollValuatorMap[i][3]);
- }
+ manager->SetDeviceListForTest(std::vector<unsigned int>(), device_list);
}
-void SetupTouchDevicesForTest(const std::vector<unsigned int>& devices) {
- std::vector<unsigned int> empty_list;
+void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices) {
TouchFactory::GetInstance()->SetTouchDeviceForTest(devices);
ui::DeviceDataManager* manager = ui::DeviceDataManager::GetInstance();
- manager->SetDeviceListForTest(devices, empty_list, empty_list);
- for (size_t i = 0; i < devices.size(); i++) {
- for (int j = 0; j < kTouchValuatorNum; j++) {
- manager->SetDeviceValuatorForTest(
- devices[i],
- kTouchValuatorMap[j][0],
- static_cast<DeviceDataManager::DataType>(kTouchValuatorMap[j][1]),
- kTouchValuatorMap[j][2],
- kTouchValuatorMap[j][3]);
- }
- }
+ manager->SetDeviceListForTest(devices, std::vector<unsigned int>());
}
} // namespace ui
diff --git a/ui/events/test/events_test_utils_x11.h b/ui/events/test/events_test_utils_x11.h
index 4faa8f4..2525f9a 100644
--- a/ui/events/test/events_test_utils_x11.h
+++ b/ui/events/test/events_test_utils_x11.h
@@ -60,6 +60,8 @@ class ScopedXI2Event {
private:
void Cleanup();
+ void SetUpValuators(const std::vector<Valuator>& valuators);
+
scoped_ptr<XEvent> event_;
DISALLOW_COPY_AND_ASSIGN(ScopedXI2Event);
@@ -69,7 +71,7 @@ class ScopedXI2Event {
void SetUpScrollDeviceForTest(unsigned int deviceid);
// Initializes a list of touchscreen devices for touch events.
-void SetupTouchDevicesForTest(const std::vector<unsigned int>& devices);
+void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices);
} // namespace ui
diff --git a/ui/events/x/device_data_manager.cc b/ui/events/x/device_data_manager.cc
index 12dfb0c..e3e91de 100644
--- a/ui/events/x/device_data_manager.cc
+++ b/ui/events/x/device_data_manager.cc
@@ -582,9 +582,8 @@ bool DeviceDataManager::GetDataRange(unsigned int deviceid,
}
void DeviceDataManager::SetDeviceListForTest(
- const std::vector<unsigned int>& devices,
- const std::vector<unsigned int>& cmt_devices,
- const std::vector<unsigned int>& touchpads) {
+ const std::vector<unsigned int>& touchscreen,
+ const std::vector<unsigned int>& cmt_devices) {
for (int i = 0; i < kMaxDeviceNum; ++i) {
valuator_count_[i] = 0;
valuator_lookup_[i].clear();
@@ -595,44 +594,59 @@ void DeviceDataManager::SetDeviceListForTest(
last_seen_valuator_[i][j].clear();
}
- for (size_t i = 0; i < devices.size(); i++) {
- unsigned int deviceid = devices[i];
- valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
- data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY);
- valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
- valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
- for (int j = 0; j < kMaxSlotNum; j++)
- last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
+ for (size_t i = 0; i < touchscreen.size(); i++) {
+ unsigned int deviceid = touchscreen[i];
+ InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd,
+ 0, 1000);
}
cmt_devices_.reset();
for (size_t i = 0; i < cmt_devices.size(); ++i) {
- unsigned int deviceid = devices[i];
+ unsigned int deviceid = cmt_devices[i];
cmt_devices_[deviceid] = true;
+ touchpads_[deviceid] = true;
+ InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd,
+ -1000, 1000);
}
+}
- touchpads_.reset();
- for (size_t i = 0; i < touchpads.size(); ++i) {
- unsigned int deviceid = devices[i];
- touchpads_[deviceid] = true;
+void DeviceDataManager::SetValuatorDataForTest(XIDeviceEvent* xievent,
+ DataType type,
+ double value) {
+ int index = valuator_lookup_[xievent->deviceid][type];
+ CHECK(!XIMaskIsSet(xievent->valuators.mask, index));
+ CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]);
+ XISetMask(xievent->valuators.mask, index);
+
+ double* valuators = xievent->valuators.values;
+ for (int i = 0; i < index; ++i) {
+ if (XIMaskIsSet(xievent->valuators.mask, i))
+ valuators++;
}
+ for (int i = valuators - xievent->valuators.values;
+ i < DT_LAST_ENTRY - 1; ++i)
+ xievent->valuators.values[i + 1] = xievent->valuators.values[i];
+ *valuators = value;
}
-void DeviceDataManager::SetDeviceValuatorForTest(int deviceid,
- int val_index,
- DataType data_type,
- double min,
- double max) {
- valuator_lookup_[deviceid][data_type] = val_index;
- data_type_lookup_[deviceid][val_index] = data_type;
- valuator_min_[deviceid][data_type] = min;
- valuator_max_[deviceid][data_type] = max;
-
- // Recalulate the number of valuators for the device.
- valuator_count_[deviceid] = 0;
- for (size_t i = 0; i < DT_LAST_ENTRY; ++i) {
- if (valuator_lookup_[deviceid][i] != -1)
- valuator_count_[deviceid]++;
+void DeviceDataManager::InitializeValuatorsForTest(int deviceid,
+ int start_valuator,
+ int end_valuator,
+ double min_value,
+ double max_value) {
+ valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
+ data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY);
+ valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
+ valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
+ for (int j = 0; j < kMaxSlotNum; j++)
+ last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
+ for (int j = start_valuator; j <= end_valuator; ++j) {
+ valuator_lookup_[deviceid][j] = valuator_count_[deviceid];
+ data_type_lookup_[deviceid][valuator_count_[deviceid]] = j;
+ valuator_min_[deviceid][j] = min_value;
+ valuator_max_[deviceid][j] = max_value;
+ valuator_count_[deviceid]++;
}
}
+
} // namespace ui
diff --git a/ui/events/x/device_data_manager.h b/ui/events/x/device_data_manager.h
index 62a95f8..aff0649 100644
--- a/ui/events/x/device_data_manager.h
+++ b/ui/events/x/device_data_manager.h
@@ -215,23 +215,17 @@ class EVENTS_BASE_EXPORT DeviceDataManager {
double* min,
double* max);
- // Setups relevant valuator informations for device ids in the list |devices|.
+ // Sets up relevant valuator informations for device ids in the device lists.
// This function is only for test purpose. It does not query the X server for
// the actual device info, but rather inits the relevant valuator structures
- // to have safe default values for testing. |cmt_devices| and |touchpads|
- // should only contain device ids in |devices|.
- void SetDeviceListForTest(const std::vector<unsigned int>& devices,
- const std::vector<unsigned int>& cmt_devices,
- const std::vector<unsigned int>& touchpads);
-
- // Setups device with |deviceid| to have valuator with type |data_type|,
- // at index |val_index|, and with |min|/|max| values. This is only for test
- // purpose.
- void SetDeviceValuatorForTest(int deviceid,
- int val_index,
- DataType data_type,
- double min,
- double max);
+ // to have safe default values for testing.
+ void SetDeviceListForTest(const std::vector<unsigned int>& touchscreen,
+ const std::vector<unsigned int>& cmt_devices);
+
+ void SetValuatorDataForTest(XIDeviceEvent* xievent,
+ DataType type,
+ double value);
+
private:
// Requirement for Singleton.
friend struct DefaultSingletonTraits<DeviceDataManager>;
@@ -245,6 +239,12 @@ class EVENTS_BASE_EXPORT DeviceDataManager {
// Check if an XI event contains data of the specified type.
bool HasEventData(const XIDeviceEvent* xiev, const DataType type) const;
+ void InitializeValuatorsForTest(int deviceid,
+ int start_valuator,
+ int end_valuator,
+ double min_value,
+ double max_value);
+
static const int kMaxDeviceNum = 128;
static const int kMaxXIEventType = XI_LASTEVENT + 1;
static const int kMaxSlotNum = 10;
diff --git a/ui/events/x/events_x_unittest.cc b/ui/events/x/events_x_unittest.cc
index 643454b..b6c7f38 100644
--- a/ui/events/x/events_x_unittest.cc
+++ b/ui/events/x/events_x_unittest.cc
@@ -175,7 +175,7 @@ TEST(EventsXTest, ClickCount) {
TEST(EventsXTest, TouchEventBasic) {
std::vector<unsigned int> devices;
devices.push_back(0);
- ui::SetupTouchDevicesForTest(devices);
+ ui::SetUpTouchDevicesForTest(devices);
std::vector<Valuator> valuators;
// Init touch begin with tracking id 5, touch id 0.