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 #include "ui/compositor/test/context_factories_for_test.h" | 22 #include "ui/compositor/test/context_factories_for_test.h" |
23 #include "ui/wm/core/default_activation_client.h" | 23 #include "ui/wm/core/default_activation_client.h" |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(USE_ASH) | 26 #if defined(USE_ASH) |
27 #include "ash/test/ash_test_helper.h" | 27 #include "ash/test/ash_test_helper.h" |
28 #include "ash/test/ash_test_views_delegate.h" | |
29 #endif | 28 #endif |
30 | 29 |
31 #if defined(TOOLKIT_VIEWS) | 30 #if defined(TOOLKIT_VIEWS) |
32 #include "ui/views/test/test_views_delegate.h" | 31 #include "ui/views/test/test_views_delegate.h" |
33 #endif | 32 #endif |
34 | 33 |
35 using content::NavigationController; | 34 using content::NavigationController; |
36 using content::RenderViewHost; | 35 using content::RenderViewHost; |
37 using content::RenderViewHostTester; | 36 using content::RenderViewHostTester; |
38 using content::WebContents; | 37 using content::WebContents; |
(...skipping 14 matching lines...) Expand all Loading... |
53 } | 52 } |
54 | 53 |
55 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 54 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
56 } | 55 } |
57 | 56 |
58 void BrowserWithTestWindowTest::SetUp() { | 57 void BrowserWithTestWindowTest::SetUp() { |
59 testing::Test::SetUp(); | 58 testing::Test::SetUp(); |
60 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
61 // TODO(jamescook): Windows Ash support. This will require refactoring | 60 // TODO(jamescook): Windows Ash support. This will require refactoring |
62 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 61 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
63 // perhaps by AshTestHelper owning an AuraTestHelper. Also, need to cleanup | 62 // perhaps by AshTestHelper owning an AuraTestHelper. |
64 // CreateViewsDelegate() below when cleanup done. | |
65 ash_test_helper_.reset(new ash::test::AshTestHelper( | 63 ash_test_helper_.reset(new ash::test::AshTestHelper( |
66 base::MessageLoopForUI::current())); | 64 base::MessageLoopForUI::current())); |
67 ash_test_helper_->SetUp(true); | 65 ash_test_helper_->SetUp(true); |
68 #elif defined(USE_AURA) | 66 #elif defined(USE_AURA) |
69 // The ContextFactory must exist before any Compositors are created. | 67 // The ContextFactory must exist before any Compositors are created. |
70 bool enable_pixel_output = false; | 68 bool enable_pixel_output = false; |
71 ui::InitializeContextFactoryForTests(enable_pixel_output); | 69 ui::InitializeContextFactoryForTests(enable_pixel_output); |
72 | 70 |
73 aura_test_helper_.reset(new aura::test::AuraTestHelper( | 71 aura_test_helper_.reset(new aura::test::AuraTestHelper( |
74 base::MessageLoopForUI::current())); | 72 base::MessageLoopForUI::current())); |
75 aura_test_helper_->SetUp(); | 73 aura_test_helper_->SetUp(); |
76 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 74 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
77 #endif // USE_AURA | 75 #endif // USE_AURA |
78 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) | 76 #if defined(TOOLKIT_VIEWS) |
79 views_delegate_.reset(CreateViewsDelegate()); | 77 views_delegate_.reset(CreateViewsDelegate()); |
| 78 views::ViewsDelegate::views_delegate = views_delegate_.get(); |
80 #endif | 79 #endif |
81 | 80 |
82 // Subclasses can provide their own Profile. | 81 // Subclasses can provide their own Profile. |
83 profile_ = CreateProfile(); | 82 profile_ = CreateProfile(); |
84 // Subclasses can provide their own test BrowserWindow. If they return NULL | 83 // Subclasses can provide their own test BrowserWindow. If they return NULL |
85 // then Browser will create the a production BrowserWindow and the subclass | 84 // then Browser will create the a production BrowserWindow and the subclass |
86 // is responsible for cleaning it up (usually by NativeWidget destruction). | 85 // is responsible for cleaning it up (usually by NativeWidget destruction). |
87 window_.reset(CreateBrowserWindow()); | 86 window_.reset(CreateBrowserWindow()); |
88 | 87 |
89 browser_.reset(CreateBrowser(profile(), browser_type_, hosted_app_, | 88 browser_.reset(CreateBrowser(profile(), browser_type_, hosted_app_, |
(...skipping 17 matching lines...) Expand all Loading... |
107 #endif | 106 #endif |
108 testing::Test::TearDown(); | 107 testing::Test::TearDown(); |
109 | 108 |
110 // A Task is leaked if we don't destroy everything, then run the message | 109 // A Task is leaked if we don't destroy everything, then run the message |
111 // loop. | 110 // loop. |
112 base::MessageLoop::current()->PostTask(FROM_HERE, | 111 base::MessageLoop::current()->PostTask(FROM_HERE, |
113 base::MessageLoop::QuitClosure()); | 112 base::MessageLoop::QuitClosure()); |
114 base::MessageLoop::current()->Run(); | 113 base::MessageLoop::current()->Run(); |
115 | 114 |
116 #if defined(TOOLKIT_VIEWS) | 115 #if defined(TOOLKIT_VIEWS) |
| 116 views::ViewsDelegate::views_delegate = NULL; |
117 views_delegate_.reset(NULL); | 117 views_delegate_.reset(NULL); |
118 #endif | 118 #endif |
119 } | 119 } |
120 | 120 |
121 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { | 121 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { |
122 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); | 122 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); |
123 params.tabstrip_index = 0; | 123 params.tabstrip_index = 0; |
124 params.disposition = NEW_FOREGROUND_TAB; | 124 params.disposition = NEW_FOREGROUND_TAB; |
125 chrome::Navigate(¶ms); | 125 chrome::Navigate(¶ms); |
126 CommitPendingLoad(¶ms.target_contents->GetController()); | 126 CommitPendingLoad(¶ms.target_contents->GetController()); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 gfx::Rect(), | 234 gfx::Rect(), |
235 profile, | 235 profile, |
236 host_desktop_type); | 236 host_desktop_type); |
237 } else { | 237 } else { |
238 params.type = browser_type; | 238 params.type = browser_type; |
239 } | 239 } |
240 params.window = browser_window; | 240 params.window = browser_window; |
241 return new Browser(params); | 241 return new Browser(params); |
242 } | 242 } |
243 | 243 |
244 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) | 244 #if defined(TOOLKIT_VIEWS) |
245 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { | 245 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { |
246 #if defined(USE_ASH) | |
247 return new ash::test::AshTestViewsDelegate; | |
248 #else | |
249 return new views::TestViewsDelegate; | 246 return new views::TestViewsDelegate; |
250 #endif | |
251 } | 247 } |
252 #endif | 248 #endif |
OLD | NEW |