1// Copyright 2014 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
5#include "config.h"
6#include "core/css/invalidation/DescendantInvalidationSet.h"
7
8#include <gtest/gtest.h>
9
10using namespace blink;
11
12namespace {
13
14// Once we setWholeSubtreeInvalid, we should not keep the HashSets.
15TEST(DescendantInvalidationSetTest, SubtreeInvalid_AddBefore)
16{
17    RefPtrWillBeRawPtr<DescendantInvalidationSet> set = DescendantInvalidationSet::create();
18    set->addClass("a");
19    set->setWholeSubtreeInvalid();
20
21    ASSERT_TRUE(set->isEmpty());
22}
23
24// Don't (re)create HashSets if we've already setWholeSubtreeInvalid.
25TEST(DescendantInvalidationSetTest, SubtreeInvalid_AddAfter)
26{
27    RefPtrWillBeRawPtr<DescendantInvalidationSet> set = DescendantInvalidationSet::create();
28    set->setWholeSubtreeInvalid();
29    set->addTagName("a");
30
31    ASSERT_TRUE(set->isEmpty());
32}
33
34// No need to keep the HashSets when combining with a wholeSubtreeInvalid set.
35TEST(DescendantInvalidationSetTest, SubtreeInvalid_Combine_1)
36{
37    RefPtrWillBeRawPtr<DescendantInvalidationSet> set1 = DescendantInvalidationSet::create();
38    RefPtrWillBeRawPtr<DescendantInvalidationSet> set2 = DescendantInvalidationSet::create();
39
40    set1->addId("a");
41    set2->setWholeSubtreeInvalid();
42
43    set1->combine(*set2);
44
45    ASSERT_TRUE(set1->wholeSubtreeInvalid());
46    ASSERT_TRUE(set1->isEmpty());
47}
48
49// No need to add HashSets from combining set when we already have wholeSubtreeInvalid.
50TEST(DescendantInvalidationSetTest, SubtreeInvalid_Combine_2)
51{
52    RefPtrWillBeRawPtr<DescendantInvalidationSet> set1 = DescendantInvalidationSet::create();
53    RefPtrWillBeRawPtr<DescendantInvalidationSet> set2 = DescendantInvalidationSet::create();
54
55    set1->setWholeSubtreeInvalid();
56    set2->addAttribute("a");
57
58    set1->combine(*set2);
59
60    ASSERT_TRUE(set1->wholeSubtreeInvalid());
61    ASSERT_TRUE(set1->isEmpty());
62}
63
64} // namespace
65