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.
5 #include "content/public/test/test_web_contents_factory.h"
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"
13 #include "ui/aura/env.h"
18 TestWebContentsFactory::TestWebContentsFactory()
19 : rvh_enabler_(new content::RenderViewHostTestEnabler()),
20 tear_down_aura_(false) {
22 if (aura::Env::GetInstanceDontCreate() == nullptr) {
23 aura::Env::CreateInstance(true);
24 tear_down_aura_
= true;
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
33 web_contents_
.clear();
34 // Let any posted tasks for web contents deletion run.
35 base::RunLoop().RunUntilIdle();
37 // Let any posted tasks for RenderProcess/ViewHost deletion run.
38 base::RunLoop().RunUntilIdle();
41 aura::Env::DeleteInstance();
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();
53 } // namespace content