Merge lp:~ahayzen/webbrowser-app/add-autopilot-multi-window-tests-001 into lp:webbrowser-app/staging

Proposed by Andrew Hayzen
Status: Merged
Merged at revision: 1574
Proposed branch: lp:~ahayzen/webbrowser-app/add-autopilot-multi-window-tests-001
Merge into: lp:webbrowser-app/staging
Diff against target: 216 lines (+119/-12)
5 files modified
tests/autopilot/webbrowser_app/emulators/browser.py (+3/-1)
tests/autopilot/webbrowser_app/tests/__init__.py (+40/-7)
tests/autopilot/webbrowser_app/tests/test_downloads.py (+36/-0)
tests/autopilot/webbrowser_app/tests/test_history.py (+30/-4)
tests/autopilot/webbrowser_app/tests/test_new_tab_view.py (+10/-0)
To merge this branch: bzr merge lp:~ahayzen/webbrowser-app/add-autopilot-multi-window-tests-001
Reviewer Review Type Date Requested Status
Olivier Tilloy Approve
Review via email: mp+309678@code.launchpad.net

Commit message

* Add test_private_download which ensures that private downloads are not available in public windows
* Add test to ensure that private tab view is shown when opening a private window
* Add test_private_window_no_history to check that navigate to pages in a private window does not add history entries
* Add switch_to_unfocused_window helper method

Description of the change

* Add test_private_download which ensures that private downloads are not available in public windows
* Add test to ensure that private tab view is shown when opening a private window
* Add test_private_window_no_history to check that navigate to pages in a private window does not add history entries
* Add switch_to_unfocused_window helper method

Note the switch_to_unfocused_window helper method should be the same as in the drag and drop branch (lp:~ahayzen/webbrowser-app/dnd-tabs-001)

To post a comment you must log in.
1556. By Andrew Hayzen

* Merge of lp:webbrowser-app/staging

1557. By Andrew Hayzen

* Add fix for history test so that it switches to the correct window

Revision history for this message
Olivier Tilloy (osomon) :
review: Needs Fixing
1558. By Andrew Hayzen

* Move test_private_window_uses_private_tab_view from test_site_previews.py to test_new_tab_view.py
* Fix for unused variable for pyflakes
* Remove unneeded code comment

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Fixed inline comments, please retest :-)

Revision history for this message
Olivier Tilloy (osomon) wrote :

switch_to_unfocused_window fails to focus a different window on a phone, and as a consequence the following tests reliably fail:

webbrowser_app.tests.test_history.TestHistory.test_private_window_no_history
webbrowser_app.tests.test_downloads.TestDownloads.test_private_download

They should probably be skipped on touch devices.

review: Needs Fixing
1559. By Andrew Hayzen

* Skip test_private_window_no_history and test_private_download on non-desktop devices due to switch_to_unfocused_window not working on mobile

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

test_private_window_no_history and test_private_download are now skipped on non-desktop devices, please retest :-)

Revision history for this message
Olivier Tilloy (osomon) wrote :

