Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / cocoa_profile_test.mm
blob10b9269d6511e8cc14b012184f3e6742e3908443
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/prefs/pref_service_syncable.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h"
21 #include "components/bookmarks/test/bookmark_test_helpers.h"
22 #include "content/public/test/test_browser_thread_bundle.h"
24 CocoaProfileTest::CocoaProfileTest()
25     : profile_manager_(TestingBrowserProcess::GetGlobal()),
26       profile_(NULL),
27       thread_bundle_(new content::TestBrowserThreadBundle) {
30 CocoaProfileTest::~CocoaProfileTest() {
31   // Delete the testing profile on the UI thread. But first release the
32   // browser, since it may trigger accesses to the profile upon destruction.
33   browser_.reset();
35   base::RunLoop().RunUntilIdle();
37   // Some services created on the TestingProfile require deletion on the UI
38   // thread. If the scoper in TestingBrowserProcess, owned by ChromeTestSuite,
39   // were to delete the ProfileManager, the UI thread would at that point no
40   // longer exist.
41   TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
43   // Make sure any pending tasks run before we destroy other threads.
44   base::RunLoop().RunUntilIdle();
47 void CocoaProfileTest::AddTestingFactories(
48     const TestingProfile::TestingFactories& testing_factories) {
49   for (auto testing_factory : testing_factories) {
50     testing_factories_.push_back(testing_factory);
51   }
54 void CocoaProfileTest::SetUp() {
55   CocoaTest::SetUp();
57   ASSERT_TRUE(profile_manager_.SetUp());
59   profile_ = profile_manager_.CreateTestingProfile(
60       "Person 1", scoped_ptr<PrefServiceSyncable>(),
61       base::UTF8ToUTF16("Person 1"), 0, std::string(),
62       testing_factories_);
63   ASSERT_TRUE(profile_);
65   // TODO(shess): These are needed in case someone creates a browser
66   // window off of browser_.  pkasting indicates that other
67   // platforms use a stub |BrowserWindow| and thus don't need to do
68   // this.
69   // http://crbug.com/39725
70   TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
71       profile_, &TemplateURLServiceFactory::BuildInstanceFor);
72   AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
73       profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
75   profile_->CreateBookmarkModel(true);
76   bookmarks::test::WaitForBookmarkModelToLoad(
77       BookmarkModelFactory::GetForProfile(profile_));
79   browser_.reset(CreateBrowser());
80   ASSERT_TRUE(browser_.get());
83 void CocoaProfileTest::TearDown() {
84   if (browser_.get() && browser_->window())
85     CloseBrowserWindow();
87   CocoaTest::TearDown();
90 void CocoaProfileTest::CloseBrowserWindow() {
91   // Check to make sure a window was actually created.
92   DCHECK(browser_->window());
93   browser_->tab_strip_model()->CloseAllTabs();
94   chrome::CloseWindow(browser_.get());
95   // |browser_| will be deleted by its BrowserWindowController.
96   ignore_result(browser_.release());
99 Browser* CocoaProfileTest::CreateBrowser() {
100   return new Browser(Browser::CreateParams(profile(),
101                                            chrome::GetActiveDesktop()));