| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 class TestingObserver final : public NoBaseWillBeGarbageCollectedFinalized<Testi
ngObserver>, public LifecycleObserver<DummyContext, TestingObserver, DummyContex
t> { | 54 class TestingObserver final : public NoBaseWillBeGarbageCollectedFinalized<Testi
ngObserver>, public LifecycleObserver<DummyContext, TestingObserver, DummyContex
t> { |
| 55 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TestingObserver); | 55 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TestingObserver); |
| 56 public: | 56 public: |
| 57 static PassOwnPtrWillBeRawPtr<TestingObserver> create(DummyContext* context) | 57 static PassOwnPtrWillBeRawPtr<TestingObserver> create(DummyContext* context) |
| 58 { | 58 { |
| 59 return adoptPtrWillBeNoop(new TestingObserver(context)); | 59 return adoptPtrWillBeNoop(new TestingObserver(context)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual void contextDestroyed() override | 62 virtual void contextDestroyed() override |
| 63 { | 63 { |
| 64 LifecycleObserver<DummyContext, TestingObserver, DummyContext>::contextD
estroyed(); | 64 LifecycleObserver::contextDestroyed(); |
| 65 if (m_observerToRemoveOnDestruct) { | 65 if (m_observerToRemoveOnDestruct) { |
| 66 lifecycleContext()->removeObserver(m_observerToRemoveOnDestruct.get(
)); | 66 lifecycleContext()->removeObserver(m_observerToRemoveOnDestruct.get(
)); |
| 67 m_observerToRemoveOnDestruct.clear(); | 67 m_observerToRemoveOnDestruct.clear(); |
| 68 } | 68 } |
| 69 m_contextDestroyedCalled = true; | 69 m_contextDestroyedCalled = true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 DEFINE_INLINE_TRACE() | 72 DEFINE_INLINE_TRACE() |
| 73 { | 73 { |
| 74 visitor->trace(m_observerToRemoveOnDestruct); | 74 visitor->trace(m_observerToRemoveOnDestruct); |
| 75 LifecycleObserver<DummyContext, TestingObserver, DummyContext>::trace(vi
sitor); | 75 LifecycleObserver::trace(visitor); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void unobserve() { setContext(nullptr); } | 78 void unobserve() { setContext(nullptr); } |
| 79 | 79 |
| 80 void setObserverToRemoveAndDestroy(PassOwnPtrWillBeRawPtr<TestingObserver> o
bserverToRemoveOnDestruct) | 80 void setObserverToRemoveAndDestroy(PassOwnPtrWillBeRawPtr<TestingObserver> o
bserverToRemoveOnDestruct) |
| 81 { | 81 { |
| 82 ASSERT(!m_observerToRemoveOnDestruct); | 82 ASSERT(!m_observerToRemoveOnDestruct); |
| 83 m_observerToRemoveOnDestruct = observerToRemoveOnDestruct; | 83 m_observerToRemoveOnDestruct = observerToRemoveOnDestruct; |
| 84 } | 84 } |
| 85 | 85 |
| 86 TestingObserver* innerObserver() const { return m_observerToRemoveOnDestruct
.get(); } | 86 TestingObserver* innerObserver() const { return m_observerToRemoveOnDestruct
.get(); } |
| 87 bool contextDestroyedCalled() const { return m_contextDestroyedCalled; } | 87 bool contextDestroyedCalled() const { return m_contextDestroyedCalled; } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 explicit TestingObserver(DummyContext* context) | 90 explicit TestingObserver(DummyContext* context) |
| 91 : m_contextDestroyedCalled(false) | 91 : LifecycleObserver(context) |
| 92 , m_contextDestroyedCalled(false) |
| 92 { | 93 { |
| 93 setContext(context); | |
| 94 } | 94 } |
| 95 | 95 |
| 96 OwnPtrWillBeMember<TestingObserver> m_observerToRemoveOnDestruct; | 96 OwnPtrWillBeMember<TestingObserver> m_observerToRemoveOnDestruct; |
| 97 bool m_contextDestroyedCalled; | 97 bool m_contextDestroyedCalled; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 TEST(LifecycleContextTest, shouldObserveContextDestroyed) | 100 TEST(LifecycleContextTest, shouldObserveContextDestroyed) |
| 101 { | 101 { |
| 102 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); | 102 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); |
| 103 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); | 103 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 context->notifyContextDestroyed(); | 142 context->notifyContextDestroyed(); |
| 143 EXPECT_EQ(observer->innerObserver(), nullptr); | 143 EXPECT_EQ(observer->innerObserver(), nullptr); |
| 144 context = nullptr; | 144 context = nullptr; |
| 145 Heap::collectAllGarbage(); | 145 Heap::collectAllGarbage(); |
| 146 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 146 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
| 147 EXPECT_TRUE(observer->contextDestroyedCalled()); | 147 EXPECT_TRUE(observer->contextDestroyedCalled()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |