Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Paweł Forysiuk | ||||
Approved revision: | 6423 | ||||
Merged at revision: | 6547 | ||||
Proposed branch: | lp:~midori/midori/desktop | ||||
Merge into: | lp:midori | ||||
Diff against target: |
418 lines (+183/-97) 5 files modified
cmake/ContainTest.cmake (+1/-0) extensions/apps.vala (+132/-61) midori/midori-dialog.vala (+32/-1) tests/completion.vala (+17/-34) tests/extensions.c (+1/-1) |
||||
To merge this branch: | bzr merge lp:~midori/midori/desktop | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paweł Forysiuk | Approve | ||
Review via email: mp+195292@code.launchpad.net |
Commit message
More robust app/ profile creation
Description of the change
This branch includes new Test.init and Test.Job API which were found to be invaluable specifically with the apps test.
To post a comment you must log in.
lp:~midori/midori/desktop
updated
- 6423. By Cris Dywan
-
Remove contained folders in ContainTest
Revision history for this message
Paweł Forysiuk (tuxator) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmake/ContainTest.cmake' | |||
2 | --- cmake/ContainTest.cmake 2013-10-01 21:35:39 +0000 | |||
3 | +++ cmake/ContainTest.cmake 2014-01-26 21:49:39 +0000 | |||
4 | @@ -7,6 +7,7 @@ | |||
5 | 7 | set(TEST_ENV "") | 7 | set(TEST_ENV "") |
6 | 8 | foreach(VARIABLE XDG_DATA_HOME XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_RUNTIME_DIR TMPDIR) | 8 | foreach(VARIABLE XDG_DATA_HOME XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_RUNTIME_DIR TMPDIR) |
7 | 9 | set(CONTAINER "${CMAKE_CURRENT_BINARY_DIR}/${test_name}-folders/${VARIABLE}") | 9 | set(CONTAINER "${CMAKE_CURRENT_BINARY_DIR}/${test_name}-folders/${VARIABLE}") |
8 | 10 | file(REMOVE_RECURSE ${CONTAINER}) | ||
9 | 10 | file(MAKE_DIRECTORY ${CONTAINER}) | 11 | file(MAKE_DIRECTORY ${CONTAINER}) |
10 | 11 | set(TEST_ENV "${TEST_ENV}${VARIABLE}=${CONTAINER};") | 12 | set(TEST_ENV "${TEST_ENV}${VARIABLE}=${CONTAINER};") |
11 | 12 | endforeach() | 13 | endforeach() |
12 | 13 | 14 | ||
13 | === modified file 'extensions/apps.vala' | |||
14 | --- extensions/apps.vala 2013-08-09 22:48:35 +0000 | |||
15 | +++ extensions/apps.vala 2014-01-26 21:49:39 +0000 | |||
16 | @@ -20,10 +20,37 @@ | |||
17 | 20 | internal string exec; | 20 | internal string exec; |
18 | 21 | internal string uri; | 21 | internal string uri; |
19 | 22 | 22 | ||
24 | 23 | internal static async void create (string prefix, GLib.File folder, string uri, string title, Gtk.Widget proxy) { | 23 | internal static string get_favicon_name_for_uri (string prefix, GLib.File folder, string uri, bool testing) |
25 | 24 | /* Strip LRE leading character and / */ | 24 | { |
26 | 25 | string name = title.delimit ("/", ' ').strip(); | 25 | string icon_name = Midori.Stock.WEB_BROWSER; |
27 | 26 | string filename = Midori.Download.clean_filename (name); | 26 | |
28 | 27 | if (testing == true) | ||
29 | 28 | return icon_name; | ||
30 | 29 | |||
31 | 30 | if (prefix != PROFILE_PREFIX) | ||
32 | 31 | { | ||
33 | 32 | try { | ||
34 | 33 | var pixbuf = Midori.Paths.get_icon (uri, null); | ||
35 | 34 | if (pixbuf == null) | ||
36 | 35 | throw new FileError.EXIST ("No favicon loaded"); | ||
37 | 36 | string icon_filename = folder.get_child ("icon.png").get_path (); | ||
38 | 37 | pixbuf.save (icon_filename, "png", null, "compression", "7", null); | ||
39 | 38 | #if HAVE_WIN32 | ||
40 | 39 | string doubleslash_icon = icon_filename.replace ("\\", "\\\\"); | ||
41 | 40 | icon_name = doubleslash_icon; | ||
42 | 41 | #else | ||
43 | 42 | icon_name = icon_filename; | ||
44 | 43 | #endif | ||
45 | 44 | } | ||
46 | 45 | catch (Error error) { | ||
47 | 46 | GLib.warning (_("Failed to fetch application icon in %s: %s"), folder.get_path (), error.message); | ||
48 | 47 | } | ||
49 | 48 | } | ||
50 | 49 | return icon_name; | ||
51 | 50 | } | ||
52 | 51 | |||
53 | 52 | internal static string prepare_desktop_file (string prefix, string name, string uri, string title, string icon_name) | ||
54 | 53 | { | ||
55 | 27 | string exec; | 54 | string exec; |
56 | 28 | #if HAVE_WIN32 | 55 | #if HAVE_WIN32 |
57 | 29 | string doubleslash_uri = uri.replace ("\\", "\\\\"); | 56 | string doubleslash_uri = uri.replace ("\\", "\\\\"); |
58 | @@ -32,62 +59,100 @@ | |||
59 | 32 | #else | 59 | #else |
60 | 33 | exec = prefix + uri; | 60 | exec = prefix + uri; |
61 | 34 | #endif | 61 | #endif |
62 | 62 | var keyfile = new GLib.KeyFile (); | ||
63 | 63 | string entry = "Desktop Entry"; | ||
64 | 64 | |||
65 | 65 | keyfile.set_string (entry, "Version", "1.0"); | ||
66 | 66 | keyfile.set_string (entry, "Type", "Application"); | ||
67 | 67 | keyfile.set_string (entry, "Name", name); | ||
68 | 68 | keyfile.set_string (entry, "Exec", exec); | ||
69 | 69 | keyfile.set_string (entry, "TryExec", PACKAGE_NAME); | ||
70 | 70 | keyfile.set_string (entry, "Icon", icon_name); | ||
71 | 71 | keyfile.set_string (entry, "Categories", "Network;"); | ||
72 | 72 | |||
73 | 73 | return keyfile.to_data(); | ||
74 | 74 | } | ||
75 | 75 | |||
76 | 76 | internal static File get_app_folder () { | ||
77 | 77 | var data_dir = File.new_for_path (Midori.Paths.get_user_data_dir ()).get_child (PACKAGE_NAME); | ||
78 | 78 | return data_dir.get_child ("apps"); | ||
79 | 79 | } | ||
80 | 80 | |||
81 | 81 | internal static async File create_app (string uri, string title, Gtk.Widget? proxy) { | ||
82 | 82 | string checksum = Checksum.compute_for_string (ChecksumType.MD5, uri, -1); | ||
83 | 83 | var folder = get_app_folder (); | ||
84 | 84 | yield Launcher.create (APP_PREFIX, folder.get_child (checksum), | ||
85 | 85 | uri, title, proxy); | ||
86 | 86 | return folder.get_child (checksum); | ||
87 | 87 | } | ||
88 | 88 | |||
89 | 89 | internal static File get_profile_folder () { | ||
90 | 90 | var data_dir = File.new_for_path (Midori.Paths.get_user_data_dir ()).get_child (PACKAGE_NAME); | ||
91 | 91 | return data_dir.get_child ("profiles"); | ||
92 | 92 | } | ||
93 | 93 | |||
94 | 94 | internal static async File create_profile (Gtk.Widget? proxy) { | ||
95 | 95 | string uuid = g_dbus_generate_guid (); | ||
96 | 96 | string config = Path.build_path (Path.DIR_SEPARATOR_S, | ||
97 | 97 | Midori.Paths.get_user_data_dir (), PACKAGE_NAME, "profiles", uuid); | ||
98 | 98 | var folder = get_profile_folder (); | ||
99 | 99 | yield Launcher.create (PROFILE_PREFIX, folder.get_child (uuid), | ||
100 | 100 | config, _("Midori (%s)").printf (uuid), proxy); | ||
101 | 101 | return folder.get_child (uuid); | ||
102 | 102 | } | ||
103 | 103 | |||
104 | 104 | internal static async void create (string prefix, GLib.File folder, string uri, string title, Gtk.Widget proxy) { | ||
105 | 105 | /* Strip LRE leading character and / */ | ||
106 | 106 | string name = title.delimit ("/", ' ').strip(); | ||
107 | 107 | string filename = Midori.Download.clean_filename (name); | ||
108 | 108 | string icon_name = Midori.Stock.WEB_BROWSER; | ||
109 | 109 | bool testing = false; | ||
110 | 110 | if (proxy == null) | ||
111 | 111 | testing = true; | ||
112 | 112 | var file = folder.get_child ("desc"); | ||
113 | 113 | |||
114 | 35 | try { | 114 | try { |
115 | 36 | folder.make_directory_with_parents (null); | 115 | folder.make_directory_with_parents (null); |
151 | 37 | } | 116 | } catch (IOError.EXISTS exist_error) { |
152 | 38 | catch (Error error) { | 117 | /* It's no error if the folder already exists */ |
153 | 39 | /* It's not an error if the folder already exists; | 118 | } catch (Error error) { |
154 | 40 | any fatal problems will fail further down the line */ | 119 | warning (_("Failed to create new launcher (%s): %s"), file.get_path (), error.message); |
155 | 41 | } | 120 | } |
156 | 42 | 121 | ||
157 | 43 | string icon_name = Midori.Stock.WEB_BROWSER; | 122 | icon_name = get_favicon_name_for_uri (prefix, folder, uri, testing); |
158 | 44 | try { | 123 | string desktop_file = prepare_desktop_file (prefix, name, uri, title, icon_name); |
159 | 45 | var pixbuf = Midori.Paths.get_icon (uri, null); | 124 | |
125 | 46 | if (pixbuf == null) | ||
126 | 47 | throw new FileError.EXIST ("No favicon loaded"); | ||
127 | 48 | string icon_filename = folder.get_child ("icon.png").get_path (); | ||
128 | 49 | pixbuf.save (icon_filename, "png", null, "compression", "7", null); | ||
129 | 50 | #if HAVE_WIN32 | ||
130 | 51 | string doubleslash_icon = icon_filename.replace ("\\", "\\\\"); | ||
131 | 52 | icon_name = doubleslash_icon; | ||
132 | 53 | #else | ||
133 | 54 | icon_name = icon_filename; | ||
134 | 55 | #endif | ||
135 | 56 | } | ||
136 | 57 | catch (Error error) { | ||
137 | 58 | GLib.warning (_("Failed to fetch application icon in %s: %s"), folder.get_path (), error.message); | ||
138 | 59 | } | ||
139 | 60 | string contents = """ | ||
140 | 61 | [Desktop Entry] | ||
141 | 62 | Version=1.0 | ||
142 | 63 | Type=Application | ||
143 | 64 | Name=%s | ||
144 | 65 | Exec=%s | ||
145 | 66 | TryExec=%s | ||
146 | 67 | Icon=%s | ||
147 | 68 | Categories=Network; | ||
148 | 69 | """.printf (name, exec, PACKAGE_NAME, icon_name); | ||
149 | 70 | var file = folder.get_child ("desc"); | ||
150 | 71 | var browser = proxy.get_toplevel () as Midori.Browser; | ||
160 | 72 | try { | 125 | try { |
161 | 73 | var stream = yield file.replace_async (null, false, GLib.FileCreateFlags.NONE); | 126 | var stream = yield file.replace_async (null, false, GLib.FileCreateFlags.NONE); |
163 | 74 | yield stream.write_async (contents.data); | 127 | yield stream.write_async (desktop_file.data); |
164 | 75 | // Create a launcher/ menu | 128 | // Create a launcher/ menu |
165 | 76 | #if HAVE_WIN32 | 129 | #if HAVE_WIN32 |
166 | 77 | Midori.Sokoke.create_win32_desktop_lnk (prefix, filename, uri); | 130 | Midori.Sokoke.create_win32_desktop_lnk (prefix, filename, uri); |
167 | 78 | #else | 131 | #else |
168 | 79 | var data_dir = File.new_for_path (Midori.Paths.get_user_data_dir ()); | 132 | var data_dir = File.new_for_path (Midori.Paths.get_user_data_dir ()); |
170 | 80 | yield file.copy_async (data_dir.get_child ("applications").get_child (filename + ".desktop"), | 133 | var desktop_dir = data_dir.get_child ("applications"); |
171 | 134 | try { | ||
172 | 135 | desktop_dir.make_directory_with_parents (null); | ||
173 | 136 | } catch (IOError.EXISTS exist_error) { | ||
174 | 137 | /* It's no error if the folder already exists */ | ||
175 | 138 | } | ||
176 | 139 | |||
177 | 140 | yield file.copy_async (desktop_dir.get_child (filename + ".desktop"), | ||
178 | 81 | GLib.FileCopyFlags.NONE); | 141 | GLib.FileCopyFlags.NONE); |
179 | 82 | #endif | 142 | #endif |
183 | 83 | 143 | if (proxy != null) { | |
184 | 84 | browser.send_notification (_("Launcher created"), | 144 | var browser = proxy.get_toplevel () as Midori.Browser; |
185 | 85 | _("You can now run <b>%s</b> from your launcher or menu").printf (name)); | 145 | browser.send_notification (_("Launcher created"), |
186 | 146 | _("You can now run <b>%s</b> from your launcher or menu").printf (name)); | ||
187 | 147 | } | ||
188 | 86 | } | 148 | } |
189 | 87 | catch (Error error) { | 149 | catch (Error error) { |
190 | 88 | warning (_("Failed to create new launcher (%s): %s"), file.get_path (), error.message); | 150 | warning (_("Failed to create new launcher (%s): %s"), file.get_path (), error.message); |
193 | 89 | browser.send_notification (_("Error creating launcher"), | 151 | if (proxy != null) { |
194 | 90 | _("Failed to create new launcher (%s): %s").printf (file.get_path (), error.message)); | 152 | var browser = proxy.get_toplevel () as Midori.Browser; |
195 | 153 | browser.send_notification (_("Error creating launcher"), | ||
196 | 154 | _("Failed to create new launcher (%s): %s").printf (file.get_path (), error.message)); | ||
197 | 155 | } | ||
198 | 91 | } | 156 | } |
199 | 92 | } | 157 | } |
200 | 93 | 158 | ||
201 | @@ -139,11 +204,7 @@ | |||
202 | 139 | profile.is_important = true; | 204 | profile.is_important = true; |
203 | 140 | profile.show (); | 205 | profile.show (); |
204 | 141 | profile.clicked.connect (() => { | 206 | profile.clicked.connect (() => { |
210 | 142 | string uuid = g_dbus_generate_guid (); | 207 | Launcher.create_profile.begin (this); |
206 | 143 | string config = Path.build_path (Path.DIR_SEPARATOR_S, | ||
207 | 144 | Midori.Paths.get_user_data_dir (), PACKAGE_NAME, "profiles", uuid); | ||
208 | 145 | Launcher.create.begin (PROFILE_PREFIX, profile_folder.get_child (uuid), | ||
209 | 146 | config, _("Midori (%s)").printf (uuid), this); | ||
211 | 147 | }); | 208 | }); |
212 | 148 | toolbar.insert (profile, -1); | 209 | toolbar.insert (profile, -1); |
213 | 149 | #endif | 210 | #endif |
214 | @@ -349,10 +410,8 @@ | |||
215 | 349 | try { | 410 | try { |
216 | 350 | try { | 411 | try { |
217 | 351 | app_folder.make_directory_with_parents (null); | 412 | app_folder.make_directory_with_parents (null); |
222 | 352 | } | 413 | } catch (IOError.EXISTS exist_error) { |
223 | 353 | catch (IOError folder_error) { | 414 | /* It's no error if the folder already exists */ |
220 | 354 | if (!(folder_error is IOError.EXISTS)) | ||
221 | 355 | throw folder_error; | ||
224 | 356 | } | 415 | } |
225 | 357 | 416 | ||
226 | 358 | var monitor = app_folder.monitor_directory (0, null); | 417 | var monitor = app_folder.monitor_directory (0, null); |
227 | @@ -392,9 +451,7 @@ | |||
228 | 392 | _("Creates a new app for a specific site"), null); | 451 | _("Creates a new app for a specific site"), null); |
229 | 393 | action.activate.connect (() => { | 452 | action.activate.connect (() => { |
230 | 394 | var view = browser.tab as Midori.View; | 453 | var view = browser.tab as Midori.View; |
234 | 395 | string checksum = Checksum.compute_for_string (ChecksumType.MD5, view.get_display_uri (), -1); | 454 | Launcher.create_app.begin (view.get_display_uri (), view.get_display_title (), view); |
232 | 396 | Launcher.create.begin (APP_PREFIX, app_folder.get_child (checksum), | ||
233 | 397 | view.get_display_uri (), view.get_display_title (), browser); | ||
235 | 398 | }); | 455 | }); |
236 | 399 | action_group.add_action_with_accel (action, "<Ctrl><Shift>A"); | 456 | action_group.add_action_with_accel (action, "<Ctrl><Shift>A"); |
237 | 400 | action.set_accel_group (accels); | 457 | action.set_accel_group (accels); |
238 | @@ -408,12 +465,11 @@ | |||
239 | 408 | 465 | ||
240 | 409 | void activated (Midori.App app) { | 466 | void activated (Midori.App app) { |
241 | 410 | array = new Katze.Array (typeof (Launcher)); | 467 | array = new Katze.Array (typeof (Launcher)); |
242 | 411 | var data_dir = File.new_for_path (Midori.Paths.get_user_data_dir ()).get_child (PACKAGE_NAME); | ||
243 | 412 | monitors = new GLib.List<GLib.FileMonitor> (); | 468 | monitors = new GLib.List<GLib.FileMonitor> (); |
245 | 413 | app_folder = data_dir.get_child ("apps"); | 469 | app_folder = Launcher.get_app_folder (); |
246 | 414 | populate_apps.begin (app_folder); | 470 | populate_apps.begin (app_folder); |
247 | 415 | /* FIXME: Profiles are broken on win32 because of no multi instance support */ | 471 | /* FIXME: Profiles are broken on win32 because of no multi instance support */ |
249 | 416 | profile_folder = data_dir.get_child ("profiles"); | 472 | profile_folder = Launcher.get_profile_folder (); |
250 | 417 | #if !HAVE_WIN32 | 473 | #if !HAVE_WIN32 |
251 | 418 | populate_apps.begin (profile_folder); | 474 | populate_apps.begin (profile_folder); |
252 | 419 | #endif | 475 | #endif |
253 | @@ -456,3 +512,18 @@ | |||
254 | 456 | return new Apps.Manager (); | 512 | return new Apps.Manager (); |
255 | 457 | } | 513 | } |
256 | 458 | 514 | ||
257 | 515 | class ExtensionsAppsDesktop : Midori.Test.Job { | ||
258 | 516 | public static void test () { new ExtensionsAppsDesktop ().run_sync (); } | ||
259 | 517 | public override async void run (Cancellable cancellable) throws GLib.Error { | ||
260 | 518 | var folder = yield Apps.Launcher.create_app ("http://example.com", "Example", null); | ||
261 | 519 | var launcher = new Apps.Launcher (folder); | ||
262 | 520 | launcher.init (); | ||
263 | 521 | Katze.assert_str_equal (folder.get_path (), launcher.uri, "http://example.com"); | ||
264 | 522 | yield Apps.Launcher.create_profile (null); | ||
265 | 523 | } | ||
266 | 524 | } | ||
267 | 525 | |||
268 | 526 | public void extension_test () { | ||
269 | 527 | Test.add_func ("/extensions/apps/desktop", ExtensionsAppsDesktop.test); | ||
270 | 528 | } | ||
271 | 529 | |||
272 | 459 | 530 | ||
273 | === modified file 'midori/midori-dialog.vala' | |||
274 | --- midori/midori-dialog.vala 2013-11-05 14:51:49 +0000 | |||
275 | +++ midori/midori-dialog.vala 2014-01-26 21:49:39 +0000 | |||
276 | @@ -24,13 +24,24 @@ | |||
277 | 24 | } | 24 | } |
278 | 25 | 25 | ||
279 | 26 | namespace Test { | 26 | namespace Test { |
280 | 27 | public void init ([CCode (array_length_pos = 0.9)] ref unowned string[] args) { | ||
281 | 28 | GLib.Test.init (ref args); | ||
282 | 29 | |||
283 | 30 | /* Always log to stderr */ | ||
284 | 31 | Log.set_handler (null, | ||
285 | 32 | LogLevelFlags.LEVEL_MASK | LogLevelFlags.FLAG_FATAL | LogLevelFlags.FLAG_RECURSION, | ||
286 | 33 | (domain, log_levels, message) => { | ||
287 | 34 | stderr.printf ("** %s\n", message); | ||
288 | 35 | }); | ||
289 | 36 | } | ||
290 | 37 | |||
291 | 27 | internal static uint test_max_timeout = 0; | 38 | internal static uint test_max_timeout = 0; |
292 | 28 | internal static string? test_first_try = null; | 39 | internal static string? test_first_try = null; |
293 | 29 | public void grab_max_timeout () { | 40 | public void grab_max_timeout () { |
294 | 30 | int seconds = (Environment.get_variable ("MIDORI_TIMEOUT") ?? "42").to_int (); | 41 | int seconds = (Environment.get_variable ("MIDORI_TIMEOUT") ?? "42").to_int (); |
295 | 31 | test_first_try = "once"; | 42 | test_first_try = "once"; |
296 | 32 | test_max_timeout = GLib.Timeout.add_seconds (seconds > 0 ? seconds / 2 : 0, ()=>{ | 43 | test_max_timeout = GLib.Timeout.add_seconds (seconds > 0 ? seconds / 2 : 0, ()=>{ |
298 | 33 | stdout.printf ("Timed out %s%s\n", test_first_try, | 44 | stderr.printf ("Timed out %s%s\n", test_first_try, |
299 | 34 | MainContext.default ().pending () ? " (loop)" : ""); | 45 | MainContext.default ().pending () ? " (loop)" : ""); |
300 | 35 | if (test_first_try == "twice") | 46 | if (test_first_try == "twice") |
301 | 36 | Process.exit (0); | 47 | Process.exit (0); |
302 | @@ -50,6 +61,26 @@ | |||
303 | 50 | test_idle_timeouts = true; | 61 | test_idle_timeouts = true; |
304 | 51 | } | 62 | } |
305 | 52 | 63 | ||
306 | 64 | public abstract class Job : GLib.Object { | ||
307 | 65 | bool done; | ||
308 | 66 | public abstract async void run (Cancellable cancellable) throws GLib.Error; | ||
309 | 67 | async void run_wrapped (Cancellable cancellable) { | ||
310 | 68 | try { | ||
311 | 69 | yield run (cancellable); | ||
312 | 70 | } catch (Error error) { | ||
313 | 71 | GLib.error (error.message); | ||
314 | 72 | } | ||
315 | 73 | done = true; | ||
316 | 74 | } | ||
317 | 75 | public void run_sync () { | ||
318 | 76 | var loop = MainContext.default (); | ||
319 | 77 | var cancellable = new Cancellable (); | ||
320 | 78 | done = false; | ||
321 | 79 | run_wrapped.begin (cancellable); | ||
322 | 80 | do { loop.iteration (true); } while (!done); | ||
323 | 81 | } | ||
324 | 82 | } | ||
325 | 83 | |||
326 | 53 | public void log_set_fatal_handler_for_icons () { | 84 | public void log_set_fatal_handler_for_icons () { |
327 | 54 | GLib.Test.log_set_fatal_handler ((domain, log_levels, message)=> { | 85 | GLib.Test.log_set_fatal_handler ((domain, log_levels, message)=> { |
328 | 55 | return !message.contains ("Error loading theme icon") | 86 | return !message.contains ("Error loading theme icon") |
329 | 56 | 87 | ||
330 | === modified file 'tests/completion.vala' | |||
331 | --- tests/completion.vala 2013-12-16 22:38:24 +0000 | |||
332 | +++ tests/completion.vala 2014-01-26 21:49:39 +0000 | |||
333 | @@ -87,43 +87,26 @@ | |||
334 | 87 | error ("Expected %d but got %d", 3, n); | 87 | error ("Expected %d but got %d", 3, n); |
335 | 88 | } | 88 | } |
336 | 89 | 89 | ||
360 | 90 | async void complete_history (Midori.HistoryDatabase history) { | 90 | class CompletionHistory : Midori.Test.Job { |
361 | 91 | try { | 91 | public static void test () { new CompletionHistory ().run_sync (); } |
362 | 92 | history.insert ("http://example.com", "Ejemplo", 0, 0); | 92 | public override async void run (Cancellable cancellable) throws GLib.Error { |
340 | 93 | } catch (Error error) { | ||
341 | 94 | assert_not_reached (); | ||
342 | 95 | } | ||
343 | 96 | var cancellable = new Cancellable (); | ||
344 | 97 | var results = yield history.list_by_count_with_bookmarks ("example", 1, cancellable); | ||
345 | 98 | assert (results.length () == 1); | ||
346 | 99 | var first = results.nth_data (0); | ||
347 | 100 | assert (first.title == "Ejemplo"); | ||
348 | 101 | results = yield history.list_by_count_with_bookmarks ("ejemplo", 1, cancellable); | ||
349 | 102 | assert (results.length () == 1); | ||
350 | 103 | first = results.nth_data (0); | ||
351 | 104 | assert (first.title == "Ejemplo"); | ||
352 | 105 | complete_history_done = true; | ||
353 | 106 | } | ||
354 | 107 | |||
355 | 108 | bool complete_history_done = false; | ||
356 | 109 | void completion_history () { | ||
357 | 110 | var app = new Midori.App (); | ||
358 | 111 | Midori.HistoryDatabase history; | ||
359 | 112 | try { | ||
363 | 113 | var bookmarks_database = new Midori.BookmarksDatabase (); | 93 | var bookmarks_database = new Midori.BookmarksDatabase (); |
364 | 114 | assert (bookmarks_database.db != null); | 94 | assert (bookmarks_database.db != null); |
366 | 115 | history = new Midori.HistoryDatabase (app); | 95 | |
367 | 96 | Midori.HistoryDatabase history = new Midori.HistoryDatabase (null); | ||
368 | 116 | assert (history.db != null); | 97 | assert (history.db != null); |
369 | 117 | history.clear (0); | 98 | history.clear (0); |
372 | 118 | } catch (Midori.DatabaseError error) { | 99 | |
373 | 119 | assert_not_reached(); | 100 | history.insert ("http://example.com", "Ejemplo", 0, 0); |
374 | 101 | var results = yield history.list_by_count_with_bookmarks ("example", 1, cancellable); | ||
375 | 102 | assert (results.length () == 1); | ||
376 | 103 | var first = results.nth_data (0); | ||
377 | 104 | assert (first.title == "Ejemplo"); | ||
378 | 105 | results = yield history.list_by_count_with_bookmarks ("ejemplo", 1, cancellable); | ||
379 | 106 | assert (results.length () == 1); | ||
380 | 107 | first = results.nth_data (0); | ||
381 | 108 | assert (first.title == "Ejemplo"); | ||
382 | 120 | } | 109 | } |
383 | 121 | |||
384 | 122 | Midori.Test.grab_max_timeout (); | ||
385 | 123 | var loop = MainContext.default (); | ||
386 | 124 | complete_history.begin (history); | ||
387 | 125 | do { loop.iteration (true); } while (!complete_history_done); | ||
388 | 126 | Midori.Test.release_max_timeout (); | ||
389 | 127 | } | 110 | } |
390 | 128 | 111 | ||
391 | 129 | struct TestCaseRender { | 112 | struct TestCaseRender { |
392 | @@ -154,11 +137,11 @@ | |||
393 | 154 | } | 137 | } |
394 | 155 | 138 | ||
395 | 156 | void main (string[] args) { | 139 | void main (string[] args) { |
397 | 157 | Test.init (ref args); | 140 | Midori.Test.init (ref args); |
398 | 158 | Midori.App.setup (ref args, null); | 141 | Midori.App.setup (ref args, null); |
399 | 159 | Midori.Paths.init (Midori.RuntimeMode.NORMAL, null); | 142 | Midori.Paths.init (Midori.RuntimeMode.NORMAL, null); |
400 | 160 | Test.add_func ("/completion/autocompleter", completion_autocompleter); | 143 | Test.add_func ("/completion/autocompleter", completion_autocompleter); |
402 | 161 | Test.add_func ("/completion/history", completion_history); | 144 | Test.add_func ("/completion/history", CompletionHistory.test); |
403 | 162 | Test.add_func ("/completion/location-action", completion_location_action); | 145 | Test.add_func ("/completion/location-action", completion_location_action); |
404 | 163 | Test.run (); | 146 | Test.run (); |
405 | 164 | } | 147 | } |
406 | 165 | 148 | ||
407 | === modified file 'tests/extensions.c' | |||
408 | --- tests/extensions.c 2013-10-29 18:45:01 +0000 | |||
409 | +++ tests/extensions.c 2014-01-26 21:49:39 +0000 | |||
410 | @@ -216,7 +216,7 @@ | |||
411 | 216 | main (int argc, | 216 | main (int argc, |
412 | 217 | char** argv) | 217 | char** argv) |
413 | 218 | { | 218 | { |
415 | 219 | g_test_init (&argc, &argv, NULL); | 219 | midori_test_init (&argc, &argv); |
416 | 220 | midori_app_setup (&argc, &argv, NULL); | 220 | midori_app_setup (&argc, &argv, NULL); |
417 | 221 | midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, NULL); | 221 | midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, NULL); |
418 | 222 | #ifndef HAVE_WEBKIT2 | 222 | #ifndef HAVE_WEBKIT2 |