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