| 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 "chrome/browser/ui/browser_navigator.h" | 8 #include "chrome/browser/ui/browser_navigator.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/page_transition_types.h" | 16 #include "content/public/common/page_transition_types.h" |
| 16 #include "content/test/test_renderer_host.h" | 17 #include "content/test/test_renderer_host.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 using content::BrowserThread; | 30 using content::BrowserThread; |
| 30 using content::NavigationController; | 31 using content::NavigationController; |
| 31 using content::RenderViewHost; | 32 using content::RenderViewHost; |
| 32 using content::RenderViewHostTester; | 33 using content::RenderViewHostTester; |
| 33 using content::WebContents; | 34 using content::WebContents; |
| 34 | 35 |
| 35 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 36 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
| 36 : ui_thread_(BrowserThread::UI, message_loop()), | 37 : ui_thread_(BrowserThread::UI, message_loop()), |
| 38 db_thread_(BrowserThread::DB), |
| 37 file_thread_(BrowserThread::FILE, message_loop()), | 39 file_thread_(BrowserThread::FILE, message_loop()), |
| 38 file_user_blocking_thread_( | 40 file_user_blocking_thread_( |
| 39 BrowserThread::FILE_USER_BLOCKING, message_loop()) { | 41 BrowserThread::FILE_USER_BLOCKING, message_loop()) { |
| 42 db_thread_.Start(); |
| 40 } | 43 } |
| 41 | 44 |
| 42 void BrowserWithTestWindowTest::SetUp() { | 45 void BrowserWithTestWindowTest::SetUp() { |
| 43 testing::Test::SetUp(); | 46 testing::Test::SetUp(); |
| 44 | 47 |
| 45 profile_.reset(CreateProfile()); | 48 profile_.reset(CreateProfile()); |
| 46 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); | 49 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); |
| 47 window_.reset(new TestBrowserWindow(browser())); | 50 window_.reset(new TestBrowserWindow(browser())); |
| 48 browser_->SetWindowForTesting(window_.get()); | 51 browser_->SetWindowForTesting(window_.get()); |
| 49 #if defined(USE_AURA) | 52 #if defined(USE_AURA) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 root_window_.reset(); | 68 root_window_.reset(); |
| 66 #endif | 69 #endif |
| 67 } | 70 } |
| 68 | 71 |
| 69 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 72 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
| 70 // A Task is leaked if we don't destroy everything, then run the message | 73 // A Task is leaked if we don't destroy everything, then run the message |
| 71 // loop. | 74 // loop. |
| 72 DestroyBrowser(); | 75 DestroyBrowser(); |
| 73 profile_.reset(NULL); | 76 profile_.reset(NULL); |
| 74 | 77 |
| 78 // Schedule another task on the DB thread to notify us that it's safe to |
| 79 // carry on with the test. |
| 80 base::WaitableEvent done(false, false); |
| 81 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 82 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 83 done.Wait(); |
| 84 db_thread_.Stop(); |
| 75 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 85 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 76 MessageLoop::current()->Run(); | 86 MessageLoop::current()->Run(); |
| 77 } | 87 } |
| 78 | 88 |
| 79 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { | 89 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { |
| 80 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); | 90 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); |
| 81 params.tabstrip_index = 0; | 91 params.tabstrip_index = 0; |
| 82 params.disposition = NEW_FOREGROUND_TAB; | 92 params.disposition = NEW_FOREGROUND_TAB; |
| 83 browser::Navigate(¶ms); | 93 browser::Navigate(¶ms); |
| 84 CommitPendingLoad(¶ms.target_contents->web_contents()->GetController()); | 94 CommitPendingLoad(¶ms.target_contents->web_contents()->GetController()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Make sure we close all tabs, otherwise Browser isn't happy in its | 154 // Make sure we close all tabs, otherwise Browser isn't happy in its |
| 145 // destructor. | 155 // destructor. |
| 146 browser()->CloseAllTabs(); | 156 browser()->CloseAllTabs(); |
| 147 browser_.reset(NULL); | 157 browser_.reset(NULL); |
| 148 window_.reset(NULL); | 158 window_.reset(NULL); |
| 149 } | 159 } |
| 150 | 160 |
| 151 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { | 161 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { |
| 152 return new TestingProfile(); | 162 return new TestingProfile(); |
| 153 } | 163 } |
| OLD | NEW |