| Index: ui/gfx/break_list_unittest.cc
|
| diff --git a/ui/gfx/break_list_unittest.cc b/ui/gfx/break_list_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..da67eae76a38af139dc190d95af1cb82097eed07
|
| --- /dev/null
|
| +++ b/ui/gfx/break_list_unittest.cc
|
| @@ -0,0 +1,128 @@
|
| +// Copyright (c) 2012 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/gfx/break_list.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/skia/include/core/SkColor.h"
|
| +#include "ui/base/range/range.h"
|
| +
|
| +namespace gfx {
|
| +
|
| +class BreakListTest : public testing::Test {};
|
| +
|
| +TEST_F(BreakListTest, SetValue) {
|
| + // Check the default values applied to new instances and adjusted text.
|
| + BreakList<bool> style_breaks(false);
|
| + EXPECT_TRUE(style_breaks.EqualsValueForTesting(false));
|
| + style_breaks.SetValue(true);
|
| + EXPECT_TRUE(style_breaks.EqualsValueForTesting(true));
|
| +
|
| + BreakList<SkColor> color_breaks(SK_ColorRED);
|
| + EXPECT_TRUE(color_breaks.EqualsValueForTesting(SK_ColorRED));
|
| + color_breaks.SetValue(SK_ColorBLACK);
|
| + EXPECT_TRUE(color_breaks.EqualsValueForTesting(SK_ColorBLACK));
|
| +}
|
| +
|
| +TEST_F(BreakListTest, ApplyValue) {
|
| + BreakList<bool> breaks(false);
|
| +
|
| + // Ensure ApplyValue is a no-op on invalid and empty ranges.
|
| + breaks.ApplyValue(true, ui::Range::InvalidRange());
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(false));
|
| + for (size_t i = 0; i < 3; ++i) {
|
| + breaks.ApplyValue(true, ui::Range(i, i));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(false));
|
| + }
|
| +
|
| + // Apply a value to a valid range, check breaks; repeating should be no-op.
|
| + std::vector<std::pair<size_t, bool> > expected;
|
| + expected.push_back(std::pair<size_t, bool>(0, false));
|
| + expected.push_back(std::pair<size_t, bool>(2, true));
|
| + expected.push_back(std::pair<size_t, bool>(3, false));
|
| + for (size_t i = 0; i < 2; ++i) {
|
| + breaks.ApplyValue(true, ui::Range(2, 3));
|
| + EXPECT_TRUE(breaks.EqualsForTesting(expected));
|
| + }
|
| +
|
| + // Ensure setting a value overrides the ranged value.
|
| + breaks.SetValue(true);
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(true));
|
| +
|
| + // Ensure applying a value over [0, INT_MAX) is the same as setting a value.
|
| + breaks.ApplyValue(false, ui::Range(0, INT_MAX));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(false));
|
| +
|
| + // Ensure applying a value that is already applied has no effect.
|
| + breaks.ApplyValue(false, ui::Range(0, 2));
|
| + breaks.ApplyValue(false, ui::Range(3, 6));
|
| + breaks.ApplyValue(false, ui::Range(7, INT_MAX));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(false));
|
| +
|
| + // Ensure applying an identical neighboring value merges the ranges.
|
| + breaks.ApplyValue(true, ui::Range(0, 3));
|
| + breaks.ApplyValue(true, ui::Range(3, 6));
|
| + breaks.ApplyValue(true, ui::Range(6, INT_MAX));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(true));
|
| +
|
| + // Ensure applying a value with the same range overrides the ranged value.
|
| + breaks.ApplyValue(false, ui::Range(2, 3));
|
| + breaks.ApplyValue(true, ui::Range(2, 3));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(true));
|
| +
|
| + // Ensure applying a value with a containing range overrides contained values.
|
| + breaks.ApplyValue(false, ui::Range(0, 1));
|
| + breaks.ApplyValue(false, ui::Range(2, 3));
|
| + breaks.ApplyValue(true, ui::Range(0, 3));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(true));
|
| + breaks.ApplyValue(false, ui::Range(4, 5));
|
| + breaks.ApplyValue(false, ui::Range(6, 7));
|
| + breaks.ApplyValue(false, ui::Range(8, 9));
|
| + breaks.ApplyValue(true, ui::Range(4, 9));
|
| + EXPECT_TRUE(breaks.EqualsValueForTesting(true));
|
| +
|
| + // Ensure applying various overlapping values yields the intended results.
|
| + breaks.ApplyValue(false, ui::Range(1, 4));
|
| + breaks.ApplyValue(false, ui::Range(5, 8));
|
| + breaks.ApplyValue(true, ui::Range(0, 2));
|
| + breaks.ApplyValue(true, ui::Range(3, 6));
|
| + breaks.ApplyValue(true, ui::Range(7, INT_MAX));
|
| + std::vector<std::pair<size_t, bool> > overlap;
|
| + overlap.push_back(std::pair<size_t, bool>(0, true));
|
| + overlap.push_back(std::pair<size_t, bool>(2, false));
|
| + overlap.push_back(std::pair<size_t, bool>(3, true));
|
| + overlap.push_back(std::pair<size_t, bool>(6, false));
|
| + overlap.push_back(std::pair<size_t, bool>(7, true));
|
| + EXPECT_TRUE(breaks.EqualsForTesting(overlap));
|
| +}
|
| +
|
| +TEST_F(BreakListTest, TrimBreaks) {
|
| + // Ensure values adjust to accommodate length changes.
|
| + BreakList<bool> breaks(false);
|
| + breaks.ApplyValue(true, ui::Range(0, 2));
|
| + breaks.ApplyValue(true, ui::Range(3, 6));
|
| + breaks.ApplyValue(true, ui::Range(7, INT_MAX));
|
| +
|
| + std::vector<std::pair<size_t, bool> > expected;
|
| + expected.push_back(std::pair<size_t, bool>(0, true));
|
| + expected.push_back(std::pair<size_t, bool>(2, false));
|
| + expected.push_back(std::pair<size_t, bool>(3, true));
|
| + expected.push_back(std::pair<size_t, bool>(6, false));
|
| + expected.push_back(std::pair<size_t, bool>(7, true));
|
| + EXPECT_TRUE(breaks.EqualsForTesting(expected));
|
| +
|
| + // Trimming to a smaller length should remove the corresponding breaks.
|
| + breaks.TrimBreaks(7);
|
| + expected.resize(4);
|
| + EXPECT_TRUE(breaks.EqualsForTesting(expected));
|
| + breaks.TrimBreaks(4);
|
| + expected.resize(3);
|
| + EXPECT_TRUE(breaks.EqualsForTesting(expected));
|
| +
|
| + // Trimming to a longer length should not change any breaks.
|
| + breaks.TrimBreaks(99);
|
| + EXPECT_TRUE(breaks.EqualsForTesting(expected));
|
| +}
|
| +
|
| +} // namespace gfx
|
|
|