Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 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 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame(); |
| 139 content::SimulateCurrentRenderFrameHostUnloading(old_rfh); | |
| 131 | 140 |
| 132 RenderFrameHost* pending_rfh = RenderFrameHostTester::GetPendingForController( | 141 RenderFrameHost* pending_rfh = RenderFrameHostTester::GetPendingForController( |
| 133 controller); | 142 controller); |
| 134 if (pending_rfh) { | 143 if (pending_rfh) { |
| 135 // Simulate the BeforeUnload_ACK that is received from the current renderer | 144 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 136 // for a cross-site navigation. | 145 // for a cross-site navigation. |
| 137 DCHECK_NE(old_rfh, pending_rfh); | 146 DCHECK_NE(old_rfh, pending_rfh); |
| 138 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); | 147 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); |
|
clamy
2016/08/30 21:17:47
PrepareForCommit actually takes care fo sending th
scottmg
2016/08/30 21:55:27
Thanks, done.
| |
| 139 } | 148 } |
| 140 // Commit on the pending_rfh, if one exists. | 149 // Commit on the pending_rfh, if one exists. |
| 141 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh; | 150 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh; |
| 142 RenderFrameHostTester* test_rfh_tester = RenderFrameHostTester::For(test_rfh); | 151 RenderFrameHostTester* test_rfh_tester = RenderFrameHostTester::For(test_rfh); |
| 143 | 152 |
| 144 // Simulate a SwapOut_ACK before the navigation commits. | 153 // Simulate a SwapOut_ACK before the navigation commits. |
| 145 if (pending_rfh) | 154 if (pending_rfh) |
| 146 RenderFrameHostTester::For(old_rfh)->SimulateSwapOutACK(); | 155 RenderFrameHostTester::For(old_rfh)->SimulateSwapOutACK(); |
| 147 | 156 |
| 148 // For new navigations, we need to send a larger page ID. For renavigations, | 157 // For new navigations, we need to send a larger page ID. For renavigations, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 Browser::CreateParams params(profile); | 238 Browser::CreateParams params(profile); |
| 230 if (hosted_app) { | 239 if (hosted_app) { |
| 231 params = Browser::CreateParams::CreateForApp( | 240 params = Browser::CreateParams::CreateForApp( |
| 232 "Test", true /* trusted_source */, gfx::Rect(), profile); | 241 "Test", true /* trusted_source */, gfx::Rect(), profile); |
| 233 } else { | 242 } else { |
| 234 params.type = browser_type; | 243 params.type = browser_type; |
| 235 } | 244 } |
| 236 params.window = browser_window; | 245 params.window = browser_window; |
| 237 return new Browser(params); | 246 return new Browser(params); |
| 238 } | 247 } |
| OLD | NEW |