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