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 DummyContext* context = DummyContext::create(); | 98 DummyContext* context = DummyContext::create(); |
99 Persistent<TestingObserver> observer = TestingObserver::create(context); | 99 Persistent<TestingObserver> observer = TestingObserver::create(context); |
100 | 100 |
101 EXPECT_EQ(observer->lifecycleContext(), context); | 101 EXPECT_EQ(observer->lifecycleContext(), context); |
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 DummyContext* context = DummyContext::create(); | 112 DummyContext* context = DummyContext::create(); |
113 Persistent<TestingObserver> observer = TestingObserver::create(context); | 113 Persistent<TestingObserver> observer = TestingObserver::create(context); |
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 DummyContext* context = DummyContext::create(); | 124 DummyContext* context = DummyContext::create(); |
125 Persistent<TestingObserver> observer = TestingObserver::create(context); | 125 Persistent<TestingObserver> observer = TestingObserver::create(context); |
126 TestingObserver* innerObserver = TestingObserver::create(context); | 126 TestingObserver* innerObserver = TestingObserver::create(context); |
127 // Attach the observer to the other. When 'observer' is notified | 127 // Attach the observer to the other. When 'observer' is notified |
128 // of destruction, it will remove & destroy 'innerObserver'. | 128 // of destruction, it will remove & destroy 'innerObserver'. |
129 observer->setObserverToRemoveAndDestroy(innerObserver); | 129 observer->setObserverToRemoveAndDestroy(innerObserver); |
130 | 130 |
131 EXPECT_EQ(observer->lifecycleContext(), context); | 131 EXPECT_EQ(observer->lifecycleContext(), context); |
132 EXPECT_EQ(observer->innerObserver()->lifecycleContext(), context); | 132 EXPECT_EQ(observer->innerObserver()->lifecycleContext(), context); |
133 EXPECT_FALSE(observer->contextDestroyedCalled()); | 133 EXPECT_FALSE(observer->contextDestroyedCalled()); |
134 EXPECT_FALSE(observer->innerObserver()->contextDestroyedCalled()); | 134 EXPECT_FALSE(observer->innerObserver()->contextDestroyedCalled()); |
135 | 135 |
136 context->notifyContextDestroyed(); | 136 context->notifyContextDestroyed(); |
137 EXPECT_EQ(observer->innerObserver(), nullptr); | 137 EXPECT_EQ(observer->innerObserver(), nullptr); |
138 context = nullptr; | 138 context = nullptr; |
139 Heap::collectAllGarbage(); | 139 ThreadHeap::collectAllGarbage(); |
140 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 140 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
141 EXPECT_TRUE(observer->contextDestroyedCalled()); | 141 EXPECT_TRUE(observer->contextDestroyedCalled()); |
142 } | 142 } |
143 | 143 |
144 } // namespace blink | 144 } // namespace blink |
OLD | NEW |