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

Side by Side Diff: cc/input/layer_selection_bound_unittest.cc

Issue 1531413002: Add support for (de)serializing LayerSelection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serialize-layer-selection-bound
Patch Set: Addressed nits from vmpstr Created 5 years 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 | « cc/input/layer_selection_bound.cc ('k') | cc/proto/layer_selection_bound.proto » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "cc/input/layer_selection_bound.h" 5 #include "cc/input/layer_selection_bound.h"
6 6
7 #include "cc/proto/layer_selection_bound.pb.h" 7 #include "cc/proto/layer_selection_bound.pb.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/geometry/point.h" 9 #include "ui/gfx/geometry/point.h"
10 10
11 namespace cc { 11 namespace cc {
12 namespace { 12 namespace {
13 13
14 void VerifySerializeAndDeserializeProto(const LayerSelectionBound& bound1) { 14 void VerifySerializeAndDeserializeProto(const LayerSelectionBound& bound1) {
15 proto::LayerSelectionBound proto; 15 proto::LayerSelectionBound proto;
16 bound1.ToProtobuf(&proto); 16 bound1.ToProtobuf(&proto);
17 LayerSelectionBound bound2; 17 LayerSelectionBound bound2;
18 bound2.FromProtobuf(proto); 18 bound2.FromProtobuf(proto);
19 EXPECT_EQ(bound1, bound2); 19 EXPECT_EQ(bound1, bound2);
20 } 20 }
21 21
22 void VerifySerializeAndDeserializeLayerSelectionProto(
23 const LayerSelection& selection1) {
24 proto::LayerSelection proto;
25 LayerSelectionToProtobuf(selection1, &proto);
26 LayerSelection selection2;
27 LayerSelectionFromProtobuf(&selection2, proto);
28 EXPECT_EQ(selection1, selection2);
29 }
30
22 TEST(LayerSelectionBoundTest, AllTypePermutations) { 31 TEST(LayerSelectionBoundTest, AllTypePermutations) {
23 LayerSelectionBound bound; 32 LayerSelectionBound bound;
24 bound.type = SelectionBoundType::SELECTION_BOUND_LEFT; 33 bound.type = SelectionBoundType::SELECTION_BOUND_LEFT;
25 bound.edge_top = gfx::Point(3, 14); 34 bound.edge_top = gfx::Point(3, 14);
26 bound.edge_bottom = gfx::Point(6, 28); 35 bound.edge_bottom = gfx::Point(6, 28);
27 bound.layer_id = 42; 36 bound.layer_id = 42;
37
28 VerifySerializeAndDeserializeProto(bound); 38 VerifySerializeAndDeserializeProto(bound);
29 bound.type = SelectionBoundType::SELECTION_BOUND_RIGHT; 39 bound.type = SelectionBoundType::SELECTION_BOUND_RIGHT;
30 VerifySerializeAndDeserializeProto(bound); 40 VerifySerializeAndDeserializeProto(bound);
31 bound.type = SelectionBoundType::SELECTION_BOUND_CENTER; 41 bound.type = SelectionBoundType::SELECTION_BOUND_CENTER;
32 VerifySerializeAndDeserializeProto(bound); 42 VerifySerializeAndDeserializeProto(bound);
33 bound.type = SelectionBoundType::SELECTION_BOUND_EMPTY; 43 bound.type = SelectionBoundType::SELECTION_BOUND_EMPTY;
34 VerifySerializeAndDeserializeProto(bound); 44 VerifySerializeAndDeserializeProto(bound);
35 } 45 }
36 46
47 TEST(LayerSelectionTest, AllSelectionPermutations) {
48 LayerSelectionBound start;
49 start.type = SelectionBoundType::SELECTION_BOUND_LEFT;
50 start.edge_top = gfx::Point(3, 14);
51 start.edge_bottom = gfx::Point(6, 28);
52 start.layer_id = 42;
53
54 LayerSelectionBound end;
55 end.type = SelectionBoundType::SELECTION_BOUND_RIGHT;
56 end.edge_top = gfx::Point(14, 3);
57 end.edge_bottom = gfx::Point(28, 6);
58 end.layer_id = 24;
59
60 LayerSelection selection;
61 selection.start = start;
62 selection.end = end;
63 selection.is_editable = true;
64 selection.is_empty_text_form_control = true;
65
66 VerifySerializeAndDeserializeLayerSelectionProto(selection);
67 selection.is_empty_text_form_control = false;
68 VerifySerializeAndDeserializeLayerSelectionProto(selection);
69 selection.is_editable = false;
70 VerifySerializeAndDeserializeLayerSelectionProto(selection);
71 selection.is_empty_text_form_control = true;
72 VerifySerializeAndDeserializeLayerSelectionProto(selection);
73 }
74
37 } // namespace 75 } // namespace
38 } // namespace cc 76 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/layer_selection_bound.cc ('k') | cc/proto/layer_selection_bound.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698