OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/custom/CustomElementUpgradeSorter.h" | 5 #include "core/dom/custom/CustomElementUpgradeSorter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/StringOrDictionary.h" | 9 #include "bindings/core/v8/StringOrDictionary.h" |
10 #include "bindings/core/v8/V8BindingForCore.h" | 10 #include "bindings/core/v8/V8BindingForCore.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 class CustomElementUpgradeSorterTest : public ::testing::Test { | 24 class CustomElementUpgradeSorterTest : public ::testing::Test { |
25 protected: | 25 protected: |
26 void SetUp() override { page_ = DummyPageHolder::Create(IntSize(1, 1)); } | 26 void SetUp() override { page_ = DummyPageHolder::Create(IntSize(1, 1)); } |
27 | 27 |
28 void TearDown() override { page_ = nullptr; } | 28 void TearDown() override { page_ = nullptr; } |
29 | 29 |
30 Element* CreateElementWithId(const char* local_name, const char* id) { | 30 Element* CreateElementWithId(const char* local_name, const char* id) { |
31 NonThrowableExceptionState no_exceptions; | 31 NonThrowableExceptionState no_exceptions; |
32 Element* element = GetDocument()->createElement( | 32 Element* element = GetDocument()->createElement( |
33 local_name, StringOrDictionary(), no_exceptions); | 33 nullptr, local_name, StringOrDictionary(), no_exceptions); |
34 element->setAttribute(HTMLNames::idAttr, id); | 34 element->setAttribute(HTMLNames::idAttr, id); |
35 return element; | 35 return element; |
36 } | 36 } |
37 | 37 |
38 Document* GetDocument() { return &page_->GetDocument(); } | 38 Document* GetDocument() { return &page_->GetDocument(); } |
39 | 39 |
40 ScriptState* GetScriptState() { | 40 ScriptState* GetScriptState() { |
41 return ToScriptStateForMainWorld(&page_->GetFrame()); | 41 return ToScriptStateForMainWorld(&page_->GetFrame()); |
42 } | 42 } |
43 | 43 |
44 ShadowRoot* AttachShadowTo(Element* element) { | 44 ShadowRoot* AttachShadowTo(Element* element) { |
45 NonThrowableExceptionState no_exceptions; | 45 NonThrowableExceptionState no_exceptions; |
46 ShadowRootInit shadow_root_init; | 46 ShadowRootInit shadow_root_init; |
47 shadow_root_init.setMode("open"); | 47 shadow_root_init.setMode("open"); |
48 return element->attachShadow(GetScriptState(), shadow_root_init, | 48 return element->attachShadow(GetScriptState(), shadow_root_init, |
49 no_exceptions); | 49 no_exceptions); |
50 } | 50 } |
51 | 51 |
52 private: | 52 private: |
53 std::unique_ptr<DummyPageHolder> page_; | 53 std::unique_ptr<DummyPageHolder> page_; |
54 }; | 54 }; |
55 | 55 |
56 TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) { | 56 TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) { |
57 NonThrowableExceptionState no_exceptions; | 57 NonThrowableExceptionState no_exceptions; |
58 Element* element = | 58 Element* element = GetDocument()->createElement( |
59 GetDocument()->createElement("a-a", StringOrDictionary(), no_exceptions); | 59 nullptr, "a-a", StringOrDictionary(), no_exceptions); |
60 | 60 |
61 Document* other_document = HTMLDocument::Create(); | 61 Document* other_document = HTMLDocument::Create(); |
62 other_document->AppendChild(element); | 62 other_document->AppendChild(element); |
63 EXPECT_EQ(other_document, element->ownerDocument()) | 63 EXPECT_EQ(other_document, element->ownerDocument()) |
64 << "sanity: another document should have adopted an element on append"; | 64 << "sanity: another document should have adopted an element on append"; |
65 | 65 |
66 CustomElementUpgradeSorter sorter; | 66 CustomElementUpgradeSorter sorter; |
67 sorter.Add(element); | 67 sorter.Add(element); |
68 | 68 |
69 HeapVector<Member<Element>> elements; | 69 HeapVector<Member<Element>> elements; |
70 sorter.Sorted(&elements, GetDocument()); | 70 sorter.Sorted(&elements, GetDocument()); |
71 EXPECT_EQ(0u, elements.size()) | 71 EXPECT_EQ(0u, elements.size()) |
72 << "the adopted-away candidate should not have been included"; | 72 << "the adopted-away candidate should not have been included"; |
73 } | 73 } |
74 | 74 |
75 TEST_F(CustomElementUpgradeSorterTest, oneCandidate) { | 75 TEST_F(CustomElementUpgradeSorterTest, oneCandidate) { |
76 NonThrowableExceptionState no_exceptions; | 76 NonThrowableExceptionState no_exceptions; |
77 Element* element = | 77 Element* element = GetDocument()->createElement( |
78 GetDocument()->createElement("a-a", StringOrDictionary(), no_exceptions); | 78 nullptr, "a-a", StringOrDictionary(), no_exceptions); |
79 GetDocument()->documentElement()->AppendChild(element); | 79 GetDocument()->documentElement()->AppendChild(element); |
80 | 80 |
81 CustomElementUpgradeSorter sorter; | 81 CustomElementUpgradeSorter sorter; |
82 sorter.Add(element); | 82 sorter.Add(element); |
83 | 83 |
84 HeapVector<Member<Element>> elements; | 84 HeapVector<Member<Element>> elements; |
85 sorter.Sorted(&elements, GetDocument()); | 85 sorter.Sorted(&elements, GetDocument()); |
86 EXPECT_EQ(1u, elements.size()) | 86 EXPECT_EQ(1u, elements.size()) |
87 << "exactly one candidate should be in the result set"; | 87 << "exactly one candidate should be in the result set"; |
88 EXPECT_TRUE(elements.Contains(element)) | 88 EXPECT_TRUE(elements.Contains(element)) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 sort.Sorted(&elements, GetDocument()); | 207 sort.Sorted(&elements, GetDocument()); |
208 EXPECT_EQ(3u, elements.size()); | 208 EXPECT_EQ(3u, elements.size()); |
209 EXPECT_EQ(a, elements[0].Get()); | 209 EXPECT_EQ(a, elements[0].Get()); |
210 EXPECT_EQ(c, elements[1].Get()); | 210 EXPECT_EQ(c, elements[1].Get()); |
211 EXPECT_EQ(d, elements[2].Get()); | 211 EXPECT_EQ(d, elements[2].Get()); |
212 } | 212 } |
213 | 213 |
214 // TODO(kochi): Add test cases which uses HTML imports. | 214 // TODO(kochi): Add test cases which uses HTML imports. |
215 | 215 |
216 } // namespace blink | 216 } // namespace blink |
OLD | NEW |