summaryrefslogtreecommitdiffstats
path: root/chrome/test/functional/shortcuts.py
blob: dec41ef99a346fa8372d7045a7141d99d00d1f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os

import pyauto_functional
import pyauto


class ShortcutsTest(pyauto.PyUITest):
  """Test for browser shortcuts.

  No tests for print, save page as... shortcuts as they involve interaction
  with OS native dialogs.
  """

  def testNewTabShortcut(self):
    """Verify new tab shortcut."""
    self.RunCommand(pyauto.IDC_NEW_TAB)
    self.assertEqual(2, self.GetTabCount(), msg='Can not open a new tab.')

  def testCloseTabShortcut(self):
    """Verify close tab shortcut."""
    self.RunCommand(pyauto.IDC_NEW_TAB)
    self.assertEqual(2, self.GetTabCount(), msg='Can not open a new tab.')
    self.RunCommand(pyauto.IDC_CLOSE_TAB)
    self.assertEqual(1, self.GetTabCount(), msg='Can not close a tab.')

  def testReopenClosedTabShortcut(self):
    """Verify reopen closed tab shortcut opens recently closed tab."""
    self.RunCommand(pyauto.IDC_NEW_TAB)
    url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html'))
    self.NavigateToURL(url)
    title = self.GetActiveTabTitle()
    self.GetBrowserWindow(0).GetTab(1).Close()
    self.assertEqual(1, self.GetTabCount(), msg='Can not close a tab.')
    # Verify shortcut reopens the correct tab.
    self.RunCommand(pyauto.IDC_RESTORE_TAB)
    self.assertEqual(2, self.GetTabCount(), msg='Can not restore a tab.')
    self.assertEqual(title, self.GetActiveTabTitle())

  def testNewWindowShortcut(self):
    """Verify new window shortcut."""
    self.RunCommand(pyauto.IDC_NEW_WINDOW)
    self.assertEquals(2, self.GetBrowserWindowCount())

  def testNewIncognitoWindowShortcut(self):
    """Verify new incognito window shortcut launches incognito window."""
    self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
    self.assertEqual(2, self.GetBrowserWindowCount())
    # Check if it is incognito by checking history.
    assert not self.GetHistoryInfo().History(), 'Expecting clean history.'
    url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html'))
    self.NavigateToURL(url, 1, 0)
    self.assertEqual(0, len(self.GetHistoryInfo().History()))

  def testCloseWindowShortcut(self):
    """Verify close window shortcut."""
    self.RunCommand(pyauto.IDC_NEW_WINDOW)
    self.assertEquals(2, self.GetBrowserWindowCount())
    self.RunCommand(pyauto.IDC_CLOSE_WINDOW)
    self.assertEquals(1, self.GetBrowserWindowCount())

  def testFindShortcut(self):
    """Verify find in box shortcut."""
    self.ApplyAccelerator(pyauto.IDC_FIND)
    self.assertTrue(self.WaitUntil(lambda: self.IsFindInPageVisible()),
                    msg='Find in box is not visible.')

  def testAlwaysShowBookmarksBarShortcut(self):
    """Verify always show bookmarks bar shortcut."""
    # Show bookmark bar.
    self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR)
    self.assertTrue(self.WaitUntil(lambda: self.GetBookmarkBarVisibility()),
                    msg='Bookmarks bar is not visible.')
    # Hide bookmark bar.
    self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR)
    self.assertTrue(self.WaitUntil(lambda:
        self.GetBookmarkBarVisibility() is False),
        msg='Bookmarks bar is visible.')

  # TODO: Task Manager Shortcut. crbug.com/73454

  def testViewSourceShortcut(self):
    """Verify view source shortcut."""
    self.ApplyAccelerator(pyauto.IDC_VIEW_SOURCE)
    self.assertEqual(2, self.GetTabCount(), msg='Cannot View Source.')
    self.assertEqual('view-source:about:blank', self.GetActiveTabURL().spec(),
                      msg='View Source URL is not correct.')

  def testDeveloperToolsShortcut(self):
    """Verify developer tools shortcut opens developer tools window.."""
    # Setting the pref to undock devtools so that it can be seen
    # as a separate window.
    self.SetPrefs(pyauto.kDevToolsOpenDocked, False)
    self.ApplyAccelerator(pyauto.IDC_DEV_TOOLS)
    self.assertEqual(2, self.GetBrowserWindowCount(),
                     msg='DevTools window is not open.')

  def testJavaScriptConsoleShortcut(self):
    """Verify javascript console shortcut opens developer tools window.
    We can not check if console is open or not.
    We are making sure at least the shortcut launches developer tools window.
    """
    # Setting the pref to undock devtools so that it can be seen
    # as a separate window.
    self.SetPrefs(pyauto.kDevToolsOpenDocked, False)
    self.ApplyAccelerator(pyauto.IDC_DEV_TOOLS_CONSOLE)
    self.assertEqual(2, self.GetBrowserWindowCount(),
                     msg='DevTools window is not open.')

  def testHistoryShortcut(self):
    """Verify history shortcut opens history page."""
    self.RunCommand(pyauto.IDC_SHOW_HISTORY)
    self.assertEqual('History', self.GetActiveTabTitle(),
                     msg='History page was not opened.')

  def testDownloadsShortcut(self):
    """Verify downloads shortcut opens downloads page."""
    self.RunCommand(pyauto.IDC_SHOW_DOWNLOADS)
    self.assertEqual('Downloads', self.GetActiveTabTitle(),
                     msg='Downloads page was not opened.')

  def testHelpShortcut(self):
    """Verify help shortcut opens help page."""
    self.ApplyAccelerator(pyauto.IDC_HELP_PAGE)
    self.assertTrue(self.WaitUntil(lambda: self.GetActiveTabTitle(),
                    expect_retval='Google Chrome Help'),
                    msg='Google Chrome help page has not opened.')

  def testSwitchingTabs(self):
    """Verify switching tabs shortcut."""
    url1 = self.GetFileURLForDataPath('title1.html')
    url2 = self.GetFileURLForDataPath('title2.html')
    url3 = self.GetFileURLForDataPath('title3.html')
    titles = ['title1.html', 'Title Of Awesomeness',
              'Title Of More Awesomeness']
    for eachurl in [url1, url2, url3]:
      self.AppendTab(pyauto.GURL(eachurl))

    # Switch to second tab.
    self.ApplyAccelerator(pyauto.IDC_SELECT_TAB_1)
    self.assertEqual(titles[0], self.GetActiveTabTitle())

    # Switch to last tab.
    self.ApplyAccelerator(pyauto.IDC_SELECT_LAST_TAB)
    self.assertEqual(titles[2], self.GetActiveTabTitle())

    # Switch to previous tab.
    for x in range(len(titles)-1, -1, -1):
      self.assertEquals(titles[x], self.GetActiveTabTitle())
      self.RunCommand(pyauto.IDC_SELECT_PREVIOUS_TAB)

    # Switch to next tab.
    for x in range(0, len(titles)):
      self.RunCommand(pyauto.IDC_SELECT_NEXT_TAB)
      self.assertEquals(titles[x], self.GetActiveTabTitle())


if __name__ == '__main__':
  pyauto_functional.Main()