Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: third_party/WebKit/Source/core/fetch/MockResourceClients.cpp

Issue 1998073002: Move some ResourceClients for testing to Oilpan heap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/fetch/MockResourceClients.h" 5 #include "core/fetch/MockResourceClients.h"
6 6
7 #include "core/fetch/ImageResource.h" 7 #include "core/fetch/ImageResource.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 MockResourceClient::MockResourceClient(Resource* resource) 12 MockResourceClient::MockResourceClient(Resource* resource)
13 : m_resource(resource) 13 : m_resource(resource)
14 , m_notifyFinishedCalled(false) 14 , m_notifyFinishedCalled(false)
15 { 15 {
16 ThreadState::current()->registerPreFinalizer(this);
16 m_resource->addClient(this); 17 m_resource->addClient(this);
17 } 18 }
18 19
19 MockResourceClient::~MockResourceClient() 20 MockResourceClient::~MockResourceClient() {}
20 { 21
21 if (m_resource)
22 m_resource->removeClient(this);
23 }
24 void MockResourceClient::notifyFinished(Resource*) 22 void MockResourceClient::notifyFinished(Resource*)
25 { 23 {
26 ASSERT_FALSE(m_notifyFinishedCalled); 24 ASSERT_FALSE(m_notifyFinishedCalled);
27 m_notifyFinishedCalled = true; 25 m_notifyFinishedCalled = true;
28 } 26 }
29 27
30 void MockResourceClient::removeAsClient() 28 void MockResourceClient::removeAsClient()
31 { 29 {
32 m_resource->removeClient(this); 30 m_resource->removeClient(this);
33 m_resource = nullptr; 31 m_resource = nullptr;
34 } 32 }
35 33
34 void MockResourceClient::dispose()
35 {
36 if (m_resource) {
37 m_resource->removeClient(this);
38 m_resource = nullptr;
39 }
40 }
41
42 DEFINE_TRACE(MockResourceClient)
43 {
44 visitor->trace(m_resource);
45 }
46
36 MockImageResourceClient::MockImageResourceClient(ImageResource* resource) 47 MockImageResourceClient::MockImageResourceClient(ImageResource* resource)
37 : MockResourceClient(resource) 48 : MockResourceClient(resource)
38 , m_imageChangedCount(0) 49 , m_imageChangedCount(0)
39 , m_imageNotifyFinishedCount(0) 50 , m_imageNotifyFinishedCount(0)
40 { 51 {
41 toImageResource(m_resource.get())->addObserver(this); 52 toImageResource(m_resource.get())->addObserver(this);
42 } 53 }
43 54
44 MockImageResourceClient::~MockImageResourceClient() 55 MockImageResourceClient::~MockImageResourceClient() {}
45 {
46 if (m_resource)
47 toImageResource(m_resource.get())->removeObserver(this);
48 }
49 56
50 void MockImageResourceClient::removeAsClient() 57 void MockImageResourceClient::removeAsClient()
51 { 58 {
52 toImageResource(m_resource.get())->removeObserver(this); 59 toImageResource(m_resource.get())->removeObserver(this);
53 MockResourceClient::removeAsClient(); 60 MockResourceClient::removeAsClient();
54 } 61 }
55 62
63 void MockImageResourceClient::dispose()
64 {
65 if (m_resource)
66 toImageResource(m_resource.get())->removeObserver(this);
haraken 2016/05/20 07:37:38 Not related to this CL, we might want to move Imag
yhirano 2016/05/20 07:45:45 LayoutObject inherits ImageResourceObserver and ac
67 MockResourceClient::dispose();
68 }
69
56 void MockImageResourceClient::imageChanged(ImageResource*, const IntRect*) 70 void MockImageResourceClient::imageChanged(ImageResource*, const IntRect*)
57 { 71 {
58 m_imageChangedCount++; 72 m_imageChangedCount++;
59 } 73 }
60 74
61 void MockImageResourceClient::imageNotifyFinished(ImageResource*) 75 void MockImageResourceClient::imageNotifyFinished(ImageResource*)
62 { 76 {
63 ASSERT_EQ(0, m_imageNotifyFinishedCount); 77 ASSERT_EQ(0, m_imageNotifyFinishedCount);
64 m_imageNotifyFinishedCount++; 78 m_imageNotifyFinishedCount++;
65 } 79 }
66 80
67 bool MockImageResourceClient::notifyFinishedCalled() const 81 bool MockImageResourceClient::notifyFinishedCalled() const
68 { 82 {
69 EXPECT_EQ(m_notifyFinishedCalled ? 1 : 0, m_imageNotifyFinishedCount); 83 EXPECT_EQ(m_notifyFinishedCalled ? 1 : 0, m_imageNotifyFinishedCount);
70 84
71 return m_notifyFinishedCalled; 85 return m_notifyFinishedCalled;
72 } 86 }
73 87
74 } // namespace blink 88 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MockResourceClients.h ('k') | third_party/WebKit/Source/core/fetch/RawResourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698