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
   55

ash / birch / coral_item_remover_unittest.cc [blame]

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

#include "ash/birch/coral_item_remover.h"

#include "testing/gmock/include/gmock/gmock.h"

namespace ash {

namespace {
using ::testing::ElementsAre;
using ::testing::Eq;
}  // namespace

using CoralItemRemoverTest = ::testing::Test;

TEST_F(CoralItemRemoverTest, FilterContent) {
  CoralItemRemover coral_item_remover_;
  auto item0 = coral::mojom::Entity::NewTab(
      coral::mojom::Tab::New("tab 0 title", GURL("http://tab0.com")));
  auto item1 = coral::mojom::Entity::NewTab(
      coral::mojom::Tab::New("tab 1 title", GURL("http://tab1.com")));
  auto item2 = coral::mojom::Entity::NewApp(
      coral::mojom::App::New("app 0 name", "app 0 id"));
  auto item3 = coral::mojom::Entity::NewApp(
      coral::mojom::App::New("app 1 name", "app 1 id"));
  std::vector<coral::mojom::EntityPtr> entities;
  entities.push_back(item0.Clone());
  entities.push_back(item1.Clone());
  entities.push_back(item2.Clone());
  entities.push_back(item3.Clone());

  // Filter `tab_items` before any items are removed. The list should remain
  // unchanged.
  coral_item_remover_.FilterRemovedItems(&entities);
  ASSERT_EQ(4u, entities.size());

  // Remove `item2`, and filter it from the list of tabs.
  coral_item_remover_.RemoveItem(*item2);
  coral_item_remover_.FilterRemovedItems(&entities);

  // Check that `item2` is filtered out.
  EXPECT_THAT(entities, ElementsAre(Eq(std::ref(item0)), Eq(std::ref(item1)),
                                    Eq(std::ref(item3))));

  // Remove `item1`, and filter it from the list of tabs.
  coral_item_remover_.RemoveItem(*item1);
  coral_item_remover_.FilterRemovedItems(&entities);

  // Check that `item1` is filtered out.
  EXPECT_THAT(entities, ElementsAre(Eq(std::ref(item0)), Eq(std::ref(item3))));
}

}  // namespace ash