Merge lp:~uriboni/webbrowser-app/merge-url-functions into lp:webbrowser-app

Proposed by Ugo Riboni on 2015-04-28
Status: Merged
Approved by: Olivier Tilloy on 2015-08-18
Approved revision: 991
Merged at revision: 1146
Proposed branch: lp:~uriboni/webbrowser-app/merge-url-functions
Merge into: lp:webbrowser-app
Diff against target: 261 lines (+84/-72)
6 files modified
src/app/UrlUtils.js (+44/-0)
src/app/webbrowser/AddressBar.qml (+4/-4)
src/app/webbrowser/Browser.qml (+2/-3)
src/app/webbrowser/SettingsPage.qml (+5/-5)
src/app/webbrowser/urlManagement.js (+0/-60)
tests/unittests/qml/tst_UrlUtils.qml (+29/-0)
To merge this branch: bzr merge lp:~uriboni/webbrowser-app/merge-url-functions
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2015-08-18
Olivier Tilloy 2015-04-28 Approve on 2015-08-18
Review via email: mp+257641@code.launchpad.net

Commit Message

Merge two url utility files into one, since they had no reason for being separate. Add unit tests for some of the functions that had none.

Description of the Change

Merge two url utility files into one, since they had no reason for being separate. Add unit tests for some of the functions that had none.

To post a comment you must log in.
Olivier Tilloy (osomon) wrote :

Note: this MR will likely conflict with https://code.launchpad.net/~rpadovani/webbrowser-app/data-address/+merge/256367, which will probably go first, so this one will need updating afterwards.

One minor comment (thus approving, but please fix anyway): the copyright notice for UrlUtils.js should be updated to include 2015.

review: Approve
Olivier Tilloy (osomon) wrote :

Riccardo’s branch has now been merged into trunk, and there is indeed a conflict when merging this one. Please resolve, and address the minor comment above, and this will be good to merge.

review: Needs Fixing
988. By Ugo Riboni on 2015-06-16

Merge changes from trunk

989. By Ugo Riboni on 2015-06-16

Pull back the changes to urlManagement.js that were done in trunk after the merge. Thank you unit tests.

Olivier Tilloy (osomon) wrote :

Please revert the changes to po/webbrowser-app.pot, they conflicts when merging this branch into trunk.

review: Needs Fixing
990. By Ugo Riboni on 2015-08-18

Revert mistaken commits to pot file

991. By Ugo Riboni on 2015-08-18

