Merge lp:~osomon/webbrowser-app/ua-override into lp:webbrowser-app
- ua-override
- Merge into trunk
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Olivier Tilloy | ||||||||
Approved revision: | 293 | ||||||||
Merged at revision: | 283 | ||||||||
Proposed branch: | lp:~osomon/webbrowser-app/ua-override | ||||||||
Merge into: | lp:webbrowser-app | ||||||||
Diff against target: |
347 lines (+263/-27) 5 files modified
src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml (+7/-26) src/Ubuntu/Components/Extras/Browser/UserAgent.qml (+80/-0) src/Ubuntu/Components/Extras/Browser/ua-overrides.js (+96/-0) tests/unittests/qml/CMakeLists.txt (+9/-1) tests/unittests/qml/tst_UserAgent.qml (+71/-0) |
||||||||
To merge this branch: | bzr merge lp:~osomon/webbrowser-app/ua-override | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Günter Schwann (community) | Approve | ||
Review via email: mp+180592@code.launchpad.net |
Commit message
Initial implementation of a user-agent string override mechanism,
largely inspired by B2G’s implementation.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
Günter Schwann (schwann) wrote : | # |
83 +import Ubuntu.Components 0.1
Seem not to be used
Just because I like small functions, I'd move the functionality of getting the domain from a url into it's own function (UserAgent.qml). Easier to read, easier to test, easier to (maybe) reuse.
Olivier Tilloy (osomon) wrote : | # |
> 83 +import Ubuntu.Components 0.1
> Seem not to be used
It is required, because I’m using units.gu(…).
> Just because I like small functions, I'd move the functionality of getting the
> domain from a url into it's own function (UserAgent.qml). Easier to read,
> easier to test, easier to (maybe) reuse.
Good idea, will do.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml' | |||
2 | --- src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml 2013-07-18 21:26:13 +0000 | |||
3 | +++ src/Ubuntu/Components/Extras/Browser/UbuntuWebView.qml 2013-08-19 08:47:57 +0000 | |||
4 | @@ -17,7 +17,6 @@ | |||
5 | 17 | */ | 17 | */ |
6 | 18 | 18 | ||
7 | 19 | import QtQuick 2.0 | 19 | import QtQuick 2.0 |
8 | 20 | import QtQuick.Window 2.0 | ||
9 | 21 | import QtWebKit 3.0 | 20 | import QtWebKit 3.0 |
10 | 22 | import QtWebKit.experimental 1.0 | 21 | import QtWebKit.experimental 1.0 |
11 | 23 | import Ubuntu.Components 0.1 | 22 | import Ubuntu.Components 0.1 |
12 | @@ -29,18 +28,6 @@ | |||
13 | 29 | 28 | ||
14 | 30 | signal newTabRequested(url url) | 29 | signal newTabRequested(url url) |
15 | 31 | 30 | ||
16 | 32 | QtObject { | ||
17 | 33 | // clumsy way of defining an enum in QML | ||
18 | 34 | id: formFactor | ||
19 | 35 | readonly property int desktop: 0 | ||
20 | 36 | readonly property int phone: 1 | ||
21 | 37 | readonly property int tablet: 2 | ||
22 | 38 | } | ||
23 | 39 | // FIXME: this is a quick hack that will become increasingly unreliable | ||
24 | 40 | // as we support more devices, so we need a better solution for this | ||
25 | 41 | // FIXME: only handling phone and tablet for now | ||
26 | 42 | property int formFactor: (Screen.width >= units.gu(60)) ? formFactor.tablet : formFactor.phone | ||
27 | 43 | |||
28 | 44 | property real devicePixelRatio: 1.0 | 31 | property real devicePixelRatio: 1.0 |
29 | 45 | onDevicePixelRatioChanged: { | 32 | onDevicePixelRatioChanged: { |
30 | 46 | // Do not make this patch to QtWebKit a hard requirement. | 33 | // Do not make this patch to QtWebKit a hard requirement. |
31 | @@ -54,19 +41,13 @@ | |||
32 | 54 | 41 | ||
33 | 55 | property real scale: experimental.test.contentsScale * experimental.test.devicePixelRatio | 42 | property real scale: experimental.test.contentsScale * experimental.test.devicePixelRatio |
34 | 56 | 43 | ||
48 | 57 | experimental.userAgent: { | 44 | UserAgent { |
49 | 58 | // FIXME: using iOS 5.0’s iPhone/iPad user-agent strings | 45 | id: userAgent |
50 | 59 | // (source: http://stackoverflow.com/questions/7825873/what-is-the-ios-5-0-user-agent-string), | 46 | } |
51 | 60 | // this should be changed to a more neutral user-agent in the | 47 | experimental.userAgent: userAgent.defaultUA |
52 | 61 | // future as we don’t want websites to recommend installing | 48 | onNavigationRequested: { |
53 | 62 | // their iPhone/iPad apps. | 49 | _webview.experimental.userAgent = userAgent.getUAString(request.url) |
54 | 63 | if (_webview.formFactor === formFactor.phone) { | 50 | request.action = WebView.AcceptRequest |
42 | 64 | return "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3" | ||
43 | 65 | } else if (_webview.formFactor === formFactor.tablet) { | ||
44 | 66 | return "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3" | ||
45 | 67 | } else { | ||
46 | 68 | return "" | ||
47 | 69 | } | ||
55 | 70 | } | 51 | } |
56 | 71 | 52 | ||
57 | 72 | experimental.preferences.navigatorQtObjectEnabled: true | 53 | experimental.preferences.navigatorQtObjectEnabled: true |
58 | 73 | 54 | ||
59 | === added file 'src/Ubuntu/Components/Extras/Browser/UserAgent.qml' | |||
60 | --- src/Ubuntu/Components/Extras/Browser/UserAgent.qml 1970-01-01 00:00:00 +0000 | |||
61 | +++ src/Ubuntu/Components/Extras/Browser/UserAgent.qml 2013-08-19 08:47:57 +0000 | |||
62 | @@ -0,0 +1,80 @@ | |||
63 | 1 | /* | ||
64 | 2 | * Copyright 2013 Canonical Ltd. | ||
65 | 3 | * | ||
66 | 4 | * This file is part of webbrowser-app. | ||
67 | 5 | * | ||
68 | 6 | * webbrowser-app is free software; you can redistribute it and/or modify | ||
69 | 7 | * it under the terms of the GNU General Public License as published by | ||
70 | 8 | * the Free Software Foundation; version 3. | ||
71 | 9 | * | ||
72 | 10 | * webbrowser-app is distributed in the hope that it will be useful, | ||
73 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
74 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
75 | 13 | * GNU General Public License for more details. | ||
76 | 14 | * | ||
77 | 15 | * You should have received a copy of the GNU General Public License | ||
78 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
79 | 17 | */ | ||
80 | 18 | |||
81 | 19 | import QtQuick 2.0 | ||
82 | 20 | import QtQuick.Window 2.0 | ||
83 | 21 | import Ubuntu.Components 0.1 | ||
84 | 22 | import "ua-overrides.js" as Overrides | ||
85 | 23 | |||
86 | 24 | /* | ||
87 | 25 | * Useful documentation: | ||
88 | 26 | * http://en.wikipedia.org/wiki/User_agent#Format | ||
89 | 27 | * https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference | ||
90 | 28 | * https://wiki.mozilla.org/B2G/User_Agent | ||
91 | 29 | * https://github.com/mozilla-b2g/gaia/blob/master/build/ua-override-prefs.js | ||
92 | 30 | * https://developers.google.com/chrome/mobile/docs/user-agent | ||
93 | 31 | */ | ||
94 | 32 | |||
95 | 33 | // This is an Item, not a QtObject, because it needs information about the Screen. | ||
96 | 34 | Item { | ||
97 | 35 | // %1: form factor (Mobile, Tablet, Desktop) | ||
98 | 36 | // %2: WebKit version | ||
99 | 37 | readonly property string _template: "Mozilla/5.0 (Ubuntu; %1) WebKit/%2" | ||
100 | 38 | |||
101 | 39 | // See Source/WebCore/Configurations/Version.xcconfig in QtWebKit’s source tree | ||
102 | 40 | // TODO: determine this value at runtime | ||
103 | 41 | readonly property string _webkitVersion: "537.21" | ||
104 | 42 | |||
105 | 43 | // FIXME: this is a quick hack that will become increasingly unreliable | ||
106 | 44 | // as we support more devices, so we need a better solution for this | ||
107 | 45 | // FIXME: only handling phone and tablet for now, need to handle desktop too | ||
108 | 46 | readonly property string _formFactor: (Screen.width >= units.gu(60)) ? "Tablet" : "Mobile" | ||
109 | 47 | |||
110 | 48 | property string defaultUA: _template.arg(_formFactor).arg(_webkitVersion) | ||
111 | 49 | |||
112 | 50 | property var overrides: Overrides.overrides | ||
113 | 51 | |||
114 | 52 | function getDomain(url) { | ||
115 | 53 | var domain = url.toString() | ||
116 | 54 | var indexOfScheme = domain.indexOf("://") | ||
117 | 55 | if (indexOfScheme !== -1) { | ||
118 | 56 | domain = domain.slice(indexOfScheme + 3) | ||
119 | 57 | } | ||
120 | 58 | var indexOfPath = domain.indexOf("/") | ||
121 | 59 | if (indexOfPath !== -1) { | ||
122 | 60 | domain = domain.slice(0, indexOfPath) | ||
123 | 61 | } | ||
124 | 62 | return domain | ||
125 | 63 | } | ||
126 | 64 | |||
127 | 65 | function getUAString(url) { | ||
128 | 66 | var ua = defaultUA | ||
129 | 67 | var domain = getDomain(url) | ||
130 | 68 | for (var override in overrides) { | ||
131 | 69 | if (domain.indexOf(override, domain.length - override.length) !== -1) { | ||
132 | 70 | var form = overrides[override] | ||
133 | 71 | if (typeof form == "string") { | ||
134 | 72 | return form | ||
135 | 73 | } else if (typeof form == "object") { | ||
136 | 74 | return ua.replace(form[0], form[1]) | ||
137 | 75 | } | ||
138 | 76 | } | ||
139 | 77 | } | ||
140 | 78 | return ua | ||
141 | 79 | } | ||
142 | 80 | } | ||
143 | 0 | 81 | ||
144 | === added file 'src/Ubuntu/Components/Extras/Browser/ua-overrides.js' | |||
145 | --- src/Ubuntu/Components/Extras/Browser/ua-overrides.js 1970-01-01 00:00:00 +0000 | |||
146 | +++ src/Ubuntu/Components/Extras/Browser/ua-overrides.js 2013-08-19 08:47:57 +0000 | |||
147 | @@ -0,0 +1,96 @@ | |||
148 | 1 | /* | ||
149 | 2 | * Copyright 2013 Canonical Ltd. | ||
150 | 3 | * | ||
151 | 4 | * This file is part of webbrowser-app. | ||
152 | 5 | * | ||
153 | 6 | * webbrowser-app is free software; you can redistribute it and/or modify | ||
154 | 7 | * it under the terms of the GNU General Public License as published by | ||
155 | 8 | * the Free Software Foundation; version 3. | ||
156 | 9 | * | ||
157 | 10 | * webbrowser-app is distributed in the hope that it will be useful, | ||
158 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
159 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
160 | 13 | * GNU General Public License for more details. | ||
161 | 14 | * | ||
162 | 15 | * You should have received a copy of the GNU General Public License | ||
163 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
164 | 17 | */ | ||
165 | 18 | |||
166 | 19 | .pragma library | ||
167 | 20 | |||
168 | 21 | // B2G’s list of overrides: https://github.com/mozilla-b2g/gaia/blob/master/build/ua-override-prefs.js | ||
169 | 22 | |||
170 | 23 | // List of user agent string overrides in the form of an object. | ||
171 | 24 | // Each key is a domain name for which the default user agent string doesn’t | ||
172 | 25 | // work well enough. Values can either be a string (full override) or an array | ||
173 | 26 | // containing two values that are passed to the String.replace method (the | ||
174 | 27 | // first value may be either a string or a regular expression, the second value | ||
175 | 28 | // must be a string). | ||
176 | 29 | |||
177 | 30 | // Examples of valid entries: | ||
178 | 31 | // "example.org": "full override" | ||
179 | 32 | // "example.com": ["Ubuntu", "Ubuntu Edge"] | ||
180 | 33 | // "google.com": [/mobi/i, "b"] | ||
181 | 34 | |||
182 | 35 | // The original list was initially built from the top 100 entries | ||
183 | 36 | // at http://www.alexa.com/topsites (2013-08-16), using Chrome on | ||
184 | 37 | // Android as a reference. | ||
185 | 38 | |||
186 | 39 | var overrides = { | ||
187 | 40 | "google.com": ["Mobile", "Android; Mobile"], | ||
188 | 41 | "youtube.com": ["Mobile", "Android; Mobile"], | ||
189 | 42 | "yahoo.com": ["Mobile", "Android; Mobile"], | ||
190 | 43 | "baidu.com": ["Mobile", "Android; Mobile"], | ||
191 | 44 | "qq.com": [/WebKit\/[.0-9]*/, "Apple$& Mobile"], | ||
192 | 45 | "amazon.com": ["Mobile", "Android; Mobile"], | ||
193 | 46 | "linkedin.com": ["Mobile", "Android; Mobile"], | ||
194 | 47 | "blogspot.com": ["Mobile", "Android; Mobile"], | ||
195 | 48 | "taobao.com": ["Mobile", "Android; Mobile"], | ||
196 | 49 | "google.co.in": ["Mobile", "Android; Mobile"], | ||
197 | 50 | "bing.com": ["Mobile", "Android; Mobile"], | ||
198 | 51 | "yahoo.co.jp": ["Ubuntu", "Linux; Android 4; Galaxy Build/"], | ||
199 | 52 | "yandex.ru": ["Mobile", "Android; Mobile"], | ||
200 | 53 | "sina.com.cn": ["Mobile", "Android; Mobile"], | ||
201 | 54 | "ebay.com": ["Mobile", "Android; Mobile"], | ||
202 | 55 | "google.de": ["Mobile", "Android; Mobile"], | ||
203 | 56 | "tumblr.com": ["Mobile", "Android; Mobile"], | ||
204 | 57 | "google.co.uk": ["Mobile", "Android; Mobile"], | ||
205 | 58 | "msn.com": ["Mobile", "Android; Mobile"], | ||
206 | 59 | "google.fr": ["Mobile", "Android; Mobile"], | ||
207 | 60 | "mail.ru": ["Ubuntu", "Linux; Android 4; Galaxy Build/"], | ||
208 | 61 | "google.com.br": ["Mobile", "Android; Mobile"], | ||
209 | 62 | "google.co.jp": ["Mobile", "Android; Mobile"], | ||
210 | 63 | "hao123.com": ["Mobile", "Android; Mobile"], | ||
211 | 64 | "ask.com": ["Mobile", "Android; Mobile"], | ||
212 | 65 | "google.com.hk": ["Mobile", "Android; Mobile"], | ||
213 | 66 | "google.ru": ["Mobile", "Android; Mobile"], | ||
214 | 67 | "blogger.com": ["Mobile", "Android; Mobile"], | ||
215 | 68 | "imdb.com": ["Mobile", "Android; Mobile"], | ||
216 | 69 | "google.it": ["Mobile", "Android; Mobile"], | ||
217 | 70 | "google.es": ["Mobile", "Android; Mobile"], | ||
218 | 71 | "amazon.co.jp": ["Mobile", "Android; Mobile"], | ||
219 | 72 | "tmall.com": ["Mobile", "Android; Mobile"], | ||
220 | 73 | "fc2.com": ["Mobile", "Android; Mobile"], | ||
221 | 74 | "google.com.mx": ["Mobile", "Android; Mobile"], | ||
222 | 75 | "google.ca": ["Mobile", "Android; Mobile"], | ||
223 | 76 | "soso.com": ["Mobile", "Android; Mobile"], | ||
224 | 77 | "delta-search.com": ["Mobile", "Android; Mobile"], | ||
225 | 78 | "odnoklassniki.ru": ["Mobile", "Android; Mobile"], | ||
226 | 79 | "alibaba.com": ["Mobile", "Android; Mobile"], | ||
227 | 80 | "flickr.com": ["Mobile", "Android; Mobile"], | ||
228 | 81 | "amazon.de": ["Mobile", "Android; Mobile"], | ||
229 | 82 | "blogspot.in": ["Mobile", "Android; Mobile"], | ||
230 | 83 | "ifeng.com": ["Mobile", "Android; Mobile"], | ||
231 | 84 | "360.cn": ["Mobile", "Android; Mobile"], | ||
232 | 85 | "google.com.tr": ["Mobile", "Android; Mobile"], | ||
233 | 86 | "google.com.au": ["Mobile", "Android; Mobile"], | ||
234 | 87 | "youku.com": ["Mobile", "Android; Mobile"], | ||
235 | 88 | "ebay.de": ["Mobile", "Android; Mobile"], | ||
236 | 89 | "uol.com.br": ["Mobile", "Android; Mobile"], | ||
237 | 90 | "aol.com": ["Mobile", "Android; Mobile"], | ||
238 | 91 | "google.pl": ["Mobile", "Android; Mobile"], | ||
239 | 92 | "alipay.com": ["Mobile", "Android; Mobile"], | ||
240 | 93 | "dailymotion.com": ["Mobile", "Android; Mobile Safari"], | ||
241 | 94 | "amazon.co.uk": ["Mobile", "Android; Mobile"], | ||
242 | 95 | "ebay.co.uk": ["Mobile", "Android; Mobile"], | ||
243 | 96 | }; | ||
244 | 0 | 97 | ||
245 | === modified file 'tests/unittests/qml/CMakeLists.txt' | |||
246 | --- tests/unittests/qml/CMakeLists.txt 2013-07-19 14:11:08 +0000 | |||
247 | +++ tests/unittests/qml/CMakeLists.txt 2013-08-19 08:47:57 +0000 | |||
248 | @@ -5,14 +5,22 @@ | |||
249 | 5 | set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal") | 5 | set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal") |
250 | 6 | 6 | ||
251 | 7 | # copy qml files under test to build dir | 7 | # copy qml files under test to build dir |
252 | 8 | set(out_qml_files) | ||
253 | 8 | file(GLOB qmlFiles RELATIVE ${webbrowser-app_SOURCE_DIR} ${webbrowser-app_SOURCE_DIR}/*.qml) | 9 | file(GLOB qmlFiles RELATIVE ${webbrowser-app_SOURCE_DIR} ${webbrowser-app_SOURCE_DIR}/*.qml) |
254 | 9 | set(out_qml_files) | ||
255 | 10 | foreach(qmlFile ${qmlFiles}) | 10 | foreach(qmlFile ${qmlFiles}) |
256 | 11 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/undertest/${qmlFile} | 11 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/undertest/${qmlFile} |
257 | 12 | DEPENDS ${webbrowser-app_SOURCE_DIR}/${qmlFile} | 12 | DEPENDS ${webbrowser-app_SOURCE_DIR}/${qmlFile} |
258 | 13 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${webbrowser-app_SOURCE_DIR}/${qmlFile} ${CMAKE_CURRENT_BINARY_DIR}/undertest/${qmlFile}) | 13 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${webbrowser-app_SOURCE_DIR}/${qmlFile} ${CMAKE_CURRENT_BINARY_DIR}/undertest/${qmlFile}) |
259 | 14 | list(APPEND out_qml_files undertest/${qmlFile}) | 14 | list(APPEND out_qml_files undertest/${qmlFile}) |
260 | 15 | endforeach(qmlFile) | 15 | endforeach(qmlFile) |
261 | 16 | file(GLOB qmlFiles RELATIVE ${webbrowser-plugin_SOURCE_DIR} ${webbrowser-plugin_SOURCE_DIR}/*.qml | ||
262 | 17 | ${webbrowser-plugin_SOURCE_DIR} ${webbrowser-plugin_SOURCE_DIR}/*.js) | ||
263 | 18 | foreach(qmlFile ${qmlFiles}) | ||
264 | 19 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/undertest/${qmlFile} | ||
265 | 20 | DEPENDS ${webbrowser-plugin_SOURCE_DIR}/${qmlFile} | ||
266 | 21 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${webbrowser-plugin_SOURCE_DIR}/${qmlFile} ${CMAKE_CURRENT_BINARY_DIR}/undertest/${qmlFile}) | ||
267 | 22 | list(APPEND out_qml_files undertest/${qmlFile}) | ||
268 | 23 | endforeach(qmlFile) | ||
269 | 16 | add_custom_target(copy_qml_files_under_test_to_build_dir DEPENDS ${out_qml_files}) | 24 | add_custom_target(copy_qml_files_under_test_to_build_dir DEPENDS ${out_qml_files}) |
270 | 17 | add_dependencies(${TEST} copy_qml_files_under_test_to_build_dir) | 25 | add_dependencies(${TEST} copy_qml_files_under_test_to_build_dir) |
271 | 18 | 26 | ||
272 | 19 | 27 | ||
273 | === added file 'tests/unittests/qml/tst_UserAgent.qml' | |||
274 | --- tests/unittests/qml/tst_UserAgent.qml 1970-01-01 00:00:00 +0000 | |||
275 | +++ tests/unittests/qml/tst_UserAgent.qml 2013-08-19 08:47:57 +0000 | |||
276 | @@ -0,0 +1,71 @@ | |||
277 | 1 | /* | ||
278 | 2 | * Copyright 2013 Canonical Ltd. | ||
279 | 3 | * | ||
280 | 4 | * This file is part of webbrowser-app. | ||
281 | 5 | * | ||
282 | 6 | * webbrowser-app is free software; you can redistribute it and/or modify | ||
283 | 7 | * it under the terms of the GNU General Public License as published by | ||
284 | 8 | * the Free Software Foundation; version 3. | ||
285 | 9 | * | ||
286 | 10 | * webbrowser-app is distributed in the hope that it will be useful, | ||
287 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
288 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
289 | 13 | * GNU General Public License for more details. | ||
290 | 14 | * | ||
291 | 15 | * You should have received a copy of the GNU General Public License | ||
292 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
293 | 17 | */ | ||
294 | 18 | |||
295 | 19 | import QtQuick 2.0 | ||
296 | 20 | import QtTest 1.0 | ||
297 | 21 | import "undertest" | ||
298 | 22 | |||
299 | 23 | TestCase { | ||
300 | 24 | name: "UserAgent" | ||
301 | 25 | |||
302 | 26 | function test_get_domain() { | ||
303 | 27 | compare(userAgent.getDomain("http://ubuntu.com"), "ubuntu.com") | ||
304 | 28 | compare(userAgent.getDomain("http://www.ubuntu.com"), "www.ubuntu.com") | ||
305 | 29 | compare(userAgent.getDomain("http://ubuntu.com/"), "ubuntu.com") | ||
306 | 30 | compare(userAgent.getDomain("http://www.ubuntu.com/"), "www.ubuntu.com") | ||
307 | 31 | compare(userAgent.getDomain("ubuntu.com"), "ubuntu.com") | ||
308 | 32 | compare(userAgent.getDomain("ubuntu.com/"), "ubuntu.com") | ||
309 | 33 | compare(userAgent.getDomain("ubuntu.com/phone"), "ubuntu.com") | ||
310 | 34 | compare(userAgent.getDomain("http://ubuntu.com/phone"), "ubuntu.com") | ||
311 | 35 | compare(userAgent.getDomain("www.ubuntu.com/phone"), "www.ubuntu.com") | ||
312 | 36 | compare(userAgent.getDomain("http://ubuntu.com/phone/index.html"), "ubuntu.com") | ||
313 | 37 | compare(userAgent.getDomain("ubuntu.com/phone/index.html"), "ubuntu.com") | ||
314 | 38 | compare(userAgent.getDomain("www.ubuntu.com/phone/index.html"), "www.ubuntu.com") | ||
315 | 39 | compare(userAgent.getDomain("http://ubuntu.com/phone/index.html?foo=bar&baz=bleh"), "ubuntu.com") | ||
316 | 40 | } | ||
317 | 41 | |||
318 | 42 | function test_ua_unmodified() { | ||
319 | 43 | compare(userAgent.getUAString("http://ubuntu.com"), userAgent.defaultUA) | ||
320 | 44 | } | ||
321 | 45 | |||
322 | 46 | function test_ua_full_override() { | ||
323 | 47 | compare(userAgent.getUAString("http://example.org"), "full override") | ||
324 | 48 | } | ||
325 | 49 | |||
326 | 50 | function test_ua_string_replace() { | ||
327 | 51 | compare(userAgent.getUAString("http://example.com/test"), | ||
328 | 52 | "Mozilla/5.0 (Ubuntu Edge; Mobile) WebKit/537.21") | ||
329 | 53 | } | ||
330 | 54 | |||
331 | 55 | function test_ua_regexp_replace() { | ||
332 | 56 | compare(userAgent.getUAString("http://www.google.com/"), | ||
333 | 57 | "Mozilla/5.0 (Ubuntu; ble) WebKit/537.21") | ||
334 | 58 | } | ||
335 | 59 | |||
336 | 60 | UserAgent { | ||
337 | 61 | id: userAgent | ||
338 | 62 | |||
339 | 63 | defaultUA: "Mozilla/5.0 (Ubuntu; Mobile) WebKit/537.21" | ||
340 | 64 | |||
341 | 65 | overrides: { | ||
342 | 66 | "example.org": "full override", | ||
343 | 67 | "example.com": ["Ubuntu", "Ubuntu Edge"], | ||
344 | 68 | "google.com": [/mobi/i, "b"], | ||
345 | 69 | } | ||
346 | 70 | } | ||
347 | 71 | } |
PASSED: Continuous integration, rev:292 jenkins. qa.ubuntu. com/job/ webbrowser- app-ci/ 280/ jenkins. qa.ubuntu. com/job/ generic- mediumtests- saucy/2323 jenkins. qa.ubuntu. com/job/ generic- mediumtests- touch/68 jenkins. qa.ubuntu. com/job/ webbrowser- app-saucy- amd64-ci/ 163 jenkins. qa.ubuntu. com/job/ webbrowser- app-saucy- armhf-ci/ 163 jenkins. qa.ubuntu. com/job/ webbrowser- app-saucy- armhf-ci/ 163/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ webbrowser- app-saucy- i386-ci/ 163 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- saucy/2329 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- saucy/2329/ artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ generic- mediumtests- runner- saucy/1974 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- saucy-armhf/ 70 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- saucy-armhf/ 70/artifact/ work/output/ *zip*/output. zip s-jenkins: 8080/job/ generic- mediumtests- runner- maguro/ 70 s-jenkins: 8080/job/ generic- mediumtests- runner- mako/67
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ webbrowser- app-ci/ 280/rebuild
http://