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

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

Issue 16174003: Make all tests use GetActiveDesktop() instead of hardcoding HOST_DESKTOP_TYPE_NATIVE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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/in_process_browser_test.h" 5 #include "chrome/test/base/in_process_browser_test.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // Propagate commandline settings from test_launcher_utils. 188 // Propagate commandline settings from test_launcher_utils.
189 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); 189 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line);
190 190
191 // This is a Browser test. 191 // This is a Browser test.
192 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); 192 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType);
193 193
194 #if defined(OS_WIN) && defined(USE_AURA) 194 #if defined(OS_WIN) && defined(USE_AURA)
195 if (command_line->HasSwitch(switches::kAshBrowserTests)) { 195 if (command_line->HasSwitch(switches::kAshBrowserTests)) {
196 command_line->AppendSwitchNative(switches::kViewerLaunchViaAppId, 196 command_line->AppendSwitchNative(switches::kViewerLaunchViaAppId,
197 win8::test::kDefaultTestAppUserModelId); 197 win8::test::kDefaultTestAppUserModelId);
198 // Ash already launches with a single browser opened, add kSilentLaunch to
199 // make sure StartupBrowserCreator doesn't attempt to launch a browser on
200 // the native desktop on startup.
201 command_line->AppendSwitch(switches::kSilentLaunch);
198 } 202 }
199 #endif 203 #endif
200 204
201 #if defined(OS_MACOSX) 205 #if defined(OS_MACOSX)
202 // Explicitly set the path of the binary used for child processes, otherwise 206 // Explicitly set the path of the binary used for child processes, otherwise
203 // they'll try to use browser_tests which doesn't contain ChromeMain. 207 // they'll try to use browser_tests which doesn't contain ChromeMain.
204 base::FilePath subprocess_path; 208 base::FilePath subprocess_path;
205 PathService::Get(base::FILE_EXE, &subprocess_path); 209 PathService::Get(base::FILE_EXE, &subprocess_path);
206 // Recreate the real environment, run the helper within the app bundle. 210 // Recreate the real environment, run the helper within the app bundle.
207 subprocess_path = subprocess_path.DirName().DirName(); 211 subprocess_path = subprocess_path.DirName().DirName();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 272 }
269 273
270 bool InProcessBrowserTest::SetUpUserDataDirectory() { 274 bool InProcessBrowserTest::SetUpUserDataDirectory() {
271 return true; 275 return true;
272 } 276 }
273 277
274 // Creates a browser with a single tab (about:blank), waits for the tab to 278 // Creates a browser with a single tab (about:blank), waits for the tab to
275 // finish loading and shows the browser. 279 // finish loading and shows the browser.
276 Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) { 280 Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) {
277 Browser* browser = new Browser( 281 Browser* browser = new Browser(
278 Browser::CreateParams(profile, chrome::HOST_DESKTOP_TYPE_NATIVE)); 282 Browser::CreateParams(profile, chrome::GetActiveDesktop()));
279 AddBlankTabAndShow(browser); 283 AddBlankTabAndShow(browser);
280 return browser; 284 return browser;
281 } 285 }
282 286
283 Browser* InProcessBrowserTest::CreateIncognitoBrowser() { 287 Browser* InProcessBrowserTest::CreateIncognitoBrowser() {
284 // Create a new browser with using the incognito profile. 288 // Create a new browser with using the incognito profile.
285 Browser* incognito = new Browser( 289 Browser* incognito = new Browser(
286 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(), 290 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(),
287 chrome::HOST_DESKTOP_TYPE_NATIVE)); 291 chrome::GetActiveDesktop()));
288 AddBlankTabAndShow(incognito); 292 AddBlankTabAndShow(incognito);
289 return incognito; 293 return incognito;
290 } 294 }
291 295
292 Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) { 296 Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) {
293 Browser* browser = 297 Browser* browser =
294 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, 298 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile,
295 chrome::HOST_DESKTOP_TYPE_NATIVE)); 299 chrome::GetActiveDesktop()));
296 AddBlankTabAndShow(browser); 300 AddBlankTabAndShow(browser);
297 return browser; 301 return browser;
298 } 302 }
299 303
300 Browser* InProcessBrowserTest::CreateBrowserForApp( 304 Browser* InProcessBrowserTest::CreateBrowserForApp(
301 const std::string& app_name, 305 const std::string& app_name,
302 Profile* profile) { 306 Profile* profile) {
303 Browser* browser = new Browser( 307 Browser* browser = new Browser(
304 Browser::CreateParams::CreateForApp( 308 Browser::CreateParams::CreateForApp(
305 Browser::TYPE_POPUP, app_name, gfx::Rect(), profile, 309 Browser::TYPE_POPUP, app_name, gfx::Rect(), profile,
306 chrome::HOST_DESKTOP_TYPE_NATIVE)); 310 chrome::GetActiveDesktop()));
307 AddBlankTabAndShow(browser); 311 AddBlankTabAndShow(browser);
308 return browser; 312 return browser;
309 } 313 }
310 314
311 void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) { 315 void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) {
312 content::WindowedNotificationObserver observer( 316 content::WindowedNotificationObserver observer(
313 content::NOTIFICATION_LOAD_STOP, 317 content::NOTIFICATION_LOAD_STOP,
314 content::NotificationService::AllSources()); 318 content::NotificationService::AllSources());
315 chrome::AddSelectedTabWithURL(browser, GURL(content::kAboutBlankURL), 319 chrome::AddSelectedTabWithURL(browser, GURL(content::kAboutBlankURL),
316 content::PAGE_TRANSITION_AUTO_TOPLEVEL); 320 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 #endif 356 #endif
353 357
354 void InProcessBrowserTest::RunTestOnMainThreadLoop() { 358 void InProcessBrowserTest::RunTestOnMainThreadLoop() {
355 // Pump startup related events. 359 // Pump startup related events.
356 content::RunAllPendingInMessageLoop(); 360 content::RunAllPendingInMessageLoop();
357 361
358 #if defined(OS_MACOSX) 362 #if defined(OS_MACOSX)
359 autorelease_pool_->Recycle(); 363 autorelease_pool_->Recycle();
360 #endif 364 #endif
361 365
362 // Browser tests do not support multi-desktop for now. 366 const BrowserList* active_browser_list =
363 const BrowserList* native_browser_list = 367 BrowserList::GetInstance(chrome::GetActiveDesktop());
364 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE); 368 if (!active_browser_list->empty()) {
365 if (!native_browser_list->empty()) { 369 browser_ = active_browser_list->get(0);
366 browser_ = native_browser_list->get(0);
367 #if defined(USE_ASH) 370 #if defined(USE_ASH)
368 // There are cases where windows get created maximized by default. 371 // There are cases where windows get created maximized by default.
369 if (browser_->window()->IsMaximized()) 372 if (browser_->window()->IsMaximized())
370 browser_->window()->Restore(); 373 browser_->window()->Restore();
371 #endif 374 #endif
372 content::WaitForLoadStop( 375 content::WaitForLoadStop(
373 browser_->tab_strip_model()->GetActiveWebContents()); 376 browser_->tab_strip_model()->GetActiveWebContents());
374 } 377 }
375 378
376 // Pump any pending events that were created as a result of creating a 379 // Pump any pending events that were created as a result of creating a
(...skipping 18 matching lines...) Expand all
395 autorelease_pool_->Recycle(); 398 autorelease_pool_->Recycle();
396 #endif 399 #endif
397 400
398 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's 401 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's
399 // run all pending messages here to avoid preempting the QuitBrowsers tasks. 402 // run all pending messages here to avoid preempting the QuitBrowsers tasks.
400 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it 403 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it
401 // will not be possible to post Quit tasks. 404 // will not be possible to post Quit tasks.
402 content::RunAllPendingInMessageLoop(); 405 content::RunAllPendingInMessageLoop();
403 406
404 QuitBrowsers(); 407 QuitBrowsers();
405 CHECK(native_browser_list->empty()); 408 CHECK(active_browser_list->empty());
406 } 409 }
407 410
408 void InProcessBrowserTest::QuitBrowsers() { 411 void InProcessBrowserTest::QuitBrowsers() {
409 if (chrome::GetTotalBrowserCount() == 0) 412 if (chrome::GetTotalBrowserCount() == 0)
410 return; 413 return;
411 414
415 // Browser tests only run on one desktop at a time and no action should result
416 // in browsers being created on any other desktop than the active desktop for
417 // this test.
418 chrome::HostDesktopType active_desktop_type = chrome::GetActiveDesktop();
419 for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST;
420 t < chrome::HOST_DESKTOP_TYPE_COUNT;
421 t = static_cast<chrome::HostDesktopType>(t + 1)) {
422 if (t != active_desktop_type)
423 CHECK(BrowserList::GetInstance(t)->empty()) << t;
424 }
425
412 // Invoke AttemptExit on a running message loop. 426 // Invoke AttemptExit on a running message loop.
413 // AttemptExit exits the message loop after everything has been 427 // AttemptExit exits the message loop after everything has been
414 // shut down properly. 428 // shut down properly.
415 base::MessageLoopForUI::current()->PostTask(FROM_HERE, 429 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
416 base::Bind(&chrome::AttemptExit)); 430 base::Bind(&chrome::AttemptExit));
417 content::RunMessageLoop(); 431 content::RunMessageLoop();
418 432
419 #if defined(OS_MACOSX) 433 #if defined(OS_MACOSX)
420 // chrome::AttemptExit() will attempt to close all browsers by deleting 434 // chrome::AttemptExit() will attempt to close all browsers by deleting
421 // their tab contents. The last tab contents being removed triggers closing of 435 // their tab contents. The last tab contents being removed triggers closing of
422 // the browser window. 436 // the browser window.
423 // 437 //
424 // On the Mac, this eventually reaches 438 // On the Mac, this eventually reaches
425 // -[BrowserWindowController windowWillClose:], which will post a deferred 439 // -[BrowserWindowController windowWillClose:], which will post a deferred
426 // -autorelease on itself to ultimately destroy the Browser object. The line 440 // -autorelease on itself to ultimately destroy the Browser object. The line
427 // below is necessary to pump these pending messages to ensure all Browsers 441 // below is necessary to pump these pending messages to ensure all Browsers
428 // get deleted. 442 // get deleted.
429 content::RunAllPendingInMessageLoop(); 443 content::RunAllPendingInMessageLoop();
430 delete autorelease_pool_; 444 delete autorelease_pool_;
431 autorelease_pool_ = NULL; 445 autorelease_pool_ = NULL;
432 #endif 446 #endif
433 } 447 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc ('k') | chrome/test/base/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698