Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/test/base/browser_with_test_window_test.cc

Issue 2804913002: mash: Test ChromeLauncherControllerImpl more like production use. (Closed)
Patch Set: Fix BrowserWindow leak; restore InitLauncherController; cleanup. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/test/base/browser_with_test_window_test.h" 5 #include "chrome/test/base/browser_with_test_window_test.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 browser_.reset( 81 browser_.reset(
82 CreateBrowser(profile(), browser_type_, hosted_app_, window_.get())); 82 CreateBrowser(profile(), browser_type_, hosted_app_, window_.get()));
83 } 83 }
84 84
85 void BrowserWithTestWindowTest::TearDown() { 85 void BrowserWithTestWindowTest::TearDown() {
86 // Some tests end up posting tasks to the DB thread that must be completed 86 // Some tests end up posting tasks to the DB thread that must be completed
87 // before the profile can be destroyed and the test safely shut down. 87 // before the profile can be destroyed and the test safely shut down.
88 base::RunLoop().RunUntilIdle(); 88 base::RunLoop().RunUntilIdle();
89 89
90 // Reset the profile here because some profile keyed services (like the 90 // Close the browser tabs and destroy the browser and window instances.
91 // audio service) depend on test stubs that the helpers below will remove. 91 if (browser_.get())
sky 2017/04/07 14:51:39 if (browser_)?
msw 2017/04/07 15:38:41 Done.
92 DestroyBrowserAndProfile(); 92 browser()->tab_strip_model()->CloseAllTabs();
93 browser_.reset();
94 window_.reset();
93 95
94 if (content::IsBrowserSideNavigationEnabled()) 96 if (content::IsBrowserSideNavigationEnabled())
95 content::BrowserSideNavigationTearDown(); 97 content::BrowserSideNavigationTearDown();
96 98
97 #if defined(TOOLKIT_VIEWS) 99 #if defined(TOOLKIT_VIEWS)
98 constrained_window::SetConstrainedWindowViewsClient(nullptr); 100 constrained_window::SetConstrainedWindowViewsClient(nullptr);
99 #endif 101 #endif
100 102
101 #if defined(OS_CHROMEOS) 103 #if defined(OS_CHROMEOS)
104 // Destroy the shell before the profile to match production shutdown ordering.
102 ash_test_helper_->TearDown(); 105 ash_test_helper_->TearDown();
103 #elif defined(TOOLKIT_VIEWS) 106 #elif defined(TOOLKIT_VIEWS)
104 views_test_helper_.reset(); 107 views_test_helper_.reset();
105 #endif 108 #endif
106 109
110 // Destroy the profile here - otherwise, if the profile is freed in the
111 // destructor, and a test subclass owns a resource that the profile depends
112 // on (such as g_browser_process()->local_state()) there's no way for the
113 // subclass to free it after the profile.
114 if (profile_)
115 DestroyProfile(profile_);
116 profile_ = nullptr;
117
107 testing::Test::TearDown(); 118 testing::Test::TearDown();
108 119
109 // A Task is leaked if we don't destroy everything, then run the message 120 // A Task is leaked if we don't destroy everything, then run the message loop.
110 // loop.
111 base::ThreadTaskRunnerHandle::Get()->PostTask( 121 base::ThreadTaskRunnerHandle::Get()->PostTask(
112 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 122 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
113 base::RunLoop().Run(); 123 base::RunLoop().Run();
114 } 124 }
115 125
116 gfx::NativeWindow BrowserWithTestWindowTest::GetContext() { 126 gfx::NativeWindow BrowserWithTestWindowTest::GetContext() {
117 #if defined(OS_CHROMEOS) 127 #if defined(OS_CHROMEOS)
118 return ash_test_helper_->CurrentContext(); 128 return ash_test_helper_->CurrentContext();
119 #elif defined(TOOLKIT_VIEWS) 129 #elif defined(TOOLKIT_VIEWS)
120 return views_test_helper_->GetContext(); 130 return views_test_helper_->GetContext();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 Browser* navigating_browser, 167 Browser* navigating_browser,
158 const GURL& url, 168 const GURL& url,
159 const base::string16& title) { 169 const base::string16& title) {
160 WebContents* contents = 170 WebContents* contents =
161 navigating_browser->tab_strip_model()->GetActiveWebContents(); 171 navigating_browser->tab_strip_model()->GetActiveWebContents();
162 NavigationController* controller = &contents->GetController(); 172 NavigationController* controller = &contents->GetController();
163 NavigateAndCommit(controller, url); 173 NavigateAndCommit(controller, url);
164 contents->UpdateTitleForEntry(controller->GetActiveEntry(), title); 174 contents->UpdateTitleForEntry(controller->GetActiveEntry(), title);
165 } 175 }
166 176
167 void BrowserWithTestWindowTest::DestroyBrowserAndProfile() {
168 if (browser_.get()) {
169 // Make sure we close all tabs, otherwise Browser isn't happy in its
170 // destructor.
171 browser()->tab_strip_model()->CloseAllTabs();
172 browser_.reset(NULL);
173 }
174 window_.reset(NULL);
175 // Destroy the profile here - otherwise, if the profile is freed in the
176 // destructor, and a test subclass owns a resource that the profile depends
177 // on (such as g_browser_process()->local_state()) there's no way for the
178 // subclass to free it after the profile.
179 if (profile_)
180 DestroyProfile(profile_);
181 profile_ = NULL;
182 }
183
184 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { 177 TestingProfile* BrowserWithTestWindowTest::CreateProfile() {
185 return new TestingProfile(); 178 return new TestingProfile();
186 } 179 }
187 180
188 void BrowserWithTestWindowTest::DestroyProfile(TestingProfile* profile) { 181 void BrowserWithTestWindowTest::DestroyProfile(TestingProfile* profile) {
189 delete profile; 182 delete profile;
190 } 183 }
191 184
192 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { 185 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() {
193 return new TestBrowserWindow(); 186 return new TestBrowserWindow();
194 } 187 }
195 188
196 Browser* BrowserWithTestWindowTest::CreateBrowser( 189 Browser* BrowserWithTestWindowTest::CreateBrowser(
197 Profile* profile, 190 Profile* profile,
198 Browser::Type browser_type, 191 Browser::Type browser_type,
199 bool hosted_app, 192 bool hosted_app,
200 BrowserWindow* browser_window) { 193 BrowserWindow* browser_window) {
201 Browser::CreateParams params(profile, true); 194 Browser::CreateParams params(profile, true);
202 if (hosted_app) { 195 if (hosted_app) {
203 params = Browser::CreateParams::CreateForApp( 196 params = Browser::CreateParams::CreateForApp(
204 "Test", true /* trusted_source */, gfx::Rect(), profile, true); 197 "Test", true /* trusted_source */, gfx::Rect(), profile, true);
205 } else { 198 } else {
206 params.type = browser_type; 199 params.type = browser_type;
207 } 200 }
208 params.window = browser_window; 201 params.window = browser_window;
209 return new Browser(params); 202 return new Browser(params);
210 } 203 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698