| 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/profiles/profile_destroyer.h" | 8 #include "chrome/browser/profiles/profile_destroyer.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" | 10 #include "chrome/browser/ui/browser_navigator.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
| 18 #include "content/public/test/test_renderer_host.h" | 18 #include "content/public/test/test_renderer_host.h" |
| 19 | 19 |
| 20 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
| 21 #include "ui/aura/test/aura_test_helper.h" | 21 #include "ui/aura/test/aura_test_helper.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 #if defined(USE_ASH) | 24 #if defined(USE_ASH) |
| 25 #include "ash/test/ash_test_helper.h" | 25 #include "ash/test/ash_test_helper.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 #if defined(TOOLKIT_VIEWS) |
| 29 #include "ui/views/test/test_views_delegate.h" |
| 30 #endif |
| 31 |
| 28 using content::NavigationController; | 32 using content::NavigationController; |
| 29 using content::RenderViewHost; | 33 using content::RenderViewHost; |
| 30 using content::RenderViewHostTester; | 34 using content::RenderViewHostTester; |
| 31 using content::WebContents; | 35 using content::WebContents; |
| 32 | 36 |
| 33 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 37 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
| 34 : host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE) { | 38 : host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE) { |
| 35 } | 39 } |
| 36 | 40 |
| 37 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 41 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 54 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
| 51 // perhaps by AshTestHelper owning an AuraTestHelper. | 55 // perhaps by AshTestHelper owning an AuraTestHelper. |
| 52 ash_test_helper_.reset(new ash::test::AshTestHelper( | 56 ash_test_helper_.reset(new ash::test::AshTestHelper( |
| 53 base::MessageLoopForUI::current())); | 57 base::MessageLoopForUI::current())); |
| 54 ash_test_helper_->SetUp(true); | 58 ash_test_helper_->SetUp(true); |
| 55 #elif defined(USE_AURA) | 59 #elif defined(USE_AURA) |
| 56 aura_test_helper_.reset(new aura::test::AuraTestHelper( | 60 aura_test_helper_.reset(new aura::test::AuraTestHelper( |
| 57 base::MessageLoopForUI::current())); | 61 base::MessageLoopForUI::current())); |
| 58 aura_test_helper_->SetUp(); | 62 aura_test_helper_->SetUp(); |
| 59 #endif // USE_AURA | 63 #endif // USE_AURA |
| 64 #if defined(TOOLKIT_VIEWS) |
| 65 views_delegate_.reset(CreateViewsDelegate()); |
| 66 views::ViewsDelegate::views_delegate = views_delegate_.get(); |
| 67 #endif |
| 60 | 68 |
| 61 // Subclasses can provide their own Profile. | 69 // Subclasses can provide their own Profile. |
| 62 profile_ = CreateProfile(); | 70 profile_ = CreateProfile(); |
| 63 // Subclasses can provide their own test BrowserWindow. If they return NULL | 71 // Subclasses can provide their own test BrowserWindow. If they return NULL |
| 64 // then Browser will create the a production BrowserWindow and the subclass | 72 // then Browser will create the a production BrowserWindow and the subclass |
| 65 // is responsible for cleaning it up (usually by NativeWidget destruction). | 73 // is responsible for cleaning it up (usually by NativeWidget destruction). |
| 66 window_.reset(CreateBrowserWindow()); | 74 window_.reset(CreateBrowserWindow()); |
| 67 | 75 |
| 68 browser_.reset(CreateBrowser(profile(), host_desktop_type_, window_.get())); | 76 browser_.reset(CreateBrowser(profile(), host_desktop_type_, window_.get())); |
| 69 } | 77 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 82 #elif defined(USE_AURA) | 90 #elif defined(USE_AURA) |
| 83 aura_test_helper_->TearDown(); | 91 aura_test_helper_->TearDown(); |
| 84 #endif | 92 #endif |
| 85 testing::Test::TearDown(); | 93 testing::Test::TearDown(); |
| 86 | 94 |
| 87 // A Task is leaked if we don't destroy everything, then run the message | 95 // A Task is leaked if we don't destroy everything, then run the message |
| 88 // loop. | 96 // loop. |
| 89 base::MessageLoop::current()->PostTask(FROM_HERE, | 97 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 90 base::MessageLoop::QuitClosure()); | 98 base::MessageLoop::QuitClosure()); |
| 91 base::MessageLoop::current()->Run(); | 99 base::MessageLoop::current()->Run(); |
| 100 |
| 101 #if defined(TOOLKIT_VIEWS) |
| 102 views::ViewsDelegate::views_delegate = NULL; |
| 103 views_delegate_.reset(NULL); |
| 104 #endif |
| 92 } | 105 } |
| 93 | 106 |
| 94 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { | 107 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { |
| 95 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); | 108 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); |
| 96 params.tabstrip_index = 0; | 109 params.tabstrip_index = 0; |
| 97 params.disposition = NEW_FOREGROUND_TAB; | 110 params.disposition = NEW_FOREGROUND_TAB; |
| 98 chrome::Navigate(¶ms); | 111 chrome::Navigate(¶ms); |
| 99 CommitPendingLoad(¶ms.target_contents->GetController()); | 112 CommitPendingLoad(¶ms.target_contents->GetController()); |
| 100 } | 113 } |
| 101 | 114 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 208 } |
| 196 | 209 |
| 197 Browser* BrowserWithTestWindowTest::CreateBrowser( | 210 Browser* BrowserWithTestWindowTest::CreateBrowser( |
| 198 Profile* profile, | 211 Profile* profile, |
| 199 chrome::HostDesktopType host_desktop_type, | 212 chrome::HostDesktopType host_desktop_type, |
| 200 BrowserWindow* browser_window) { | 213 BrowserWindow* browser_window) { |
| 201 Browser::CreateParams params(profile, host_desktop_type); | 214 Browser::CreateParams params(profile, host_desktop_type); |
| 202 params.window = browser_window; | 215 params.window = browser_window; |
| 203 return new Browser(params); | 216 return new Browser(params); |
| 204 } | 217 } |
| 218 |
| 219 #if defined(TOOLKIT_VIEWS) |
| 220 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { |
| 221 return new views::TestViewsDelegate; |
| 222 } |
| 223 #endif |
| OLD | NEW |