chromium/ui/views/controls/table/table_view_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/controls/table/table_view.h"

#include <stddef.h>

#include <algorithm>
#include <string>
#include <tuple>
#include <utility>

#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/text_utils.h"
#include "ui/views/accessibility/ax_virtual_view.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/table/table_grouper.h"
#include "ui/views/controls/table/table_header.h"
#include "ui/views/controls/table/table_view_observer.h"
#include "ui/views/style/platform_style.h"
#include "ui/views/test/focus_manager_test.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/widget/unique_widget_ptr.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_utils.h"

// Put the tests in the views namespace to make it easier to declare them as
// friend classes.
namespace views {

constexpr int kGroupingIndicatorSize =;

class TableViewTestHelper {};

namespace {

// TestTableModel2 -------------------------------------------------------------

// Trivial TableModel implementation that is backed by a vector of vectors.
// Provides methods for adding/removing/changing the contents that notify the
// observer appropriately.
//
// Initial contents are:
// 0, 1
// 1, 1
// 2, 2
// 3, 0
class TestTableModel2 : public ui::TableModel {};

TestTableModel2::TestTableModel2() {}

void TestTableModel2::Clear() {}

void TestTableModel2::AddRow(size_t row, int c1_value, int c2_value) {}

void TestTableModel2::AddRows(size_t row, size_t length, int value_multiplier) {}

void TestTableModel2::RemoveRow(size_t row) {}

void TestTableModel2::RemoveRows(size_t row, size_t length) {}

void TestTableModel2::ChangeRow(size_t row, int c1_value, int c2_value) {}

void TestTableModel2::MoveRows(size_t row_from, size_t length, size_t row_to) {}

void TestTableModel2::SetTooltip(const std::u16string& tooltip) {}

size_t TestTableModel2::RowCount() {}

std::u16string TestTableModel2::GetText(size_t row, int column_id) {}

std::u16string TestTableModel2::GetTooltip(size_t row) {}

void TestTableModel2::SetObserver(ui::TableModelObserver* observer) {}

int TestTableModel2::CompareValues(size_t row1, size_t row2, int column_id) {}

// Returns the view to model mapping as a string.
std::string GetViewToModelAsString(TableView* table) {}

// Returns the model to view mapping as a string.
std::string GetModelToViewAsString(TableView* table) {}

// Formats the whole table as a string, like: "[a, b, c], [d, e, f]". Rows
// scrolled out of view are included; hidden columns are excluded.
std::string GetRowsInViewOrderAsString(TableView* table) {}

// Formats the whole accessibility views as a string.
// Like: "[a, b, c], [d, e, f]".
std::string GetRowsInVirtualViewAsString(TableView* table) {}

std::string GetHeaderRowAsString(TableView* table) {}

bool PressLeftMouseAt(views::View* target, const gfx::Point& point) {}

void ReleaseLeftMouseAt(views::View* target, const gfx::Point& point) {}

bool DragLeftMouseTo(views::View* target, const gfx::Point& point) {}

}  // namespace

// The test parameter is used to control whether or not to test the TableView
// using the default construction path.
class TableViewTest : public ViewsTestBase,
                      public ::testing::WithParamInterface<
                          std::tuple</*use_default_construction=*/bool,
                                     /*use_rtl=*/bool>> {};

INSTANTIATE_TEST_SUITE_P();

// Using one of the arrow keys (which normally change selection) with an empty
// table must leave the selection state empty.
// Regression test for https://issues.chromium.org/issues/342341277
TEST_P(TableViewTest, SelectedIndexWithNoRows) {}

// Verifies GetPaintRegion.
TEST_P(TableViewTest, GetPaintRegion) {}

TEST_P(TableViewTest, RebuildVirtualAccessibilityChildren) {}

// Verifies the bounding rect of each virtual accessibility child of the
// TableView (rows and cells) is updated appropriately as the table changes. For
// example, verifies that if a column is resized or hidden, the bounds are
// updated.
TEST_P(TableViewTest, UpdateVirtualAccessibilityChildrenBounds) {}

TEST_P(TableViewTest, UpdateVirtualAccessibilityChildrenBoundsWithResize) {}

TEST_P(TableViewTest, UpdateVirtualAccessibilityChildrenBoundsHideColumn) {}

TEST_P(TableViewTest, GetVirtualAccessibilityBodyRow) {}

TEST_P(TableViewTest, GetVirtualAccessibilityCell) {}

TEST_P(TableViewTest, ChangingCellFiresAccessibilityEvent) {}

// Verifies SetColumnVisibility().
TEST_P(TableViewTest, ColumnVisibility) {}

// Regression tests for https://crbug.com/1283805, and
// https://crbug.com/1283807.
TEST_P(TableViewTest, NoCrashesWithAllColumnsHidden) {}

// Verifies resizing a column using the mouse works.
TEST_P(TableViewTest, Resize) {}

// Verifies resizing a column works with a gesture.
TEST_P(TableViewTest, ResizeViaGesture) {}

// Verifies resizing a column works with the keyboard.
// The resize keyboard amount is 5 pixels.
TEST_P(TableViewTest, ResizeViaKeyboard) {}

// Verifies resizing a column won't reduce the column width below the width of
// the column's title text.
TEST_P(TableViewTest, ResizeHonorsMinimum) {}

// Assertions for table sorting.
TEST_P(TableViewTest, Sort) {}

// Verifies clicking on the header sorts.
TEST_P(TableViewTest, SortOnMouse) {}

// Verifies that pressing the space bar when a particular visible column is
// active will sort by that column.
TEST_P(TableViewTest, SortOnSpaceBar) {}

TEST_P(TableViewTest, ActiveCellBoundsFollowColumnSorting) {}

TEST_P(TableViewTest, Tooltip) {}

namespace {

class TableGrouperImpl : public TableGrouper {};

}  // namespace

// Assertions around grouping.
TEST_P(TableViewTest, Grouping) {}

TEST_P(TableViewTest, VirtualAccessibilitySetSelectionAll) {}

TEST_P(TableViewTest, VirtualAccessibilitySetSelectionRowsInRange) {}

TEST_P(TableViewTest, VirtualAccessibilitySelectOnRemove) {}

namespace {

class TableViewObserverImpl : public TableViewObserver {};

}  // namespace

// Assertions around changing the selection.
TEST_P(TableViewTest, Selection) {}

TEST_P(TableViewTest, SelectAll) {}

TEST_P(TableViewTest, RemoveUnselectedRows) {}

TEST_P(TableViewTest, AddingRemovingMultipleRows) {}

// 0 1 2 3:
// select 3 -> 0 1 2 [3]
// remove 3 -> 0 1 2 (none selected)
// select 1 -> 0 [1] 2
// remove 1 -> 0 1 (none selected)
// select 0 -> [0] 1
// remove 0 -> 0 (none selected)
TEST_P(TableViewTest, SelectionNoSelectOnRemove) {}

// No touch on desktop Mac. Tracked in http://crbug.com/445520.
#if !BUILDFLAG(IS_MAC)
// Verifies selection works by way of a gesture.
TEST_P(TableViewTest, SelectOnTap) {}
#endif

// Verifies up/down correctly navigate through groups.
TEST_P(TableViewTest, KeyUpDown) {}

// Verifies left/right correctly navigate through visible columns.
TEST_P(TableViewTest, KeyLeftRight) {}

// Verify table view that the left/right navigation scrolls the visible rect
// correctly.
TEST_P(TableViewTest, KeyLeftRightScrollRectToVisibleInTableView) {}

// Verify table header that the left/right navigation scrolls the visible rect
// correctly.
TEST_P(TableViewTest, KeyLeftRightScrollRectToVisibleInTableHeader) {}

// Verify that the table view visible bounds remains stable when up/down
// switching between different rows when the layout is RTL or LTR. use_rtl()
// returns true for testing the RTL layout and false for testing the LTR layout
TEST_P(TableViewTest, KeyUpDownHorizontalScrollbarStability) {}

// Verify that the table view visible boundsr remains stable when clicking on
// different rows when the layout is RTL or LTR. use_rtl() returns true for
// testing the RTL layout and false for testing the LTR layout
TEST_P(TableViewTest, ClickRowHorizontalScrollbarStability) {}

// Verifies home/end do the right thing.
TEST_P(TableViewTest, HomeEnd) {}

// Verifies multiple selection gestures work (control-click, shift-click ...).
TEST_P(TableViewTest, Multiselection) {}

// Verifies multiple selection gestures work when sorted.
TEST_P(TableViewTest, MultiselectionWithSort) {}

TEST_P(TableViewTest, MoveRowsWithMultipleSelection) {}

TEST_P(TableViewTest, MoveRowsWithMultipleSelectionAndSort) {}

// Verifies we don't crash after removing the selected row when there is
// sorting and the anchor/active index also match the selected row.
TEST_P(TableViewTest, FocusAfterRemovingAnchor) {}

// OnItemsRemoved() should ensure view-model mappings are updated in response to
// the table model change before these view-model mappings are used.
// Test for (https://crbug.com/1173373).
TEST_P(TableViewTest, RemovingSortedRowsDoesNotCauseOverflow) {}

// Ensure that the TableView's header row is keyboard accessible.
// Tests for crbug.com/1189851.
TEST_P(TableViewTest, TableHeaderRowAccessibleViewFocusable) {}

// Ensure that the TableView's header columns are keyboard accessible.
// Tests for crbug.com/1189851.
TEST_P(TableViewTest, TableHeaderColumnAccessibleViewsFocusable) {}

class TableViewFocusTest : public TableViewTest {};

INSTANTIATE_TEST_SUITE_P();

// Verifies that the active focus is cleared when the widget is destroyed.
// In MD mode, if that doesn't happen a DCHECK in View::DoRemoveChildView(...)
// will trigger due to an attempt to modify the child view list while iterating.
TEST_P(TableViewFocusTest, FocusClearedDuringWidgetDestruction) {}

class TableViewDefaultConstructabilityTest : public ViewsTestBase {};

TEST_F(TableViewDefaultConstructabilityTest, TestFunctionalWithoutModel) {}

class TestTableModel3 : public TestTableModel2 {};

// The test calculation paint icon bounds.
class TableViewPaintIconBoundsTest : public ViewsTestBase {};

TEST_F(TableViewPaintIconBoundsTest, TestPaintIconBoundsForNormally) {}

TEST_F(TableViewPaintIconBoundsTest, TestPaintIconBoundsForClipped) {}

TEST_F(TableViewPaintIconBoundsTest, TestPaintIconBoundsNotNeedDisplay) {}
}  // namespace views