Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 logging | 7 import logging |
| 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 |
| 11 | 11 import test_utils |
| 12 | 12 |
| 13 class PopupsTest(pyauto.PyUITest): | 13 class PopupsTest(pyauto.PyUITest): |
| 14 """TestCase for Popup blocking.""" | 14 """TestCase for Popup blocking.""" |
| 15 | 15 |
| 16 def Debug(self): | 16 def Debug(self): |
| 17 """Test method for experimentation. | 17 """Test method for experimentation. |
| 18 | 18 |
| 19 This method will not run automatically. | 19 This method will not run automatically. |
| 20 """ | 20 """ |
| 21 import pprint | 21 import pprint |
| 22 pp = pprint.PrettyPrinter(indent=2) | 22 pp = pprint.PrettyPrinter(indent=2) |
| 23 while True: | 23 while True: |
| 24 raw_input('Interact with the browser and hit <enter>') | 24 raw_input('Interact with the browser and hit <enter>') |
| 25 pp.pprint(self.GetBlockedPopupsInfo()) | 25 pp.pprint(self.GetBlockedPopupsInfo()) |
| 26 | 26 |
|
Nirnimesh
2011/05/19 06:14:45
remove spaces from this line
| |
| 27 def testPopupBlockerEnabled(self): | 27 def testPopupBlockerEnabled(self): |
| 28 """Verify popup blocking is enabled.""" | 28 """Verify popup blocking is enabled.""" |
| 29 self.assertFalse(self.GetBlockedPopupsInfo(), | 29 self.assertFalse(self.GetBlockedPopupsInfo(), |
| 30 msg='Should have no blocked popups on startup') | 30 msg='Should have no blocked popups on startup') |
| 31 file_url = self.GetFileURLForPath(os.path.join( | 31 file_url = self.GetFileURLForPath(os.path.join( |
| 32 self.DataDir(), 'popup_blocker', 'popup-window-open.html')) | 32 self.DataDir(), 'popup_blocker', 'popup-window-open.html')) |
| 33 self.NavigateToURL(file_url) | 33 self.NavigateToURL(file_url) |
| 34 blocked_popups = self.GetBlockedPopupsInfo() | 34 blocked_popups = self.GetBlockedPopupsInfo() |
| 35 self.assertEqual(1, len(blocked_popups), msg='Popup not blocked') | 35 self.assertEqual(1, len(blocked_popups), msg='Popup not blocked') |
| 36 # It might take a while for the title to get set. Don't need to check it. | 36 # It might take a while for the title to get set. Don't need to check it. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 def testPopupsLaunchWhenTabIsClosed(self): | 133 def testPopupsLaunchWhenTabIsClosed(self): |
| 134 """Verify popups are launched when closing a tab.""" | 134 """Verify popups are launched when closing a tab.""" |
| 135 self._SetPopupsException() | 135 self._SetPopupsException() |
| 136 self.AppendTab(pyauto.GURL('http://www.popuptest.com/popuptest12.html')) | 136 self.AppendTab(pyauto.GURL('http://www.popuptest.com/popuptest12.html')) |
| 137 self.assertEqual(4, self.GetBrowserWindowCount(), | 137 self.assertEqual(4, self.GetBrowserWindowCount(), |
| 138 msg='Popups did not launch from the external site.') | 138 msg='Popups did not launch from the external site.') |
| 139 self.GetBrowserWindow(0).GetTab(1).Close(True) | 139 self.GetBrowserWindow(0).GetTab(1).Close(True) |
| 140 # Check if last popup is launched when the tab is closed. | 140 # Check if last popup is launched when the tab is closed. |
| 141 self.assertEqual(5, self.GetBrowserWindowCount(), | 141 self.assertEqual(5, self.GetBrowserWindowCount(), |
| 142 msg='Last popup did not launch when the tab is closed.') | 142 msg='Last popup did not launch when the tab is closed.') |
| 143 | 143 |
| 144 | 144 def testUnblockedPopupShowsInHistory(self): |
| 145 """Verify that when you unblock popup, the popup shows in history.""" | |
| 146 file_url = self.GetFileURLForPath(os.path.join( | |
|
Nirnimesh
2011/05/19 06:14:45
I've made GetFileURLForPath easier to use. Now you
aocampo
2011/05/20 00:36:05
Done.
| |
| 147 self.DataDir(), 'popup_blocker', 'popup-window-open.html')) | |
| 148 self.NavigateToURL(file_url) | |
| 149 self.assertEqual(1, len(self.GetBlockedPopupsInfo())) | |
| 150 self.UnblockAndLaunchBlockedPopup(0) | |
| 151 history = self.GetHistoryInfo().History() | |
| 152 self.assertEqual(2, len(history)) | |
| 153 self.assertEqual('Popup Success!', history[0]['title']) | |
| 154 | |
| 155 def testBlockedPopupNotShowInHistory(self): | |
| 156 """Verify that a blocked popup does not show up in history. | |
| 157 Currently failing because of issue # 47935. | |
|
Nirnimesh
2011/05/19 06:14:45
remove this line. Disable this test in PYAUTO_TEST
aocampo
2011/05/20 00:36:05
Done.
| |
| 158 """ | |
| 159 file_url = self.GetFileURLForPath(os.path.join( | |
|
Nirnimesh
2011/05/19 06:14:45
same here
aocampo
2011/05/20 00:36:05
Done.
| |
| 160 self.DataDir(), 'popup_blocker', 'popup-window-open.html')) | |
| 161 self.NavigateToURL(file_url) | |
| 162 self.assertEqual(1, len(self.GetBlockedPopupsInfo())) | |
| 163 history = self.GetHistoryInfo().History() | |
| 164 self.assertEqual(1, len(history)) | |
|
Nirnimesh
2011/05/19 06:14:45
merge with previous line
aocampo
2011/05/20 00:36:05
Done.
| |
| 165 | |
| 166 def testUnblockedPopupAddedToOmnibox(self): | |
| 167 """Verify that an unblocked popup shows up in omnibox suggestions.""" | |
| 168 file_url = self.GetFileURLForPath(os.path.join( | |
|
Nirnimesh
2011/05/19 06:14:45
same comment as above
aocampo
2011/05/20 00:36:05
Done.
| |
| 169 self.DataDir(), 'popup_blocker', 'popup-window-open.html')) | |
| 170 self.NavigateToURL(file_url) | |
| 171 self.assertEqual(1, len(self.GetBlockedPopupsInfo())) | |
| 172 self.UnblockAndLaunchBlockedPopup(0) | |
| 173 search_string = 'data:text/html,<title>Popup Success!</title> \ | |
|
Nirnimesh
2011/05/19 06:14:45
why not do an omnibox search for something saner,
aocampo
2011/05/20 00:36:05
The html test file already provided isn't written
| |
| 174 you should not see this message if popup blocker is enabled' | |
| 175 matches = test_utils.GetOmniboxMatchesFor(self, search_string) | |
| 176 self.assertEqual(search_string, matches[0]['destination_url']) | |
| 177 self.assertEqual(search_string, matches[0]['contents']) | |
| 178 | |
| 179 | |
| 145 if __name__ == '__main__': | 180 if __name__ == '__main__': |
| 146 pyauto_functional.Main() | 181 pyauto_functional.Main() |
| OLD | NEW |