Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 2248873002: Convert WindowOpenDisposition to an enum class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/base/tracing_browsertest.cc ('k') | chrome/test/base/web_ui_browser_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 std::string post_data("test=body"); 160 std::string post_data("test=body");
161 params.post_data = content::ResourceRequestBody::CreateFromBytes( 161 params.post_data = content::ResourceRequestBody::CreateFromBytes(
162 post_data.data(), post_data.size()); 162 post_data.data(), post_data.size());
163 params.uses_post = true; 163 params.uses_post = true;
164 164
165 NavigateToURL(&params); 165 NavigateToURL(&params);
166 } 166 }
167 167
168 void NavigateToURL(Browser* browser, const GURL& url) { 168 void NavigateToURL(Browser* browser, const GURL& url) {
169 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, 169 NavigateToURLWithDisposition(browser, url, WindowOpenDisposition::CURRENT_TAB,
170 BROWSER_TEST_WAIT_FOR_NAVIGATION); 170 BROWSER_TEST_WAIT_FOR_NAVIGATION);
171 } 171 }
172 172
173 void NavigateToURLWithDispositionBlockUntilNavigationsComplete( 173 void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
174 Browser* browser, 174 Browser* browser,
175 const GURL& url, 175 const GURL& url,
176 int number_of_navigations, 176 int number_of_navigations,
177 WindowOpenDisposition disposition, 177 WindowOpenDisposition disposition,
178 int browser_test_flags) { 178 int browser_test_flags) {
179 TabStripModel* tab_strip = browser->tab_strip_model(); 179 TabStripModel* tab_strip = browser->tab_strip_model();
180 if (disposition == CURRENT_TAB && tab_strip->GetActiveWebContents()) 180 if (disposition == WindowOpenDisposition::CURRENT_TAB &&
181 content::WaitForLoadStop(tab_strip->GetActiveWebContents()); 181 tab_strip->GetActiveWebContents())
182 content::WaitForLoadStop(tab_strip->GetActiveWebContents());
182 content::TestNavigationObserver same_tab_observer( 183 content::TestNavigationObserver same_tab_observer(
183 tab_strip->GetActiveWebContents(), 184 tab_strip->GetActiveWebContents(),
184 number_of_navigations); 185 number_of_navigations);
185 186
186 std::set<Browser*> initial_browsers; 187 std::set<Browser*> initial_browsers;
187 for (auto* browser : *BrowserList::GetInstance()) 188 for (auto* browser : *BrowserList::GetInstance())
188 initial_browsers.insert(browser); 189 initial_browsers.insert(browser);
189 190
190 content::WindowedNotificationObserver tab_added_observer( 191 content::WindowedNotificationObserver tab_added_observer(
191 chrome::NOTIFICATION_TAB_ADDED, 192 chrome::NOTIFICATION_TAB_ADDED,
192 content::NotificationService::AllSources()); 193 content::NotificationService::AllSources());
193 194
194 browser->OpenURL(OpenURLParams( 195 browser->OpenURL(OpenURLParams(
195 url, Referrer(), disposition, ui::PAGE_TRANSITION_TYPED, false)); 196 url, Referrer(), disposition, ui::PAGE_TRANSITION_TYPED, false));
196 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) 197 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
197 browser = WaitForBrowserNotInSet(initial_browsers); 198 browser = WaitForBrowserNotInSet(initial_browsers);
198 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) 199 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
199 tab_added_observer.Wait(); 200 tab_added_observer.Wait();
200 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { 201 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) {
201 // Some other flag caused the wait prior to this. 202 // Some other flag caused the wait prior to this.
202 return; 203 return;
203 } 204 }
204 WebContents* web_contents = NULL; 205 WebContents* web_contents = NULL;
205 if (disposition == NEW_BACKGROUND_TAB) { 206 if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) {
206 // We've opened up a new tab, but not selected it. 207 // We've opened up a new tab, but not selected it.
207 TabStripModel* tab_strip = browser->tab_strip_model(); 208 TabStripModel* tab_strip = browser->tab_strip_model();
208 web_contents = tab_strip->GetWebContentsAt(tab_strip->active_index() + 1); 209 web_contents = tab_strip->GetWebContentsAt(tab_strip->active_index() + 1);
209 EXPECT_TRUE(web_contents != NULL) 210 EXPECT_TRUE(web_contents != NULL)
210 << " Unable to wait for navigation to \"" << url.spec() 211 << " Unable to wait for navigation to \"" << url.spec()
211 << "\" because the new tab is not available yet"; 212 << "\" because the new tab is not available yet";
212 if (!web_contents) 213 if (!web_contents)
213 return; 214 return;
214 } else if ((disposition == CURRENT_TAB) || 215 } else if ((disposition == WindowOpenDisposition::CURRENT_TAB) ||
215 (disposition == NEW_FOREGROUND_TAB) || 216 (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) ||
216 (disposition == SINGLETON_TAB)) { 217 (disposition == WindowOpenDisposition::SINGLETON_TAB)) {
217 // The currently selected tab is the right one. 218 // The currently selected tab is the right one.
218 web_contents = browser->tab_strip_model()->GetActiveWebContents(); 219 web_contents = browser->tab_strip_model()->GetActiveWebContents();
219 } 220 }
220 if (disposition == CURRENT_TAB) { 221 if (disposition == WindowOpenDisposition::CURRENT_TAB) {
221 same_tab_observer.Wait(); 222 same_tab_observer.Wait();
222 return; 223 return;
223 } else if (web_contents) { 224 } else if (web_contents) {
224 content::TestNavigationObserver observer(web_contents, 225 content::TestNavigationObserver observer(web_contents,
225 number_of_navigations); 226 number_of_navigations);
226 observer.Wait(); 227 observer.Wait();
227 return; 228 return;
228 } 229 }
229 EXPECT_TRUE(NULL != web_contents) << " Unable to wait for navigation to \"" 230 EXPECT_TRUE(NULL != web_contents) << " Unable to wait for navigation to \""
230 << url.spec() << "\"" 231 << url.spec() << "\""
231 << " because we can't get the tab contents"; 232 << " because we can't get the tab contents";
232 } 233 }
233 234
234 void NavigateToURLWithDisposition(Browser* browser, 235 void NavigateToURLWithDisposition(Browser* browser,
235 const GURL& url, 236 const GURL& url,
236 WindowOpenDisposition disposition, 237 WindowOpenDisposition disposition,
237 int browser_test_flags) { 238 int browser_test_flags) {
238 NavigateToURLWithDispositionBlockUntilNavigationsComplete( 239 NavigateToURLWithDispositionBlockUntilNavigationsComplete(
239 browser, 240 browser,
240 url, 241 url,
241 1, 242 1,
242 disposition, 243 disposition,
243 browser_test_flags); 244 browser_test_flags);
244 } 245 }
245 246
246 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser, 247 void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
247 const GURL& url, 248 const GURL& url,
248 int number_of_navigations) { 249 int number_of_navigations) {
249 NavigateToURLWithDispositionBlockUntilNavigationsComplete( 250 NavigateToURLWithDispositionBlockUntilNavigationsComplete(
250 browser, 251 browser, url, number_of_navigations, WindowOpenDisposition::CURRENT_TAB,
251 url,
252 number_of_navigations,
253 CURRENT_TAB,
254 BROWSER_TEST_WAIT_FOR_NAVIGATION); 252 BROWSER_TEST_WAIT_FOR_NAVIGATION);
255 } 253 }
256 254
257 base::FilePath GetTestFilePath(const base::FilePath& dir, 255 base::FilePath GetTestFilePath(const base::FilePath& dir,
258 const base::FilePath& file) { 256 const base::FilePath& file) {
259 base::FilePath path; 257 base::FilePath path;
260 PathService::Get(chrome::DIR_TEST_DATA, &path); 258 PathService::Get(chrome::DIR_TEST_DATA, &path);
261 return path.Append(dir).Append(file); 259 return path.Append(dir).Append(file);
262 } 260 }
263 261
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 new content::MessageLoopRunner; 534 new content::MessageLoopRunner;
537 WaitHistoryLoadedObserver observer(runner.get()); 535 WaitHistoryLoadedObserver observer(runner.get());
538 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 536 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
539 scoped_observer(&observer); 537 scoped_observer(&observer);
540 scoped_observer.Add(history_service); 538 scoped_observer.Add(history_service);
541 runner->Run(); 539 runner->Run();
542 } 540 }
543 } 541 }
544 542
545 } // namespace ui_test_utils 543 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/tracing_browsertest.cc ('k') | chrome/test/base/web_ui_browser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698