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 #endif | 23 #endif |
23 | 24 |
24 #if defined(USE_ASH) | 25 #if defined(USE_ASH) |
25 #include "ash/test/ash_test_helper.h" | 26 #include "ash/test/ash_test_helper.h" |
26 #endif | 27 #endif |
27 | 28 |
28 #if defined(TOOLKIT_VIEWS) | 29 #if defined(TOOLKIT_VIEWS) |
29 #include "ui/views/test/test_views_delegate.h" | 30 #include "ui/views/test/test_views_delegate.h" |
30 #endif | 31 #endif |
31 | 32 |
(...skipping 18 matching lines...) Expand all Loading... |
50 void BrowserWithTestWindowTest::SetUp() { | 51 void BrowserWithTestWindowTest::SetUp() { |
51 testing::Test::SetUp(); | 52 testing::Test::SetUp(); |
52 #if defined(OS_CHROMEOS) | 53 #if defined(OS_CHROMEOS) |
53 // TODO(jamescook): Windows Ash support. This will require refactoring | 54 // TODO(jamescook): Windows Ash support. This will require refactoring |
54 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 55 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
55 // perhaps by AshTestHelper owning an AuraTestHelper. | 56 // perhaps by AshTestHelper owning an AuraTestHelper. |
56 ash_test_helper_.reset(new ash::test::AshTestHelper( | 57 ash_test_helper_.reset(new ash::test::AshTestHelper( |
57 base::MessageLoopForUI::current())); | 58 base::MessageLoopForUI::current())); |
58 ash_test_helper_->SetUp(true); | 59 ash_test_helper_->SetUp(true); |
59 #elif defined(USE_AURA) | 60 #elif defined(USE_AURA) |
| 61 // The ContextFactory must exist before any Compositors are created. |
| 62 bool enable_pixel_output = false; |
| 63 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 64 |
60 aura_test_helper_.reset(new aura::test::AuraTestHelper( | 65 aura_test_helper_.reset(new aura::test::AuraTestHelper( |
61 base::MessageLoopForUI::current())); | 66 base::MessageLoopForUI::current())); |
62 bool allow_test_contexts = true; | 67 aura_test_helper_->SetUp(); |
63 aura_test_helper_->SetUp(allow_test_contexts); | |
64 #endif // USE_AURA | 68 #endif // USE_AURA |
65 #if defined(TOOLKIT_VIEWS) | 69 #if defined(TOOLKIT_VIEWS) |
66 views_delegate_.reset(CreateViewsDelegate()); | 70 views_delegate_.reset(CreateViewsDelegate()); |
67 views::ViewsDelegate::views_delegate = views_delegate_.get(); | 71 views::ViewsDelegate::views_delegate = views_delegate_.get(); |
68 #endif | 72 #endif |
69 | 73 |
70 // Subclasses can provide their own Profile. | 74 // Subclasses can provide their own Profile. |
71 profile_ = CreateProfile(); | 75 profile_ = CreateProfile(); |
72 // Subclasses can provide their own test BrowserWindow. If they return NULL | 76 // Subclasses can provide their own test BrowserWindow. If they return NULL |
73 // then Browser will create the a production BrowserWindow and the subclass | 77 // then Browser will create the a production BrowserWindow and the subclass |
74 // is responsible for cleaning it up (usually by NativeWidget destruction). | 78 // is responsible for cleaning it up (usually by NativeWidget destruction). |
75 window_.reset(CreateBrowserWindow()); | 79 window_.reset(CreateBrowserWindow()); |
76 | 80 |
77 browser_.reset(CreateBrowser(profile(), host_desktop_type_, window_.get())); | 81 browser_.reset(CreateBrowser(profile(), host_desktop_type_, window_.get())); |
78 } | 82 } |
79 | 83 |
80 void BrowserWithTestWindowTest::TearDown() { | 84 void BrowserWithTestWindowTest::TearDown() { |
81 // Some tests end up posting tasks to the DB thread that must be completed | 85 // Some tests end up posting tasks to the DB thread that must be completed |
82 // before the profile can be destroyed and the test safely shut down. | 86 // before the profile can be destroyed and the test safely shut down. |
83 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
84 | 88 |
85 // Reset the profile here because some profile keyed services (like the | 89 // Reset the profile here because some profile keyed services (like the |
86 // audio service) depend on test stubs that the helpers below will remove. | 90 // audio service) depend on test stubs that the helpers below will remove. |
87 DestroyBrowserAndProfile(); | 91 DestroyBrowserAndProfile(); |
88 | 92 |
89 #if defined(OS_CHROMEOS) | 93 #if defined(OS_CHROMEOS) |
90 ash_test_helper_->TearDown(); | 94 ash_test_helper_->TearDown(); |
91 #elif defined(USE_AURA) | 95 #elif defined(USE_AURA) |
92 aura_test_helper_->TearDown(); | 96 aura_test_helper_->TearDown(); |
| 97 ui::TerminateContextFactoryForTests(); |
93 #endif | 98 #endif |
94 testing::Test::TearDown(); | 99 testing::Test::TearDown(); |
95 | 100 |
96 // A Task is leaked if we don't destroy everything, then run the message | 101 // A Task is leaked if we don't destroy everything, then run the message |
97 // loop. | 102 // loop. |
98 base::MessageLoop::current()->PostTask(FROM_HERE, | 103 base::MessageLoop::current()->PostTask(FROM_HERE, |
99 base::MessageLoop::QuitClosure()); | 104 base::MessageLoop::QuitClosure()); |
100 base::MessageLoop::current()->Run(); | 105 base::MessageLoop::current()->Run(); |
101 | 106 |
102 #if defined(TOOLKIT_VIEWS) | 107 #if defined(TOOLKIT_VIEWS) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 Browser::CreateParams params(profile, host_desktop_type); | 220 Browser::CreateParams params(profile, host_desktop_type); |
216 params.window = browser_window; | 221 params.window = browser_window; |
217 return new Browser(params); | 222 return new Browser(params); |
218 } | 223 } |
219 | 224 |
220 #if defined(TOOLKIT_VIEWS) | 225 #if defined(TOOLKIT_VIEWS) |
221 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { | 226 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { |
222 return new views::TestViewsDelegate; | 227 return new views::TestViewsDelegate; |
223 } | 228 } |
224 #endif | 229 #endif |
OLD | NEW |