summaryrefslogtreecommitdiff
path: root/chromium/cc/proto/cc_conversions_unittest.cc
blob: 8612dda7d0995a9c3aafe762a23e82adac595640 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/proto/cc_conversions.h"

#include "cc/base/region.h"
#include "cc/proto/region.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"

namespace cc {
namespace {

void VerifySerializeAndDeserializeProto(const Region& region1) {
  proto::Region proto;
  RegionToProto(region1, &proto);
  Region region2 = RegionFromProto(proto);
  EXPECT_EQ(region1, region2);
}

TEST(RegionTest, SingleRectProtoConversion) {
  Region region(gfx::Rect(14, 15, 16, 17));
  VerifySerializeAndDeserializeProto(region);
}

TEST(RegionTest, MultipleRectProtoConversion) {
  Region region(gfx::Rect(0, 0, 1, 1));
  region.Union(gfx::Rect(9, 0, 1, 1));
  region.Union(gfx::Rect(0, 9, 1, 1));
  region.Union(gfx::Rect(9, 9, 1, 1));
  VerifySerializeAndDeserializeProto(region);
}

TEST(RegionTest, OverlappingRectIntersectProtoConversion) {
  Region region(gfx::Rect(0, 0, 10, 10));
  region.Intersect(gfx::Rect(5, 5, 10, 10));
  VerifySerializeAndDeserializeProto(region);
}

TEST(RegionTest, OverlappingRectUnionProtoConversion) {
  Region region(gfx::Rect(0, 0, 10, 10));
  region.Union(gfx::Rect(5, 5, 10, 10));
  VerifySerializeAndDeserializeProto(region);
}

TEST(RegionTest, OverlappingRectSubtractProtoConversion) {
  Region region(gfx::Rect(0, 0, 10, 10));
  region.Subtract(gfx::Rect(5, 5, 1, 1));
  VerifySerializeAndDeserializeProto(region);
}

}  // namespace
}  // namespace cc