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/blimp_client_context_impl.h" | 5 #include "blimp/client/core/blimp_client_context_impl.h" |
6 | 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "base/threading/thread.h" |
7 #include "blimp/client/public/blimp_client_context_delegate.h" | 11 #include "blimp/client/public/blimp_client_context_delegate.h" |
8 #include "blimp/client/public/contents/blimp_contents.h" | 12 #include "blimp/client/public/contents/blimp_contents.h" |
9 #include "blimp/client/test/test_blimp_client_context_delegate.h" | 13 #include "blimp/client/test/test_blimp_client_context_delegate.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
11 | 16 |
12 namespace blimp { | 17 namespace blimp { |
13 namespace client { | 18 namespace client { |
14 namespace { | 19 namespace { |
15 | 20 |
16 TEST(BlimpClientContextImpl, CreatedBlimpContentsGetsHelpersAttached) { | 21 class BlimpClientContextImplTest : public testing::Test { |
17 BlimpClientContextImpl blimp_client_context; | 22 public: |
| 23 BlimpClientContextImplTest() : io_thread_("BlimpTestIO") {} |
| 24 ~BlimpClientContextImplTest() override {} |
| 25 |
| 26 void SetUp() override { |
| 27 base::Thread::Options options; |
| 28 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 29 io_thread_.StartWithOptions(options); |
| 30 } |
| 31 |
| 32 void TearDown() override { |
| 33 io_thread_.Stop(); |
| 34 base::RunLoop().RunUntilIdle(); |
| 35 } |
| 36 |
| 37 protected: |
| 38 // The thread to use for IO related tasks. |
| 39 base::Thread io_thread_; |
| 40 |
| 41 private: |
| 42 // Message loop for the test thread. |
| 43 base::MessageLoop message_loop_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImplTest); |
| 46 }; |
| 47 |
| 48 TEST_F(BlimpClientContextImplTest, CreatedBlimpContentsGetsHelpersAttached) { |
| 49 BlimpClientContextImpl blimp_client_context(io_thread_.task_runner()); |
18 TestBlimpClientContextDelegate delegate; | 50 TestBlimpClientContextDelegate delegate; |
19 blimp_client_context.SetDelegate(&delegate); | 51 blimp_client_context.SetDelegate(&delegate); |
20 | 52 |
| 53 BlimpContents* attached_blimp_contents = nullptr; |
| 54 |
| 55 EXPECT_CALL(delegate, AttachBlimpContentsHelpers(testing::_)) |
| 56 .WillOnce(testing::SaveArg<0>(&attached_blimp_contents)) |
| 57 .RetiresOnSaturation(); |
| 58 |
21 std::unique_ptr<BlimpContents> blimp_contents = | 59 std::unique_ptr<BlimpContents> blimp_contents = |
22 blimp_client_context.CreateBlimpContents(); | 60 blimp_client_context.CreateBlimpContents(); |
23 DCHECK(blimp_contents); | 61 DCHECK(blimp_contents); |
24 DCHECK_EQ(blimp_contents.get(), | 62 DCHECK_EQ(blimp_contents.get(), attached_blimp_contents); |
25 delegate.GetBlimpContentsWithLastAttachedHelpers()); | |
26 } | 63 } |
27 | 64 |
28 } // namespace | 65 } // namespace |
29 } // namespace client | 66 } // namespace client |
30 } // namespace blimp | 67 } // namespace blimp |
OLD | NEW |