| 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" |   7 #include "base/macros.h" | 
|   8 #include "base/memory/ptr_util.h" |   8 #include "base/memory/ptr_util.h" | 
|   9 #include "base/message_loop/message_loop.h" |   9 #include "base/message_loop/message_loop.h" | 
|  10 #include "base/run_loop.h" |  10 #include "base/run_loop.h" | 
|  11 #include "base/threading/thread.h" |  11 #include "base/threading/thread.h" | 
|  12 #include "blimp/client/core/contents/blimp_contents_impl.h" |  12 #include "blimp/client/core/contents/blimp_contents_impl.h" | 
|  13 #include "blimp/client/core/contents/tab_control_feature.h" |  13 #include "blimp/client/core/contents/tab_control_feature.h" | 
|  14 #include "blimp/client/public/blimp_client_context_delegate.h" |  14 #include "blimp/client/public/blimp_client_context_delegate.h" | 
|  15 #include "blimp/client/public/contents/blimp_contents.h" |  15 #include "blimp/client/public/contents/blimp_contents.h" | 
|  16 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" |  16 #include "blimp/client/support/compositor/mock_compositor_dependencies.h" | 
|  17 #include "blimp/client/test/test_blimp_client_context_delegate.h" |  17 #include "blimp/client/test/test_blimp_client_context_delegate.h" | 
|  18 #include "testing/gmock/include/gmock/gmock.h" |  18 #include "testing/gmock/include/gmock/gmock.h" | 
|  19 #include "testing/gtest/include/gtest/gtest.h" |  19 #include "testing/gtest/include/gtest/gtest.h" | 
 |  20 #include "ui/gfx/native_widget_types.h" | 
 |  21  | 
 |  22 #if defined(OS_ANDROID) | 
 |  23 #include "ui/android/window_android.h" | 
 |  24 #endif  // defined(OS_ANDROID) | 
|  20  |  25  | 
|  21 namespace blimp { |  26 namespace blimp { | 
|  22 namespace client { |  27 namespace client { | 
|  23 namespace { |  28 namespace { | 
|  24  |  29  | 
|  25 class BlimpClientContextImplTest : public testing::Test { |  30 class BlimpClientContextImplTest : public testing::Test { | 
|  26  public: |  31  public: | 
|  27   BlimpClientContextImplTest() : io_thread_("BlimpTestIO") {} |  32   BlimpClientContextImplTest() : io_thread_("BlimpTestIO") {} | 
|  28   ~BlimpClientContextImplTest() override {} |  33   ~BlimpClientContextImplTest() override {} | 
|  29  |  34  | 
|  30   void SetUp() override { |  35   void SetUp() override { | 
|  31     base::Thread::Options options; |  36     base::Thread::Options options; | 
|  32     options.message_loop_type = base::MessageLoop::TYPE_IO; |  37     options.message_loop_type = base::MessageLoop::TYPE_IO; | 
|  33     io_thread_.StartWithOptions(options); |  38     io_thread_.StartWithOptions(options); | 
 |  39 #if defined(OS_ANDROID) | 
 |  40     window_ = ui::WindowAndroid::CreateForTesting(); | 
 |  41 #endif  // defined(OS_ANDROID) | 
|  34   } |  42   } | 
|  35  |  43  | 
|  36   void TearDown() override { |  44   void TearDown() override { | 
|  37     io_thread_.Stop(); |  45     io_thread_.Stop(); | 
|  38     base::RunLoop().RunUntilIdle(); |  46     base::RunLoop().RunUntilIdle(); | 
 |  47 #if defined(OS_ANDROID) | 
 |  48     window_->DestroyForTesting(); | 
 |  49 #endif  // defined(OS_ANDROID) | 
|  39   } |  50   } | 
|  40  |  51  | 
|  41  protected: |  52  protected: | 
|  42   base::Thread io_thread_; |  53   base::Thread io_thread_; | 
 |  54   gfx::NativeWindow window_ = nullptr; | 
|  43  |  55  | 
|  44  private: |  56  private: | 
|  45   base::MessageLoop message_loop_; |  57   base::MessageLoop message_loop_; | 
|  46  |  58  | 
|  47   DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImplTest); |  59   DISALLOW_COPY_AND_ASSIGN(BlimpClientContextImplTest); | 
|  48 }; |  60 }; | 
|  49  |  61  | 
|  50 TEST_F(BlimpClientContextImplTest, |  62 TEST_F(BlimpClientContextImplTest, | 
|  51        CreatedBlimpContentsGetsHelpersAttachedAndHasTabControlFeature) { |  63        CreatedBlimpContentsGetsHelpersAttachedAndHasTabControlFeature) { | 
|  52   BlimpClientContextImpl blimp_client_context( |  64   BlimpClientContextImpl blimp_client_context( | 
|  53       io_thread_.task_runner(), io_thread_.task_runner(), |  65       io_thread_.task_runner(), io_thread_.task_runner(), | 
|  54       base::MakeUnique<MockCompositorDependencies>()); |  66       base::MakeUnique<MockCompositorDependencies>()); | 
|  55   TestBlimpClientContextDelegate delegate; |  67   TestBlimpClientContextDelegate delegate; | 
|  56   blimp_client_context.SetDelegate(&delegate); |  68   blimp_client_context.SetDelegate(&delegate); | 
|  57  |  69  | 
|  58   BlimpContents* attached_blimp_contents = nullptr; |  70   BlimpContents* attached_blimp_contents = nullptr; | 
|  59  |  71  | 
|  60   EXPECT_CALL(delegate, AttachBlimpContentsHelpers(testing::_)) |  72   EXPECT_CALL(delegate, AttachBlimpContentsHelpers(testing::_)) | 
|  61       .WillOnce(testing::SaveArg<0>(&attached_blimp_contents)) |  73       .WillOnce(testing::SaveArg<0>(&attached_blimp_contents)) | 
|  62       .RetiresOnSaturation(); |  74       .RetiresOnSaturation(); | 
|  63  |  75  | 
|  64   std::unique_ptr<BlimpContents> blimp_contents = |  76   std::unique_ptr<BlimpContents> blimp_contents = | 
|  65       blimp_client_context.CreateBlimpContents(); |  77       blimp_client_context.CreateBlimpContents(window_); | 
|  66   DCHECK(blimp_contents); |  78   DCHECK(blimp_contents); | 
|  67   DCHECK_EQ(blimp_contents.get(), attached_blimp_contents); |  79   DCHECK_EQ(blimp_contents.get(), attached_blimp_contents); | 
|  68 } |  80 } | 
|  69  |  81  | 
|  70 }  // namespace |  82 }  // namespace | 
|  71 }  // namespace client |  83 }  // namespace client | 
|  72 }  // namespace blimp |  84 }  // namespace blimp | 
| OLD | NEW |