OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // deletes the |constructed_life_cycle_object_|, if any when the | 55 // deletes the |constructed_life_cycle_object_|, if any when the |
56 // LifeCycleWatcher is destroyed. To keep this simple, the only expected state | 56 // LifeCycleWatcher is destroyed. To keep this simple, the only expected state |
57 // changes are: | 57 // changes are: |
58 // INITIAL -> CONSTRUCTED -> DESTROYED. | 58 // INITIAL -> CONSTRUCTED -> DESTROYED. |
59 // Anything more complicated than that should start another test. | 59 // Anything more complicated than that should start another test. |
60 class LifeCycleWatcher : public LifeCycleObject::Observer { | 60 class LifeCycleWatcher : public LifeCycleObject::Observer { |
61 public: | 61 public: |
62 LifeCycleWatcher() | 62 LifeCycleWatcher() |
63 : life_cycle_state_(LC_INITIAL), | 63 : life_cycle_state_(LC_INITIAL), |
64 constructed_life_cycle_object_(NULL) {} | 64 constructed_life_cycle_object_(NULL) {} |
65 ~LifeCycleWatcher() { | 65 virtual ~LifeCycleWatcher() {} |
66 } | |
67 | 66 |
68 // Assert INITIAL -> CONSTRUCTED and no LifeCycleObject associated with this | 67 // Assert INITIAL -> CONSTRUCTED and no LifeCycleObject associated with this |
69 // LifeCycleWatcher. | 68 // LifeCycleWatcher. |
70 virtual void OnLifeCycleConstruct(LifeCycleObject* object) { | 69 virtual void OnLifeCycleConstruct(LifeCycleObject* object) OVERRIDE { |
71 ASSERT_EQ(LC_INITIAL, life_cycle_state_); | 70 ASSERT_EQ(LC_INITIAL, life_cycle_state_); |
72 ASSERT_EQ(NULL, constructed_life_cycle_object_.get()); | 71 ASSERT_EQ(NULL, constructed_life_cycle_object_.get()); |
73 life_cycle_state_ = LC_CONSTRUCTED; | 72 life_cycle_state_ = LC_CONSTRUCTED; |
74 constructed_life_cycle_object_.reset(object); | 73 constructed_life_cycle_object_.reset(object); |
75 } | 74 } |
76 | 75 |
77 // Assert CONSTRUCTED -> DESTROYED and the |object| being destroyed is the | 76 // Assert CONSTRUCTED -> DESTROYED and the |object| being destroyed is the |
78 // same one we saw constructed. | 77 // same one we saw constructed. |
79 virtual void OnLifeCycleDestroy(LifeCycleObject* object) { | 78 virtual void OnLifeCycleDestroy(LifeCycleObject* object) OVERRIDE { |
80 ASSERT_EQ(LC_CONSTRUCTED, life_cycle_state_); | 79 ASSERT_EQ(LC_CONSTRUCTED, life_cycle_state_); |
81 LifeCycleObject* constructed_life_cycle_object = | 80 LifeCycleObject* constructed_life_cycle_object = |
82 constructed_life_cycle_object_.release(); | 81 constructed_life_cycle_object_.release(); |
83 ASSERT_EQ(constructed_life_cycle_object, object); | 82 ASSERT_EQ(constructed_life_cycle_object, object); |
84 life_cycle_state_ = LC_DESTROYED; | 83 life_cycle_state_ = LC_DESTROYED; |
85 } | 84 } |
86 | 85 |
87 LifeCycleState life_cycle_state() const { return life_cycle_state_; } | 86 LifeCycleState life_cycle_state() const { return life_cycle_state_; } |
88 | 87 |
89 // Factory method for creating a new LifeCycleObject tied to this | 88 // Factory method for creating a new LifeCycleObject tied to this |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 for(LifeCycleWatcher* it = watchers; it != watchers + 1; ++it) | 221 for(LifeCycleWatcher* it = watchers; it != watchers + 1; ++it) |
223 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); | 222 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); |
224 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it) | 223 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it) |
225 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state()); | 224 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state()); |
226 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers); | 225 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers); |
227 ++it) | 226 ++it) |
228 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); | 227 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); |
229 } | 228 } |
230 | 229 |
231 } // namespace | 230 } // namespace |
OLD | NEW |