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

Side by Side Diff: ui/aura/window_tree_host_unittest.cc

Issue 2916673002: Don't rewrite events twice. (Closed)
Patch Set: Don't depend on MockInputMethod. Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « ui/aura/window_tree_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/test/aura_test_base.h" 5 #include "ui/aura/test/aura_test_base.h"
6 #include "ui/aura/test/test_screen.h" 6 #include "ui/aura/test/test_screen.h"
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/base/ime/input_method.h"
8 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/events/event_rewriter.h"
11
12 namespace {
13
14 // Counts number of events observed.
15 class CounterEventRewriter : public ui::EventRewriter {
16 public:
17 CounterEventRewriter() : events_seen_(0) {}
18 ~CounterEventRewriter() override {}
19
20 int events_seen() const { return events_seen_; }
21
22 private:
23 // ui::EventRewriter:
24 ui::EventRewriteStatus RewriteEvent(
25 const ui::Event& event,
26 std::unique_ptr<ui::Event>* new_event) override {
27 events_seen_++;
28 return ui::EVENT_REWRITE_CONTINUE;
29 }
30
31 ui::EventRewriteStatus NextDispatchEvent(
32 const ui::Event& last_event,
33 std::unique_ptr<ui::Event>* new_event) override {
34 return ui::EVENT_REWRITE_CONTINUE;
35 }
36
37 int events_seen_;
38
39 DISALLOW_COPY_AND_ASSIGN(CounterEventRewriter);
40 };
41
42 } // namespace
9 43
10 namespace aura { 44 namespace aura {
11 45
12 using WindowTreeHostTest = test::AuraTestBase; 46 using WindowTreeHostTest = test::AuraTestBase;
13 47
14 TEST_F(WindowTreeHostTest, DPIWindowSize) { 48 TEST_F(WindowTreeHostTest, DPIWindowSize) {
15 gfx::Rect starting_bounds(0, 0, 800, 600); 49 gfx::Rect starting_bounds(0, 0, 800, 600);
16 EXPECT_EQ(starting_bounds.size(), host()->compositor()->size()); 50 EXPECT_EQ(starting_bounds.size(), host()->compositor()->size());
17 EXPECT_EQ(starting_bounds, host()->GetBoundsInPixels()); 51 EXPECT_EQ(starting_bounds, host()->GetBoundsInPixels());
18 EXPECT_EQ(starting_bounds, root_window()->bounds()); 52 EXPECT_EQ(starting_bounds, root_window()->bounds());
(...skipping 13 matching lines...) Expand all
32 host()->SetOutputSurfacePaddingInPixels(padding); 66 host()->SetOutputSurfacePaddingInPixels(padding);
33 gfx::Rect padded_rect = starting_bounds; 67 gfx::Rect padded_rect = starting_bounds;
34 padded_rect.Inset(-padding); 68 padded_rect.Inset(-padding);
35 EXPECT_EQ(padded_rect.size(), host()->compositor()->size()); 69 EXPECT_EQ(padded_rect.size(), host()->compositor()->size());
36 EXPECT_EQ(starting_bounds, host()->GetBoundsInPixels()); 70 EXPECT_EQ(starting_bounds, host()->GetBoundsInPixels());
37 EXPECT_EQ(gfx::Rect(1, 1, 534, 401), root_window()->bounds()); 71 EXPECT_EQ(gfx::Rect(1, 1, 534, 401), root_window()->bounds());
38 EXPECT_EQ(gfx::Vector2dF(0, 0), 72 EXPECT_EQ(gfx::Vector2dF(0, 0),
39 host()->compositor()->root_layer()->subpixel_position_offset()); 73 host()->compositor()->root_layer()->subpixel_position_offset());
40 } 74 }
41 75
76 TEST_F(WindowTreeHostTest, NoRewritesPostIME) {
77 CounterEventRewriter event_rewriter;
78 host()->AddEventRewriter(&event_rewriter);
79
80 ui::KeyEvent key_event('A', ui::VKEY_A, 0);
81 host()->GetInputMethod()->DispatchKeyEvent(&key_event);
82 EXPECT_EQ(0, event_rewriter.events_seen());
sadrul 2017/06/02 20:04:39 Can you do SendEventToSink() on the WTH, and verif
83
84 host()->RemoveEventRewriter(&event_rewriter);
85 }
86
42 } // namespace aura 87 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_tree_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698