summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/core/fetch/MockResourceClients.cpp
blob: f735e582ac7f7226d8d7e7999c61073d8a22f4ea (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
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/fetch/MockResourceClients.h"

#include "core/fetch/ImageResource.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace blink {

MockResourceClient::MockResourceClient(PassRefPtrWillBeRawPtr<Resource> resource)
    : m_resource(resource.get())
    , m_notifyFinishedCalled(false)
{
    m_resource->addClient(this);
}

MockResourceClient::~MockResourceClient()
{
    if (m_resource)
        m_resource->removeClient(this);
}
void MockResourceClient::notifyFinished(Resource*)
{
    ASSERT_FALSE(m_notifyFinishedCalled);
    m_notifyFinishedCalled = true;
}

void MockResourceClient::removeAsClient()
{
    m_resource->removeClient(this);
    m_resource = nullptr;
}

MockImageResourceClient::MockImageResourceClient(PassRefPtrWillBeRawPtr<ImageResource> resource)
    : MockResourceClient(resource)
    , m_imageChangedCount(0)
    , m_imageNotifyFinishedCount(0)
{
    toImageResource(m_resource.get())->addObserver(this);
}

MockImageResourceClient::~MockImageResourceClient()
{
    if (m_resource)
        toImageResource(m_resource.get())->removeObserver(this);
}

void MockImageResourceClient::removeAsClient()
{
    toImageResource(m_resource.get())->removeObserver(this);
    MockResourceClient::removeAsClient();
}

void MockImageResourceClient::imageChanged(ImageResource*, const IntRect*)
{
    m_imageChangedCount++;
}

void MockImageResourceClient::imageNotifyFinished(ImageResource*)
{
    ASSERT_EQ(0, m_imageNotifyFinishedCount);
    m_imageNotifyFinishedCount++;
}

bool MockImageResourceClient::notifyFinishedCalled() const
{
    EXPECT_EQ(m_notifyFinishedCalled ? 1 : 0, m_imageNotifyFinishedCount);

    return m_notifyFinishedCalled;
}

} // namespace blink