| 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 18 matching lines...) Expand all Loading... |
| 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; | 37 using content::RenderFrameHost; |
| 38 using content::RenderFrameHostTester; | 38 using content::RenderFrameHostTester; |
| 39 using content::RenderViewHost; | |
| 40 using content::RenderViewHostTester; | |
| 41 using content::WebContents; | 39 using content::WebContents; |
| 42 | 40 |
| 43 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 41 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
| 44 : browser_type_(Browser::TYPE_TABBED), | 42 : browser_type_(Browser::TYPE_TABBED), |
| 45 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 43 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
| 46 hosted_app_(false) { | 44 hosted_app_(false) { |
| 47 } | 45 } |
| 48 | 46 |
| 49 BrowserWithTestWindowTest::BrowserWithTestWindowTest( | 47 BrowserWithTestWindowTest::BrowserWithTestWindowTest( |
| 50 Browser::Type browser_type, | 48 Browser::Type browser_type, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 params.disposition = NEW_FOREGROUND_TAB; | 126 params.disposition = NEW_FOREGROUND_TAB; |
| 129 chrome::Navigate(¶ms); | 127 chrome::Navigate(¶ms); |
| 130 CommitPendingLoad(¶ms.target_contents->GetController()); | 128 CommitPendingLoad(¶ms.target_contents->GetController()); |
| 131 } | 129 } |
| 132 | 130 |
| 133 void BrowserWithTestWindowTest::CommitPendingLoad( | 131 void BrowserWithTestWindowTest::CommitPendingLoad( |
| 134 NavigationController* controller) { | 132 NavigationController* controller) { |
| 135 if (!controller->GetPendingEntry()) | 133 if (!controller->GetPendingEntry()) |
| 136 return; // Nothing to commit. | 134 return; // Nothing to commit. |
| 137 | 135 |
| 138 RenderViewHost* old_rvh = | 136 RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame(); |
| 139 controller->GetWebContents()->GetRenderViewHost(); | |
| 140 RenderFrameHost* old_rfh = old_rvh->GetMainFrame(); | |
| 141 | 137 |
| 142 RenderViewHost* pending_rvh = RenderViewHostTester::GetPendingForController( | 138 RenderFrameHost* pending_rfh = RenderFrameHostTester::GetPendingForController( |
| 143 controller); | 139 controller); |
| 144 if (pending_rvh) { | 140 if (pending_rfh) { |
| 145 // Simulate the BeforeUnload_ACK that is received from the current renderer | 141 // Simulate the BeforeUnload_ACK that is received from the current renderer |
| 146 // for a cross-site navigation. | 142 // for a cross-site navigation. |
| 147 DCHECK_NE(old_rvh, pending_rvh); | 143 DCHECK_NE(old_rfh, pending_rfh); |
| 148 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); | 144 RenderFrameHostTester::For(old_rfh)->SendBeforeUnloadACK(true); |
| 149 } | 145 } |
| 150 // Commit on the pending_rvh, if one exists. | 146 // Commit on the pending_rfh, if one exists. |
| 151 RenderViewHost* test_rvh = pending_rvh ? pending_rvh : old_rvh; | 147 RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh; |
| 152 RenderViewHostTester* test_rvh_tester = RenderViewHostTester::For(test_rvh); | 148 RenderFrameHostTester* test_rfh_tester = RenderFrameHostTester::For(test_rfh); |
| 153 | 149 |
| 154 // Simulate a SwapOut_ACK before the navigation commits. | 150 // Simulate a SwapOut_ACK before the navigation commits. |
| 155 if (pending_rvh) | 151 if (pending_rfh) |
| 156 RenderFrameHostTester::For(old_rfh)->SimulateSwapOutACK(); | 152 RenderFrameHostTester::For(old_rfh)->SimulateSwapOutACK(); |
| 157 | 153 |
| 158 // For new navigations, we need to send a larger page ID. For renavigations, | 154 // For new navigations, we need to send a larger page ID. For renavigations, |
| 159 // we need to send the preexisting page ID. We can tell these apart because | 155 // we need to send the preexisting page ID. We can tell these apart because |
| 160 // renavigations will have a pending_entry_index while new ones won't (they'll | 156 // renavigations will have a pending_entry_index while new ones won't (they'll |
| 161 // just have a standalong pending_entry that isn't in the list already). | 157 // just have a standalong pending_entry that isn't in the list already). |
| 162 if (controller->GetPendingEntryIndex() >= 0) { | 158 if (controller->GetPendingEntryIndex() >= 0) { |
| 163 test_rvh_tester->SendNavigateWithTransition( | 159 test_rfh_tester->SendNavigateWithTransition( |
| 164 controller->GetPendingEntry()->GetPageID(), | 160 controller->GetPendingEntry()->GetPageID(), |
| 165 controller->GetPendingEntry()->GetURL(), | 161 controller->GetPendingEntry()->GetURL(), |
| 166 controller->GetPendingEntry()->GetTransitionType()); | 162 controller->GetPendingEntry()->GetTransitionType()); |
| 167 } else { | 163 } else { |
| 168 test_rvh_tester->SendNavigateWithTransition( | 164 test_rfh_tester->SendNavigateWithTransition( |
| 169 controller->GetWebContents()-> | 165 controller->GetWebContents()->GetMaxPageIDForSiteInstance( |
| 170 GetMaxPageIDForSiteInstance(test_rvh->GetSiteInstance()) + 1, | 166 test_rfh->GetSiteInstance()) + 1, |
| 171 controller->GetPendingEntry()->GetURL(), | 167 controller->GetPendingEntry()->GetURL(), |
| 172 controller->GetPendingEntry()->GetTransitionType()); | 168 controller->GetPendingEntry()->GetTransitionType()); |
| 173 } | 169 } |
| 174 } | 170 } |
| 175 | 171 |
| 176 void BrowserWithTestWindowTest::NavigateAndCommit( | 172 void BrowserWithTestWindowTest::NavigateAndCommit( |
| 177 NavigationController* controller, | 173 NavigationController* controller, |
| 178 const GURL& url) { | 174 const GURL& url) { |
| 179 controller->LoadURL( | 175 controller->LoadURL( |
| 180 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 176 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 244 |
| 249 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) | 245 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) |
| 250 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { | 246 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { |
| 251 #if defined(USE_ASH) | 247 #if defined(USE_ASH) |
| 252 return new ash::test::AshTestViewsDelegate; | 248 return new ash::test::AshTestViewsDelegate; |
| 253 #else | 249 #else |
| 254 return new views::TestViewsDelegate; | 250 return new views::TestViewsDelegate; |
| 255 #endif | 251 #endif |
| 256 } | 252 } |
| 257 #endif | 253 #endif |
| OLD | NEW |