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
=== modified file 'tests/autopilot/webbrowser_app/emulators/browser.py'
--- tests/autopilot/webbrowser_app/emulators/browser.py 2015-05-12 19:50:02 +0000
+++ tests/autopilot/webbrowser_app/emulators/browser.py 2015-05-13 00:24:44 +0000
@@ -18,7 +18,10 @@
1818
19import autopilot.logging19import autopilot.logging
20import ubuntuuitoolkit as uitk20import ubuntuuitoolkit as uitk
21from autopilot import introspection21from autopilot import (
22 exceptions,
23 introspection
24)
2225
2326
24class Webbrowser(uitk.UbuntuUIToolkitCustomProxyObjectBase):27class Webbrowser(uitk.UbuntuUIToolkitCustomProxyObjectBase):
@@ -66,6 +69,45 @@
66 def go_forward(self):69 def go_forward(self):
67 self.chrome.go_forward()70 self.chrome.go_forward()
6871
72 @autopilot.logging.log_action(logger.info)
73 def enter_private_mode(self):
74 if not self.is_in_private_mode():
75 self.chrome.toggle_private_mode()
76 else:
77 logger.warning('The browser is already in private mode.')
78
79 def is_in_private_mode(self):
80 return self.get_current_webview().incognito
81
82 @autopilot.logging.log_action(logger.info)
83 def leave_private_mode(self, confirm=True):
84 if self.is_in_private_mode():
85 self.chrome.toggle_private_mode()
86 dialog = self._get_leave_private_mode_dialog()
87 if confirm:
88 dialog.confirm()
89 dialog.wait_until_destroyed()
90 else:
91 dialog.cancel()
92 dialog.wait_until_destroyed()
93 else:
94 logger.warning('The browser is not in private mode.')
95
96 def _get_leave_private_mode_dialog(self):
97 return self.wait_select_single(LeavePrivateModeDialog, visible=True)
98
99 # Since the NewPrivateTabView does not define any new QML property in its
100 # extended file, it does not report itself to autopilot with the same name
101 # as the extended file. (See http://pad.lv/1454394)
102 def is_new_private_tab_view_visible(self):
103 try:
104 self.wait_select_single("QQuickItem",
105 objectName="newPrivateTabView",
106 visible=True)
107 return True
108 except exceptions.StateNotFoundError:
109 return False
110
69 def get_window(self):111 def get_window(self):
70 return self.get_parent()112 return self.get_parent()
71113
@@ -104,17 +146,6 @@
104 def get_new_tab_view(self):146 def get_new_tab_view(self):
105 return self.wait_select_single("NewTabView", visible=True)147 return self.wait_select_single("NewTabView", visible=True)
106148
107 # Since the NewPrivateTabView does not define any new QML property in its
108 # extended file, it does not report itself to autopilot with the same name
109 # as the extended file. (See http://pad.lv/1454394)
110 def get_new_private_tab_view(self):
111 return self.wait_select_single("QQuickItem",
112 objectName="newPrivateTabView",
113 visible=True)
114
115 def get_leave_private_mode_dialog(self):
116 return self.wait_select_single(LeavePrivateModeDialog, visible=True)
117
118 def get_settings_page(self):149 def get_settings_page(self):
119 return self.wait_select_single(SettingsPage, visible=True)150 return self.wait_select_single(SettingsPage, visible=True)
120151
@@ -162,6 +193,13 @@
162 forward_button = self._get_forward_button()193 forward_button = self._get_forward_button()
163 return forward_button.enabled194 return forward_button.enabled
164195
196 def toggle_private_mode(self):
197 drawer_button = self.get_drawer_button()
198 self.pointing_device.click_object(drawer_button)
199 self.get_drawer()
200 private_mode_action = self.get_drawer_action("privatemode")
201 self.pointing_device.click_object(private_mode_action)
202
165 def get_drawer_button(self):203 def get_drawer_button(self):
166 return self.select_single("ChromeButton", objectName="drawerButton")204 return self.select_single("ChromeButton", objectName="drawerButton")
167205
@@ -306,13 +344,15 @@
306 self.pointing_device.click_object(button)344 self.pointing_device.click_object(button)
307345
308346
309class LeavePrivateModeDialog(uitk.UbuntuUIToolkitCustomProxyObjectBase):347class LeavePrivateModeDialog(uitk.Dialog):
310348
349 @autopilot.logging.log_action(logger.info)
311 def confirm(self):350 def confirm(self):
312 confirm_button = self.select_single(351 confirm_button = self.select_single(
313 "Button", objectName="leavePrivateModeDialog.okButton")352 "Button", objectName="leavePrivateModeDialog.okButton")
314 self.pointing_device.click_object(confirm_button)353 self.pointing_device.click_object(confirm_button)
315354
355 @autopilot.logging.log_action(logger.info)
316 def cancel(self):356 def cancel(self):
317 cancel_button = self.select_single(357 cancel_button = self.select_single(
318 "Button", objectName="leavePrivateModeDialog.cancelButton")358 "Button", objectName="leavePrivateModeDialog.cancelButton")
319359
=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
--- tests/autopilot/webbrowser_app/tests/__init__.py 2015-05-12 14:55:22 +0000
+++ tests/autopilot/webbrowser_app/tests/__init__.py 2015-05-13 00:24:44 +0000
@@ -154,41 +154,6 @@
154 self.pointing_device.click_object(settings_action)154 self.pointing_device.click_object(settings_action)
155 return self.main_window.get_settings_page()155 return self.main_window.get_settings_page()
156156
157 def toggle_private_mode(self):
158 chrome = self.main_window.chrome
159 drawer_button = chrome.get_drawer_button()
160 self.pointing_device.click_object(drawer_button)
161 chrome.get_drawer()
162 privatemode_action = chrome.get_drawer_action("privatemode")
163 self.pointing_device.click_object(privatemode_action)
164
165 def go_into_private_mode(self):
166 self.assertThat(self.main_window.get_current_webview().incognito,
167 Eventually(Equals(False)))
168 self.toggle_private_mode()
169 self.assertThat(self.main_window.get_current_webview().incognito,
170 Eventually(Equals(True)))
171
172 def leave_private_mode_and_confirm(self):
173 self.assertThat(self.main_window.get_current_webview().incognito,
174 Eventually(Equals(True)))
175 self.toggle_private_mode()
176 dialog = self.main_window.get_leave_private_mode_dialog()
177 dialog.confirm()
178 dialog.wait_until_destroyed()
179 self.assertThat(self.main_window.get_current_webview().incognito,
180 Eventually(Equals(False)))
181
182 def leave_private_mode_and_cancel(self):
183 self.assertThat(self.main_window.get_current_webview().incognito,
184 Eventually(Equals(True)))
185 self.toggle_private_mode()
186 dialog = self.main_window.get_leave_private_mode_dialog()
187 dialog.cancel()
188 dialog.wait_until_destroyed()
189 self.assertThat(self.main_window.get_current_webview().incognito,
190 Eventually(Equals(True)))
191
192 def assert_number_webviews_eventually(self, count):157 def assert_number_webviews_eventually(self, count):
193 self.assertThat(lambda: len(self.main_window.get_webviews()),158 self.assertThat(lambda: len(self.main_window.get_webviews()),
194 Eventually(Equals(count)))159 Eventually(Equals(count)))
195160
=== modified file 'tests/autopilot/webbrowser_app/tests/test_private.py'
--- tests/autopilot/webbrowser_app/tests/test_private.py 2015-05-12 17:54:34 +0000
+++ tests/autopilot/webbrowser_app/tests/test_private.py 2015-05-13 00:24:44 +0000
@@ -35,28 +35,47 @@
35 return ret35 return ret
3636
37 def test_going_in_and_out_private_mode(self):37 def test_going_in_and_out_private_mode(self):
38 self.go_into_private_mode()38 self.main_window.enter_private_mode()
39 self.main_window.get_new_private_tab_view()39 self.assertTrue(self.main_window.is_in_private_mode())
40 self.leave_private_mode_and_confirm()40 self.assertTrue(self.main_window.is_new_private_tab_view_visible())
41 self.main_window.leave_private_mode()
42 self.assertFalse(self.main_window.is_in_private_mode())
4143
42 def test_cancel_leaving_private_mode(self):44 def test_cancel_leaving_private_mode(self):
43 self.go_into_private_mode()45 self.main_window.enter_private_mode()
44 new_private_tab_view = self.main_window.get_new_private_tab_view()46 self.assertTrue(self.main_window.is_in_private_mode())
45 self.leave_private_mode_and_cancel()47 self.assertTrue(self.main_window.is_new_private_tab_view_visible())
46 self.assertThat(new_private_tab_view.visible, Eventually(Equals(True)))48 self.main_window.leave_private_mode(confirm=False)
4749 self.assertTrue(self.main_window.is_in_private_mode())
48 def test_url_not_stored_in_private_mode(self):50 self.assertTrue(self.main_window.is_new_private_tab_view_visible())
49 history = self.get_url_list_from_history()51
50 url = self.base_url + "/test2"52 def test_url_must_not_be_stored_in_history_in_private_mode(self):
51 self.assertThat(url not in history, Equals(True))53 history = self.get_url_list_from_history()
52 self.go_into_private_mode()54 url = self.base_url + "/test2"
53 self.main_window.go_to_url(url)55 self.assertNotIn(url, history)
54 self.main_window.wait_until_page_loaded(url)56
55 self.leave_private_mode_and_confirm()57 self.main_window.enter_private_mode()
56 history = self.get_url_list_from_history()58 self.main_window.go_to_url(url)
57 self.assertThat(url not in history, Equals(True))59 self.main_window.wait_until_page_loaded(url)
5860
59 def test_usual_tabs_not_visible_in_private(self):61 history = self.get_url_list_from_history()
62 self.assertNotIn(url, history)
63
64 def test_url_must_be_stored_in_history_after_leaving_private_mode(self):
65 history = self.get_url_list_from_history()
66 url = self.base_url + "/test2"
67 self.assertNotIn(url, history)
68
69 self.main_window.enter_private_mode()
70 self.main_window.leave_private_mode()
71 self.main_window.go_to_url(url)
72 self.main_window.wait_until_page_loaded(url)
73
74 history = self.get_url_list_from_history()
75 self.assertIn(url, history)
76
77 def test_previews_tabs_must_not_be_visible_after_entering_private_mode(
78 self):
60 self.open_tabs_view()79 self.open_tabs_view()
61 self.open_new_tab()80 self.open_new_tab()
62 new_tab_view = self.main_window.get_new_tab_view()81 new_tab_view = self.main_window.get_new_tab_view()
@@ -72,7 +91,7 @@
72 self.assertThat(lambda: self.main_window.get_current_webview().url,91 self.assertThat(lambda: self.main_window.get_current_webview().url,
73 Eventually(Equals(url)))92 Eventually(Equals(url)))
7493
75 self.go_into_private_mode()94 self.main_window.enter_private_mode()
76 self.open_tabs_view()95 self.open_tabs_view()
77 tabs_view = self.main_window.get_tabs_view()96 tabs_view = self.main_window.get_tabs_view()
78 previews = tabs_view.get_previews()97 previews = tabs_view.get_previews()

Subscribers

People subscribed via source and target branches