| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 TEST(LifecycleContextTest, shouldObserveContextDestroyed) | 96 TEST(LifecycleContextTest, shouldObserveContextDestroyed) |
| 97 { | 97 { |
| 98 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); | 98 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); |
| 99 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); | 99 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); |
| 100 | 100 |
| 101 EXPECT_EQ(observer->lifecycleContext(), context.get()); | 101 EXPECT_EQ(observer->lifecycleContext(), context.get()); |
| 102 EXPECT_FALSE(observer->contextDestroyedCalled()); | 102 EXPECT_FALSE(observer->contextDestroyedCalled()); |
| 103 context->notifyContextDestroyed(); | 103 context->notifyContextDestroyed(); |
| 104 context = nullptr; | 104 context = nullptr; |
| 105 Heap::collectAllGarbage(); | 105 ThreadHeap::collectAllGarbage(); |
| 106 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 106 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
| 107 EXPECT_TRUE(observer->contextDestroyedCalled()); | 107 EXPECT_TRUE(observer->contextDestroyedCalled()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(LifecycleContextTest, shouldNotObserveContextDestroyedIfUnobserve) | 110 TEST(LifecycleContextTest, shouldNotObserveContextDestroyedIfUnobserve) |
| 111 { | 111 { |
| 112 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); | 112 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); |
| 113 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); | 113 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); |
| 114 observer->unobserve(); | 114 observer->unobserve(); |
| 115 context->notifyContextDestroyed(); | 115 context->notifyContextDestroyed(); |
| 116 context = nullptr; | 116 context = nullptr; |
| 117 Heap::collectAllGarbage(); | 117 ThreadHeap::collectAllGarbage(); |
| 118 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 118 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
| 119 EXPECT_FALSE(observer->contextDestroyedCalled()); | 119 EXPECT_FALSE(observer->contextDestroyedCalled()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 TEST(LifecycleContextTest, observerRemovedDuringNotifyDestroyed) | 122 TEST(LifecycleContextTest, observerRemovedDuringNotifyDestroyed) |
| 123 { | 123 { |
| 124 // FIXME: Oilpan: this test can be removed when the LifecycleNotifier<T>::m_
observers | 124 // FIXME: Oilpan: this test can be removed when the LifecycleNotifier<T>::m_
observers |
| 125 // hash set is on the heap and membership is handled implicitly by the garba
ge collector. | 125 // hash set is on the heap and membership is handled implicitly by the garba
ge collector. |
| 126 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); | 126 OwnPtrWillBeRawPtr<DummyContext> context = DummyContext::create(); |
| 127 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); | 127 OwnPtrWillBePersistent<TestingObserver> observer = TestingObserver::create(c
ontext.get()); |
| 128 OwnPtrWillBeRawPtr<TestingObserver> innerObserver = TestingObserver::create(
context.get()); | 128 OwnPtrWillBeRawPtr<TestingObserver> innerObserver = TestingObserver::create(
context.get()); |
| 129 // Attach the observer to the other. When 'observer' is notified | 129 // Attach the observer to the other. When 'observer' is notified |
| 130 // of destruction, it will remove & destroy 'innerObserver'. | 130 // of destruction, it will remove & destroy 'innerObserver'. |
| 131 observer->setObserverToRemoveAndDestroy(innerObserver.release()); | 131 observer->setObserverToRemoveAndDestroy(innerObserver.release()); |
| 132 | 132 |
| 133 EXPECT_EQ(observer->lifecycleContext(), context.get()); | 133 EXPECT_EQ(observer->lifecycleContext(), context.get()); |
| 134 EXPECT_EQ(observer->innerObserver()->lifecycleContext(), context.get()); | 134 EXPECT_EQ(observer->innerObserver()->lifecycleContext(), context.get()); |
| 135 EXPECT_FALSE(observer->contextDestroyedCalled()); | 135 EXPECT_FALSE(observer->contextDestroyedCalled()); |
| 136 EXPECT_FALSE(observer->innerObserver()->contextDestroyedCalled()); | 136 EXPECT_FALSE(observer->innerObserver()->contextDestroyedCalled()); |
| 137 | 137 |
| 138 context->notifyContextDestroyed(); | 138 context->notifyContextDestroyed(); |
| 139 EXPECT_EQ(observer->innerObserver(), nullptr); | 139 EXPECT_EQ(observer->innerObserver(), nullptr); |
| 140 context = nullptr; | 140 context = nullptr; |
| 141 Heap::collectAllGarbage(); | 141 ThreadHeap::collectAllGarbage(); |
| 142 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 142 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
| 143 EXPECT_TRUE(observer->contextDestroyedCalled()); | 143 EXPECT_TRUE(observer->contextDestroyedCalled()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace blink | 146 } // namespace blink |
| OLD | NEW |