Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1331)

Unified Diff: ui/aura/root_window_unittest.cc

Issue 23202016: Addressing sadruls comments from the previous CL https://codereview.chromium.org/22865036/ which was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/root_window_unittest.cc
===================================================================
--- ui/aura/root_window_unittest.cc (revision 219190)
+++ ui/aura/root_window_unittest.cc (working copy)
@@ -7,13 +7,16 @@
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/event_client.h"
+#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_cursor_client.h"
#include "ui/aura/test/test_event_handler.h"
+#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window_tracker.h"
@@ -908,4 +911,139 @@
filter->events().clear();
}
+// This class inherits from the EventFilterRecorder class which provides a
+// facility to record events. This class additionally provides a facility to
+// repost the ET_GESTURE_TAP_DOWN gesture to the target window and records
+// events after that.
+class RepostGestureEventRecorder : public EventFilterRecorder {
+ public:
+ explicit RepostGestureEventRecorder(aura::Window* repost_target)
+ : repost_target_(repost_target),
+ reposted_(false) {}
+
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+ if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
+ if (!reposted_) {
+ EXPECT_NE(repost_target_, event->target());
+ reposted_ = true;
+ repost_target_->GetRootWindow()->RepostEvent(*event);
+ return;
+ }
+ }
+ EventFilterRecorder::OnGestureEvent(event);
+ }
+
+ private:
+ aura::Window* repost_target_;
+ // set to true if we reposted the ET_GESTURE_TAP_DOWN event.
+ bool reposted_;
+ DISALLOW_COPY_AND_ASSIGN(RepostGestureEventRecorder);
+};
+
+// Dummy screen position client implementation for the gesture repost test.
+// We need two root windows for the repost to succeed. The AURA code assumes
+// the existence of a screen position client if the source and target windows
+// are in different root window hierarchies.
+class RepostGestureDummyScreenPositionClient :
+ public aura::client::ScreenPositionClient {
+ public:
+ virtual void ConvertPointToScreen(const Window* window,
+ gfx::Point* point) OVERRIDE {
+ }
+
+ virtual void ConvertPointFromScreen(const Window* window,
+ gfx::Point* point) OVERRIDE {
+ }
+
+ virtual void ConvertHostPointToScreen(aura::RootWindow* root_window,
+ gfx::Point* point) OVERRIDE {
+ }
+
+ virtual void SetBounds(Window* window,
+ const gfx::Rect& bounds,
+ const gfx::Display& display) {
+ }
+};
+
+// Tests whether events which are generated after the reposted gesture event
+// are received after that. In this case the scroll sequence events should
+// be received after the reposted gesture event.
+TEST_F(RootWindowTest, GestureRepostEventOrder) {
+ // We create two windows in different root window hierarchies. The
sadrul 2013/08/26 17:07:18 Can you explain why it is necessary to create two
ananta 2013/08/26 19:19:03 As per our discussion, changed the test to only us
+ // window (repost_window) is the one to which the initial tap gesture is
+ // sent. It reposts this event to the second window (window2) below. We then
+ // generate the scroll sequence for window 2 and validate the event list at
+ // the end.
+ test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> repost_window(CreateTestWindowWithDelegate(
+ &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window()));
+
+ scoped_ptr<TestScreen> test_screen;
+ test_screen.reset(TestScreen::Create());
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
+ scoped_ptr<aura::RootWindow> root_window2;
+ root_window2.reset(test_screen->CreateRootWindowForPrimaryDisplay());
+
+ aura::Window* window2 = CreateTestWindowWithDelegate(
+ &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window2.get());
+
+ RepostGestureEventRecorder* event_recorder =
+ new RepostGestureEventRecorder(window2);
+ root_window()->SetEventFilter(event_recorder); // passes ownership
+
+ EventFilterRecorder* root_window2_filter = new EventFilterRecorder;
+ root_window2->SetEventFilter(root_window2_filter); // passes ownership
+
+ // Dummy screen position client. Needed to avoid a crash
+ scoped_ptr<RepostGestureDummyScreenPositionClient> screen_pos_client1;
+ screen_pos_client1.reset(new RepostGestureDummyScreenPositionClient);
+ scoped_ptr<RepostGestureDummyScreenPositionClient> screen_pos_client2;
+ screen_pos_client2.reset(new RepostGestureDummyScreenPositionClient);
+
+ aura::client::SetScreenPositionClient(root_window(),
+ screen_pos_client1.get());
+ aura::client::SetScreenPositionClient(root_window2.get(),
+ screen_pos_client2.get());
+
+ // Dummy capture client. Needed to avoid a crash
+ scoped_ptr<aura::client::DefaultCaptureClient> capture_client2;
+ capture_client2.reset(new aura::client::DefaultCaptureClient(
+ root_window2.get()));
+
+ // Generate a tap down gesture for the source window. This will be reposted
+ // to window 2.
+ test::EventGenerator repost_generator(root_window(), repost_window.get());
+ repost_generator.GestureTapAt(gfx::Point(40, 40));
+ RunAllPendingInMessageLoop();
+
+ test::EventGenerator scroll_generator(root_window2.get(), window2);
+ scroll_generator.GestureScrollSequence(
+ gfx::Point(80, 80),
+ gfx::Point(100, 100),
+ base::TimeDelta::FromMilliseconds(100),
+ 3);
+ RunAllPendingInMessageLoop();
+
+ std::string event_string = EventTypesToString(root_window2_filter->events());
+ DLOG(INFO) << "Event types: " << event_string;
+
+ int tap_down_count = 0;
+ for (size_t i = 0; i < root_window2_filter->events().size(); ++i) {
+ if (root_window2_filter->events()[i] == ui::ET_GESTURE_TAP_DOWN)
+ ++tap_down_count;
+ }
+
+ aura::client::SetScreenPositionClient(root_window(), NULL);
+ aura::client::SetScreenPositionClient(root_window2.get(), NULL);
+
+ capture_client2.reset(NULL);
+ root_window2.reset(NULL);
+ screen_pos_client1.reset();
+ screen_pos_client2.reset(NULL);
+
+ // We expect two tap down events. One from the repost and the other one from
+ // the scroll sequence posted above.
+ EXPECT_EQ(tap_down_count, 2);
+}
+
} // namespace aura
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698