Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
| 6 #include "chrome/app/chrome_dll_resource.h" | 6 #include "chrome/app/chrome_dll_resource.h" |
| 7 #include "chrome/test/automated_ui_tests/automated_ui_test_base.h" | 7 #include "chrome/test/automated_ui_tests/automated_ui_test_base.h" |
| 8 #include "chrome/test/automation/browser_proxy.h" | 8 #include "chrome/test/automation/browser_proxy.h" |
| 9 #include "chrome/test/automation/tab_proxy.h" | 9 #include "chrome/test/automation/tab_proxy.h" |
| 10 #include "chrome/test/automation/window_proxy.h" | 10 #include "chrome/test/automation/window_proxy.h" |
| 11 #include "chrome/test/ui/ui_test.h" | 11 #include "chrome/test/ui/ui_test.h" |
| 12 | 12 |
| 13 AutomatedUITestBase::AutomatedUITestBase() {} | 13 AutomatedUITestBase::AutomatedUITestBase() {} |
| 14 | 14 |
| 15 AutomatedUITestBase::~AutomatedUITestBase() {} | 15 AutomatedUITestBase::~AutomatedUITestBase() {} |
| 16 | 16 |
| 17 void AutomatedUITestBase::LogErrorMessage(const std::string& error) {} | 17 void AutomatedUITestBase::LogErrorMessage(const std::string& error) {} |
| 18 | 18 |
| 19 void AutomatedUITestBase::LogWarningMessage(const std::string& warning) {} | 19 void AutomatedUITestBase::LogWarningMessage(const std::string& warning) {} |
| 20 | 20 |
| 21 void AutomatedUITestBase::LogInfoMessage(const std::string& info) {} | 21 void AutomatedUITestBase::LogInfoMessage(const std::string& info) {} |
| 22 | 22 |
| 23 void AutomatedUITestBase::SetUp() { | 23 void AutomatedUITestBase::SetUp() { |
| 24 UITest::SetUp(); | 24 UITest::SetUp(); |
| 25 set_active_browser(automation()->GetBrowserWindow(0)); | 25 set_active_browser(automation()->GetBrowserWindow(0)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool AutomatedUITestBase::CloseActiveTab() { | |
| 29 BrowserProxy* browser = active_browser(); | |
| 30 int tab_count; | |
| 31 bool is_timeout; | |
| 32 browser->GetTabCountWithTimeout(&tab_count, | |
| 33 action_max_timeout_ms(), | |
| 34 &is_timeout); | |
| 35 | |
| 36 if (is_timeout) { | |
| 37 LogInfoMessage("get_tab_count_time_out"); | |
|
Finnur
2009/05/01 04:05:49
nit: add a 'd' after time (timed_out)
| |
| 38 return false; | |
| 39 } | |
| 40 | |
| 41 if (tab_count > 1) { | |
| 42 scoped_ptr<TabProxy> tab(GetActiveTab()); | |
| 43 // Wait until tab is closed | |
|
Finnur
2009/05/01 04:05:49
nit: End the comment in a period.
| |
| 44 return tab->Close(true); | |
| 45 } else if (tab_count == 1) { | |
| 46 // Synchronously close the window if it is not the last window. | |
| 47 return CloseActiveWindow(); | |
| 48 } else { | |
| 49 LogInfoMessage("invalid_tab_count"); | |
| 50 return false; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 bool AutomatedUITestBase::CloseActiveWindow() { | |
| 55 int browser_windows_count = 0; | |
| 56 if (!automation()->GetNormalBrowserWindowCount(&browser_windows_count)) | |
| 57 return false; | |
| 58 // Avoid quitting the application by not closing the last window. | |
| 59 if (browser_windows_count < 2) | |
| 60 return false; | |
| 61 bool application_closed; | |
| 62 CloseBrowser(active_browser(), &application_closed); | |
| 63 if (application_closed) { | |
| 64 LogErrorMessage("Application closed unexpectedly."); | |
| 65 return false; | |
| 66 } | |
| 67 BrowserProxy* browser = automation()->FindNormalBrowserWindow(); | |
| 68 if (browser == NULL) { | |
| 69 LogErrorMessage("Can't find browser window."); | |
| 70 return false; | |
| 71 } | |
| 72 set_active_browser(browser); | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 28 bool AutomatedUITestBase::DuplicateTab() { | 76 bool AutomatedUITestBase::DuplicateTab() { |
| 29 return RunCommand(IDC_DUPLICATE_TAB); | 77 return RunCommand(IDC_DUPLICATE_TAB); |
| 30 } | 78 } |
| 31 | 79 |
| 32 bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( | 80 bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( |
| 33 BrowserProxy** previous_browser) { | 81 BrowserProxy** previous_browser) { |
| 34 if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { | 82 if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { |
| 35 LogWarningMessage("failed_to_open_new_browser_window"); | 83 LogWarningMessage("failed_to_open_new_browser_window"); |
| 36 return false; | 84 return false; |
| 37 } | 85 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 LogErrorMessage("browser_window_not_found"); | 132 LogErrorMessage("browser_window_not_found"); |
| 85 return false; | 133 return false; |
| 86 } | 134 } |
| 87 | 135 |
| 88 if (!browser->RunCommand(browser_command)) { | 136 if (!browser->RunCommand(browser_command)) { |
| 89 LogWarningMessage("failure_running_browser_command"); | 137 LogWarningMessage("failure_running_browser_command"); |
| 90 return false; | 138 return false; |
| 91 } | 139 } |
| 92 return true; | 140 return true; |
| 93 } | 141 } |
| 142 | |
| 143 TabProxy* AutomatedUITestBase::GetActiveTab() { | |
| 144 BrowserProxy* browser = active_browser(); | |
| 145 if (browser == NULL) { | |
| 146 LogErrorMessage("browser_window_not_found"); | |
| 147 return false; | |
| 148 } | |
| 149 | |
| 150 bool did_timeout; | |
| 151 TabProxy* tab = | |
| 152 browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout); | |
| 153 if (did_timeout) | |
| 154 return NULL; | |
| 155 return tab; | |
| 156 } | |
| OLD | NEW |