summaryrefslogtreecommitdiff
path: root/tests/ephy-uri-helpers-test.c
blob: f536ab9eb45143f525cd304d3089ffc96b1d0ce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 *  Copyright © 2013 Bastien Nocera <hadess@hadess.net>
 *
 *  This file is part of Epiphany.
 *
 *  Epiphany is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Epiphany is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"
#include "ephy-debug.h"
#include "ephy-uri-helpers.h"
#include "ephy-settings.h"

#include <glib.h>
#include <gtk/gtk.h>

static void
test_ephy_uri_helpers_remove_tracking (void)
{
  struct {
    const char *input;
    const char *output;
  } const items[] = {
    { "http://www.test.com/", "http://www.test.com/" },
    { "http://www.test.com/?key=foo", "http://www.test.com/?key=foo" },
    /* From the description in https://addons.mozilla.org/fr/firefox/addon/pure-url/ */
    { "http://bigpicture.ru/?p=431513&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%%3A+bigpictures+%%28%%D0%%9D%%D0%%9E%%D0%%92%%D0%%9E%%D0%%A1%%D0%%A2%%D0%%98+%%D0%%92+%%D0%%A4%%D0%%9E%%D0%%A2%%D0%%9E%%D0%%93%%D0%%A0%%D0%%90%%D0%%A4%%D0%%98%%D0%%AF%%D0%%A5%%29", "http://bigpicture.ru/?p=431513" },
    { "http://www.test.com/?utm_source=feedburner", "http://www.test.com/" },
    { "http://www.test.com/?feature=foo", "http://www.test.com/?feature=foo" },
    { "http://foo.youtube.com/?feature=foo", "http://foo.youtube.com/" },
    /* https://bugzilla.gnome.org/show_bug.cgi?id=724724 */
    { "http://git.savannah.gnu.org/gitweb/?p=grep.git;a=commit;h=97318f5e59a1ef6feb8a378434a00932a3fc1e0b",
      "http://git.savannah.gnu.org/gitweb/?p=grep.git;a=commit;h=97318f5e59a1ef6feb8a378434a00932a3fc1e0b" },
    /* https://bugzilla.gnome.org/show_bug.cgi?id=730464 */
    { "https://mail.google.com/mail/u/0/?ui=2&ik=37373eb942&rid=7cea..&auto=1&view=lno&_reqid=1168127&pcd=1&mb=0&rt=j",
      "https://mail.google.com/mail/u/0/?ui=2&ik=37373eb942&rid=7cea..&auto=1&view=lno&_reqid=1168127&pcd=1&mb=0&rt=j" },
    { "http://www.test.com/?utm_source=feedburner&view=lno&_reqid=1234", "http://www.test.com/?view=lno&_reqid=1234" },
    { "http://www.test.com/?some&valid&query", "http://www.test.com/?some&valid&query" },
    { "http://www.test.com/?utm_source=feedburner&some&valid&query", "http://www.test.com/?some&valid&query" },
  };
  guint i;

  for (i = 0; i < G_N_ELEMENTS (items); i++) {
    char *result;

    g_test_message ("TRACKING: uri: %s; expected: %s;",
                    items[i].input, items[i].output);
    result = ephy_remove_tracking_from_uri (items[i].input);
    if (result == NULL)
      result = g_strdup (items[i].input);
    g_assert_cmpstr (items[i].output, ==, result);
    g_free (result);
  }
}

int
main (int argc, char *argv[])
{
  int ret;

  /* This should affect only this test, we use it so we can test for
   * default directory changes. */
  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);

  gtk_test_init (&argc, &argv);

  ephy_debug_init ();

  g_test_add_func ("/lib/ephy-uri-helpers/remove_tracking",
                   test_ephy_uri_helpers_remove_tracking);

  ret = g_test_run ();

  return ret;
}