OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "content/public/test/test_web_contents_factory.h" |
| 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "content/public/browser/web_contents.h" |
| 9 #include "content/public/test/test_renderer_host.h" |
| 10 #include "content/public/test/web_contents_tester.h" |
| 11 |
| 12 #if defined(USE_AURA) |
| 13 #include "ui/aura/env.h" |
| 14 #endif |
| 15 |
| 16 namespace content { |
| 17 |
| 18 TestWebContentsFactory::TestWebContentsFactory() |
| 19 : rvh_enabler_(new content::RenderViewHostTestEnabler()), |
| 20 tear_down_aura_(false) { |
| 21 #if defined(USE_AURA) |
| 22 if (aura::Env::GetInstanceDontCreate() == nullptr) { |
| 23 aura::Env::CreateInstance(true); |
| 24 tear_down_aura_ = true; |
| 25 } |
| 26 #endif |
| 27 } |
| 28 |
| 29 TestWebContentsFactory::~TestWebContentsFactory() { |
| 30 // We explicitly clear the vector to force destruction of any created web |
| 31 // contents so that we can properly handle their cleanup (running posted |
| 32 // tasks, etc). |
| 33 web_contents_.clear(); |
| 34 // Let any posted tasks for web contents deletion run. |
| 35 base::RunLoop().RunUntilIdle(); |
| 36 rvh_enabler_.reset(); |
| 37 // Let any posted tasks for RenderProcess/ViewHost deletion run. |
| 38 base::RunLoop().RunUntilIdle(); |
| 39 #if defined(USE_AURA) |
| 40 if (tear_down_aura_) |
| 41 aura::Env::DeleteInstance(); |
| 42 #endif |
| 43 } |
| 44 |
| 45 WebContents* TestWebContentsFactory::CreateWebContents( |
| 46 BrowserContext* context) { |
| 47 web_contents_.push_back( |
| 48 WebContentsTester::CreateTestWebContents(context, nullptr)); |
| 49 DCHECK(web_contents_.back()); |
| 50 return web_contents_.back(); |
| 51 } |
| 52 |
| 53 } // namespace content |
OLD | NEW |