| 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/CustomElementsRegistry.h" | 5 #include "core/dom/custom/CustomElementsRegistry.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 visitor->trace(m_element); | 283 visitor->trace(m_element); |
| 284 } | 284 } |
| 285 | 285 |
| 286 // TODO(dominicc): Make this class collect a vector of what's | 286 // TODO(dominicc): Make this class collect a vector of what's |
| 287 // upgraded; it will be useful in more tests. | 287 // upgraded; it will be useful in more tests. |
| 288 Member<Element> m_element; | 288 Member<Element> m_element; |
| 289 enum MethodType { | 289 enum MethodType { |
| 290 Constructor, | 290 Constructor, |
| 291 ConnectedCallback, | 291 ConnectedCallback, |
| 292 DisconnectedCallback, | 292 DisconnectedCallback, |
| 293 AdoptedCallback, |
| 293 AttributeChangedCallback, | 294 AttributeChangedCallback, |
| 294 }; | 295 }; |
| 295 Vector<MethodType> m_logs; | 296 Vector<MethodType> m_logs; |
| 296 | 297 |
| 297 struct AttributeChanged { | 298 struct AttributeChanged { |
| 298 QualifiedName name; | 299 QualifiedName name; |
| 299 AtomicString oldValue; | 300 AtomicString oldValue; |
| 300 AtomicString newValue; | 301 AtomicString newValue; |
| 301 }; | 302 }; |
| 302 Vector<AttributeChanged> m_attributeChanged; | 303 Vector<AttributeChanged> m_attributeChanged; |
| 303 | 304 |
| 304 void clear() | 305 void clear() |
| 305 { | 306 { |
| 306 m_logs.clear(); | 307 m_logs.clear(); |
| 307 m_attributeChanged.clear(); | 308 m_attributeChanged.clear(); |
| 308 } | 309 } |
| 309 | 310 |
| 310 bool runConstructor(Element* element) override | 311 bool runConstructor(Element* element) override |
| 311 { | 312 { |
| 312 m_logs.append(Constructor); | 313 m_logs.append(Constructor); |
| 313 m_element = element; | 314 m_element = element; |
| 314 return TestCustomElementDefinition::runConstructor(element); | 315 return TestCustomElementDefinition::runConstructor(element); |
| 315 } | 316 } |
| 316 | 317 |
| 317 bool hasConnectedCallback() const override { return true; } | 318 bool hasConnectedCallback() const override { return true; } |
| 318 bool hasDisconnectedCallback() const override { return true; } | 319 bool hasDisconnectedCallback() const override { return true; } |
| 320 bool hasAdoptedCallback() const override {return true;} |
| 319 | 321 |
| 320 void runConnectedCallback(Element* element) override | 322 void runConnectedCallback(Element* element) override |
| 321 { | 323 { |
| 322 m_logs.append(ConnectedCallback); | 324 m_logs.append(ConnectedCallback); |
| 323 EXPECT_EQ(element, m_element); | 325 EXPECT_EQ(element, m_element); |
| 324 } | 326 } |
| 325 | 327 |
| 326 void runDisconnectedCallback(Element* element) override | 328 void runDisconnectedCallback(Element* element) override |
| 327 { | 329 { |
| 328 m_logs.append(DisconnectedCallback); | 330 m_logs.append(DisconnectedCallback); |
| 329 EXPECT_EQ(element, m_element); | 331 EXPECT_EQ(element, m_element); |
| 330 } | 332 } |
| 331 | 333 |
| 334 void runAdoptedCallback(Element* element) override |
| 335 { |
| 336 m_logs.append(AdoptedCallback); |
| 337 EXPECT_EQ(element, m_element); |
| 338 } |
| 339 |
| 332 void runAttributeChangedCallback(Element* element, const QualifiedName& name
, const AtomicString& oldValue, const AtomicString& newValue) override | 340 void runAttributeChangedCallback(Element* element, const QualifiedName& name
, const AtomicString& oldValue, const AtomicString& newValue) override |
| 333 { | 341 { |
| 334 m_logs.append(AttributeChangedCallback); | 342 m_logs.append(AttributeChangedCallback); |
| 335 EXPECT_EQ(element, m_element); | 343 EXPECT_EQ(element, m_element); |
| 336 m_attributeChanged.append(AttributeChanged { name, oldValue, newValue })
; | 344 m_attributeChanged.append(AttributeChanged { name, oldValue, newValue })
; |
| 337 } | 345 } |
| 338 }; | 346 }; |
| 339 | 347 |
| 340 class LogUpgradeBuilder final : public CustomElementDefinitionBuilder { | 348 class LogUpgradeBuilder final : public CustomElementDefinitionBuilder { |
| 341 STACK_ALLOCATED(); | 349 STACK_ALLOCATED(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 << "remove() should invoke disconnectedCallback"; | 474 << "remove() should invoke disconnectedCallback"; |
| 467 | 475 |
| 468 EXPECT_EQ(1u, definition->m_logs.size()) | 476 EXPECT_EQ(1u, definition->m_logs.size()) |
| 469 << "remove() should not invoke other callbacks"; | 477 << "remove() should not invoke other callbacks"; |
| 470 } | 478 } |
| 471 | 479 |
| 472 // TODO(dominicc): Add tests which adjust the "is" attribute when type | 480 // TODO(dominicc): Add tests which adjust the "is" attribute when type |
| 473 // extensions are implemented. | 481 // extensions are implemented. |
| 474 | 482 |
| 475 } // namespace blink | 483 } // namespace blink |
| OLD | NEW |