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

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

Issue 10551002: TabContentsWrapper -> TabContents, part 56. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Not killing GetSelectedWebContents yet Created 8 years, 6 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
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/gpu/gpu_pixel_browsertest.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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/search_engines/template_url_service_test_util.h" 34 #include "chrome/browser/search_engines/template_url_service_test_util.h"
35 #include "chrome/browser/tab_contents/thumbnail_generator.h" 35 #include "chrome/browser/tab_contents/thumbnail_generator.h"
36 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 36 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
37 #include "chrome/browser/ui/browser.h" 37 #include "chrome/browser/ui/browser.h"
38 #include "chrome/browser/ui/browser_finder.h" 38 #include "chrome/browser/ui/browser_finder.h"
39 #include "chrome/browser/ui/browser_list.h" 39 #include "chrome/browser/ui/browser_list.h"
40 #include "chrome/browser/ui/browser_navigator.h" 40 #include "chrome/browser/ui/browser_navigator.h"
41 #include "chrome/browser/ui/browser_window.h" 41 #include "chrome/browser/ui/browser_window.h"
42 #include "chrome/browser/ui/find_bar/find_notification_details.h" 42 #include "chrome/browser/ui/find_bar/find_notification_details.h"
43 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 43 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
44 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 44 #include "chrome/browser/ui/tab_contents/tab_contents.h"
45 #include "chrome/common/chrome_notification_types.h" 45 #include "chrome/common/chrome_notification_types.h"
46 #include "chrome/common/chrome_paths.h" 46 #include "chrome/common/chrome_paths.h"
47 #include "chrome/common/extensions/extension_action.h" 47 #include "chrome/common/extensions/extension_action.h"
48 #include "chrome/test/automation/javascript_execution_controller.h" 48 #include "chrome/test/automation/javascript_execution_controller.h"
49 #include "chrome/test/base/bookmark_load_observer.h" 49 #include "chrome/test/base/bookmark_load_observer.h"
50 #include "content/public/browser/dom_operation_notification_details.h" 50 #include "content/public/browser/dom_operation_notification_details.h"
51 #include "content/public/browser/download_item.h" 51 #include "content/public/browser/download_item.h"
52 #include "content/public/browser/download_manager.h" 52 #include "content/public/browser/download_manager.h"
53 #include "content/public/browser/geolocation.h" 53 #include "content/public/browser/geolocation.h"
54 #include "content/public/browser/navigation_controller.h" 54 #include "content/public/browser/navigation_controller.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 private: 130 private:
131 content::NotificationRegistrar registrar_; 131 content::NotificationRegistrar registrar_;
132 std::string response_; 132 std::string response_;
133 bool did_respond_; 133 bool did_respond_;
134 134
135 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver); 135 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
136 }; 136 };
137 137
138 class FindInPageNotificationObserver : public content::NotificationObserver { 138 class FindInPageNotificationObserver : public content::NotificationObserver {
139 public: 139 public:
140 explicit FindInPageNotificationObserver(TabContentsWrapper* parent_tab) 140 explicit FindInPageNotificationObserver(TabContents* parent_tab)
141 : parent_tab_(parent_tab), 141 : parent_tab_(parent_tab),
142 active_match_ordinal_(-1), 142 active_match_ordinal_(-1),
143 number_of_matches_(0) { 143 number_of_matches_(0) {
144 current_find_request_id_ = 144 current_find_request_id_ =
145 parent_tab->find_tab_helper()->current_find_request_id(); 145 parent_tab->find_tab_helper()->current_find_request_id();
146 registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, 146 registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE,
147 content::Source<WebContents>(parent_tab_->web_contents())); 147 content::Source<WebContents>(parent_tab_->web_contents()));
148 ui_test_utils::RunMessageLoop(); 148 ui_test_utils::RunMessageLoop();
149 } 149 }
150 150
(...skipping 17 matching lines...) Expand all
168 DVLOG(1) << "Ignoring, since we only care about the final message"; 168 DVLOG(1) << "Ignoring, since we only care about the final message";
169 } 169 }
170 } 170 }
171 } else { 171 } else {
172 NOTREACHED(); 172 NOTREACHED();
173 } 173 }
174 } 174 }
175 175
176 private: 176 private:
177 content::NotificationRegistrar registrar_; 177 content::NotificationRegistrar registrar_;
178 TabContentsWrapper* parent_tab_; 178 TabContents* parent_tab_;
179 // We will at some point (before final update) be notified of the ordinal and 179 // We will at some point (before final update) be notified of the ordinal and
180 // we need to preserve it so we can send it later. 180 // we need to preserve it so we can send it later.
181 int active_match_ordinal_; 181 int active_match_ordinal_;
182 int number_of_matches_; 182 int number_of_matches_;
183 // The id of the current find request, obtained from WebContents. Allows us 183 // The id of the current find request, obtained from WebContents. Allows us
184 // to monitor when the search completes. 184 // to monitor when the search completes.
185 int current_find_request_id_; 185 int current_find_request_id_;
186 186
187 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); 187 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
188 }; 188 };
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 NOTREACHED(); 307 NOTREACHED();
308 return; 308 return;
309 } 309 }
310 content::BrowserThread::PostTask(thread_id, FROM_HERE, 310 content::BrowserThread::PostTask(thread_id, FROM_HERE,
311 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id)); 311 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id));
312 312
313 ui_test_utils::RunMessageLoop(); 313 ui_test_utils::RunMessageLoop();
314 } 314 }
315 315
316 bool GetCurrentTabTitle(const Browser* browser, string16* title) { 316 bool GetCurrentTabTitle(const Browser* browser, string16* title) {
317 WebContents* web_contents = browser->GetSelectedWebContents(); 317 WebContents* web_contents = browser->GetActiveWebContents();
318 if (!web_contents) 318 if (!web_contents)
319 return false; 319 return false;
320 NavigationEntry* last_entry = web_contents->GetController().GetActiveEntry(); 320 NavigationEntry* last_entry = web_contents->GetController().GetActiveEntry();
321 if (!last_entry) 321 if (!last_entry)
322 return false; 322 return false;
323 title->assign(last_entry->GetTitleForDisplay("")); 323 title->assign(last_entry->GetTitleForDisplay(""));
324 return true; 324 return true;
325 } 325 }
326 326
327 void WaitForNavigations(NavigationController* controller, 327 void WaitForNavigations(NavigationController* controller,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // The new browser should never be in |excluded_browsers|. 375 // The new browser should never be in |excluded_browsers|.
376 DCHECK(!ContainsKey(excluded_browsers, new_browser)); 376 DCHECK(!ContainsKey(excluded_browsers, new_browser));
377 } 377 }
378 return new_browser; 378 return new_browser;
379 } 379 }
380 380
381 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { 381 void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
382 Browser::OpenURLOffTheRecord(profile, url); 382 Browser::OpenURLOffTheRecord(profile, url);
383 Browser* browser = browser::FindTabbedBrowser( 383 Browser* browser = browser::FindTabbedBrowser(
384 profile->GetOffTheRecordProfile(), false); 384 profile->GetOffTheRecordProfile(), false);
385 WaitForNavigations(&browser->GetSelectedWebContents()->GetController(), 1); 385 WaitForNavigations(&browser->GetActiveWebContents()->GetController(), 1);
386 } 386 }
387 387
388 void NavigateToURL(browser::NavigateParams* params) { 388 void NavigateToURL(browser::NavigateParams* params) {
389 content::TestNavigationObserver observer( 389 content::TestNavigationObserver observer(
390 content::NotificationService::AllSources(), NULL, 1); 390 content::NotificationService::AllSources(), NULL, 1);
391 browser::Navigate(params); 391 browser::Navigate(params);
392 observer.WaitForObservation( 392 observer.WaitForObservation(
393 base::Bind(&ui_test_utils::RunMessageLoop), 393 base::Bind(&ui_test_utils::RunMessageLoop),
394 base::Bind(&MessageLoop::Quit, 394 base::Bind(&MessageLoop::Quit,
395 base::Unretained(MessageLoopForUI::current()))); 395 base::Unretained(MessageLoopForUI::current())));
396 396
397 } 397 }
398 398
399 void NavigateToURL(Browser* browser, const GURL& url) { 399 void NavigateToURL(Browser* browser, const GURL& url) {
400 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, 400 NavigateToURLWithDisposition(browser, url, CURRENT_TAB,
401 BROWSER_TEST_WAIT_FOR_NAVIGATION); 401 BROWSER_TEST_WAIT_FOR_NAVIGATION);
402 } 402 }
403 403
404 // Navigates the specified tab (via |disposition|) of |browser| to |url|, 404 // Navigates the specified tab (via |disposition|) of |browser| to |url|,
405 // blocking until the |number_of_navigations| specified complete. 405 // blocking until the |number_of_navigations| specified complete.
406 // |disposition| indicates what tab the download occurs in, and 406 // |disposition| indicates what tab the download occurs in, and
407 // |browser_test_flags| controls what to wait for before continuing. 407 // |browser_test_flags| controls what to wait for before continuing.
408 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( 408 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
409 Browser* browser, 409 Browser* browser,
410 const GURL& url, 410 const GURL& url,
411 int number_of_navigations, 411 int number_of_navigations,
412 WindowOpenDisposition disposition, 412 WindowOpenDisposition disposition,
413 int browser_test_flags) { 413 int browser_test_flags) {
414 if (disposition == CURRENT_TAB && browser->GetSelectedWebContents()) 414 if (disposition == CURRENT_TAB && browser->GetActiveWebContents())
415 WaitForLoadStop(browser->GetSelectedWebContents()); 415 WaitForLoadStop(browser->GetActiveWebContents());
416 NavigationController* controller = 416 NavigationController* controller =
417 browser->GetSelectedWebContents() ? 417 browser->GetActiveWebContents() ?
418 &browser->GetSelectedWebContents()->GetController() : NULL; 418 &browser->GetActiveWebContents()->GetController() : NULL;
419 content::TestNavigationObserver same_tab_observer( 419 content::TestNavigationObserver same_tab_observer(
420 content::Source<NavigationController>(controller), 420 content::Source<NavigationController>(controller),
421 NULL, 421 NULL,
422 number_of_navigations); 422 number_of_navigations);
423 423
424 std::set<Browser*> initial_browsers; 424 std::set<Browser*> initial_browsers;
425 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); 425 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
426 iter != BrowserList::end(); 426 iter != BrowserList::end();
427 ++iter) { 427 ++iter) {
428 initial_browsers.insert(*iter); 428 initial_browsers.insert(*iter);
(...skipping 24 matching lines...) Expand all
453 // We've opened up a new tab, but not selected it. 453 // We've opened up a new tab, but not selected it.
454 web_contents = browser->GetWebContentsAt(browser->active_index() + 1); 454 web_contents = browser->GetWebContentsAt(browser->active_index() + 1);
455 EXPECT_TRUE(web_contents != NULL) 455 EXPECT_TRUE(web_contents != NULL)
456 << " Unable to wait for navigation to \"" << url.spec() 456 << " Unable to wait for navigation to \"" << url.spec()
457 << "\" because the new tab is not available yet"; 457 << "\" because the new tab is not available yet";
458 return; 458 return;
459 } else if ((disposition == CURRENT_TAB) || 459 } else if ((disposition == CURRENT_TAB) ||
460 (disposition == NEW_FOREGROUND_TAB) || 460 (disposition == NEW_FOREGROUND_TAB) ||
461 (disposition == SINGLETON_TAB)) { 461 (disposition == SINGLETON_TAB)) {
462 // The currently selected tab is the right one. 462 // The currently selected tab is the right one.
463 web_contents = browser->GetSelectedWebContents(); 463 web_contents = browser->GetActiveWebContents();
464 } 464 }
465 if (disposition == CURRENT_TAB) { 465 if (disposition == CURRENT_TAB) {
466 same_tab_observer.WaitForObservation( 466 same_tab_observer.WaitForObservation(
467 base::Bind(&ui_test_utils::RunMessageLoop), 467 base::Bind(&ui_test_utils::RunMessageLoop),
468 base::Bind(&MessageLoop::Quit, 468 base::Bind(&MessageLoop::Quit,
469 base::Unretained(MessageLoopForUI::current()))); 469 base::Unretained(MessageLoopForUI::current())));
470 return; 470 return;
471 } else if (web_contents) { 471 } else if (web_contents) {
472 NavigationController* controller = &web_contents->GetController(); 472 NavigationController* controller = &web_contents->GetController();
473 WaitForNavigations(controller, number_of_navigations); 473 WaitForNavigations(controller, number_of_navigations);
(...skipping 23 matching lines...) Expand all
497 browser, 497 browser,
498 url, 498 url,
499 number_of_navigations, 499 number_of_navigations,
500 CURRENT_TAB, 500 CURRENT_TAB,
501 BROWSER_TEST_WAIT_FOR_NAVIGATION); 501 BROWSER_TEST_WAIT_FOR_NAVIGATION);
502 } 502 }
503 503
504 DOMElementProxyRef GetActiveDOMDocument(Browser* browser) { 504 DOMElementProxyRef GetActiveDOMDocument(Browser* browser) {
505 JavaScriptExecutionController* executor = 505 JavaScriptExecutionController* executor =
506 new InProcessJavaScriptExecutionController( 506 new InProcessJavaScriptExecutionController(
507 browser->GetSelectedWebContents()->GetRenderViewHost()); 507 browser->GetActiveWebContents()->GetRenderViewHost());
508 int element_handle; 508 int element_handle;
509 executor->ExecuteJavaScriptAndGetReturn("document;", &element_handle); 509 executor->ExecuteJavaScriptAndGetReturn("document;", &element_handle);
510 return executor->GetObjectProxy<DOMElementProxy>(element_handle); 510 return executor->GetObjectProxy<DOMElementProxy>(element_handle);
511 } 511 }
512 512
513 bool ExecuteJavaScript(RenderViewHost* render_view_host, 513 bool ExecuteJavaScript(RenderViewHost* render_view_host,
514 const std::wstring& frame_xpath, 514 const std::wstring& frame_xpath,
515 const std::wstring& original_script) { 515 const std::wstring& original_script) {
516 std::wstring script = 516 std::wstring script =
517 original_script + L";window.domAutomationController.send(0);"; 517 original_script + L";window.domAutomationController.send(0);";
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 593
594 void CrashTab(WebContents* tab) { 594 void CrashTab(WebContents* tab) {
595 content::RenderProcessHost* rph = tab->GetRenderProcessHost(); 595 content::RenderProcessHost* rph = tab->GetRenderProcessHost();
596 WindowedNotificationObserver observer( 596 WindowedNotificationObserver observer(
597 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 597 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
598 content::Source<content::RenderProcessHost>(rph)); 598 content::Source<content::RenderProcessHost>(rph));
599 base::KillProcess(rph->GetHandle(), 0, false); 599 base::KillProcess(rph->GetHandle(), 0, false);
600 observer.Wait(); 600 observer.Wait();
601 } 601 }
602 602
603 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string, 603 int FindInPage(TabContents* tab_contents, const string16& search_string,
604 bool forward, bool match_case, int* ordinal) { 604 bool forward, bool match_case, int* ordinal) {
605 tab_contents-> 605 tab_contents->
606 find_tab_helper()->StartFinding(search_string, forward, match_case); 606 find_tab_helper()->StartFinding(search_string, forward, match_case);
607 FindInPageNotificationObserver observer(tab_contents); 607 FindInPageNotificationObserver observer(tab_contents);
608 if (ordinal) 608 if (ordinal)
609 *ordinal = observer.active_match_ordinal(); 609 *ordinal = observer.active_match_ordinal();
610 return observer.number_of_matches(); 610 return observer.number_of_matches();
611 } 611 }
612 612
613 void SimulateMouseClick(content::WebContents* tab) { 613 void SimulateMouseClick(content::WebContents* tab) {
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 int state, 1264 int state,
1265 const base::Closure& followup) { 1265 const base::Closure& followup) {
1266 if (!followup.is_null()) 1266 if (!followup.is_null())
1267 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); 1267 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup);
1268 else 1268 else
1269 ui_controls::SendMouseEvents(button, state); 1269 ui_controls::SendMouseEvents(button, state);
1270 } 1270 }
1271 1271
1272 } // namespace internal 1272 } // namespace internal
1273 } // namespace ui_test_utils 1273 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/gpu/gpu_pixel_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698