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.
5 #ifndef CHROME_BROWSER_UI_COCOA_PROFILE_TEST_H_
6 #define CHROME_BROWSER_UI_COCOA_PROFILE_TEST_H_
8 #include "base/memory/scoped_ptr.h"
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #include "chrome/test/base/testing_profile_manager.h"
13 class TestBrowserThreadBundle
;
19 // Base class which contains a valid Browser*. Lots of boilerplate to
20 // recycle between unit test classes.
22 // This class creates fake UI, file, and IO threads because many objects that
23 // are attached to the TestingProfile (and other objects) have traits that limit
24 // their destruction to certain threads. For example, the net::URLRequestContext
25 // can only be deleted on the IO thread; without this fake IO thread, the object
26 // would never be deleted and would report as a leak under Valgrind. Note that
27 // these are fake threads and they all share the same MessageLoop.
29 // TODO(jrg): move up a level (chrome/browser/ui/cocoa -->
30 // chrome/browser), and use in non-Mac unit tests such as
31 // back_forward_menu_model_unittest.cc,
32 // navigation_controller_unittest.cc, ..
33 class CocoaProfileTest
: public CocoaTest
{
36 ~CocoaProfileTest() override
;
38 // This constructs a a Browser and a TestingProfile. It is guaranteed to
39 // succeed, else it will ASSERT and cause the test to fail. Subclasses that
40 // do work in SetUp should ASSERT that either browser() or profile() are
41 // non-NULL before proceeding after the call to super (this).
42 void SetUp() override
;
44 void TearDown() override
;
46 TestingProfileManager
* testing_profile_manager() {
47 return &profile_manager_
;
49 TestingProfile
* profile() { return profile_
; }
50 Browser
* browser() { return browser_
.get(); }
52 // Closes the window for this browser. This will automatically be called as
53 // part of TearDown() if it's not been done already.
54 void CloseBrowserWindow();
57 // Overridden by test subclasses to create their own browser, e.g. with a
59 virtual Browser
* CreateBrowser();
61 // Define the TestingFactories to be used when SetUp() builds a Profile. To be
62 // called in the subclass' constructor.
63 void AddTestingFactories(
64 const TestingProfile::TestingFactories
& testing_factories
);
66 const TestingProfile::TestingFactories
& testing_factories() {
67 return testing_factories_
;
71 TestingProfileManager profile_manager_
;
72 TestingProfile
* profile_
; // Weak; owned by profile_manager_.
73 TestingProfile::TestingFactories testing_factories_
;
74 scoped_ptr
<Browser
> browser_
;
76 scoped_ptr
<content::TestBrowserThreadBundle
> thread_bundle_
;
79 #endif // CHROME_BROWSER_UI_COCOA_PROFILE_TEST_H_