LGTM, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/webbrowser_app/emulators/browser.py'
2--- tests/autopilot/webbrowser_app/emulators/browser.py 2016-10-13 14:36:24 +0000
3+++ tests/autopilot/webbrowser_app/emulators/browser.py 2016-11-03 13:09:49 +0000
4@@ -522,7 +522,9 @@
5
6 class DownloadsPage(BrowserPage):
7
8- pass
9+ def get_download_entries(self):
10+ return sorted(self.select_many("DownloadDelegate"),
11+ key=lambda item: item.globalRect.y)
12
13
14 class HistoryView(uitk.UbuntuUIToolkitCustomProxyObjectBase):
15
16=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
17--- tests/autopilot/webbrowser_app/tests/__init__.py 2016-09-20 21:56:25 +0000
18+++ tests/autopilot/webbrowser_app/tests/__init__.py 2016-11-03 13:09:49 +0000
19@@ -216,23 +216,29 @@
20 self.pointing_device.click_object(bookmarks_action)
21 return self.main_window.get_bookmarks_view()
22
23- def open_history(self):
24- chrome = self.main_window.chrome
25+ def open_history(self, window=None):
26+ if window is None:
27+ window = self.main_window
28+
29+ chrome = window.chrome
30 drawer_button = chrome.get_drawer_button()
31 self.pointing_device.click_object(drawer_button)
32 chrome.get_drawer()
33 history_action = chrome.get_drawer_action("history")
34 self.pointing_device.click_object(history_action)
35- return self.main_window.get_history_view()
36-
37- def open_downloads(self):
38- chrome = self.main_window.chrome
39+ return window.get_history_view()
40+
41+ def open_downloads(self, window=None):
42+ if window is None:
43+ window = self.main_window
44+
45+ chrome = window.chrome
46 drawer_button = chrome.get_drawer_button()
47 self.pointing_device.click_object(drawer_button)
48 chrome.get_drawer()
49 downloads_action = chrome.get_drawer_action("downloads")
50 self.pointing_device.click_object(downloads_action)
51- return self.main_window.get_downloads_page()
52+ return window.get_downloads_page()
53
54 def assert_number_webviews_eventually(self, count):
55 self.assertThat(lambda: len(self.main_window.get_webviews()),
56@@ -256,6 +262,33 @@
57 os.kill(child.pid, signal)
58 break
59
60+ def switch_to_unfocused_window(self, target_window,
61+ expected_number_unfocused_windows=1):
62+ try:
63+ windows = [
64+ window for window in self.process_manager.get_open_windows()
65+ if window.application.desktop_file ==
66+ "webbrowser-app.desktop" and
67+ not window.is_focused
68+ ]
69+
70+ self.assertThat(len(windows),
71+ Equals(expected_number_unfocused_windows))
72+
73+ # Cycle through possible windows until target gets focus
74+ for window in windows:
75+ window.set_focus()
76+ self.assertThat(lambda: window.is_focused,
77+ Eventually(Equals(True)))
78+
79+ if target_window.activeFocus:
80+ break
81+ except (RuntimeError, ImportError):
82+ # Fallback to clicking on the window
83+ self.pointing_device.click_object(target_window)
84+
85+ self.assertThat(target_window.activeFocus, Eventually(Equals(True)))
86+
87
88 class StartOpenRemotePageTestCaseBase(BrowserTestCaseBase):
89
90
91=== modified file 'tests/autopilot/webbrowser_app/tests/test_downloads.py'
92--- tests/autopilot/webbrowser_app/tests/test_downloads.py 2015-12-15 16:02:16 +0000
93+++ tests/autopilot/webbrowser_app/tests/test_downloads.py 2016-11-03 13:09:49 +0000
94@@ -75,3 +75,39 @@
95 self.main_window.click_download_file_button()
96 downloads_page = self.main_window.get_downloads_page()
97 self.assertThat(downloads_page.visible, Eventually(Equals(True)))
98+
99+ @testtools.skipIf(model() != "Desktop",
100+ "Desktop only due to switch_to_unfocused_window")
101+ def test_private_download(self):
102+ self.open_new_private_window()
103+
104+ public_window = self.app.get_windows(incognito=False)[0]
105+ private_window = self.app.get_windows(incognito=True)[0]
106+ pdf_download_url = self.base_url + "/downloadpdf"
107+
108+ # Download pdf in private window
109+ private_window.go_to_url(pdf_download_url)
110+ options_dialog = private_window.get_download_options_dialog()
111+ self.assertThat(options_dialog.visible, Eventually(Equals(True)))
112+ private_window.click_download_file_button()
113+
114+ # Open downloads page in private window
115+ private_downloads_page = private_window.get_downloads_page()
116+ private_downloads_page.visible.wait_for(True)
117+
118+ # Check that there is one url in the private downloads window
119+ entries = private_downloads_page.get_download_entries()
120+ self.assertThat(len(entries), Equals(1))
121+ self.assertThat(entries[0].url, Equals(pdf_download_url))
122+ self.assertThat(entries[0].incognito, Equals(True))
123+
124+ # Focus public window
125+ self.switch_to_unfocused_window(public_window)
126+
127+ # Open downloads page in public window
128+ public_downloads_page = self.open_downloads(public_window)
129+ public_downloads_page.visible.wait_for(True)
130+
131+ # Check that there are no entries in the public downloads window
132+ entries = public_downloads_page.get_download_entries()
133+ self.assertThat(len(entries), Equals(0))
134
135=== modified file 'tests/autopilot/webbrowser_app/tests/test_history.py'
136--- tests/autopilot/webbrowser_app/tests/test_history.py 2016-10-06 21:07:50 +0000
137+++ tests/autopilot/webbrowser_app/tests/test_history.py 2016-11-03 13:09:49 +0000
138@@ -18,15 +18,21 @@
139
140 from testtools.matchers import EndsWith, Equals, StartsWith
141 from autopilot.matchers import Eventually
142+from autopilot.platform import model
143
144 from webbrowser_app.tests import StartOpenRemotePageTestCaseBase
145
146+import testtools
147+
148
149 class TestHistory(StartOpenRemotePageTestCaseBase):
150
151- def expect_history_entries(self, ordered_urls):
152- history = self.main_window.get_history_view()
153- if self.main_window.wide:
154+ def expect_history_entries(self, ordered_urls, window=None):
155+ if window is None:
156+ window = self.main_window
157+
158+ history = window.get_history_view()
159+ if window.wide:
160 self.assertThat(lambda: len(history.get_entries()),
161 Eventually(Equals(len(ordered_urls))))
162 entries = history.get_entries()
163@@ -34,7 +40,7 @@
164 self.assertThat(lambda: len(history.get_domain_entries()),
165 Eventually(Equals(1)))
166 self.pointing_device.click_object(history.get_domain_entries()[0])
167- expanded_history = self.main_window.get_expanded_history_view()
168+ expanded_history = window.get_expanded_history_view()
169 self.assertThat(lambda: len(expanded_history.get_entries()),
170 Eventually(Equals(len(ordered_urls))))
171 entries = expanded_history.get_entries()
172@@ -125,6 +131,26 @@
173 self.open_history()
174 self.expect_history_entries([pushed, url, self.url])
175
176+ @testtools.skipIf(model() != "Desktop",
177+ "Desktop only due to switch_to_unfocused_window")
178+ def test_private_window_no_history(self):
179+ self.open_new_private_window()
180+
181+ public_window = self.app.get_windows(incognito=False)[0]
182+ private_window = self.app.get_windows(incognito=True)[0]
183+
184+ # Open link in private window
185+ url = self.base_url + "/test2"
186+ private_window.go_to_url(url)
187+ private_window.wait_until_page_loaded(url)
188+
189+ # Focus public window
190+ self.switch_to_unfocused_window(public_window)
191+
192+ # Check link is not in history of public window
193+ self.open_history(window=public_window)
194+ self.expect_history_entries([self.url], window=public_window)
195+
196 def test_title_correct_redirect_header(self):
197 # Regression test for https://launchpad.net/bugs/1603835
198 url_redirect = self.base_url + "/redirect-no-title-header"
199
200=== modified file 'tests/autopilot/webbrowser_app/tests/test_new_tab_view.py'
201--- tests/autopilot/webbrowser_app/tests/test_new_tab_view.py 2016-10-11 11:25:23 +0000
202+++ tests/autopilot/webbrowser_app/tests/test_new_tab_view.py 2016-11-03 13:09:49 +0000
203@@ -466,3 +466,13 @@
204 self.assertThat(lambda: len(view.get_bookmarks_list()),
205 Eventually(Equals(2)))
206 self.assertThat(view.get_bookmarks_list()[0].title, Equals(title))
207+
208+
209+class TestNewTabViewPrivate(StartOpenRemotePageTestCaseBase):
210+ def test_private_window_uses_private_tab_view(self):
211+ self.open_new_private_window()
212+
213+ private_window = self.app.get_windows(incognito=True)[0]
214+
215+ self.assertThat(private_window.get_new_private_tab_view().visible,
216+ Eventually(Equals(True)))

Subscribers

People subscribed via source and target branches