tile_unittest.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/query_tiles/tile.h"
  5. #include <utility>
  6. #include "base/test/task_environment.h"
  7. #include "components/query_tiles/test/test_utils.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace query_tiles {
  10. namespace {
  11. TEST(TileTest, CompareOperators) {
  12. Tile lhs, rhs;
  13. test::ResetTestEntry(&lhs);
  14. test::ResetTestEntry(&rhs);
  15. EXPECT_EQ(lhs, rhs);
  16. EXPECT_FALSE(lhs != rhs);
  17. rhs.id = "changed";
  18. EXPECT_NE(lhs, rhs);
  19. test::ResetTestEntry(&rhs);
  20. rhs.query_text = "changed";
  21. EXPECT_NE(lhs, rhs);
  22. test::ResetTestEntry(&rhs);
  23. rhs.display_text = "changed";
  24. EXPECT_NE(lhs, rhs);
  25. test::ResetTestEntry(&rhs);
  26. rhs.accessibility_text = "changed";
  27. EXPECT_NE(lhs, rhs);
  28. test::ResetTestEntry(&rhs);
  29. rhs.search_params = {"xyz=1"};
  30. EXPECT_NE(lhs, rhs);
  31. test::ResetTestEntry(&rhs);
  32. }
  33. TEST(TileTest, DeepComparison) {
  34. Tile lhs, rhs;
  35. test::ResetTestEntry(&lhs);
  36. test::ResetTestEntry(&rhs);
  37. EXPECT_TRUE(test::AreTilesIdentical(lhs, rhs));
  38. // Test image metadatas changed.
  39. rhs.image_metadatas.front().url = GURL("http://www.url-changed.com");
  40. EXPECT_FALSE(test::AreTilesIdentical(lhs, rhs));
  41. test::ResetTestEntry(&rhs);
  42. rhs.image_metadatas.pop_back();
  43. EXPECT_FALSE(test::AreTilesIdentical(lhs, rhs));
  44. test::ResetTestEntry(&rhs);
  45. rhs.image_metadatas.emplace_back(ImageMetadata());
  46. EXPECT_FALSE(test::AreTilesIdentical(lhs, rhs));
  47. test::ResetTestEntry(&rhs);
  48. std::reverse(rhs.image_metadatas.begin(), rhs.image_metadatas.end());
  49. EXPECT_TRUE(test::AreTilesIdentical(lhs, rhs));
  50. test::ResetTestEntry(&rhs);
  51. // Test children changed.
  52. rhs.sub_tiles.front()->id = "changed";
  53. EXPECT_FALSE(test::AreTilesIdentical(lhs, rhs));
  54. test::ResetTestEntry(&rhs);
  55. rhs.sub_tiles.pop_back();
  56. EXPECT_FALSE(test::AreTilesIdentical(lhs, rhs));
  57. test::ResetTestEntry(&rhs);
  58. rhs.sub_tiles.emplace_back(std::make_unique<Tile>());
  59. EXPECT_FALSE(test::AreTilesIdentical(lhs, rhs));
  60. test::ResetTestEntry(&rhs);
  61. std::reverse(rhs.sub_tiles.begin(), rhs.sub_tiles.end());
  62. EXPECT_TRUE(test::AreTilesIdentical(lhs, rhs));
  63. }
  64. TEST(TileTest, CopyOperator) {
  65. Tile lhs;
  66. test::ResetTestEntry(&lhs);
  67. Tile rhs(lhs);
  68. EXPECT_TRUE(test::AreTilesIdentical(lhs, rhs));
  69. }
  70. TEST(TileTest, AssignOperator) {
  71. Tile lhs;
  72. test::ResetTestEntry(&lhs);
  73. Tile rhs = lhs;
  74. EXPECT_TRUE(test::AreTilesIdentical(lhs, rhs));
  75. }
  76. TEST(TileTest, MoveOperator) {
  77. Tile lhs;
  78. test::ResetTestEntry(&lhs);
  79. Tile rhs = std::move(lhs);
  80. Tile expected;
  81. test::ResetTestEntry(&expected);
  82. EXPECT_TRUE(test::AreTilesIdentical(expected, rhs));
  83. }
  84. } // namespace
  85. } // namespace query_tiles