summaryrefslogtreecommitdiff
path: root/chromium/ui/base/ime/composition_text_unittest.cc
blob: c03090a5623c9dc326ece0a1508df63006f5cdea (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
// 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 "ui/base/ime/composition_text.h"

#include <stddef.h>

#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace ui {

TEST(CompositionTextTest, CopyTest) {
  const base::string16 kSampleText = base::UTF8ToUTF16("Sample Text");
  const CompositionUnderline kSampleUnderline1(10, 20, SK_ColorBLACK, false,
                                               SK_ColorTRANSPARENT);

  const CompositionUnderline kSampleUnderline2(11, 21, SK_ColorBLACK, true,
                                               SK_ColorTRANSPARENT);

  const CompositionUnderline kSampleUnderline3(12, 22, SK_ColorRED, false,
                                               SK_ColorTRANSPARENT);

  // Make CompositionText
  CompositionText text;
  text.text = kSampleText;
  text.underlines.push_back(kSampleUnderline1);
  text.underlines.push_back(kSampleUnderline2);
  text.underlines.push_back(kSampleUnderline3);
  text.selection.set_start(30);
  text.selection.set_end(40);

  CompositionText text2;
  text2.CopyFrom(text);

  EXPECT_EQ(text.text, text2.text);
  EXPECT_EQ(text.underlines.size(), text2.underlines.size());
  for (size_t i = 0; i < text.underlines.size(); ++i) {
    EXPECT_EQ(text.underlines[i].start_offset,
              text2.underlines[i].start_offset);
    EXPECT_EQ(text.underlines[i].end_offset, text2.underlines[i].end_offset);
    EXPECT_EQ(text.underlines[i].color, text2.underlines[i].color);
    EXPECT_EQ(text.underlines[i].thick, text2.underlines[i].thick);
    EXPECT_EQ(text.underlines[i].background_color,
              text2.underlines[i].background_color);
  }

  EXPECT_EQ(text.selection.start(), text2.selection.start());
  EXPECT_EQ(text.selection.end(), text2.selection.end());
}

}  // namespace ui