Merge lp:~mandel/ubuntu-sso-client/tc-not-loading into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Natalia Bidart
Approved revision: 914
Merged at revision: 914
Proposed branch: lp:~mandel/ubuntu-sso-client/tc-not-loading
Merge into: lp:ubuntu-sso-client
Diff against target: 177 lines (+52/-38)
2 files modified
ubuntu_sso/gtk/gui.py (+18/-33)
ubuntu_sso/gtk/tests/test_gui.py (+34/-5)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/tc-not-loading
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+97698@code.launchpad.net

Commit message

- Connected the WebKit browser correctly so that the tc page gets loaded (LP: #933081).
- Added code to check if the browser with the t&c was already loaded. If it is just show the t&c page, otherwise perform the request (LP: #956185).

Description of the change

- Connected the Webkit correctly so that the tc page gets loaded (LP: #933081).
- Added code to check if the browser with the t&c was already loaded. If it is just show the t&c page, otherwise perform the request (LP: #956185).

In order to do an IRL you ca do something like ./bin/ubuntu-sso-login-gtk --app_name test --tc_url https://one.ubuntu.com/terms/

PS: remember to set the python path.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good, T&C loads

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/gtk/gui.py'
2--- ubuntu_sso/gtk/gui.py 2012-02-17 18:43:17 +0000
3+++ ubuntu_sso/gtk/gui.py 2012-03-15 16:57:19 +0000
4@@ -90,23 +90,6 @@
5 return c
6 # pylint: enable=C0103
7
8-
9-# To be removed when Python bindings provide these constants
10-# as per http://code.google.com/p/pywebkitgtk/issues/detail?id=44
11-# WebKitLoadStatus
12-WEBKIT_LOAD_PROVISIONAL = 0
13-WEBKIT_LOAD_COMMITTED = 1
14-WEBKIT_LOAD_FINISHED = 2
15-WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT = 3
16-WEBKIT_LOAD_FAILED = 4
17-# WebKitWebNavigationReason
18-WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED = 0
19-WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED = 1
20-WEBKIT_WEB_NAVIGATION_REASON_BACK_FORWARD = 2
21-WEBKIT_WEB_NAVIGATION_REASON_RELOAD = 3
22-WEBKIT_WEB_NAVIGATION_REASON_FORM_RESUBMITTED = 4
23-WEBKIT_WEB_NAVIGATION_REASON_OTHER = 5
24-
25 DEFAULT_WIDTH = 30
26 # To be replaced by values from the theme (LP: #616526)
27 HELP_TEXT_COLOR = parse_color("#bfbfbf")
28@@ -947,23 +930,14 @@
29
30 self._set_current_page(self.processing_vbox)
31
32- def on_tc_button_clicked(self, *args, **kwargs):
33- """The T&C button was clicked, create the browser and load terms."""
34+ def _add_webkit_browser(self):
35+ """Add the webkit browser for the t&c."""
36 # delay the import of webkit to be able to build without it
37 from gi.repository import WebKit # pylint: disable=E0611
38+
39 browser = WebKit.WebView()
40
41- # The signal WebKitWebView::load-finished is deprecated and should not
42- # be used in newly-written code. Use the "load-status" property
43- # instead. Connect to "notify::load-status" to monitor loading.
44-
45- # nataliabidart (2010-10-04): connecting this signal makes the loading
46- # of the Ubuntu One terms URL to fail. So we're using the deprecated
47- # 'load-finished' for now.
48-
49- #browser.connect('notify::load-status',
50- # self.on_tc_browser_notify_load_status)
51- browser.connect('load-finished',
52+ browser.connect('notify::load-status',
53 self.on_tc_browser_notify_load_status)
54 browser.connect('navigation-policy-decision-requested',
55 self.on_tc_browser_navigation_requested)
56@@ -978,7 +952,14 @@
57 browser.load_uri(self.tc_url)
58 browser.show()
59 self.tc_browser_window.add(browser)
60- self._set_current_page(self.processing_vbox)
61+
62+ def on_tc_button_clicked(self, *args, **kwargs):
63+ """The T&C button was clicked, create the browser and load terms."""
64+ if self.tc_browser_window.get_child() is None:
65+ self._add_webkit_browser()
66+ self._set_current_page(self.processing_vbox)
67+ else:
68+ self._set_current_page(self.tc_browser_vbox)
69
70 def on_tc_back_button_clicked(self, *args, **kwargs):
71 """T & C 'back' button was clicked, return to the previous page."""
72@@ -986,14 +967,18 @@
73
74 def on_tc_browser_notify_load_status(self, browser, *args, **kwargs):
75 """The T&C page is being loaded."""
76- if browser.get_load_status() == WEBKIT_LOAD_FINISHED:
77+ from gi.repository import WebKit # pylint: disable=E0611
78+
79+ if browser.get_load_status().real == WebKit.LoadStatus.FINISHED:
80 self._set_current_page(self.tc_browser_vbox)
81
82 def on_tc_browser_navigation_requested(self, browser, frame, request,
83 action, decision, *args, **kwargs):
84 """The user wants to navigate within the T&C browser."""
85+ from gi.repository import WebKit # pylint: disable=E0611
86+
87 if action is not None and \
88- action.get_reason() == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED:
89+ action.get_reason() == WebKit.WebNavigationReason.LINK_CLICKED:
90 if decision is not None:
91 decision.ignore()
92 url = action.get_original_uri()
93
94=== modified file 'ubuntu_sso/gtk/tests/test_gui.py'
95--- ubuntu_sso/gtk/tests/test_gui.py 2012-02-17 18:43:17 +0000
96+++ ubuntu_sso/gtk/tests/test_gui.py 2012-03-15 16:57:19 +0000
97@@ -134,7 +134,7 @@
98
99 def get_load_status(self):
100 """Return the current load status."""
101- return gui.WEBKIT_LOAD_FINISHED
102+ return WebKit.LoadStatus.FINISHED
103
104 def show(self):
105 """Show this instance."""
106@@ -981,7 +981,7 @@
107 def test_notify_load_finished_connected(self):
108 """The 'load-finished' signal is connected."""
109 expected = [self.ui.on_tc_browser_notify_load_status]
110- self.assertEqual(self.browser._signals['load-finished'],
111+ self.assertEqual(self.browser._signals['notify::load-status'],
112 expected)
113
114 def test_tc_loaded_morphs_into_tc_browser_vbox(self):
115@@ -998,7 +998,7 @@
116 def test_navigation_requested_succeeds_for_no_clicking(self):
117 """The navigation request succeeds when user hasn't clicked a link."""
118 action = WebKit.WebNavigationAction()
119- action.set_reason(gui.WEBKIT_WEB_NAVIGATION_REASON_OTHER)
120+ action.set_reason(WebKit.WebNavigationReason.OTHER)
121
122 decision = WebKit.WebPolicyDecision()
123 decision.use = self._set_called
124@@ -1011,7 +1011,7 @@
125 def test_navigation_requested_ignores_clicked_links(self):
126 """The navigation request is ignored if a link was clicked."""
127 action = WebKit.WebNavigationAction()
128- action.set_reason(gui.WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED)
129+ action.set_reason(WebKit.WebNavigationReason.LINK_CLICKED)
130
131 decision = WebKit.WebPolicyDecision()
132 decision.ignore = self._set_called
133@@ -1037,7 +1037,7 @@
134 """
135 url = 'http://something.com/yadda'
136 action = WebKit.WebNavigationAction()
137- action.set_reason(gui.WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED)
138+ action.set_reason(WebKit.WebNavigationReason.LINK_CLICKED)
139 action.set_original_uri(url)
140
141 decision = WebKit.WebPolicyDecision()
142@@ -1050,6 +1050,35 @@
143 self.ui.on_tc_browser_navigation_requested(**kwargs)
144 self.assertEqual(self._called, ((url,), {}))
145
146+ def test_on_tc_button_clicked_no_child(self):
147+ """Test the tc loading with no child."""
148+ called = []
149+
150+ def fake_add_browser():
151+ """Fake add browser."""
152+ called.append('fake_add_browser')
153+
154+ self.patch(self.ui, '_add_webkit_browser', fake_add_browser)
155+ self.patch(self.ui.tc_browser_window, 'get_child', lambda: None)
156+
157+ self.ui.on_tc_button_clicked()
158+ self.assertIn('fake_add_browser', called)
159+
160+ def test_on_tc_button_clicked_child(self):
161+ """Test the tc loading with child."""
162+ called = []
163+
164+ def fake_add_browser(i_self):
165+ """Fake add browser."""
166+ called.append('fake_add_browser')
167+
168+ self.patch(self.ui, '_add_webkit_browser', fake_add_browser)
169+
170+ browser = WebKit.WebView()
171+ self.ui.tc_browser_window.add(browser)
172+ self.ui.on_tc_button_clicked()
173+ self.assertNotIn('fake_add_browser', called)
174+
175
176 class RegistrationErrorTestCase(UbuntuSSOClientTestCase):
177 """Test suite for the user registration error handling."""

Subscribers

People subscribed via source and target branches