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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementRegistryTest.cpp

Issue 2299033005: Pass the old and new owner documents to the adoptedCallback. (Closed)
Patch Set: WTF_ARRAY_LENGTH Created 4 years, 3 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 | « third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp ('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
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/CustomElementRegistry.h" 5 #include "core/dom/custom/CustomElementRegistry.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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 "attr2", 239 "attr2",
240 HTMLNames::contenteditableAttr.localName(), 240 HTMLNames::contenteditableAttr.localName(),
241 }) 241 })
242 { 242 {
243 } 243 }
244 244
245 DEFINE_INLINE_VIRTUAL_TRACE() 245 DEFINE_INLINE_VIRTUAL_TRACE()
246 { 246 {
247 TestCustomElementDefinition::trace(visitor); 247 TestCustomElementDefinition::trace(visitor);
248 visitor->trace(m_element); 248 visitor->trace(m_element);
249 visitor->trace(m_adopted);
249 } 250 }
250 251
251 // TODO(dominicc): Make this class collect a vector of what's 252 // TODO(dominicc): Make this class collect a vector of what's
252 // upgraded; it will be useful in more tests. 253 // upgraded; it will be useful in more tests.
253 Member<Element> m_element; 254 Member<Element> m_element;
254 enum MethodType { 255 enum MethodType {
255 Constructor, 256 Constructor,
256 ConnectedCallback, 257 ConnectedCallback,
257 DisconnectedCallback, 258 DisconnectedCallback,
258 AdoptedCallback, 259 AdoptedCallback,
259 AttributeChangedCallback, 260 AttributeChangedCallback,
260 }; 261 };
261 Vector<MethodType> m_logs; 262 Vector<MethodType> m_logs;
262 263
263 struct AttributeChanged { 264 struct AttributeChanged {
264 QualifiedName name; 265 QualifiedName name;
265 AtomicString oldValue; 266 AtomicString oldValue;
266 AtomicString newValue; 267 AtomicString newValue;
267 }; 268 };
268 Vector<AttributeChanged> m_attributeChanged; 269 Vector<AttributeChanged> m_attributeChanged;
269 270
271 struct Adopted : public GarbageCollected<Adopted> {
272 Adopted(Document* oldOwner, Document* newOwner)
273 : m_oldOwner(oldOwner)
274 , m_newOwner(newOwner) { }
275
276 Member<Document> m_oldOwner;
277 Member<Document> m_newOwner;
278
279 DEFINE_INLINE_TRACE()
280 {
281 visitor->trace(m_oldOwner);
282 visitor->trace(m_newOwner);
283 }
284 };
285 HeapVector<Member<Adopted>> m_adopted;
286
270 void clear() 287 void clear()
271 { 288 {
272 m_logs.clear(); 289 m_logs.clear();
273 m_attributeChanged.clear(); 290 m_attributeChanged.clear();
274 } 291 }
275 292
276 bool runConstructor(Element* element) override 293 bool runConstructor(Element* element) override
277 { 294 {
278 m_logs.append(Constructor); 295 m_logs.append(Constructor);
279 m_element = element; 296 m_element = element;
280 return TestCustomElementDefinition::runConstructor(element); 297 return TestCustomElementDefinition::runConstructor(element);
281 } 298 }
282 299
283 bool hasConnectedCallback() const override { return true; } 300 bool hasConnectedCallback() const override { return true; }
284 bool hasDisconnectedCallback() const override { return true; } 301 bool hasDisconnectedCallback() const override { return true; }
285 bool hasAdoptedCallback() const override {return true;} 302 bool hasAdoptedCallback() const override {return true;}
286 303
287 void runConnectedCallback(Element* element) override 304 void runConnectedCallback(Element* element) override
288 { 305 {
289 m_logs.append(ConnectedCallback); 306 m_logs.append(ConnectedCallback);
290 EXPECT_EQ(element, m_element); 307 EXPECT_EQ(element, m_element);
291 } 308 }
292 309
293 void runDisconnectedCallback(Element* element) override 310 void runDisconnectedCallback(Element* element) override
294 { 311 {
295 m_logs.append(DisconnectedCallback); 312 m_logs.append(DisconnectedCallback);
296 EXPECT_EQ(element, m_element); 313 EXPECT_EQ(element, m_element);
297 } 314 }
298 315
299 void runAdoptedCallback(Element* element) override 316 void runAdoptedCallback(
317 Element* element, Document* oldOwner, Document* newOwner) override
300 { 318 {
301 m_logs.append(AdoptedCallback); 319 m_logs.append(AdoptedCallback);
302 EXPECT_EQ(element, m_element); 320 EXPECT_EQ(element, m_element);
321 m_adopted.append(new Adopted(oldOwner, newOwner));
303 } 322 }
304 323
305 void runAttributeChangedCallback(Element* element, const QualifiedName& name , const AtomicString& oldValue, const AtomicString& newValue) override 324 void runAttributeChangedCallback(Element* element, const QualifiedName& name , const AtomicString& oldValue, const AtomicString& newValue) override
306 { 325 {
307 m_logs.append(AttributeChangedCallback); 326 m_logs.append(AttributeChangedCallback);
308 EXPECT_EQ(element, m_element); 327 EXPECT_EQ(element, m_element);
309 m_attributeChanged.append(AttributeChanged { name, oldValue, newValue }) ; 328 m_attributeChanged.append(AttributeChanged { name, oldValue, newValue }) ;
310 } 329 }
311 }; 330 };
312 331
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 { 486 {
468 CEReactionsScope reactions; 487 CEReactionsScope reactions;
469 otherDocument->adoptNode(element, ASSERT_NO_EXCEPTION); 488 otherDocument->adoptNode(element, ASSERT_NO_EXCEPTION);
470 } 489 }
471 EXPECT_EQ(LogUpgradeDefinition::DisconnectedCallback, definition->m_logs[0]) 490 EXPECT_EQ(LogUpgradeDefinition::DisconnectedCallback, definition->m_logs[0])
472 << "adoptNode() should invoke disconnectedCallback"; 491 << "adoptNode() should invoke disconnectedCallback";
473 492
474 EXPECT_EQ(LogUpgradeDefinition::AdoptedCallback, definition->m_logs[1]) 493 EXPECT_EQ(LogUpgradeDefinition::AdoptedCallback, definition->m_logs[1])
475 << "adoptNode() should invoke adoptedCallback"; 494 << "adoptNode() should invoke adoptedCallback";
476 495
496 EXPECT_EQ(&document(), definition->m_adopted[0]->m_oldOwner.get())
497 << "adoptedCallback should have been passed the old owner document";
498 EXPECT_EQ(otherDocument, definition->m_adopted[0]->m_newOwner.get())
499 << "adoptedCallback should have been passed the new owner document";
500
477 EXPECT_EQ(2u, definition->m_logs.size()) 501 EXPECT_EQ(2u, definition->m_logs.size())
478 << "adoptNode() should not invoke other callbacks"; 502 << "adoptNode() should not invoke other callbacks";
479 } 503 }
480 504
481 // TODO(dominicc): Add tests which adjust the "is" attribute when type 505 // TODO(dominicc): Add tests which adjust the "is" attribute when type
482 // extensions are implemented. 506 // extensions are implemented.
483 507
484 } // namespace blink 508 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698