Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: Source/core/dom/TreeScopeStyleSheetCollectionTest.cpp

Issue 1076163002: Don't clear FontFaceCache if no @font-face were removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/dom/TreeScopeStyleSheetCollection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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/dom/TreeScopeStyleSheetCollection.h"
7
8 #include "core/css/CSSStyleSheet.h"
9 #include "core/css/StyleSheetContents.h"
10 #include "core/css/parser/CSSParserMode.h"
11 #include <gtest/gtest.h>
12
13 namespace blink {
14
15 class TreeScopeStyleSheetCollectionTest : public testing::Test {
16 protected:
17 using SheetVector = WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>>;
18 using ContentsVector = WillBeHeapVector<RawPtrWillBeMember<StyleSheetContent s>>;
19
20 enum UpdateType {
21 Reconstruct = TreeScopeStyleSheetCollection::Reconstruct,
22 Reset = TreeScopeStyleSheetCollection::Reset,
23 Additive = TreeScopeStyleSheetCollection::Additive
24 };
25
26 static PassRefPtrWillBeRawPtr<CSSStyleSheet> createSheet()
27 {
28 return CSSStyleSheet::create(StyleSheetContents::create(CSSParserContext (HTMLStandardMode, nullptr)));
29 }
30
31 static void compareStyleSheets(const SheetVector& oldStyleSheets, const Shee tVector& newStyleSheets, const ContentsVector& expAddedSheets, UpdateType testUp dateType)
32 {
33 ContentsVector addedSheets;
34 UpdateType updateType = static_cast<UpdateType>(TreeScopeStyleSheetColle ction::compareStyleSheets(oldStyleSheets, newStyleSheets, addedSheets));
35 EXPECT_EQ(testUpdateType, updateType);
36 EXPECT_EQ(expAddedSheets.size(), addedSheets.size());
37 if (expAddedSheets.size() == addedSheets.size()) {
38 for (unsigned i = 0; i < addedSheets.size(); i++)
39 EXPECT_EQ(expAddedSheets.at(i), addedSheets.at(i));
40 }
41 }
42 };
43
44 TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsAppend)
45 {
46 RefPtrWillBeRawPtr<CSSStyleSheet> sheet1 = createSheet();
47 RefPtrWillBeRawPtr<CSSStyleSheet> sheet2 = createSheet();
48
49 ContentsVector added;
50 SheetVector previous;
51 SheetVector current;
52
53 previous.append(sheet1);
54
55 current.append(sheet1);
56 current.append(sheet2);
57
58 added.append(sheet2->contents());
59
60 compareStyleSheets(previous, current, added, Additive);
61 }
62
63 TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsPrepend)
64 {
65 RefPtrWillBeRawPtr<CSSStyleSheet> sheet1 = createSheet();
66 RefPtrWillBeRawPtr<CSSStyleSheet> sheet2 = createSheet();
67
68 ContentsVector added;
69 SheetVector previous;
70 SheetVector current;
71
72 previous.append(sheet2);
73
74 current.append(sheet1);
75 current.append(sheet2);
76
77 added.append(sheet1->contents());
78
79 compareStyleSheets(previous, current, added, Reconstruct);
80 }
81
82 TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsInsert)
83 {
84 RefPtrWillBeRawPtr<CSSStyleSheet> sheet1 = createSheet();
85 RefPtrWillBeRawPtr<CSSStyleSheet> sheet2 = createSheet();
86 RefPtrWillBeRawPtr<CSSStyleSheet> sheet3 = createSheet();
87
88 ContentsVector added;
89 SheetVector previous;
90 SheetVector current;
91
92 previous.append(sheet1);
93 previous.append(sheet3);
94
95 current.append(sheet1);
96 current.append(sheet2);
97 current.append(sheet3);
98
99 added.append(sheet2->contents());
100
101 compareStyleSheets(previous, current, added, Reconstruct);
102 }
103
104 TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsRemove)
105 {
106 RefPtrWillBeRawPtr<CSSStyleSheet> sheet1 = createSheet();
107 RefPtrWillBeRawPtr<CSSStyleSheet> sheet2 = createSheet();
108 RefPtrWillBeRawPtr<CSSStyleSheet> sheet3 = createSheet();
109
110 ContentsVector added;
111 SheetVector previous;
112 SheetVector current;
113
114 previous.append(sheet1);
115 previous.append(sheet2);
116 previous.append(sheet3);
117
118 current.append(sheet1);
119 current.append(sheet3);
120
121 added.append(sheet2->contents());
122
123 // This is really the same as Insert. TreeScopeStyleSheetCollection::compare StyleSheets
124 // will assert if you pass an array that is longer as the first parameter.
125 compareStyleSheets(current, previous, added, Reconstruct);
126 }
127
128 TEST_F(TreeScopeStyleSheetCollectionTest, CompareStyleSheetsInsertRemove)
129 {
130 RefPtrWillBeRawPtr<CSSStyleSheet> sheet1 = createSheet();
131 RefPtrWillBeRawPtr<CSSStyleSheet> sheet2 = createSheet();
132 RefPtrWillBeRawPtr<CSSStyleSheet> sheet3 = createSheet();
133
134 ContentsVector added;
135 SheetVector previous;
136 SheetVector current;
137
138 previous.append(sheet1);
139 previous.append(sheet2);
140
141 current.append(sheet2);
142 current.append(sheet3);
143
144 // TODO(rune@opera.com): This is clearly wrong. We add sheet3 and remove she et1 and
145 // compareStyleSheets returns sheet2 and sheet3 as added (crbug/475858).
146 added.append(sheet2->contents());
147 added.append(sheet3->contents());
148
149 compareStyleSheets(previous, current, added, Reconstruct);
150 }
151
152 }
OLDNEW
« no previous file with comments | « Source/core/dom/TreeScopeStyleSheetCollection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698