| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #if defined(USE_ASH) | 27 #if defined(USE_ASH) |
| 28 #include "ash/test/ash_test_helper.h" | 28 #include "ash/test/ash_test_helper.h" |
| 29 #include "ash/test/ash_test_views_delegate.h" | 29 #include "ash/test/ash_test_views_delegate.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 #if defined(TOOLKIT_VIEWS) | 32 #if defined(TOOLKIT_VIEWS) |
| 33 #include "ui/views/test/test_views_delegate.h" | 33 #include "ui/views/test/test_views_delegate.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 using content::NavigationController; | 36 using content::NavigationController; |
| 37 using content::RenderFrameHost; |
| 38 using content::RenderFrameHostTester; |
| 37 using content::RenderViewHost; | 39 using content::RenderViewHost; |
| 38 using content::RenderViewHostTester; | 40 using content::RenderViewHostTester; |
| 39 using content::WebContents; | 41 using content::WebContents; |
| 40 | 42 |
| 41 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 43 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
| 42 : browser_type_(Browser::TYPE_TABBED), | 44 : browser_type_(Browser::TYPE_TABBED), |
| 43 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 45 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
| 44 hosted_app_(false) { | 46 hosted_app_(false) { |
| 45 } | 47 } |
| 46 | 48 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 CommitPendingLoad(¶ms.target_contents->GetController()); | 130 CommitPendingLoad(¶ms.target_contents->GetController()); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void BrowserWithTestWindowTest::CommitPendingLoad( | 133 void BrowserWithTestWindowTest::CommitPendingLoad( |
| 132 NavigationController* controller) { | 134 NavigationController* controller) { |
| 133 if (!controller->GetPendingEntry()) | 135 if (!controller->GetPendingEntry()) |
| 134 return; // Nothing to commit. | 136 return; // Nothing to commit. |
| 135 | 137 |
| 136 RenderViewHost* old_rvh = | 138 RenderViewHost* old_rvh = |
| 137 controller->GetWebContents()->GetRenderViewHost(); | 139 controller->GetWebContents()->GetRenderViewHost(); |
| 140 RenderFrameHost* old_rfh = old_rvh->GetMainFrame(); |
| 138 | 141 |
| 139 RenderViewHost* pending_rvh = RenderViewHostTester::GetPendingForController( | 142 RenderViewHost* pending_rvh = RenderViewHostTester::GetPendingForController( |
| 140 controller); | 143 controller); |
| 141 if (pending_rvh) { | 144 if (pending_rvh) { |
| 142 // Simulate the BeforeUnload_ACK that is received from the current renderer | 145 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 143 // for a cross-site navigation. | 146 // for a cross-site navigation. |
| 144 DCHECK_NE(old_rvh, pending_rvh); | 147 DCHECK_NE(old_rvh, pending_rvh); |
| 145 RenderViewHostTester::For(old_rvh)->SendBeforeUnloadACK(true); | 148 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); |
| 146 } | 149 } |
| 147 // Commit on the pending_rvh, if one exists. | 150 // Commit on the pending_rvh, if one exists. |
| 148 RenderViewHost* test_rvh = pending_rvh ? pending_rvh : old_rvh; | 151 RenderViewHost* test_rvh = pending_rvh ? pending_rvh : old_rvh; |
| 149 RenderViewHostTester* test_rvh_tester = RenderViewHostTester::For(test_rvh); | 152 RenderViewHostTester* test_rvh_tester = RenderViewHostTester::For(test_rvh); |
| 150 | 153 |
| 151 // Simulate a SwapOut_ACK before the navigation commits. | 154 // Simulate a SwapOut_ACK before the navigation commits. |
| 152 if (pending_rvh) | 155 if (pending_rvh) |
| 153 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); | 156 RenderFrameHostTester::For(old_rfh)->SimulateSwapOutACK(); |
| 154 | 157 |
| 155 // For new navigations, we need to send a larger page ID. For renavigations, | 158 // For new navigations, we need to send a larger page ID. For renavigations, |
| 156 // we need to send the preexisting page ID. We can tell these apart because | 159 // we need to send the preexisting page ID. We can tell these apart because |
| 157 // renavigations will have a pending_entry_index while new ones won't (they'll | 160 // renavigations will have a pending_entry_index while new ones won't (they'll |
| 158 // just have a standalong pending_entry that isn't in the list already). | 161 // just have a standalong pending_entry that isn't in the list already). |
| 159 if (controller->GetPendingEntryIndex() >= 0) { | 162 if (controller->GetPendingEntryIndex() >= 0) { |
| 160 test_rvh_tester->SendNavigateWithTransition( | 163 test_rvh_tester->SendNavigateWithTransition( |
| 161 controller->GetPendingEntry()->GetPageID(), | 164 controller->GetPendingEntry()->GetPageID(), |
| 162 controller->GetPendingEntry()->GetURL(), | 165 controller->GetPendingEntry()->GetURL(), |
| 163 controller->GetPendingEntry()->GetTransitionType()); | 166 controller->GetPendingEntry()->GetTransitionType()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 248 |
| 246 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) | 249 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) |
| 247 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { | 250 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { |
| 248 #if defined(USE_ASH) | 251 #if defined(USE_ASH) |
| 249 return new ash::test::AshTestViewsDelegate; | 252 return new ash::test::AshTestViewsDelegate; |
| 250 #else | 253 #else |
| 251 return new views::TestViewsDelegate; | 254 return new views::TestViewsDelegate; |
| 252 #endif | 255 #endif |
| 253 } | 256 } |
| 254 #endif | 257 #endif |
| OLD | NEW |