| 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 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 chrome::Navigate(¶ms); | 126 chrome::Navigate(¶ms); |
| 122 CommitPendingLoad(¶ms.target_contents->GetController()); | 127 CommitPendingLoad(¶ms.target_contents->GetController()); |
| 123 } | 128 } |
| 124 | 129 |
| 125 void BrowserWithTestWindowTest::CommitPendingLoad( | 130 void BrowserWithTestWindowTest::CommitPendingLoad( |
| 126 NavigationController* controller) { | 131 NavigationController* controller) { |
| 127 if (!controller->GetPendingEntry()) | 132 if (!controller->GetPendingEntry()) |
| 128 return; // Nothing to commit. | 133 return; // Nothing to commit. |
| 129 | 134 |
| 130 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame(); | 135 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame(); |
| 136 content::SimulateCurrentRenderFrameHostUnloading(old_rfh); |
| 131 | 137 |
| 132 RenderFrameHost* pending_rfh = RenderFrameHostTester::GetPendingForController( | 138 RenderFrameHost* pending_rfh = RenderFrameHostTester::GetPendingForController( |
| 133 controller); | 139 controller); |
| 134 if (pending_rfh) { | 140 if (pending_rfh) { |
| 135 // Simulate the BeforeUnload_ACK that is received from the current renderer | 141 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 136 // for a cross-site navigation. | 142 // for a cross-site navigation. |
| 137 DCHECK_NE(old_rfh, pending_rfh); | 143 DCHECK_NE(old_rfh, pending_rfh); |
| 138 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); | 144 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); |
| 139 } | 145 } |
| 140 // Commit on the pending_rfh, if one exists. | 146 // Commit on the pending_rfh, if one exists. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 Browser::CreateParams params(profile); | 235 Browser::CreateParams params(profile); |
| 230 if (hosted_app) { | 236 if (hosted_app) { |
| 231 params = Browser::CreateParams::CreateForApp( | 237 params = Browser::CreateParams::CreateForApp( |
| 232 "Test", true /* trusted_source */, gfx::Rect(), profile); | 238 "Test", true /* trusted_source */, gfx::Rect(), profile); |
| 233 } else { | 239 } else { |
| 234 params.type = browser_type; | 240 params.type = browser_type; |
| 235 } | 241 } |
| 236 params.window = browser_window; | 242 params.window = browser_window; |
| 237 return new Browser(params); | 243 return new Browser(params); |
| 238 } | 244 } |
| OLD | NEW |