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

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

Issue 1228723002: Extract duplicated code in browser_tests for closing a browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/WithoutWaiting/Asynchronously Created 5 years, 5 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
« no previous file with comments | « chrome/test/base/in_process_browser_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/test/test_file_util.h" 18 #include "base/test/test_file_util.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/non_thread_safe.h" 20 #include "base/threading/non_thread_safe.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/lifetime/application_lifetime.h" 23 #include "chrome/browser/lifetime/application_lifetime.h"
23 #include "chrome/browser/net/net_error_tab_helper.h" 24 #include "chrome/browser/net/net_error_tab_helper.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_list_observer.h" 30 #include "chrome/browser/ui/browser_list_observer.h"
30 #include "chrome/browser/ui/browser_navigator.h" 31 #include "chrome/browser/ui/browser_navigator.h"
31 #include "chrome/browser/ui/browser_tabstrip.h" 32 #include "chrome/browser/ui/browser_tabstrip.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 376 }
376 377
377 void InProcessBrowserTest::TearDown() { 378 void InProcessBrowserTest::TearDown() {
378 DCHECK(!g_browser_process); 379 DCHECK(!g_browser_process);
379 #if defined(OS_WIN) 380 #if defined(OS_WIN)
380 com_initializer_.reset(); 381 com_initializer_.reset();
381 #endif 382 #endif
382 BrowserTestBase::TearDown(); 383 BrowserTestBase::TearDown();
383 } 384 }
384 385
386 void InProcessBrowserTest::CloseBrowserSynchronously(Browser* browser) {
387 content::WindowedNotificationObserver observer(
388 chrome::NOTIFICATION_BROWSER_CLOSED,
389 content::Source<Browser>(browser));
390 CloseBrowserAsynchronously(browser);
391 observer.Wait();
392 }
393
394 void InProcessBrowserTest::CloseBrowserAsynchronously(Browser* browser) {
395 browser->window()->Close();
396 #if defined(OS_MACOSX)
397 // BrowserWindowController depends on the auto release pool being recycled
398 // in the message loop to delete itself.
399 AutoreleasePool()->Recycle();
400 #endif
401 }
402
403 void InProcessBrowserTest::CloseAllBrowsers() {
404 chrome::CloseAllBrowsers();
405 #if defined(OS_MACOSX)
406 // BrowserWindowController depends on the auto release pool being recycled
407 // in the message loop to delete itself.
408 AutoreleasePool()->Recycle();
409 #endif
410 }
411
385 // TODO(alexmos): This function should expose success of the underlying 412 // TODO(alexmos): This function should expose success of the underlying
386 // navigation to tests, which should make sure navigations succeed when 413 // navigation to tests, which should make sure navigations succeed when
387 // appropriate. See https://crbug.com/425335 414 // appropriate. See https://crbug.com/425335
388 void InProcessBrowserTest::AddTabAtIndexToBrowser( 415 void InProcessBrowserTest::AddTabAtIndexToBrowser(
389 Browser* browser, 416 Browser* browser,
390 int index, 417 int index,
391 const GURL& url, 418 const GURL& url,
392 ui::PageTransition transition, 419 ui::PageTransition transition,
393 bool check_navigation_success) { 420 bool check_navigation_success) {
394 chrome::NavigateParams params(browser, url, transition); 421 chrome::NavigateParams params(browser, url, transition);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // On the Mac, this eventually reaches 623 // On the Mac, this eventually reaches
597 // -[BrowserWindowController windowWillClose:], which will post a deferred 624 // -[BrowserWindowController windowWillClose:], which will post a deferred
598 // -autorelease on itself to ultimately destroy the Browser object. The line 625 // -autorelease on itself to ultimately destroy the Browser object. The line
599 // below is necessary to pump these pending messages to ensure all Browsers 626 // below is necessary to pump these pending messages to ensure all Browsers
600 // get deleted. 627 // get deleted.
601 content::RunAllPendingInMessageLoop(); 628 content::RunAllPendingInMessageLoop();
602 delete autorelease_pool_; 629 delete autorelease_pool_;
603 autorelease_pool_ = NULL; 630 autorelease_pool_ = NULL;
604 #endif 631 #endif
605 } 632 }
OLDNEW
« no previous file with comments | « chrome/test/base/in_process_browser_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698