OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/browser_with_test_window_test.h" | 5 #include "chrome/test/base/browser_with_test_window_test.h" |
6 | 6 |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "chrome/browser/profiles/profile_destroyer.h" |
8 #include "chrome/browser/ui/browser_navigator.h" | 9 #include "chrome/browser/ui/browser_navigator.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
13 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
14 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
17 #include "content/test/test_renderer_host.h" | 18 #include "content/test/test_renderer_host.h" |
(...skipping 20 matching lines...) Expand all Loading... |
38 db_thread_(BrowserThread::DB), | 39 db_thread_(BrowserThread::DB), |
39 file_thread_(BrowserThread::FILE, message_loop()), | 40 file_thread_(BrowserThread::FILE, message_loop()), |
40 file_user_blocking_thread_( | 41 file_user_blocking_thread_( |
41 BrowserThread::FILE_USER_BLOCKING, message_loop()) { | 42 BrowserThread::FILE_USER_BLOCKING, message_loop()) { |
42 db_thread_.Start(); | 43 db_thread_.Start(); |
43 } | 44 } |
44 | 45 |
45 void BrowserWithTestWindowTest::SetUp() { | 46 void BrowserWithTestWindowTest::SetUp() { |
46 testing::Test::SetUp(); | 47 testing::Test::SetUp(); |
47 | 48 |
48 profile_.reset(CreateProfile()); | 49 set_profile(CreateProfile()); |
49 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); | 50 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); |
50 window_.reset(new TestBrowserWindow(browser())); | 51 window_.reset(new TestBrowserWindow(browser())); |
51 browser_->SetWindowForTesting(window_.get()); | 52 browser_->SetWindowForTesting(window_.get()); |
52 #if defined(USE_AURA) | 53 #if defined(USE_AURA) |
53 aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); | 54 aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); |
54 root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); | 55 root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); |
55 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); | 56 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); |
56 test_activation_client_.reset( | 57 test_activation_client_.reset( |
57 new aura::test::TestActivationClient(root_window_.get())); | 58 new aura::test::TestActivationClient(root_window_.get())); |
58 test_stacking_client_.reset( | 59 test_stacking_client_.reset( |
(...skipping 20 matching lines...) Expand all Loading... |
79 // carry on with the test. | 80 // carry on with the test. |
80 base::WaitableEvent done(false, false); | 81 base::WaitableEvent done(false, false); |
81 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 82 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
82 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 83 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
83 done.Wait(); | 84 done.Wait(); |
84 db_thread_.Stop(); | 85 db_thread_.Stop(); |
85 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 86 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
86 MessageLoop::current()->Run(); | 87 MessageLoop::current()->Run(); |
87 } | 88 } |
88 | 89 |
| 90 void BrowserWithTestWindowTest::set_profile(TestingProfile* profile) { |
| 91 if (profile_.get() != NULL) |
| 92 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_.release()); |
| 93 |
| 94 profile_.reset(profile); |
| 95 } |
| 96 |
89 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { | 97 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { |
90 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); | 98 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); |
91 params.tabstrip_index = 0; | 99 params.tabstrip_index = 0; |
92 params.disposition = NEW_FOREGROUND_TAB; | 100 params.disposition = NEW_FOREGROUND_TAB; |
93 browser::Navigate(¶ms); | 101 browser::Navigate(¶ms); |
94 CommitPendingLoad(¶ms.target_contents->web_contents()->GetController()); | 102 CommitPendingLoad(¶ms.target_contents->web_contents()->GetController()); |
95 } | 103 } |
96 | 104 |
97 void BrowserWithTestWindowTest::CommitPendingLoad( | 105 void BrowserWithTestWindowTest::CommitPendingLoad( |
98 NavigationController* controller) { | 106 NavigationController* controller) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Make sure we close all tabs, otherwise Browser isn't happy in its | 162 // Make sure we close all tabs, otherwise Browser isn't happy in its |
155 // destructor. | 163 // destructor. |
156 browser()->CloseAllTabs(); | 164 browser()->CloseAllTabs(); |
157 browser_.reset(NULL); | 165 browser_.reset(NULL); |
158 window_.reset(NULL); | 166 window_.reset(NULL); |
159 } | 167 } |
160 | 168 |
161 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { | 169 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { |
162 return new TestingProfile(); | 170 return new TestingProfile(); |
163 } | 171 } |
OLD | NEW |