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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 | 82 |
83 bool m_contextDestroyedCalled; | 83 bool m_contextDestroyedCalled; |
84 | 84 |
85 void unobserve() { observeContext(0); } | 85 void unobserve() { observeContext(0); } |
86 }; | 86 }; |
87 | 87 |
88 TEST(LifecycleContextTest, shouldObserveContextDestroyed) | 88 TEST(LifecycleContextTest, shouldObserveContextDestroyed) |
89 { | 89 { |
90 OwnPtrWillBeRawPtr<DummyContext> context = adoptPtrWillBeNoop(new DummyConte
xt()); | 90 OwnPtrWillBeRawPtr<DummyContext> context = adoptPtrWillBeNoop(new DummyConte
xt()); |
91 TestingObserver* observer = new TestingObserver(context.get()); | 91 Persistent<TestingObserver> observer = new TestingObserver(context.get()); |
92 | 92 |
93 EXPECT_EQ(observer->lifecycleContext(), context.get()); | 93 EXPECT_EQ(observer->lifecycleContext(), context.get()); |
94 EXPECT_FALSE(observer->m_contextDestroyedCalled); | 94 EXPECT_FALSE(observer->m_contextDestroyedCalled); |
95 context->notifyContextDestroyed(); | 95 context->notifyContextDestroyed(); |
96 context.clear(); | 96 context = nullptr; |
| 97 Heap::collectAllGarbage(); |
97 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 98 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
98 EXPECT_TRUE(observer->m_contextDestroyedCalled); | 99 EXPECT_TRUE(observer->m_contextDestroyedCalled); |
99 } | 100 } |
100 | 101 |
101 TEST(LifecycleContextTest, shouldNotObserveContextDestroyedIfUnobserve) | 102 TEST(LifecycleContextTest, shouldNotObserveContextDestroyedIfUnobserve) |
102 { | 103 { |
103 OwnPtrWillBeRawPtr<DummyContext> context = adoptPtrWillBeNoop(new DummyConte
xt()); | 104 OwnPtrWillBeRawPtr<DummyContext> context = adoptPtrWillBeNoop(new DummyConte
xt()); |
104 TestingObserver* observer = new TestingObserver(context.get()); | 105 Persistent<TestingObserver> observer = new TestingObserver(context.get()); |
105 observer->unobserve(); | 106 observer->unobserve(); |
106 context->notifyContextDestroyed(); | 107 context->notifyContextDestroyed(); |
107 context.clear(); | 108 context = nullptr; |
| 109 Heap::collectAllGarbage(); |
108 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); | 110 EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0)); |
109 EXPECT_FALSE(observer->m_contextDestroyedCalled); | 111 EXPECT_FALSE(observer->m_contextDestroyedCalled); |
110 } | 112 } |
111 | 113 |
112 } | 114 } |
OLD | NEW |