• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/browser_test_helper.h"
6 
BrowserTestHelper()7 BrowserTestHelper::BrowserTestHelper()
8     : ui_thread_(BrowserThread::UI, &message_loop_),
9       file_thread_(new BrowserThread(BrowserThread::FILE, &message_loop_)),
10       io_thread_(new BrowserThread(BrowserThread::IO, &message_loop_)) {
11   profile_.reset(new TestingProfile());
12   profile_->CreateBookmarkModel(true);
13   profile_->BlockUntilBookmarkModelLoaded();
14 
15   // TODO(shess): These are needed in case someone creates a browser
16   // window off of browser_.  pkasting indicates that other
17   // platforms use a stub |BrowserWindow| and thus don't need to do
18   // this.
19   // http://crbug.com/39725
20   profile_->CreateAutocompleteClassifier();
21   profile_->CreateTemplateURLModel();
22 
23   browser_.reset(new Browser(Browser::TYPE_NORMAL, profile_.get()));
24 }
25 
~BrowserTestHelper()26 BrowserTestHelper::~BrowserTestHelper() {
27   // Delete the testing profile on the UI thread. But first release the
28   // browser, since it may trigger accesses to the profile upon destruction.
29   browser_.reset();
30   message_loop_.DeleteSoon(FROM_HERE, profile_.release());
31 
32   // Make sure any pending tasks run before we destroy other threads.
33   message_loop_.RunAllPending();
34 
35   // Drop any new tasks for the IO and FILE threads.
36   io_thread_.reset();
37   file_thread_.reset();
38 
39   message_loop_.RunAllPending();
40 }
41 
profile() const42 TestingProfile* BrowserTestHelper::profile() const {
43   return profile_.get();
44 }
45 
CreateBrowserWindow()46 BrowserWindow* BrowserTestHelper::CreateBrowserWindow() {
47   browser_->InitBrowserWindow();
48   return browser_->window();
49 }
50 
CloseBrowserWindow()51 void BrowserTestHelper::CloseBrowserWindow() {
52   // Check to make sure a window was actually created.
53   DCHECK(browser_->window());
54   browser_->CloseAllTabs();
55   browser_->CloseWindow();
56   // |browser_| will be deleted by its BrowserWindowController.
57   ignore_result(browser_.release());
58 }
59