Index: third_party/WebKit/Source/core/loader/resource/MockImageResourceObserver.cpp |
diff --git a/third_party/WebKit/Source/core/loader/resource/MockImageResourceClient.cpp b/third_party/WebKit/Source/core/loader/resource/MockImageResourceObserver.cpp |
similarity index 32% |
rename from third_party/WebKit/Source/core/loader/resource/MockImageResourceClient.cpp |
rename to third_party/WebKit/Source/core/loader/resource/MockImageResourceObserver.cpp |
index 56e0c2eeb5c81f6881fcd609193540db2843b697..504ee10ab86c1778adfef9f873ae511db3f25263 100644 |
--- a/third_party/WebKit/Source/core/loader/resource/MockImageResourceClient.cpp |
+++ b/third_party/WebKit/Source/core/loader/resource/MockImageResourceObserver.cpp |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "core/loader/resource/MockImageResourceClient.h" |
+#include "core/loader/resource/MockImageResourceObserver.h" |
#include "core/loader/resource/ImageResource.h" |
#include "core/loader/resource/ImageResourceContent.h" |
@@ -10,42 +10,45 @@ |
namespace blink { |
-MockImageResourceClient::MockImageResourceClient(ImageResource* resource) |
- : MockResourceClient(resource), |
+MockImageResourceObserver::MockImageResourceObserver( |
+ ImageResourceContent* content) |
+ : m_content(content), |
m_imageChangedCount(0), |
- m_encodedSizeOnLastImageChanged(0), |
+ m_imageWidthOnLastImageChanged(0), |
m_imageNotifyFinishedCount(0), |
- m_encodedSizeOnImageNotifyFinished(0) { |
- toImageResource(m_resource)->getContent()->addObserver(this); |
+ m_imageWidthOnImageNotifyFinished(0) { |
+ m_content->addObserver(this); |
} |
-MockImageResourceClient::~MockImageResourceClient() {} |
- |
-void MockImageResourceClient::removeAsClient() { |
- toImageResource(m_resource)->getContent()->removeObserver(this); |
- MockResourceClient::removeAsClient(); |
+MockImageResourceObserver::~MockImageResourceObserver() { |
+ removeAsObserver(); |
} |
-void MockImageResourceClient::dispose() { |
- if (m_resource) |
- toImageResource(m_resource)->getContent()->removeObserver(this); |
- MockResourceClient::dispose(); |
+void MockImageResourceObserver::removeAsObserver() { |
+ if (!m_content) |
+ return; |
+ m_content->removeObserver(this); |
+ m_content = nullptr; |
} |
-void MockImageResourceClient::imageChanged(ImageResourceContent* image, |
- const IntRect*) { |
+void MockImageResourceObserver::imageChanged(ImageResourceContent* image, |
+ const IntRect*) { |
m_imageChangedCount++; |
- m_encodedSizeOnLastImageChanged = m_resource->encodedSize(); |
+ m_imageWidthOnLastImageChanged = |
+ m_content->hasImage() ? m_content->getImage()->width() : 0; |
} |
-void MockImageResourceClient::imageNotifyFinished(ImageResourceContent* image) { |
+void MockImageResourceObserver::imageNotifyFinished( |
+ ImageResourceContent* image) { |
ASSERT_EQ(0, m_imageNotifyFinishedCount); |
m_imageNotifyFinishedCount++; |
- m_encodedSizeOnImageNotifyFinished = m_resource->encodedSize(); |
+ m_imageWidthOnImageNotifyFinished = |
+ m_content->hasImage() ? m_content->getImage()->width() : 0; |
} |
-bool MockImageResourceClient::notifyFinishedCalled() const { |
- return m_notifyFinishedCalled; |
+bool MockImageResourceObserver::imageNotifyFinishedCalled() const { |
+ DCHECK_LE(m_imageNotifyFinishedCount, 1); |
+ return m_imageNotifyFinishedCount; |
} |
} // namespace blink |