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" | |
6 #include "chrome/app/chrome_dll_resource.h" | 5 #include "chrome/app/chrome_dll_resource.h" |
7 #include "chrome/test/automated_ui_tests/automated_ui_test_base.h" | 6 #include "chrome/test/automated_ui_tests/automated_ui_test_base.h" |
8 #include "chrome/test/automation/browser_proxy.h" | 7 #include "chrome/test/automation/browser_proxy.h" |
9 #include "chrome/test/automation/tab_proxy.h" | 8 #include "chrome/test/automation/tab_proxy.h" |
10 #include "chrome/test/automation/window_proxy.h" | 9 #include "chrome/test/automation/window_proxy.h" |
11 #include "chrome/test/ui/ui_test.h" | 10 #include "chrome/test/ui/ui_test.h" |
12 | 11 |
13 AutomatedUITestBase::AutomatedUITestBase() {} | 12 AutomatedUITestBase::AutomatedUITestBase() {} |
14 | 13 |
15 AutomatedUITestBase::~AutomatedUITestBase() {} | 14 AutomatedUITestBase::~AutomatedUITestBase() {} |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 return false; | 58 return false; |
60 // Avoid quitting the application by not closing the last window. | 59 // Avoid quitting the application by not closing the last window. |
61 if (browser_windows_count < 2) | 60 if (browser_windows_count < 2) |
62 return false; | 61 return false; |
63 bool application_closed; | 62 bool application_closed; |
64 CloseBrowser(active_browser(), &application_closed); | 63 CloseBrowser(active_browser(), &application_closed); |
65 if (application_closed) { | 64 if (application_closed) { |
66 LogErrorMessage("Application closed unexpectedly."); | 65 LogErrorMessage("Application closed unexpectedly."); |
67 return false; | 66 return false; |
68 } | 67 } |
69 BrowserProxy* browser = automation()->FindNormalBrowserWindow(); | 68 scoped_refptr<BrowserProxy> browser(automation()->FindNormalBrowserWindow()); |
70 if (browser == NULL) { | 69 if (!browser.get()) { |
71 LogErrorMessage("Can't find browser window."); | 70 LogErrorMessage("Can't find browser window."); |
72 return false; | 71 return false; |
73 } | 72 } |
74 set_active_browser(browser); | 73 set_active_browser(browser); |
75 return true; | 74 return true; |
76 } | 75 } |
77 | 76 |
78 bool AutomatedUITestBase::DuplicateTab() { | 77 bool AutomatedUITestBase::DuplicateTab() { |
79 return RunCommand(IDC_DUPLICATE_TAB); | 78 return RunCommand(IDC_DUPLICATE_TAB); |
80 } | 79 } |
81 | 80 |
82 bool AutomatedUITestBase::ForwardButton() { | 81 bool AutomatedUITestBase::ForwardButton() { |
83 return RunCommand(IDC_FORWARD); | 82 return RunCommand(IDC_FORWARD); |
84 } | 83 } |
85 | 84 |
86 bool AutomatedUITestBase::GoOffTheRecord() { | 85 bool AutomatedUITestBase::GoOffTheRecord() { |
87 return RunCommand(IDC_NEW_INCOGNITO_WINDOW); | 86 return RunCommand(IDC_NEW_INCOGNITO_WINDOW); |
88 } | 87 } |
89 | 88 |
90 bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( | 89 bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( |
91 BrowserProxy** previous_browser) { | 90 scoped_refptr<BrowserProxy>* previous_browser) { |
92 if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { | 91 if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { |
93 LogWarningMessage("failed_to_open_new_browser_window"); | 92 LogWarningMessage("failed_to_open_new_browser_window"); |
94 return false; | 93 return false; |
95 } | 94 } |
96 int num_browser_windows; | 95 int num_browser_windows; |
97 automation()->GetBrowserWindowCount(&num_browser_windows); | 96 automation()->GetBrowserWindowCount(&num_browser_windows); |
98 // Get the most recently opened browser window and activate the tab | 97 // Get the most recently opened browser window and activate the tab |
99 // in order to activate this browser window. | 98 // in order to activate this browser window. |
100 scoped_ptr<BrowserProxy> browser( | 99 scoped_refptr<BrowserProxy> browser( |
101 automation()->GetBrowserWindow(num_browser_windows - 1)); | 100 automation()->GetBrowserWindow(num_browser_windows - 1)); |
102 if (browser.get() == NULL) { | 101 if (browser.get() == NULL) { |
103 LogErrorMessage("browser_window_not_found"); | 102 LogErrorMessage("browser_window_not_found"); |
104 return false; | 103 return false; |
105 } | 104 } |
106 bool is_timeout; | 105 bool is_timeout; |
107 if (!browser->ActivateTabWithTimeout(0, action_max_timeout_ms(), | 106 if (!browser->ActivateTabWithTimeout(0, action_max_timeout_ms(), |
108 &is_timeout)) { | 107 &is_timeout)) { |
109 LogWarningMessage("failed_to_activate_tab"); | 108 LogWarningMessage("failed_to_activate_tab"); |
110 return false; | 109 return false; |
111 } | 110 } |
112 | 111 |
| 112 if (previous_browser) { |
| 113 DCHECK(previous_browser->get() == NULL); |
| 114 active_browser_.swap(*previous_browser); |
| 115 } |
| 116 |
113 active_browser_.swap(browser); | 117 active_browser_.swap(browser); |
114 if (previous_browser) | |
115 *previous_browser = browser.release(); | |
116 return true; | 118 return true; |
117 } | 119 } |
118 | 120 |
119 bool AutomatedUITestBase::Navigate(const GURL& url) { | 121 bool AutomatedUITestBase::Navigate(const GURL& url) { |
120 scoped_ptr<TabProxy> tab(GetActiveTab()); | 122 scoped_refptr<TabProxy> tab(GetActiveTab()); |
121 if (tab.get() == NULL) { | 123 if (tab.get() == NULL) { |
122 LogErrorMessage("active_tab_not_found"); | 124 LogErrorMessage("active_tab_not_found"); |
123 return false; | 125 return false; |
124 } | 126 } |
125 bool did_timeout = false; | 127 bool did_timeout = false; |
126 tab->NavigateToURLWithTimeout(url, | 128 tab->NavigateToURLWithTimeout(url, |
127 command_execution_timeout_ms(), | 129 command_execution_timeout_ms(), |
128 &did_timeout); | 130 &did_timeout); |
129 | 131 |
130 if (did_timeout) { | 132 if (did_timeout) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return false; | 171 return false; |
170 } | 172 } |
171 | 173 |
172 if (!browser->RunCommand(browser_command)) { | 174 if (!browser->RunCommand(browser_command)) { |
173 LogWarningMessage("failure_running_browser_command"); | 175 LogWarningMessage("failure_running_browser_command"); |
174 return false; | 176 return false; |
175 } | 177 } |
176 return true; | 178 return true; |
177 } | 179 } |
178 | 180 |
179 TabProxy* AutomatedUITestBase::GetActiveTab() { | 181 scoped_refptr<TabProxy> AutomatedUITestBase::GetActiveTab() { |
180 BrowserProxy* browser = active_browser(); | 182 BrowserProxy* browser = active_browser(); |
181 if (browser == NULL) { | 183 if (browser == NULL) { |
182 LogErrorMessage("browser_window_not_found"); | 184 LogErrorMessage("browser_window_not_found"); |
183 return false; | 185 return false; |
184 } | 186 } |
185 | 187 |
186 bool did_timeout; | 188 bool did_timeout; |
187 TabProxy* tab = | 189 scoped_refptr<TabProxy> tab = |
188 browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout); | 190 browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout); |
189 if (did_timeout) | 191 if (did_timeout) |
190 return NULL; | 192 return NULL; |
191 return tab; | 193 return tab; |
192 } | 194 } |
OLD | NEW |