File: WebProcessTest.h

package info (click to toggle)
wpewebkit 2.50.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 438,288 kB
  • sloc: cpp: 3,777,429; javascript: 197,888; ansic: 156,951; python: 49,118; asm: 21,987; ruby: 18,540; perl: 16,722; xml: 4,623; yacc: 2,360; sh: 2,096; java: 2,019; lex: 1,327; pascal: 366; makefile: 92
file content (83 lines) | stat: -rw-r--r-- 2,616 bytes parent folder | download | duplicates (5)
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
/*
 * Copyright (C) 2013 Igalia S.L.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include <functional>
#include <wtf/HashSet.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>

#if PLATFORM(GTK) && USE(GTK4)
#include <webkit/webkit-web-process-extension.h>
#elif PLATFORM(GTK)
#include <webkit2/webkit-web-extension.h>
#elif PLATFORM(WPE) && ENABLE(2022_GLIB_API)
#include <wpe/webkit-web-process-extension.h>
#elif PLATFORM(WPE)
#include <wpe/webkit-web-extension.h>
#endif

class Watcher {
public:
    ~Watcher()
    {
        checkLeaks();
    }

    void assertObjectIsDeletedWhenTestFinishes(GObject* object)
    {
        m_watchedObjects.add(object);
        g_object_weak_ref(object, [](gpointer data, GObject* whereTheObjectWas) {
            Watcher* watcher = static_cast<Watcher*>(data);
            watcher->m_watchedObjects.remove(whereTheObjectWas);
        }, this);
    }

    void checkLeaks()
    {
        if (m_watchedObjects.isEmpty())
            return;

        g_print("Leaked objects in WebProcess:");
        for (const auto object : m_watchedObjects)
            g_print(" %s(%p)", g_type_name_from_instance(reinterpret_cast<GTypeInstance*>(object)), object);
        g_print("\n");

        g_assert_true(m_watchedObjects.isEmpty());
    }

private:
    HashSet<GObject*> m_watchedObjects;
};

static Watcher s_watcher;

class WebProcessTest {
    WTF_DEPRECATED_MAKE_FAST_ALLOCATED(WebProcessTest);
public:
    virtual ~WebProcessTest() { }
    virtual bool runTest(const char* testName, WebKitWebPage*) = 0;

    static void add(const String& testName, std::function<std::unique_ptr<WebProcessTest> ()>);
    static std::unique_ptr<WebProcessTest> create(const String& testName);
};

#define REGISTER_TEST(ClassName, TestName) \
    WebProcessTest::add(String::fromUTF8(TestName), ClassName::create)