• 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 #ifndef CHROME_BROWSER_UI_COCOA_BROWSER_TEST_HELPER_H_
6 #define CHROME_BROWSER_UI_COCOA_BROWSER_TEST_HELPER_H_
7 #pragma once
8 
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/test/testing_profile.h"
11 #include "content/browser/browser_thread.h"
12 
13 // Base class which contains a valid Browser*.  Lots of boilerplate to
14 // recycle between unit test classes.
15 //
16 // This class creates fake UI, file, and IO threads because many objects that
17 // are attached to the TestingProfile (and other objects) have traits that limit
18 // their destruction to certain threads. For example, the net::URLRequestContext
19 // can only be deleted on the IO thread; without this fake IO thread, the object
20 // would never be deleted and would report as a leak under Valgrind. Note that
21 // these are fake threads and they all share the same MessageLoop.
22 //
23 // TODO(jrg): move up a level (chrome/browser/ui/cocoa -->
24 // chrome/browser), and use in non-Mac unit tests such as
25 // back_forward_menu_model_unittest.cc,
26 // navigation_controller_unittest.cc, ..
27 class BrowserTestHelper {
28  public:
29   BrowserTestHelper();
30   virtual ~BrowserTestHelper();
31 
32   virtual TestingProfile* profile() const;
browser()33   Browser* browser() const { return browser_.get(); }
34 
35   // Creates the browser window. To close this window call |CloseBrowserWindow|.
36   // Do NOT call close directly on the window.
37   BrowserWindow* CreateBrowserWindow();
38 
39   // Closes the window for this browser. This must only be called after
40   // CreateBrowserWindow().
41   void CloseBrowserWindow();
42 
43  private:
44   scoped_ptr<TestingProfile> profile_;
45   scoped_ptr<Browser> browser_;
46   MessageLoopForUI message_loop_;
47   BrowserThread ui_thread_;
48   scoped_ptr<BrowserThread> file_thread_;
49   scoped_ptr<BrowserThread> io_thread_;
50 };
51 
52 #endif  // CHROME_BROWSER_UI_COCOA_BROWSER_TEST_HELPER_H_
53