OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "blimp/client/core/contents/blimp_contents_manager.h" | 5 #include "blimp/client/core/contents/blimp_contents_manager.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "blimp/client/core/contents/blimp_contents_impl.h" | 9 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 10 #include "blimp/client/core/contents/tab_control_feature.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
| 14 using testing::_; |
| 15 |
12 namespace { | 16 namespace { |
13 const int kDummyTabId = 0; | 17 const int kDummyTabId = 0; |
14 } | 18 } |
15 | 19 |
16 namespace blimp { | 20 namespace blimp { |
17 namespace client { | 21 namespace client { |
18 namespace { | 22 namespace { |
19 | 23 |
| 24 class MockTabControlFeature : public TabControlFeature { |
| 25 public: |
| 26 MockTabControlFeature() {} |
| 27 ~MockTabControlFeature() override = default; |
| 28 |
| 29 MOCK_METHOD1(CreateTab, void(int)); |
| 30 MOCK_METHOD1(CloseTab, void(int)); |
| 31 |
| 32 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(MockTabControlFeature); |
| 34 }; |
| 35 |
20 TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { | 36 TEST(BlimpContentsManagerUnittest, GetExistingBlimpContents) { |
21 base::MessageLoop loop; | 37 base::MessageLoop loop; |
22 BlimpContentsManager blimp_contents_manager; | 38 MockTabControlFeature tab_control_feature; |
23 | 39 |
| 40 BlimpContentsManager blimp_contents_manager(&tab_control_feature); |
| 41 |
| 42 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); |
24 std::unique_ptr<BlimpContentsImpl> blimp_contents = | 43 std::unique_ptr<BlimpContentsImpl> blimp_contents = |
25 blimp_contents_manager.CreateBlimpContents(); | 44 blimp_contents_manager.CreateBlimpContents(); |
26 int id = blimp_contents->id(); | 45 int id = blimp_contents->id(); |
27 BlimpContentsImpl* existing_contents = | 46 BlimpContentsImpl* existing_contents = |
28 blimp_contents_manager.GetBlimpContents(id); | 47 blimp_contents_manager.GetBlimpContents(id); |
29 EXPECT_EQ(blimp_contents.get(), existing_contents); | 48 EXPECT_EQ(blimp_contents.get(), existing_contents); |
30 } | 49 } |
31 | 50 |
32 TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { | 51 TEST(BlimpContentsManagerUnittest, GetNonExistingBlimpContents) { |
33 BlimpContentsManager blimp_contents_manager; | 52 MockTabControlFeature tab_control_feature; |
| 53 |
| 54 BlimpContentsManager blimp_contents_manager(&tab_control_feature); |
34 | 55 |
35 BlimpContentsImpl* existing_contents = | 56 BlimpContentsImpl* existing_contents = |
36 blimp_contents_manager.GetBlimpContents(kDummyTabId); | 57 blimp_contents_manager.GetBlimpContents(kDummyTabId); |
37 EXPECT_EQ(nullptr, existing_contents); | 58 EXPECT_EQ(nullptr, existing_contents); |
38 } | 59 } |
39 | 60 |
40 TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) { | 61 TEST(BlimpContentsManagerUnittest, GetDestroyedBlimpContents) { |
41 base::MessageLoop loop; | 62 base::MessageLoop loop; |
42 BlimpContentsManager blimp_contents_manager; | 63 MockTabControlFeature tab_control_feature; |
| 64 BlimpContentsManager blimp_contents_manager(&tab_control_feature); |
43 int id; | 65 int id; |
44 | 66 |
| 67 EXPECT_CALL(tab_control_feature, CreateTab(_)).Times(1); |
45 std::unique_ptr<BlimpContentsImpl> blimp_contents = | 68 std::unique_ptr<BlimpContentsImpl> blimp_contents = |
46 blimp_contents_manager.CreateBlimpContents(); | 69 blimp_contents_manager.CreateBlimpContents(); |
47 id = blimp_contents.get()->id(); | 70 id = blimp_contents.get()->id(); |
48 BlimpContentsImpl* existing_contents = | 71 BlimpContentsImpl* existing_contents = |
49 blimp_contents_manager.GetBlimpContents(id); | 72 blimp_contents_manager.GetBlimpContents(id); |
50 EXPECT_EQ(blimp_contents.get(), existing_contents); | 73 EXPECT_EQ(blimp_contents.get(), existing_contents); |
| 74 |
| 75 EXPECT_CALL(tab_control_feature, CloseTab(id)).Times(1); |
51 blimp_contents.reset(); | 76 blimp_contents.reset(); |
52 | 77 |
53 loop.RunUntilIdle(); | 78 loop.RunUntilIdle(); |
54 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id)); | 79 EXPECT_EQ(nullptr, blimp_contents_manager.GetBlimpContents(id)); |
55 } | 80 } |
56 | 81 |
57 } // namespace | 82 } // namespace |
58 } // namespace client | 83 } // namespace client |
59 } // namespace blimp | 84 } // namespace blimp |
OLD | NEW |