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

Side by Side Diff: chrome/test/automated_ui_tests/automated_ui_tests.cc

Issue 67139: Remove the usage of GetLastActiveBrowserWindow... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <fstream> 5 #include <fstream>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } else if (LowerCaseEqualsASCII(action, "restoretab")) { 333 } else if (LowerCaseEqualsASCII(action, "restoretab")) {
334 did_complete_action = RestoreTab(); 334 did_complete_action = RestoreTab();
335 } else if (LowerCaseEqualsASCII(action, "selectnexttab")) { 335 } else if (LowerCaseEqualsASCII(action, "selectnexttab")) {
336 did_complete_action = SelectNextTab(); 336 did_complete_action = SelectNextTab();
337 } else if (LowerCaseEqualsASCII(action, "selectprevtab")) { 337 } else if (LowerCaseEqualsASCII(action, "selectprevtab")) {
338 did_complete_action = SelectPreviousTab(); 338 did_complete_action = SelectPreviousTab();
339 } else if (LowerCaseEqualsASCII(action, "showbookmarks")) { 339 } else if (LowerCaseEqualsASCII(action, "showbookmarks")) {
340 did_complete_action = ShowBookmarkBar(); 340 did_complete_action = ShowBookmarkBar();
341 } else if (LowerCaseEqualsASCII(action, "setup")) { 341 } else if (LowerCaseEqualsASCII(action, "setup")) {
342 LaunchBrowserAndServer(); 342 LaunchBrowserAndServer();
343 set_active_browser(automation()->GetBrowserWindow(0));
Finnur 2009/04/14 20:22:14 Do you need a release_active_browser somewhere?
huanr 2009/04/14 20:58:26 set_active_browser() calls active_browser_.reset()
343 did_complete_action = true; 344 did_complete_action = true;
344 } else if (LowerCaseEqualsASCII(action, "sleep")) { 345 } else if (LowerCaseEqualsASCII(action, "sleep")) {
345 // This is for debugging, it probably shouldn't be used real tests. 346 // This is for debugging, it probably shouldn't be used real tests.
346 Sleep(kDebuggingTimeoutMsec); 347 Sleep(kDebuggingTimeoutMsec);
347 did_complete_action = true; 348 did_complete_action = true;
348 } else if (LowerCaseEqualsASCII(action, "star")) { 349 } else if (LowerCaseEqualsASCII(action, "star")) {
349 did_complete_action = StarPage(); 350 did_complete_action = StarPage();
350 } else if (LowerCaseEqualsASCII(action, "taskmanager")) { 351 } else if (LowerCaseEqualsASCII(action, "taskmanager")) {
351 did_complete_action = OpenTaskManagerDialog(); 352 did_complete_action = OpenTaskManagerDialog();
352 } else if (LowerCaseEqualsASCII(action, "teardown")) { 353 } else if (LowerCaseEqualsASCII(action, "teardown")) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 int index = base::RandInt(0, len); 411 int index = base::RandInt(0, len);
411 while ((*encodings)[index].encoding_id == 0) { 412 while ((*encodings)[index].encoding_id == 0) {
412 index = base::RandInt(0, len); 413 index = base::RandInt(0, len);
413 } 414 }
414 415
415 return RunCommandAsync((*encodings)[index].encoding_id); 416 return RunCommandAsync((*encodings)[index].encoding_id);
416 } 417 }
417 418
418 bool AutomatedUITest::CloseActiveTab() { 419 bool AutomatedUITest::CloseActiveTab() {
419 bool return_value = false; 420 bool return_value = false;
420 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); 421 BrowserProxy* browser = active_browser();
421 if (browser.get() == NULL) { 422 if (browser == NULL) {
422 AddErrorAttribute("browser_window_not_found"); 423 AddErrorAttribute("browser_window_not_found");
423 return false; 424 return false;
424 } 425 }
425 int browser_windows_count; 426 int browser_windows_count;
426 int tab_count; 427 int tab_count;
427 bool is_timeout; 428 bool is_timeout;
428 browser->GetTabCountWithTimeout(&tab_count, 429 browser->GetTabCountWithTimeout(&tab_count,
429 action_max_timeout_ms(), 430 action_max_timeout_ms(),
430 &is_timeout); 431 &is_timeout);
431 automation()->GetBrowserWindowCount(&browser_windows_count); 432 automation()->GetBrowserWindowCount(&browser_windows_count);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 472
472 bool AutomatedUITest::JavaScriptConsole() { 473 bool AutomatedUITest::JavaScriptConsole() {
473 return RunCommandAsync(IDC_JS_CONSOLE); 474 return RunCommandAsync(IDC_JS_CONSOLE);
474 } 475 }
475 476
476 bool AutomatedUITest::JavaScriptDebugger() { 477 bool AutomatedUITest::JavaScriptDebugger() {
477 return RunCommandAsync(IDC_DEBUGGER); 478 return RunCommandAsync(IDC_DEBUGGER);
478 } 479 }
479 480
480 bool AutomatedUITest::Navigate() { 481 bool AutomatedUITest::Navigate() {
481 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); 482 BrowserProxy* browser = active_browser();
482 if (browser.get() == NULL) { 483 if (browser == NULL) {
483 AddErrorAttribute("browser_window_not_found"); 484 AddErrorAttribute("browser_window_not_found");
484 return false; 485 return false;
485 } 486 }
486 bool did_timeout; 487 bool did_timeout;
487 scoped_ptr<TabProxy> tab( 488 scoped_ptr<TabProxy> tab(
488 browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout)); 489 browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout));
489 // TODO(devint): This might be masking a bug. I can't think of many 490 // TODO(devint): This might be masking a bug. I can't think of many
490 // valid cases where we would get a browser window, but not be able 491 // valid cases where we would get a browser window, but not be able
491 // to return an active tab. Yet this has happened and has triggered crashes. 492 // to return an active tab. Yet this has happened and has triggered crashes.
492 // Investigate this. 493 // Investigate this.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 - 1); 670 - 1);
670 return_value = return_value && 671 return_value = return_value &&
671 DoAction(kTestDialogPossibleActions[action_index]); 672 DoAction(kTestDialogPossibleActions[action_index]);
672 if (DidCrash(false)) 673 if (DidCrash(false))
673 break; 674 break;
674 } 675 }
675 return DoAction("PressEscapeKey") && return_value; 676 return DoAction("PressEscapeKey") && return_value;
676 } 677 }
677 678
678 bool AutomatedUITest::ForceCrash() { 679 bool AutomatedUITest::ForceCrash() {
679 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); 680 BrowserProxy* browser = active_browser();
680 if (browser.get() == NULL) { 681 if (browser == NULL) {
681 AddErrorAttribute("browser_window_not_found"); 682 AddErrorAttribute("browser_window_not_found");
682 return false; 683 return false;
683 } 684 }
684 scoped_ptr<TabProxy> tab(browser->GetActiveTab()); 685 scoped_ptr<TabProxy> tab(browser->GetActiveTab());
685 GURL test_url("about:crash"); 686 GURL test_url("about:crash");
686 bool did_timeout; 687 bool did_timeout;
687 tab->NavigateToURLWithTimeout(test_url, kDebuggingTimeoutMsec, &did_timeout); 688 tab->NavigateToURLWithTimeout(test_url, kDebuggingTimeoutMsec, &did_timeout);
688 if (!did_timeout) { 689 if (!did_timeout) {
689 AddInfoAttribute("expected_crash"); 690 AddInfoAttribute("expected_crash");
690 return false; 691 return false;
691 } 692 }
692 return true; 693 return true;
693 } 694 }
694 695
695 bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) { 696 bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) {
696 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); 697 BrowserProxy* browser = active_browser();
698 if (browser == NULL) {
699 AddErrorAttribute("browser_window_not_found");
700 return false;
701 }
702
697 scoped_ptr<WindowProxy> window( 703 scoped_ptr<WindowProxy> window(
698 GetAndActivateWindowForBrowser(browser.get())); 704 GetAndActivateWindowForBrowser(browser));
699 if (window.get() == NULL) { 705 if (window.get() == NULL) {
700 AddErrorAttribute("active_window_not_found"); 706 AddErrorAttribute("active_window_not_found");
701 return false; 707 return false;
702 } 708 }
703 bool is_timeout; 709 bool is_timeout;
704 710
705 if (browser.get() == NULL) {
706 AddErrorAttribute("browser_window_not_found");
707 return false;
708 }
709 int tab_count; 711 int tab_count;
710 browser->GetTabCountWithTimeout(&tab_count, 712 browser->GetTabCountWithTimeout(&tab_count,
711 action_max_timeout_ms(), 713 action_max_timeout_ms(),
712 &is_timeout); 714 &is_timeout);
713 // As far as we're concerned, if we can't get a view for a tab, it doesn't 715 // As far as we're concerned, if we can't get a view for a tab, it doesn't
714 // exist, so cap tab_count at the number of tab view ids there are. 716 // exist, so cap tab_count at the number of tab view ids there are.
715 tab_count = std::min(tab_count, VIEW_ID_TAB_LAST - VIEW_ID_TAB_0); 717 tab_count = std::min(tab_count, VIEW_ID_TAB_LAST - VIEW_ID_TAB_0);
716 718
717 int tab_index; 719 int tab_index;
718 if (!browser->GetActiveTabIndexWithTimeout(&tab_index, 720 if (!browser->GetActiveTabIndexWithTimeout(&tab_index,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 } 957 }
956 } 958 }
957 959
958 TEST_F(AutomatedUITest, TheOneAndOnlyTest) { 960 TEST_F(AutomatedUITest, TheOneAndOnlyTest) {
959 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 961 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
960 if (parsed_command_line.HasSwitch(kReproSwitch)) 962 if (parsed_command_line.HasSwitch(kReproSwitch))
961 RunReproduction(); 963 RunReproduction();
962 else 964 else
963 RunAutomatedUITest(); 965 RunAutomatedUITest();
964 } 966 }
OLDNEW
« no previous file with comments | « chrome/test/automated_ui_tests/automated_ui_test_base.cc ('k') | chrome/test/automation/automation_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698