Merge lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests into lp:~artmello/webbrowser-app/webbrowser-app-private_browsing

Proposed by Leo Arias
Status: Merged
Approved by: Arthur Mello
Approved revision: 1024
Merged at revision: 1019
Proposed branch: lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests
Merge into: lp:~artmello/webbrowser-app/webbrowser-app-private_browsing
Diff against target: 237 lines (+93/-69)
3 files modified
tests/autopilot/webbrowser_app/emulators/browser.py (+53/-13)
tests/autopilot/webbrowser_app/tests/__init__.py (+0/-35)
tests/autopilot/webbrowser_app/tests/test_private.py (+40/-21)
To merge this branch: bzr merge lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests
Reviewer Review Type Date Requested Status
Arthur Mello Approve
Review via email: mp+258945@code.launchpad.net

Commit message

Refactor private mode autopilot tests.

Description of the change

Moved the helpers out of the testcase and into the Webbrowser object, so they can be reused in other tests that don't inherit from the browser test case. This also provides better encapsulation.

Added the logging decorator to the action helpers, so in case of failure it leaves a more useful trace of what the test was doing.

Added is_new_private_tab_view_visible, which hides the internal implementation of the QML so if it changes, only one helper will have to change instead of multiple tests.

Removed the assertions from the helpers. In most of the cases, the test should be the one checking that the actions were successful. This makes it clear what's the purpose of the test.

On test_url_must_not_be_stored_in_history_in_private_mode, I think it's unnecessary to leave the private mode to check that the history was not written. Unnecessary steps should be removed.

I added test_url_must_be_stored_in_history_after_leaving_private_mode, because it's good to have complementary tests: one to check that history is not written, one to test that history is written. This is a way to check that the test is correct.

I didn't modify the last test because it would mean changing some of the existing helpers and updating existing tests. If you find this refactor useful, I can do it in a following branch.

After the refactoring, what I noticed is that test_going_in_and_out_private_mode and test_cancel_leaving_private_mode are not a good fit for autopilot. From the user point of view, this story is about making sure that on private mode the history is not written, and autopilot is good to test that. Autopilot is not so good to test the changes in the UI components. I attempted to turn those two into QML tests, but it's hard. More about that in:
https://code.launchpad.net/~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests-qml/+merge/258946

To post a comment you must log in.
1022. By Leo Arias

Some more cleanaups.

1023. By Leo Arias

Reverted pot changes.

1024. By Leo Arias

Fixed the call to private mode on the last test.

Revision history for this message
Arthur Mello (artmello) wrote :

