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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <ole2.h> | 8 #include <ole2.h> |
9 #endif // defined(OS_WIN) | 9 #endif // defined(OS_WIN) |
10 | 10 |
11 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/browser_navigator.h" | 12 #include "chrome/browser/ui/browser_navigator.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "content/public/common/page_transition_types.h" | 19 #include "content/public/common/page_transition_types.h" |
| 20 #include "content/test/test_renderer_host.h" |
20 | 21 |
21 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
22 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/test_activation_client.h" | 24 #include "ui/aura/test/test_activation_client.h" |
24 #include "ui/aura/test/test_stacking_client.h" | 25 #include "ui/aura/test/test_stacking_client.h" |
25 #endif | 26 #endif |
26 | 27 |
27 using content::BrowserThread; | 28 using content::BrowserThread; |
28 using content::NavigationController; | 29 using content::NavigationController; |
29 using content::TestRenderViewHost; | 30 using content::RenderViewHost; |
| 31 using content::RenderViewHostTester; |
30 using content::WebContents; | 32 using content::WebContents; |
31 | 33 |
32 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 34 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
33 : ui_thread_(BrowserThread::UI, message_loop()), | 35 : ui_thread_(BrowserThread::UI, message_loop()), |
34 file_thread_(BrowserThread::FILE, message_loop()), | 36 file_thread_(BrowserThread::FILE, message_loop()), |
35 file_user_blocking_thread_( | 37 file_user_blocking_thread_( |
36 BrowserThread::FILE_USER_BLOCKING, message_loop()), | 38 BrowserThread::FILE_USER_BLOCKING, message_loop()) { |
37 rph_factory_(), | |
38 rvh_factory_(&rph_factory_) { | |
39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
40 OleInitialize(NULL); | 40 OleInitialize(NULL); |
41 #endif | 41 #endif |
42 } | 42 } |
43 | 43 |
44 void BrowserWithTestWindowTest::SetUp() { | 44 void BrowserWithTestWindowTest::SetUp() { |
45 testing::Test::SetUp(); | 45 testing::Test::SetUp(); |
46 | 46 |
47 profile_.reset(CreateProfile()); | 47 profile_.reset(CreateProfile()); |
48 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); | 48 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); |
(...skipping 24 matching lines...) Expand all Loading... |
73 profile_.reset(NULL); | 73 profile_.reset(NULL); |
74 | 74 |
75 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 75 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
76 MessageLoop::current()->Run(); | 76 MessageLoop::current()->Run(); |
77 | 77 |
78 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
79 OleUninitialize(); | 79 OleUninitialize(); |
80 #endif | 80 #endif |
81 } | 81 } |
82 | 82 |
83 TestRenderViewHost* BrowserWithTestWindowTest::TestRenderViewHostForTab( | |
84 WebContents* web_contents) { | |
85 return static_cast<TestRenderViewHost*>(web_contents->GetRenderViewHost()); | |
86 } | |
87 | |
88 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { | 83 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { |
89 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); | 84 browser::NavigateParams params(browser, url, content::PAGE_TRANSITION_TYPED); |
90 params.tabstrip_index = 0; | 85 params.tabstrip_index = 0; |
91 params.disposition = NEW_FOREGROUND_TAB; | 86 params.disposition = NEW_FOREGROUND_TAB; |
92 browser::Navigate(¶ms); | 87 browser::Navigate(¶ms); |
93 CommitPendingLoad(¶ms.target_contents->web_contents()->GetController()); | 88 CommitPendingLoad(¶ms.target_contents->web_contents()->GetController()); |
94 } | 89 } |
95 | 90 |
96 void BrowserWithTestWindowTest::CommitPendingLoad( | 91 void BrowserWithTestWindowTest::CommitPendingLoad( |
97 NavigationController* controller) { | 92 NavigationController* controller) { |
98 if (!controller->GetPendingEntry()) | 93 if (!controller->GetPendingEntry()) |
99 return; // Nothing to commit. | 94 return; // Nothing to commit. |
100 | 95 |
101 TestRenderViewHost* old_rvh = | 96 RenderViewHost* old_rvh = |
102 TestRenderViewHostForTab(controller->GetWebContents()); | 97 controller->GetWebContents()->GetRenderViewHost(); |
103 | 98 |
104 TestRenderViewHost* pending_rvh = TestRenderViewHost::GetPendingForController( | 99 RenderViewHost* pending_rvh = RenderViewHostTester::GetPendingForController( |
105 controller); | 100 controller); |
106 if (pending_rvh) { | 101 if (pending_rvh) { |
107 // Simulate the ShouldClose_ACK that is received from the current renderer | 102 // Simulate the ShouldClose_ACK that is received from the current renderer |
108 // for a cross-site navigation. | 103 // for a cross-site navigation. |
109 DCHECK_NE(old_rvh, pending_rvh); | 104 DCHECK_NE(old_rvh, pending_rvh); |
110 old_rvh->SendShouldCloseACK(true); | 105 RenderViewHostTester::For(old_rvh)->SendShouldCloseACK(true); |
111 } | 106 } |
112 // Commit on the pending_rvh, if one exists. | 107 // Commit on the pending_rvh, if one exists. |
113 TestRenderViewHost* test_rvh = pending_rvh ? pending_rvh : old_rvh; | 108 RenderViewHost* test_rvh = pending_rvh ? pending_rvh : old_rvh; |
| 109 RenderViewHostTester* test_rvh_tester = RenderViewHostTester::For(test_rvh); |
114 | 110 |
115 // For new navigations, we need to send a larger page ID. For renavigations, | 111 // For new navigations, we need to send a larger page ID. For renavigations, |
116 // we need to send the preexisting page ID. We can tell these apart because | 112 // we need to send the preexisting page ID. We can tell these apart because |
117 // renavigations will have a pending_entry_index while new ones won't (they'll | 113 // renavigations will have a pending_entry_index while new ones won't (they'll |
118 // just have a standalong pending_entry that isn't in the list already). | 114 // just have a standalong pending_entry that isn't in the list already). |
119 if (controller->GetPendingEntryIndex() >= 0) { | 115 if (controller->GetPendingEntryIndex() >= 0) { |
120 test_rvh->SendNavigateWithTransition( | 116 test_rvh_tester->SendNavigateWithTransition( |
121 controller->GetPendingEntry()->GetPageID(), | 117 controller->GetPendingEntry()->GetPageID(), |
122 controller->GetPendingEntry()->GetURL(), | 118 controller->GetPendingEntry()->GetURL(), |
123 controller->GetPendingEntry()->GetTransitionType()); | 119 controller->GetPendingEntry()->GetTransitionType()); |
124 } else { | 120 } else { |
125 test_rvh->SendNavigateWithTransition( | 121 test_rvh_tester->SendNavigateWithTransition( |
126 controller->GetWebContents()-> | 122 controller->GetWebContents()-> |
127 GetMaxPageIDForSiteInstance(test_rvh->GetSiteInstance()) + 1, | 123 GetMaxPageIDForSiteInstance(test_rvh->GetSiteInstance()) + 1, |
128 controller->GetPendingEntry()->GetURL(), | 124 controller->GetPendingEntry()->GetURL(), |
129 controller->GetPendingEntry()->GetTransitionType()); | 125 controller->GetPendingEntry()->GetTransitionType()); |
130 } | 126 } |
131 | 127 |
132 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation | |
133 // without making any network requests. | |
134 if (pending_rvh) | 128 if (pending_rvh) |
135 old_rvh->OnSwapOutACK(); | 129 RenderViewHostTester::For(old_rvh)->SimulateSwapOutACK(); |
136 } | 130 } |
137 | 131 |
138 void BrowserWithTestWindowTest::NavigateAndCommit( | 132 void BrowserWithTestWindowTest::NavigateAndCommit( |
139 NavigationController* controller, | 133 NavigationController* controller, |
140 const GURL& url) { | 134 const GURL& url) { |
141 controller->LoadURL( | 135 controller->LoadURL( |
142 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 136 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
143 CommitPendingLoad(controller); | 137 CommitPendingLoad(controller); |
144 } | 138 } |
145 | 139 |
146 void BrowserWithTestWindowTest::NavigateAndCommitActiveTab(const GURL& url) { | 140 void BrowserWithTestWindowTest::NavigateAndCommitActiveTab(const GURL& url) { |
147 NavigateAndCommit(&browser()->GetSelectedTabContentsWrapper()-> | 141 NavigateAndCommit(&browser()->GetSelectedTabContentsWrapper()-> |
148 web_contents()->GetController(), url); | 142 web_contents()->GetController(), url); |
149 } | 143 } |
150 | 144 |
151 void BrowserWithTestWindowTest::DestroyBrowser() { | 145 void BrowserWithTestWindowTest::DestroyBrowser() { |
152 if (!browser_.get()) | 146 if (!browser_.get()) |
153 return; | 147 return; |
154 // Make sure we close all tabs, otherwise Browser isn't happy in its | 148 // Make sure we close all tabs, otherwise Browser isn't happy in its |
155 // destructor. | 149 // destructor. |
156 browser()->CloseAllTabs(); | 150 browser()->CloseAllTabs(); |
157 browser_.reset(NULL); | 151 browser_.reset(NULL); |
158 window_.reset(NULL); | 152 window_.reset(NULL); |
159 } | 153 } |
160 | 154 |
161 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { | 155 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { |
162 return new TestingProfile(); | 156 return new TestingProfile(); |
163 } | 157 } |
OLD | NEW |