Chromium Code Reviews| Index: ash/test/ash_test_environment_default.cc |
| diff --git a/ash/test/ash_test_environment_default.cc b/ash/test/ash_test_environment_default.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7780ae4e87c8027f66f90e0b0614bd1ca1a0bbf |
| --- /dev/null |
| +++ b/ash/test/ash_test_environment_default.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/test/ash_test_environment.h" |
| + |
| +#include "ash/test/ash_test_views_delegate.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "base/threading/sequenced_worker_pool.h" |
| + |
| +namespace ash { |
| +namespace test { |
| +namespace { |
| + |
| +class AshTestEnvironmentDefault : public AshTestEnvironment { |
| + public: |
| + AshTestEnvironmentDefault() {} |
| + |
| + ~AshTestEnvironmentDefault() override { |
| + base::RunLoop().RunUntilIdle(); |
| + if (blocking_pool_) { |
| + blocking_pool_->FlushForTesting(); |
| + blocking_pool_->Shutdown(); |
| + blocking_pool_ = nullptr; |
| + } |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + // AshTestEnvironment: |
| + base::SequencedWorkerPool* GetBlockingPool() override { |
| + if (!blocking_pool_) { |
| + blocking_pool_ = new base::SequencedWorkerPool( |
| + 3, "AshBlocking", base::TaskPriority::USER_VISIBLE); |
|
James Cook
2016/08/31 16:20:16
nit: put 3 in a named constant or comment what it
sky
2016/08/31 17:35:57
Done.
|
| + } |
| + return blocking_pool_.get(); |
| + } |
| + std::unique_ptr<views::ViewsDelegate> CreateViewsDelegate() override { |
| + return base::MakeUnique<AshTestViewsDelegate>(); |
| + } |
| + |
| + private: |
| + base::MessageLoopForUI message_loop_; |
| + scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AshTestEnvironmentDefault); |
| +}; |
| + |
| +} // namespace |
| + |
| +// static |
| +std::unique_ptr<AshTestEnvironment> AshTestEnvironment::Create() { |
| + return base::MakeUnique<AshTestEnvironmentDefault>(); |
| +} |
| + |
| +} // namespace test |
| +} // namespace ash |