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

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

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 NOTREACHED(); 297 NOTREACHED();
298 return; 298 return;
299 } 299 }
300 content::BrowserThread::PostTask(thread_id, FROM_HERE, 300 content::BrowserThread::PostTask(thread_id, FROM_HERE,
301 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id)); 301 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id));
302 302
303 ui_test_utils::RunMessageLoop(); 303 ui_test_utils::RunMessageLoop();
304 } 304 }
305 305
306 bool GetCurrentTabTitle(const Browser* browser, string16* title) { 306 bool GetCurrentTabTitle(const Browser* browser, string16* title) {
307 TabContents* tab_contents = browser->GetSelectedTabContents(); 307 WebContents* web_contents = browser->GetSelectedWebContents();
308 if (!tab_contents) 308 if (!web_contents)
309 return false; 309 return false;
310 NavigationEntry* last_entry = tab_contents->GetController().GetActiveEntry(); 310 NavigationEntry* last_entry = web_contents->GetController().GetActiveEntry();
311 if (!last_entry) 311 if (!last_entry)
312 return false; 312 return false;
313 title->assign(last_entry->GetTitleForDisplay("")); 313 title->assign(last_entry->GetTitleForDisplay(""));
314 return true; 314 return true;
315 } 315 }
316 316
317 void WaitForNavigations(NavigationController* controller, 317 void WaitForNavigations(NavigationController* controller,
318 int number_of_navigations) { 318 int number_of_navigations) {
319 TestNavigationObserver observer( 319 TestNavigationObserver observer(
320 content::Source<NavigationController>(controller), NULL, 320 content::Source<NavigationController>(controller), NULL,
(...skipping 10 matching lines...) Expand all
331 content::Source<content::WebContentsDelegate>(browser)); 331 content::Source<content::WebContentsDelegate>(browser));
332 } 332 }
333 333
334 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) { 334 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) {
335 TestNotificationObserver observer; 335 TestNotificationObserver observer;
336 RegisterAndWait(&observer, 336 RegisterAndWait(&observer,
337 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, 337 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
338 content::Source<ExtensionAction>(browser_action)); 338 content::Source<ExtensionAction>(browser_action));
339 } 339 }
340 340
341 void WaitForLoadStop(TabContents* tab) { 341 void WaitForLoadStop(WebContents* tab) {
342 WindowedNotificationObserver load_stop_observer( 342 WindowedNotificationObserver load_stop_observer(
343 content::NOTIFICATION_LOAD_STOP, 343 content::NOTIFICATION_LOAD_STOP,
344 content::Source<NavigationController>(&tab->GetController())); 344 content::Source<NavigationController>(&tab->GetController()));
345 // In many cases, the load may have finished before we get here. Only wait if 345 // In many cases, the load may have finished before we get here. Only wait if
346 // the tab still has a pending navigation. 346 // the tab still has a pending navigation.
347 if (!tab->IsLoading()) 347 if (!tab->IsLoading())
348 return; 348 return;
349 load_stop_observer.Wait(); 349 load_stop_observer.Wait();
350 } 350 }
351 351
(...skipping 12 matching lines...) Expand all
364 // The new browser should never be in |excluded_browsers|. 364 // The new browser should never be in |excluded_browsers|.
365 DCHECK(!ContainsKey(excluded_browsers, new_browser)); 365 DCHECK(!ContainsKey(excluded_browsers, new_browser));
366 } 366 }
367 return new_browser; 367 return new_browser;
368 } 368 }
369 369
370 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { 370 void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
371 Browser::OpenURLOffTheRecord(profile, url); 371 Browser::OpenURLOffTheRecord(profile, url);
372 Browser* browser = BrowserList::FindTabbedBrowser( 372 Browser* browser = BrowserList::FindTabbedBrowser(
373 profile->GetOffTheRecordProfile(), false); 373 profile->GetOffTheRecordProfile(), false);
374 WaitForNavigations(&browser->GetSelectedTabContents()->GetController(), 1); 374 WaitForNavigations(&browser->GetSelectedWebContents()->GetController(), 1);
375 } 375 }
376 376
377 void NavigateToURL(browser::NavigateParams* params) { 377 void NavigateToURL(browser::NavigateParams* params) {
378 TestNavigationObserver observer( 378 TestNavigationObserver observer(
379 content::NotificationService::AllSources(), NULL, 1); 379 content::NotificationService::AllSources(), NULL, 1);
380 browser::Navigate(params); 380 browser::Navigate(params);
381 observer.WaitForObservation( 381 observer.WaitForObservation(
382 base::Bind(&ui_test_utils::RunMessageLoop), 382 base::Bind(&ui_test_utils::RunMessageLoop),
383 base::Bind(&MessageLoop::Quit, 383 base::Bind(&MessageLoop::Quit,
384 base::Unretained(MessageLoopForUI::current()))); 384 base::Unretained(MessageLoopForUI::current())));
385 385
386 } 386 }
387 387
388 void NavigateToURL(Browser* browser, const GURL& url) { 388 void NavigateToURL(Browser* browser, const GURL& url) {
389 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, 389 NavigateToURLWithDisposition(browser, url, CURRENT_TAB,
390 BROWSER_TEST_WAIT_FOR_NAVIGATION); 390 BROWSER_TEST_WAIT_FOR_NAVIGATION);
391 } 391 }
392 392
393 // Navigates the specified tab (via |disposition|) of |browser| to |url|, 393 // Navigates the specified tab (via |disposition|) of |browser| to |url|,
394 // blocking until the |number_of_navigations| specified complete. 394 // blocking until the |number_of_navigations| specified complete.
395 // |disposition| indicates what tab the download occurs in, and 395 // |disposition| indicates what tab the download occurs in, and
396 // |browser_test_flags| controls what to wait for before continuing. 396 // |browser_test_flags| controls what to wait for before continuing.
397 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( 397 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
398 Browser* browser, 398 Browser* browser,
399 const GURL& url, 399 const GURL& url,
400 int number_of_navigations, 400 int number_of_navigations,
401 WindowOpenDisposition disposition, 401 WindowOpenDisposition disposition,
402 int browser_test_flags) { 402 int browser_test_flags) {
403 if (disposition == CURRENT_TAB && browser->GetSelectedTabContents()) 403 if (disposition == CURRENT_TAB && browser->GetSelectedWebContents())
404 WaitForLoadStop(browser->GetSelectedTabContents()); 404 WaitForLoadStop(browser->GetSelectedWebContents());
405 TestNavigationObserver same_tab_observer( 405 TestNavigationObserver same_tab_observer(
406 content::Source<NavigationController>( 406 content::Source<NavigationController>(
407 &browser->GetSelectedTabContents()->GetController()), 407 &browser->GetSelectedWebContents()->GetController()),
408 NULL, 408 NULL,
409 number_of_navigations); 409 number_of_navigations);
410 410
411 std::set<Browser*> initial_browsers; 411 std::set<Browser*> initial_browsers;
412 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); 412 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
413 iter != BrowserList::end(); 413 iter != BrowserList::end();
414 ++iter) { 414 ++iter) {
415 initial_browsers.insert(*iter); 415 initial_browsers.insert(*iter);
416 } 416 }
417 417
418 WindowedNotificationObserver tab_added_observer( 418 WindowedNotificationObserver tab_added_observer(
419 content::NOTIFICATION_TAB_ADDED, 419 content::NOTIFICATION_TAB_ADDED,
420 content::NotificationService::AllSources()); 420 content::NotificationService::AllSources());
421 421
422 browser->OpenURL(OpenURLParams( 422 browser->OpenURL(OpenURLParams(
423 url, Referrer(), disposition, content::PAGE_TRANSITION_TYPED, false)); 423 url, Referrer(), disposition, content::PAGE_TRANSITION_TYPED, false));
424 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) 424 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
425 browser = WaitForBrowserNotInSet(initial_browsers); 425 browser = WaitForBrowserNotInSet(initial_browsers);
426 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) 426 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
427 tab_added_observer.Wait(); 427 tab_added_observer.Wait();
428 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { 428 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) {
429 // Some other flag caused the wait prior to this. 429 // Some other flag caused the wait prior to this.
430 return; 430 return;
431 } 431 }
432 TabContents* tab_contents = NULL; 432 WebContents* web_contents = NULL;
433 if (disposition == NEW_BACKGROUND_TAB) { 433 if (disposition == NEW_BACKGROUND_TAB) {
434 // We've opened up a new tab, but not selected it. 434 // We've opened up a new tab, but not selected it.
435 tab_contents = browser->GetTabContentsAt(browser->active_index() + 1); 435 web_contents = browser->GetTabContentsAt(browser->active_index() + 1);
436 EXPECT_TRUE(tab_contents != NULL) 436 EXPECT_TRUE(web_contents != NULL)
437 << " Unable to wait for navigation to \"" << url.spec() 437 << " Unable to wait for navigation to \"" << url.spec()
438 << "\" because the new tab is not available yet"; 438 << "\" because the new tab is not available yet";
439 return; 439 return;
440 } else if ((disposition == CURRENT_TAB) || 440 } else if ((disposition == CURRENT_TAB) ||
441 (disposition == NEW_FOREGROUND_TAB) || 441 (disposition == NEW_FOREGROUND_TAB) ||
442 (disposition == SINGLETON_TAB)) { 442 (disposition == SINGLETON_TAB)) {
443 // The currently selected tab is the right one. 443 // The currently selected tab is the right one.
444 tab_contents = browser->GetSelectedTabContents(); 444 web_contents = browser->GetSelectedWebContents();
445 } 445 }
446 if (disposition == CURRENT_TAB) { 446 if (disposition == CURRENT_TAB) {
447 same_tab_observer.WaitForObservation( 447 same_tab_observer.WaitForObservation(
448 base::Bind(&ui_test_utils::RunMessageLoop), 448 base::Bind(&ui_test_utils::RunMessageLoop),
449 base::Bind(&MessageLoop::Quit, 449 base::Bind(&MessageLoop::Quit,
450 base::Unretained(MessageLoopForUI::current()))); 450 base::Unretained(MessageLoopForUI::current())));
451 return; 451 return;
452 } else if (tab_contents) { 452 } else if (web_contents) {
453 NavigationController* controller = &tab_contents->GetController(); 453 NavigationController* controller = &web_contents->GetController();
454 WaitForNavigations(controller, number_of_navigations); 454 WaitForNavigations(controller, number_of_navigations);
455 return; 455 return;
456 } 456 }
457 EXPECT_TRUE(NULL != tab_contents) << " Unable to wait for navigation to \"" 457 EXPECT_TRUE(NULL != web_contents) << " Unable to wait for navigation to \""
458 << url.spec() << "\"" 458 << url.spec() << "\""
459 << " because we can't get the tab contents"; 459 << " because we can't get the tab contents";
460 } 460 }
461 461
462 void NavigateToURLWithDisposition(Browser* browser, 462 void NavigateToURLWithDisposition(Browser* browser,
463 const GURL& url, 463 const GURL& url,
464 WindowOpenDisposition disposition, 464 WindowOpenDisposition disposition,
465 int browser_test_flags) { 465 int browser_test_flags) {
466 NavigateToURLWithDispositionBlockUntilNavigationsComplete( 466 NavigateToURLWithDispositionBlockUntilNavigationsComplete(
467 browser, 467 browser,
(...skipping 10 matching lines...) Expand all
478 browser, 478 browser,
479 url, 479 url,
480 number_of_navigations, 480 number_of_navigations,
481 CURRENT_TAB, 481 CURRENT_TAB,
482 BROWSER_TEST_WAIT_FOR_NAVIGATION); 482 BROWSER_TEST_WAIT_FOR_NAVIGATION);
483 } 483 }
484 484
485 DOMElementProxyRef GetActiveDOMDocument(Browser* browser) { 485 DOMElementProxyRef GetActiveDOMDocument(Browser* browser) {
486 JavaScriptExecutionController* executor = 486 JavaScriptExecutionController* executor =
487 new InProcessJavaScriptExecutionController( 487 new InProcessJavaScriptExecutionController(
488 browser->GetSelectedTabContents()->GetRenderViewHost()); 488 browser->GetSelectedWebContents()->GetRenderViewHost());
489 int element_handle; 489 int element_handle;
490 executor->ExecuteJavaScriptAndGetReturn("document;", &element_handle); 490 executor->ExecuteJavaScriptAndGetReturn("document;", &element_handle);
491 return executor->GetObjectProxy<DOMElementProxy>(element_handle); 491 return executor->GetObjectProxy<DOMElementProxy>(element_handle);
492 } 492 }
493 493
494 bool ExecuteJavaScript(RenderViewHost* render_view_host, 494 bool ExecuteJavaScript(RenderViewHost* render_view_host,
495 const std::wstring& frame_xpath, 495 const std::wstring& frame_xpath,
496 const std::wstring& original_script) { 496 const std::wstring& original_script) {
497 std::wstring script = 497 std::wstring script =
498 original_script + L"window.domAutomationController.send(0);"; 498 original_script + L"window.domAutomationController.send(0);";
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 return url; 559 return url;
560 } 560 }
561 561
562 AppModalDialog* WaitForAppModalDialog() { 562 AppModalDialog* WaitForAppModalDialog() {
563 TestNotificationObserver observer; 563 TestNotificationObserver observer;
564 RegisterAndWait(&observer, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, 564 RegisterAndWait(&observer, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
565 content::NotificationService::AllSources()); 565 content::NotificationService::AllSources());
566 return content::Source<AppModalDialog>(observer.source()).ptr(); 566 return content::Source<AppModalDialog>(observer.source()).ptr();
567 } 567 }
568 568
569 void CrashTab(TabContents* tab) { 569 void CrashTab(WebContents* tab) {
570 content::RenderProcessHost* rph = tab->GetRenderProcessHost(); 570 content::RenderProcessHost* rph = tab->GetRenderProcessHost();
571 base::KillProcess(rph->GetHandle(), 0, false); 571 base::KillProcess(rph->GetHandle(), 0, false);
572 TestNotificationObserver observer; 572 TestNotificationObserver observer;
573 RegisterAndWait(&observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 573 RegisterAndWait(&observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
574 content::Source<content::RenderProcessHost>(rph)); 574 content::Source<content::RenderProcessHost>(rph));
575 } 575 }
576 576
577 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string, 577 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string,
578 bool forward, bool match_case, int* ordinal) { 578 bool forward, bool match_case, int* ordinal) {
579 tab_contents-> 579 tab_contents->
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); 1078 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap);
1079 } 1079 }
1080 1080
1081 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { 1081 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
1082 DCHECK(bitmap); 1082 DCHECK(bitmap);
1083 SnapshotTaker taker; 1083 SnapshotTaker taker;
1084 return taker.TakeEntirePageSnapshot(rvh, bitmap); 1084 return taker.TakeEntirePageSnapshot(rvh, bitmap);
1085 } 1085 }
1086 1086
1087 } // namespace ui_test_utils 1087 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/data/webui/hung_renderer_dialog_ui_test-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698