Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/client/public/contents/blimp_contents_observer.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "blimp/client/core/contents/blimp_contents_impl.h" | |
| 9 #include "testing/gmock/include/gmock/gmock.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace { | |
| 13 const int kDummyTabId = 0; | |
| 14 } | |
| 15 | |
| 16 namespace blimp { | |
| 17 namespace client { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class BlimpContentsObserverTest : public BlimpContentsObserver { | |
| 22 public: | |
| 23 explicit BlimpContentsObserverTest(BlimpContents* blimp_contents) | |
| 24 : BlimpContentsObserver(blimp_contents) {} | |
| 25 | |
| 26 MOCK_METHOD0(OnContentsDestroyed, void()); | |
| 27 | |
| 28 private: | |
| 29 DISALLOW_COPY_AND_ASSIGN(BlimpContentsObserverTest); | |
| 30 }; | |
| 31 | |
| 32 TEST(BlimpContentsObserverUnittests, ObserverDies) { | |
| 33 BlimpContentsImpl contents(kDummyTabId); | |
| 34 | |
| 35 std::unique_ptr<BlimpContentsObserver> observer = | |
| 36 base::MakeUnique<BlimpContentsObserverTest>(&contents); | |
| 37 BlimpContentsObserver* observer_ptr = observer.get(); | |
| 38 EXPECT_TRUE(contents.HasObserver(observer_ptr)); | |
| 39 observer.reset(); | |
| 40 | |
| 41 EXPECT_FALSE(contents.HasObserver(observer_ptr)); | |
| 42 } | |
| 43 | |
| 44 TEST(BlimpContentsObserverUnittests, ContentsDies) { | |
| 45 std::unique_ptr<BlimpContentsObserverTest> observer; | |
| 46 | |
| 47 std::unique_ptr<BlimpContentsImpl> contents = | |
| 48 base::MakeUnique<BlimpContentsImpl>(kDummyTabId); | |
| 49 observer.reset(new BlimpContentsObserverTest(contents.get())); | |
| 50 EXPECT_CALL(*observer, OnContentsDestroyed()).Times(1); | |
| 51 EXPECT_EQ(observer.get()->blimp_contents(), contents.get()); | |
|
David Trainor- moved to gerrit
2016/08/09 05:34:12
I don't think you need .get() before the ->
Menglin
2016/08/09 18:19:31
Done.
| |
| 52 contents.reset(); | |
| 53 | |
| 54 EXPECT_EQ(observer.get()->blimp_contents(), nullptr); | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 59 } // namespace client | |
| 60 } // namespace blimp | |
| OLD | NEW |