Merge changes from trunk

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 'src/app/UrlUtils.js'
2--- src/app/UrlUtils.js 2014-11-11 16:20:47 +0000
3+++ src/app/UrlUtils.js 2015-08-18 08:49:36 +0000
4@@ -16,6 +16,8 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8+'use strict';
9+
10 function extractAuthority(url) {
11 var authority = url.toString()
12 var indexOfScheme = authority.indexOf("://")
13@@ -41,3 +43,45 @@
14 }
15 return host
16 }
17+
18+function fixUrl(address) {
19+ var url = address
20+ if (address.toLowerCase() == "about:blank") {
21+ return address.toLowerCase()
22+ } else if (address.match(/^data:/i)) {
23+ return "data:" + address.substr(5)
24+ } else if (address.substr(0, 1) == "/") {
25+ url = "file://" + address
26+ } else if (address.indexOf("://") == -1) {
27+ url = "http://" + address
28+ }
29+ return url
30+}
31+
32+function looksLikeAUrl(address) {
33+ if (address.match(/^data:/i)) {
34+ return true;
35+ }
36+ var terms = address.split(/\s/)
37+ if (terms.length > 1) {
38+ return false
39+ }
40+ if (address.toLowerCase() == "about:blank") {
41+ return true
42+ }
43+ if (address.substr(0, 1) == "/") {
44+ return true
45+ }
46+ if (address.match(/^https?:\/\//i) ||
47+ address.match(/^file:\/\//i) ||
48+ address.match(/^[a-z]+:\/\//i)) {
49+ return true
50+ }
51+ if (address.split('/', 1)[0].match(/\.[a-zA-Z]{2,}$/)) {
52+ return true
53+ }
54+ if (address.split('/', 1)[0].match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}/)) {
55+ return true
56+ }
57+ return false
58+}
59
60=== modified file 'src/app/webbrowser/AddressBar.qml'
61--- src/app/webbrowser/AddressBar.qml 2015-08-11 10:37:56 +0000
62+++ src/app/webbrowser/AddressBar.qml 2015-08-18 08:49:36 +0000
63@@ -21,7 +21,7 @@
64 import Ubuntu.Components.Popups 1.3
65 import com.canonical.Oxide 1.8 as Oxide
66 import ".."
67-import "urlManagement.js" as UrlManagement
68+import "../UrlUtils.js" as UrlUtils
69
70 FocusScope {
71 id: addressbar
72@@ -109,7 +109,7 @@
73
74 readonly property bool reload: addressbar.activeFocus && addressbar.text &&
75 (addressbar.text == addressbar.actualUrl)
76- readonly property bool looksLikeAUrl: UrlManagement.looksLikeAUrl(addressbar.text.trim())
77+ readonly property bool looksLikeAUrl: UrlUtils.looksLikeAUrl(addressbar.text.trim())
78
79 name: addressbar.loading ? "stop" :
80 reload ? "reload" :
81@@ -302,8 +302,8 @@
82
83 function validate() {
84 var query = text.trim()
85- if (UrlManagement.looksLikeAUrl(query)) {
86- requestedUrl = UrlManagement.fixUrl(query)
87+ if (UrlUtils.looksLikeAUrl(query)) {
88+ requestedUrl = UrlUtils.fixUrl(query)
89 } else {
90 requestedUrl = internal.buildSearchUrl(query)
91 }
92
93=== modified file 'src/app/webbrowser/Browser.qml'
94--- src/app/webbrowser/Browser.qml 2015-08-16 01:37:08 +0000
95+++ src/app/webbrowser/Browser.qml 2015-08-18 08:49:36 +0000
96@@ -27,7 +27,6 @@
97 import "../actions" as Actions
98 import ".."
99 import "../UrlUtils.js" as UrlUtils
100-import "urlManagement.js" as UrlManagement
101
102 BrowserView {
103 id: browser
104@@ -496,7 +495,7 @@
105 searchEngine: currentSearchEngine
106 active: (chrome.activeFocus || suggestionsList.activeFocus) &&
107 !browser.incognito && !chrome.findInPageMode &&
108- !UrlManagement.looksLikeAUrl(chrome.text.replace(/ /g, "+"))
109+ !UrlUtils.looksLikeAUrl(chrome.text.replace(/ /g, "+"))
110
111 function limit(number) {
112 var slice = results.slice(0, number)
113@@ -788,7 +787,7 @@
114
115 FocusScope {
116 id: expandedHistoryViewContainer
117-
118+
119 visible: children.length > 0
120 anchors.fill: parent
121
122
123=== modified file 'src/app/webbrowser/SettingsPage.qml'
124--- src/app/webbrowser/SettingsPage.qml 2015-08-10 15:22:00 +0000
125+++ src/app/webbrowser/SettingsPage.qml 2015-08-18 08:49:36 +0000
126@@ -24,7 +24,7 @@
127 import Ubuntu.Web 0.2
128 import webbrowserapp.private 0.1
129
130-import "urlManagement.js" as UrlManagement
131+import "../UrlUtils.js" as UrlUtils
132
133 Item {
134 id: settingsItem
135@@ -327,8 +327,8 @@
136 text: settingsObject.homepage
137 inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhUrlCharactersOnly
138 onAccepted: {
139- if (UrlManagement.looksLikeAUrl(text)) {
140- settingsObject.homepage = UrlManagement.fixUrl(text)
141+ if (UrlUtils.looksLikeAUrl(text)) {
142+ settingsObject.homepage = UrlUtils.fixUrl(text)
143 PopupUtils.close(dialogue)
144 }
145 }
146@@ -351,10 +351,10 @@
147 right: parent.right
148 }
149 text: i18n.tr("Save")
150- enabled: UrlManagement.looksLikeAUrl(homepageTextField.text.trim())
151+ enabled: UrlUtils.looksLikeAUrl(homepageTextField.text.trim())
152 color: "#3fb24f"
153 onClicked: {
154- settingsObject.homepage = UrlManagement.fixUrl(homepageTextField.text)
155+ settingsObject.homepage = UrlUtils.fixUrl(homepageTextField.text)
156 PopupUtils.close(dialogue)
157 }
158 }
159
160=== removed file 'src/app/webbrowser/urlManagement.js'
161--- src/app/webbrowser/urlManagement.js 2015-04-27 08:23:06 +0000
162+++ src/app/webbrowser/urlManagement.js 1970-01-01 00:00:00 +0000
163@@ -1,60 +0,0 @@
164-/*
165- * Copyright 2015 Canonical Ltd.
166- *
167- * This file is part of webbrowser-app.
168- *
169- * webbrowser-app is free software; you can redistribute it and/or modify
170- * it under the terms of the GNU General Public License as published by
171- * the Free Software Foundation; version 3.
172- *
173- * webbrowser-app is distributed in the hope that it will be useful,
174- * but WITHOUT ANY WARRANTY; without even the implied warranty of
175- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
176- * GNU General Public License for more details.
177- *
178- * You should have received a copy of the GNU General Public License
179- * along with this program. If not, see <http://www.gnu.org/licenses/>.
180-*/
181-'use strict';
182-
183-function fixUrl(address) {
184- var url = address
185- if (address.toLowerCase() == "about:blank") {
186- return address.toLowerCase()
187- } else if (address.match(/^data:/i)) {
188- return "data:" + address.substr(5)
189- } else if (address.substr(0, 1) == "/") {
190- url = "file://" + address
191- } else if (address.indexOf("://") == -1) {
192- url = "http://" + address
193- }
194- return url
195-}
196-
197-function looksLikeAUrl(address) {
198- if (address.match(/^data:/i)) {
199- return true;
200- }
201- var terms = address.split(/\s/)
202- if (terms.length > 1) {
203- return false
204- }
205- if (address.toLowerCase() == "about:blank") {
206- return true
207- }
208- if (address.substr(0, 1) == "/") {
209- return true
210- }
211- if (address.match(/^https?:\/\//i) ||
212- address.match(/^file:\/\//i) ||
213- address.match(/^[a-z]+:\/\//i)) {
214- return true
215- }
216- if (address.split('/', 1)[0].match(/\.[a-zA-Z]{2,}$/)) {
217- return true
218- }
219- if (address.split('/', 1)[0].match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}/)) {
220- return true
221- }
222- return false
223-}
224
225=== modified file 'tests/unittests/qml/tst_UrlUtils.qml'
226--- tests/unittests/qml/tst_UrlUtils.qml 2014-11-13 14:43:16 +0000
227+++ tests/unittests/qml/tst_UrlUtils.qml 2015-08-18 08:49:36 +0000
228@@ -54,4 +54,33 @@
229 function test_extractHost(data) {
230 compare(UrlUtils.extractHost(data.url), data.host)
231 }
232+
233+ function test_looksLikeAUrl_data() {
234+ return [
235+ {url: "", looksLike: false},
236+ {url: "http://example.org/", looksLike: true},
237+ {url: "example.org", looksLike: true},
238+ {url: "http://www.example.org?q=foo bar", looksLike: false},
239+ {url: "about:blank", looksLike: true},
240+ {url: "file:///usr/foo/bar", looksLike: true},
241+ {url: "hello://my/name/is/", looksLike: true},
242+ {url: "192.168.1.0", looksLike: true}
243+ ]
244+ }
245+
246+ function test_looksLikeAUrl(data) {
247+ compare(UrlUtils.looksLikeAUrl(data.url), data.looksLike)
248+ }
249+
250+ function test_fixUrl_data() {
251+ return [
252+ {url: "About:BLANK", fixed: "about:blank"},
253+ {url: "/usr/bin/", fixed: "file:///usr/bin/"},
254+ {url: "example.org", fixed: "http://example.org"}
255+ ]
256+ }
257+
258+ function test_fixUrl(data) {
259+ compare(UrlUtils.fixUrl(data.url), data.fixed)
260+ }
261 }

Subscribers

People subscribed via source and target branches

to status/vote changes: