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 "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/profiles/profile_destroyer.h" | 13 #include "chrome/browser/profiles/profile_destroyer.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_navigator.h" | 15 #include "chrome/browser/ui/browser_navigator.h" |
16 #include "chrome/browser/ui/browser_navigator_params.h" | 16 #include "chrome/browser/ui/browser_navigator_params.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/browser_side_navigation_policy.h" |
| 23 #include "content/public/test/browser_side_navigation_test_utils.h" |
22 #include "content/public/test/test_renderer_host.h" | 24 #include "content/public/test/test_renderer_host.h" |
23 #include "ui/base/page_transition_types.h" | 25 #include "ui/base/page_transition_types.h" |
24 | 26 |
25 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
26 #include "ash/test/ash_test_helper.h" | 28 #include "ash/test/ash_test_helper.h" |
27 #elif defined(TOOLKIT_VIEWS) | 29 #elif defined(TOOLKIT_VIEWS) |
28 #include "ui/views/test/scoped_views_test_helper.h" | 30 #include "ui/views/test/scoped_views_test_helper.h" |
29 #endif | 31 #endif |
30 | 32 |
31 #if defined(TOOLKIT_VIEWS) | 33 #if defined(TOOLKIT_VIEWS) |
(...skipping 26 matching lines...) Expand all Loading... |
58 base::MessageLoopForUI::current())); | 60 base::MessageLoopForUI::current())); |
59 ash_test_helper_->SetUp(true, | 61 ash_test_helper_->SetUp(true, |
60 ash::MaterialDesignController::Mode::UNINITIALIZED); | 62 ash::MaterialDesignController::Mode::UNINITIALIZED); |
61 #elif defined(TOOLKIT_VIEWS) | 63 #elif defined(TOOLKIT_VIEWS) |
62 views_test_helper_.reset(new views::ScopedViewsTestHelper()); | 64 views_test_helper_.reset(new views::ScopedViewsTestHelper()); |
63 #endif | 65 #endif |
64 #if defined(TOOLKIT_VIEWS) | 66 #if defined(TOOLKIT_VIEWS) |
65 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); | 67 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); |
66 #endif | 68 #endif |
67 | 69 |
| 70 if (content::IsBrowserSideNavigationEnabled()) |
| 71 content::BrowserSideNavigationSetUp(); |
| 72 |
68 // Subclasses can provide their own Profile. | 73 // Subclasses can provide their own Profile. |
69 profile_ = CreateProfile(); | 74 profile_ = CreateProfile(); |
70 // Subclasses can provide their own test BrowserWindow. If they return NULL | 75 // Subclasses can provide their own test BrowserWindow. If they return NULL |
71 // then Browser will create the a production BrowserWindow and the subclass | 76 // then Browser will create the a production BrowserWindow and the subclass |
72 // is responsible for cleaning it up (usually by NativeWidget destruction). | 77 // is responsible for cleaning it up (usually by NativeWidget destruction). |
73 window_.reset(CreateBrowserWindow()); | 78 window_.reset(CreateBrowserWindow()); |
74 | 79 |
75 browser_.reset( | 80 browser_.reset( |
76 CreateBrowser(profile(), browser_type_, hosted_app_, window_.get())); | 81 CreateBrowser(profile(), browser_type_, hosted_app_, window_.get())); |
77 } | 82 } |
78 | 83 |
79 void BrowserWithTestWindowTest::TearDown() { | 84 void BrowserWithTestWindowTest::TearDown() { |
80 // 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 |
81 // 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. |
82 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
83 | 88 |
84 // Reset the profile here because some profile keyed services (like the | 89 // Reset the profile here because some profile keyed services (like the |
85 // 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. |
86 DestroyBrowserAndProfile(); | 91 DestroyBrowserAndProfile(); |
87 | 92 |
| 93 if (content::IsBrowserSideNavigationEnabled()) |
| 94 content::BrowserSideNavigationTearDown(); |
| 95 |
88 #if defined(TOOLKIT_VIEWS) | 96 #if defined(TOOLKIT_VIEWS) |
89 constrained_window::SetConstrainedWindowViewsClient(nullptr); | 97 constrained_window::SetConstrainedWindowViewsClient(nullptr); |
90 #endif | 98 #endif |
91 | 99 |
92 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
93 ash_test_helper_->TearDown(); | 101 ash_test_helper_->TearDown(); |
94 #elif defined(TOOLKIT_VIEWS) | 102 #elif defined(TOOLKIT_VIEWS) |
95 views_test_helper_.reset(); | 103 views_test_helper_.reset(); |
96 #endif | 104 #endif |
97 | 105 |
(...skipping 22 matching lines...) Expand all Loading... |
120 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 128 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
121 chrome::Navigate(¶ms); | 129 chrome::Navigate(¶ms); |
122 CommitPendingLoad(¶ms.target_contents->GetController()); | 130 CommitPendingLoad(¶ms.target_contents->GetController()); |
123 } | 131 } |
124 | 132 |
125 void BrowserWithTestWindowTest::CommitPendingLoad( | 133 void BrowserWithTestWindowTest::CommitPendingLoad( |
126 NavigationController* controller) { | 134 NavigationController* controller) { |
127 if (!controller->GetPendingEntry()) | 135 if (!controller->GetPendingEntry()) |
128 return; // Nothing to commit. | 136 return; // Nothing to commit. |
129 | 137 |
130 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame(); | 138 RenderFrameHostTester::CommitPendingLoad(controller); |
131 | |
132 RenderFrameHost* pending_rfh = RenderFrameHostTester::GetPendingForController( | |
133 controller); | |
134 if (pending_rfh) { | |
135 // Simulate the BeforeUnload_ACK that is received from the current renderer | |
136 // for a cross-site navigation. | |
137 DCHECK_NE(old_rfh, pending_rfh); | |
138 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); | |
139 } | |
140 // Commit on the pending_rfh, if one exists. | |
141 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh; | |
142 RenderFrameHostTester* test_rfh_tester = RenderFrameHostTester::For(test_rfh); | |
143 | |
144 // Simulate a SwapOut_ACK before the navigation commits. | |
145 if (pending_rfh) | |
146 RenderFrameHostTester::For(old_rfh)->SimulateSwapOutACK(); | |
147 | |
148 // For new navigations, we need to send a larger page ID. For renavigations, | |
149 // we need to send the preexisting page ID. We can tell these apart because | |
150 // renavigations will have a pending_entry_index while new ones won't (they'll | |
151 // just have a standalong pending_entry that isn't in the list already). | |
152 if (controller->GetPendingEntryIndex() >= 0) { | |
153 test_rfh_tester->SendNavigateWithTransition( | |
154 controller->GetPendingEntry()->GetPageID(), | |
155 controller->GetPendingEntry()->GetUniqueID(), | |
156 false, | |
157 controller->GetPendingEntry()->GetURL(), | |
158 controller->GetPendingEntry()->GetTransitionType()); | |
159 } else { | |
160 test_rfh_tester->SendNavigateWithTransition( | |
161 controller->GetWebContents()->GetMaxPageIDForSiteInstance( | |
162 test_rfh->GetSiteInstance()) + 1, | |
163 controller->GetPendingEntry()->GetUniqueID(), | |
164 true, | |
165 controller->GetPendingEntry()->GetURL(), | |
166 controller->GetPendingEntry()->GetTransitionType()); | |
167 } | |
168 } | 139 } |
169 | 140 |
170 void BrowserWithTestWindowTest::NavigateAndCommit( | 141 void BrowserWithTestWindowTest::NavigateAndCommit( |
171 NavigationController* controller, | 142 NavigationController* controller, |
172 const GURL& url) { | 143 const GURL& url) { |
173 controller->LoadURL( | 144 controller->LoadURL( |
174 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 145 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
175 CommitPendingLoad(controller); | 146 CommitPendingLoad(controller); |
176 } | 147 } |
177 | 148 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 Browser::CreateParams params(profile); | 200 Browser::CreateParams params(profile); |
230 if (hosted_app) { | 201 if (hosted_app) { |
231 params = Browser::CreateParams::CreateForApp( | 202 params = Browser::CreateParams::CreateForApp( |
232 "Test", true /* trusted_source */, gfx::Rect(), profile); | 203 "Test", true /* trusted_source */, gfx::Rect(), profile); |
233 } else { | 204 } else { |
234 params.type = browser_type; | 205 params.type = browser_type; |
235 } | 206 } |
236 params.window = browser_window; | 207 params.window = browser_window; |
237 return new Browser(params); | 208 return new Browser(params); |
238 } | 209 } |
OLD | NEW |