Merge lp:~abreu-alexandre/webbrowser-app/fix-local-webapp-properties-ua-override into lp:webbrowser-app

Proposed by Alexandre Abreu
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 865
Merged at revision: 864
Proposed branch: lp:~abreu-alexandre/webbrowser-app/fix-local-webapp-properties-ua-override
Merge into: lp:webbrowser-app
Diff against target: 161 lines (+86/-10)
3 files modified
src/app/webcontainer/webapp-container.qml (+28/-8)
tests/autopilot/webapp_container/tests/test_app_launch.py (+8/-2)
tests/autopilot/webapp_container/tests/test_user_agent.py (+50/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/webbrowser-app/fix-local-webapp-properties-ua-override
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Olivier Tilloy Approve
Review via email: mp+245687@code.launchpad.net

Commit message

MAke sure that we properly consider the local webapp name that could be imported by a webapp-properties file for things like UA overrides.

Description of the change

MAke sure that we properly consider the local webapp name that could be imported by a webapp-properties file for things like UA overrides.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
865. By Alexandre Abreu

fix flake8

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

Looks good to me.

As a side note, getWindowTitle() should probably be updated to remove references to "Ubuntu Web Browser". But that can be done separately.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webcontainer/webapp-container.qml'
2--- src/app/webcontainer/webapp-container.qml 2014-12-02 10:04:28 +0000
3+++ src/app/webcontainer/webapp-container.qml 2015-01-08 14:32:50 +0000
4@@ -51,9 +51,12 @@
5 title: getWindowTitle()
6
7 function getWindowTitle() {
8- var webappViewTitle = webappViewLoader.item ? webappViewLoader.item.title : ""
9- if (typeof(webappName) === 'string' && webappName.length !== 0) {
10- return webappName
11+ var webappViewTitle =
12+ webappViewLoader.item
13+ ? webappViewLoader.item.title : ""
14+ var name = getWebappName()
15+ if (typeof(name) === 'string' && name.length !== 0) {
16+ return name
17 } else if (webappViewTitle) {
18 // TRANSLATORS: %1 refers to the current page’s title
19 return i18n.tr("%1 - Ubuntu Web Browser").arg(webappViewTitle)
20@@ -100,12 +103,27 @@
21 }
22 }
23
24+ function getWebappName() {
25+ /**
26+ Any webapp name coming from the command line takes over.
27+ A webapp can also be defined by a specific drop-in webapp-properties.json
28+ file that can bundle a few specific 'properties' (as the name implies)
29+ instead of having them listed in the command line.
30+ */
31+ if (webappName)
32+ return webappName
33+ return webappModelSearchPath && webappModel.providesSingleInlineWebapp()
34+ ? webappModel.getSingleInlineWebappName()
35+ : ""
36+ }
37+
38 function getLocalUserAgentOverrideIfAny() {
39 if (localUserAgentOverride.length !== 0)
40 return localUserAgentOverride
41
42- if (webappName && webappModel.exists(webappName))
43- return webappModel.userAgentOverrideFor(webappName)
44+ var name = getWebappName()
45+ if (name && webappModel.exists(name))
46+ return webappModel.userAgentOverrideFor(name)
47
48 return ""
49 }
50@@ -115,9 +133,11 @@
51 searchPath: root.webappModelSearchPath
52
53 onModelContentChanged: {
54- if (root.webappName && root.url.length === 0) {
55- var idx = webappModel.getWebappIndex(root.webappName)
56- root.url = webappModel.data(idx, UnityWebApps.UnityWebappsAppModel.Homepage)
57+ var name = getWebappName()
58+ if (name && root.url.length === 0) {
59+ var idx = webappModel.getWebappIndex(name)
60+ root.url = webappModel.data(
61+ idx, UnityWebApps.UnityWebappsAppModel.Homepage)
62 }
63 }
64 }
65
66=== modified file 'tests/autopilot/webapp_container/tests/test_app_launch.py'
67--- tests/autopilot/webapp_container/tests/test_app_launch.py 2014-11-26 15:37:55 +0000
68+++ tests/autopilot/webapp_container/tests/test_app_launch.py 2015-01-08 14:32:50 +0000
69@@ -31,9 +31,11 @@
70 os.mkdir(webapp_folder_name)
71 manifest_content = """
72 {
73- "includes": ["http://test.com:*/*"], "name": "test",
74+ "includes": ["http://test.com:*/*"],
75+ "name": "test",
76 "scripts": ["test.user.js"],
77- "domain":"", "homepage":"http://www.test.com/"
78+ "domain":"",
79+ "homepage":"http://www.test.com/"
80 }
81 """
82 manifest_file = "{}/manifest.json".format(webapp_folder_name)
83@@ -94,3 +96,7 @@
84 webview = self.get_oxide_webview()
85 webapp_url = 'http://www.test.com/'
86 self.assertThat(webview.url, Eventually(Equals(webapp_url)))
87+
88+ result = 'test'
89+ self.assertThat(self.get_webcontainer_window().title,
90+ Eventually(Equals(result)))
91
92=== modified file 'tests/autopilot/webapp_container/tests/test_user_agent.py'
93--- tests/autopilot/webapp_container/tests/test_user_agent.py 2014-12-04 16:10:39 +0000
94+++ tests/autopilot/webapp_container/tests/test_user_agent.py 2015-01-08 14:32:50 +0000
95@@ -13,12 +13,40 @@
96 # You should have received a copy of the GNU General Public License
97 # along with this program. If not, see <http://www.gnu.org/licenses/>.
98
99+from contextlib import contextmanager
100+import os
101+import tempfile
102+import shutil
103+
104 from testtools.matchers import Equals
105 from autopilot.matchers import Eventually
106
107 from webapp_container.tests import WebappContainerTestCaseWithLocalContentBase
108
109
110+@contextmanager
111+def generate_temp_local_props_webapp():
112+ tmpdir = tempfile.mkdtemp()
113+ webapp_folder_name = '{}/unity-webapps-test'.format(tmpdir)
114+ os.mkdir(webapp_folder_name)
115+ manifest_content = """
116+ {
117+ "includes": ["http://test.com:*/*"],
118+ "name": "test",
119+ "domain": "",
120+ "homepage": "http://www.test.com/show-user-agent",
121+ "user-agent-override": "MyUserAgent"
122+ }
123+ """
124+ manifest_file = "{}/webapp-properties.json".format(webapp_folder_name)
125+ with open(manifest_file, "w+") as f:
126+ f.write(manifest_content)
127+ try:
128+ yield webapp_folder_name
129+ finally:
130+ shutil.rmtree(tmpdir)
131+
132+
133 class WebappUserAgentTestCase(
134 WebappContainerTestCaseWithLocalContentBase):
135
136@@ -33,3 +61,25 @@
137 result = 'MyUserAgent MyUserAgent'
138 self.assertThat(self.get_oxide_webview().title,
139 Eventually(Equals(result)))
140+
141+ def test_webapp_properties_override(self):
142+ rule = 'MAP *.test.com:80 ' + self.get_base_url_hostname()
143+ with generate_temp_local_props_webapp() as webapp_install_path:
144+ args = ['--webappModelSearchPath=' + webapp_install_path]
145+ self.launch_webcontainer_app(
146+ args,
147+ {'UBUNTU_WEBVIEW_HOST_MAPPING_RULES': rule})
148+ self.get_webcontainer_window().visible.wait_for(True)
149+
150+ webview = self.get_oxide_webview()
151+ webapp_url = 'http://www.test.com/show-user-agent'
152+ self.assertThat(webview.url, Eventually(Equals(webapp_url)))
153+
154+ webapp_name = 'test'
155+ self.assertThat(self.get_webcontainer_window().title,
156+ Eventually(Equals(webapp_name)))
157+
158+ # trick until we get e.g. selenium/chromedriver tests
159+ result = 'MyUserAgent MyUserAgent'
160+ self.assertThat(self.get_oxide_webview().title,
161+ Eventually(Equals(result)))

Subscribers

People subscribed via source and target branches

to status/vote changes: