OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import time | 7 import time |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 def testFtpHistory(self): | 212 def testFtpHistory(self): |
213 """Verify a site using ftp protocol shows up within history.""" | 213 """Verify a site using ftp protocol shows up within history.""" |
214 ftp_url = 'ftp://ftp.kernel.org/' | 214 ftp_url = 'ftp://ftp.kernel.org/' |
215 ftp_title = 'Index of /' | 215 ftp_title = 'Index of /' |
216 self.NavigateToURL(ftp_url) | 216 self.NavigateToURL(ftp_url) |
217 history = self.GetHistoryInfo().History() | 217 history = self.GetHistoryInfo().History() |
218 self.assertEqual(len(history), 1) | 218 self.assertEqual(len(history), 1) |
219 self.assertEqual(ftp_title, history[0]['title']) | 219 self.assertEqual(ftp_title, history[0]['title']) |
220 self.assertEqual(ftp_url, history[0]['url']) | 220 self.assertEqual(ftp_url, history[0]['url']) |
221 | 221 |
| 222 def _CheckHistory(self, title, url, length, index=0): |
| 223 """Verify that the current history matches expectations. |
| 224 |
| 225 Verify that history item has the given title and url |
| 226 and that length of history list is as expected. |
| 227 |
| 228 Args: |
| 229 title: Expected title of given web page. |
| 230 url: Expected address of given web page. |
| 231 length: Expected length of history list. |
| 232 index: Position of item we want to check in history list. |
| 233 """ |
| 234 history = self.GetHistoryInfo().History() |
| 235 self.assertEqual( |
| 236 length, len(history), |
| 237 msg='History length: expected = %d, actual = %d.' |
| 238 % (length, len(history))) |
| 239 self.assertEqual( |
| 240 title, history[index]['title'], |
| 241 msg='Title: expected = %s, actual = %s.' |
| 242 % (title, history[index]['title'])) |
| 243 self.assertEqual( |
| 244 url, history[index]['url'], msg='URL: expected = %s, actual = %s.' |
| 245 % (url, history[index]['url'])) |
| 246 |
| 247 def _NavigateAndCheckHistory(self, title, page, length): |
| 248 """Navigate to a page, then verify the history. |
| 249 |
| 250 Args: |
| 251 title: Title of given web page. |
| 252 page: Filename of given web page. |
| 253 length: Length of history list. |
| 254 """ |
| 255 url = self.GetFileURLForDataPath(page) |
| 256 self.NavigateToURL(url) |
| 257 self._CheckHistory(title, url, length) |
| 258 |
| 259 def testNavigateBringPageToTop(self): |
| 260 """Verify that navigation brings current page to top of history list.""" |
| 261 self._NavigateAndCheckHistory('Title Of Awesomeness', 'title2.html', 1) |
| 262 self._NavigateAndCheckHistory('Title Of More Awesomeness', 'title3.html', |
| 263 2) |
| 264 |
| 265 def testReloadBringPageToTop(self): |
| 266 """Verify that reloading a page brings it to top of history list.""" |
| 267 url1 = self.GetFileURLForDataPath('title2.html') |
| 268 title1 = 'Title Of Awesomeness' |
| 269 self._NavigateAndCheckHistory(title1, 'title2.html', 1) |
| 270 |
| 271 url2 = self.GetFileURLForDataPath('title3.html') |
| 272 title2 = 'Title Of More Awesomeness' |
| 273 self.AppendTab(pyauto.GURL(url2)) |
| 274 self._CheckHistory(title2, url2, 2) |
| 275 |
| 276 self.ActivateTab(0) |
| 277 self.ReloadActiveTab() |
| 278 self._CheckHistory(title1, url1, 2) |
| 279 |
| 280 def testBackForwardBringPageToTop(self): |
| 281 """Verify that back/forward brings current page to top of history list.""" |
| 282 url1 = self.GetFileURLForDataPath('title2.html') |
| 283 title1 = 'Title Of Awesomeness' |
| 284 self._NavigateAndCheckHistory(title1, 'title2.html', 1) |
| 285 |
| 286 url2 = self.GetFileURLForDataPath('title3.html') |
| 287 title2 = 'Title Of More Awesomeness' |
| 288 self._NavigateAndCheckHistory(title2, 'title3.html', 2) |
| 289 |
| 290 tab = self.GetBrowserWindow(0).GetTab(0) |
| 291 tab.GoBack() |
| 292 self._CheckHistory(title1, url1, 2) |
| 293 tab.GoForward() |
| 294 self._CheckHistory(title2, url2, 2) |
| 295 |
| 296 def testAppendTabAddPage(self): |
| 297 """Verify that opening a new tab adds that page to history.""" |
| 298 self._NavigateAndCheckHistory('Title Of Awesomeness', 'title2.html', 1) |
| 299 |
| 300 url2 = self.GetFileURLForDataPath('title3.html') |
| 301 title2 = 'Title Of More Awesomeness' |
| 302 self.AppendTab(pyauto.GURL(url2)) |
| 303 self._CheckHistory(title2, url2, 2) |
| 304 |
| 305 def testOpenWindowAddPage(self): |
| 306 """Verify that opening new window to a page adds the page to history.""" |
| 307 self._NavigateAndCheckHistory('Title Of Awesomeness', 'title2.html', 1) |
| 308 |
| 309 url2 = self.GetFileURLForDataPath('title3.html') |
| 310 title2 = 'Title Of More Awesomeness' |
| 311 self.OpenNewBrowserWindow(True) |
| 312 self.NavigateToURL(url2, 1) |
| 313 self._CheckHistory(title2, url2, 2) |
| 314 |
222 | 315 |
223 if __name__ == '__main__': | 316 if __name__ == '__main__': |
224 pyauto_functional.Main() | 317 pyauto_functional.Main() |
OLD | NEW |