Looks good to me. Thanks a lot for the feedback and the proposed fixes

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 2015-05-12 19:50:02 +0000
3+++ tests/autopilot/webbrowser_app/emulators/browser.py 2015-05-13 00:24:44 +0000
4@@ -18,7 +18,10 @@
5
6 import autopilot.logging
7 import ubuntuuitoolkit as uitk
8-from autopilot import introspection
9+from autopilot import (
10+ exceptions,
11+ introspection
12+)
13
14
15 class Webbrowser(uitk.UbuntuUIToolkitCustomProxyObjectBase):
16@@ -66,6 +69,45 @@
17 def go_forward(self):
18 self.chrome.go_forward()
19
20+ @autopilot.logging.log_action(logger.info)
21+ def enter_private_mode(self):
22+ if not self.is_in_private_mode():
23+ self.chrome.toggle_private_mode()
24+ else:
25+ logger.warning('The browser is already in private mode.')
26+
27+ def is_in_private_mode(self):
28+ return self.get_current_webview().incognito
29+
30+ @autopilot.logging.log_action(logger.info)
31+ def leave_private_mode(self, confirm=True):
32+ if self.is_in_private_mode():
33+ self.chrome.toggle_private_mode()
34+ dialog = self._get_leave_private_mode_dialog()
35+ if confirm:
36+ dialog.confirm()
37+ dialog.wait_until_destroyed()
38+ else:
39+ dialog.cancel()
40+ dialog.wait_until_destroyed()
41+ else:
42+ logger.warning('The browser is not in private mode.')
43+
44+ def _get_leave_private_mode_dialog(self):
45+ return self.wait_select_single(LeavePrivateModeDialog, visible=True)
46+
47+ # Since the NewPrivateTabView does not define any new QML property in its
48+ # extended file, it does not report itself to autopilot with the same name
49+ # as the extended file. (See http://pad.lv/1454394)
50+ def is_new_private_tab_view_visible(self):
51+ try:
52+ self.wait_select_single("QQuickItem",
53+ objectName="newPrivateTabView",
54+ visible=True)
55+ return True
56+ except exceptions.StateNotFoundError:
57+ return False
58+
59 def get_window(self):
60 return self.get_parent()
61
62@@ -104,17 +146,6 @@
63 def get_new_tab_view(self):
64 return self.wait_select_single("NewTabView", visible=True)
65
66- # Since the NewPrivateTabView does not define any new QML property in its
67- # extended file, it does not report itself to autopilot with the same name
68- # as the extended file. (See http://pad.lv/1454394)
69- def get_new_private_tab_view(self):
70- return self.wait_select_single("QQuickItem",
71- objectName="newPrivateTabView",
72- visible=True)
73-
74- def get_leave_private_mode_dialog(self):
75- return self.wait_select_single(LeavePrivateModeDialog, visible=True)
76-
77 def get_settings_page(self):
78 return self.wait_select_single(SettingsPage, visible=True)
79
80@@ -162,6 +193,13 @@
81 forward_button = self._get_forward_button()
82 return forward_button.enabled
83
84+ def toggle_private_mode(self):
85+ drawer_button = self.get_drawer_button()
86+ self.pointing_device.click_object(drawer_button)
87+ self.get_drawer()
88+ private_mode_action = self.get_drawer_action("privatemode")
89+ self.pointing_device.click_object(private_mode_action)
90+
91 def get_drawer_button(self):
92 return self.select_single("ChromeButton", objectName="drawerButton")
93
94@@ -306,13 +344,15 @@
95 self.pointing_device.click_object(button)
96
97
98-class LeavePrivateModeDialog(uitk.UbuntuUIToolkitCustomProxyObjectBase):
99+class LeavePrivateModeDialog(uitk.Dialog):
100
101+ @autopilot.logging.log_action(logger.info)
102 def confirm(self):
103 confirm_button = self.select_single(
104 "Button", objectName="leavePrivateModeDialog.okButton")
105 self.pointing_device.click_object(confirm_button)
106
107+ @autopilot.logging.log_action(logger.info)
108 def cancel(self):
109 cancel_button = self.select_single(
110 "Button", objectName="leavePrivateModeDialog.cancelButton")
111
112=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
113--- tests/autopilot/webbrowser_app/tests/__init__.py 2015-05-12 14:55:22 +0000
114+++ tests/autopilot/webbrowser_app/tests/__init__.py 2015-05-13 00:24:44 +0000
115@@ -154,41 +154,6 @@
116 self.pointing_device.click_object(settings_action)
117 return self.main_window.get_settings_page()
118
119- def toggle_private_mode(self):
120- chrome = self.main_window.chrome
121- drawer_button = chrome.get_drawer_button()
122- self.pointing_device.click_object(drawer_button)
123- chrome.get_drawer()
124- privatemode_action = chrome.get_drawer_action("privatemode")
125- self.pointing_device.click_object(privatemode_action)
126-
127- def go_into_private_mode(self):
128- self.assertThat(self.main_window.get_current_webview().incognito,
129- Eventually(Equals(False)))
130- self.toggle_private_mode()
131- self.assertThat(self.main_window.get_current_webview().incognito,
132- Eventually(Equals(True)))
133-
134- def leave_private_mode_and_confirm(self):
135- self.assertThat(self.main_window.get_current_webview().incognito,
136- Eventually(Equals(True)))
137- self.toggle_private_mode()
138- dialog = self.main_window.get_leave_private_mode_dialog()
139- dialog.confirm()
140- dialog.wait_until_destroyed()
141- self.assertThat(self.main_window.get_current_webview().incognito,
142- Eventually(Equals(False)))
143-
144- def leave_private_mode_and_cancel(self):
145- self.assertThat(self.main_window.get_current_webview().incognito,
146- Eventually(Equals(True)))
147- self.toggle_private_mode()
148- dialog = self.main_window.get_leave_private_mode_dialog()
149- dialog.cancel()
150- dialog.wait_until_destroyed()
151- self.assertThat(self.main_window.get_current_webview().incognito,
152- Eventually(Equals(True)))
153-
154 def assert_number_webviews_eventually(self, count):
155 self.assertThat(lambda: len(self.main_window.get_webviews()),
156 Eventually(Equals(count)))
157
158=== modified file 'tests/autopilot/webbrowser_app/tests/test_private.py'
159--- tests/autopilot/webbrowser_app/tests/test_private.py 2015-05-12 17:54:34 +0000
160+++ tests/autopilot/webbrowser_app/tests/test_private.py 2015-05-13 00:24:44 +0000
161@@ -35,28 +35,47 @@
162 return ret
163
164 def test_going_in_and_out_private_mode(self):
165- self.go_into_private_mode()
166- self.main_window.get_new_private_tab_view()
167- self.leave_private_mode_and_confirm()
168+ self.main_window.enter_private_mode()
169+ self.assertTrue(self.main_window.is_in_private_mode())
170+ self.assertTrue(self.main_window.is_new_private_tab_view_visible())
171+ self.main_window.leave_private_mode()
172+ self.assertFalse(self.main_window.is_in_private_mode())
173
174 def test_cancel_leaving_private_mode(self):
175- self.go_into_private_mode()
176- new_private_tab_view = self.main_window.get_new_private_tab_view()
177- self.leave_private_mode_and_cancel()
178- self.assertThat(new_private_tab_view.visible, Eventually(Equals(True)))
179-
180- def test_url_not_stored_in_private_mode(self):
181- history = self.get_url_list_from_history()
182- url = self.base_url + "/test2"
183- self.assertThat(url not in history, Equals(True))
184- self.go_into_private_mode()
185- self.main_window.go_to_url(url)
186- self.main_window.wait_until_page_loaded(url)
187- self.leave_private_mode_and_confirm()
188- history = self.get_url_list_from_history()
189- self.assertThat(url not in history, Equals(True))
190-
191- def test_usual_tabs_not_visible_in_private(self):
192+ self.main_window.enter_private_mode()
193+ self.assertTrue(self.main_window.is_in_private_mode())
194+ self.assertTrue(self.main_window.is_new_private_tab_view_visible())
195+ self.main_window.leave_private_mode(confirm=False)
196+ self.assertTrue(self.main_window.is_in_private_mode())
197+ self.assertTrue(self.main_window.is_new_private_tab_view_visible())
198+
199+ def test_url_must_not_be_stored_in_history_in_private_mode(self):
200+ history = self.get_url_list_from_history()
201+ url = self.base_url + "/test2"
202+ self.assertNotIn(url, history)
203+
204+ self.main_window.enter_private_mode()
205+ self.main_window.go_to_url(url)
206+ self.main_window.wait_until_page_loaded(url)
207+
208+ history = self.get_url_list_from_history()
209+ self.assertNotIn(url, history)
210+
211+ def test_url_must_be_stored_in_history_after_leaving_private_mode(self):
212+ history = self.get_url_list_from_history()
213+ url = self.base_url + "/test2"
214+ self.assertNotIn(url, history)
215+
216+ self.main_window.enter_private_mode()
217+ self.main_window.leave_private_mode()
218+ self.main_window.go_to_url(url)
219+ self.main_window.wait_until_page_loaded(url)
220+
221+ history = self.get_url_list_from_history()
222+ self.assertIn(url, history)
223+
224+ def test_previews_tabs_must_not_be_visible_after_entering_private_mode(
225+ self):
226 self.open_tabs_view()
227 self.open_new_tab()
228 new_tab_view = self.main_window.get_new_tab_view()
229@@ -72,7 +91,7 @@
230 self.assertThat(lambda: self.main_window.get_current_webview().url,
231 Eventually(Equals(url)))
232
233- self.go_into_private_mode()
234+ self.main_window.enter_private_mode()
235 self.open_tabs_view()
236 tabs_view = self.main_window.get_tabs_view()
237 previews = tabs_view.get_previews()

Subscribers

People subscribed via source and target branches