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

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

Issue 2407573002: Wait to notify completion until after a Lo-Fi image is reloaded. (Closed)
Patch Set: removed unnecessary m_isSchedulingReload check Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MockResourceClients.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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), m_notifyFinishedCalled(false) { 13 : m_resource(resource),
14 m_notifyFinishedCalled(false),
15 m_encodedSizeOnNotifyFinished(0) {
14 ThreadState::current()->registerPreFinalizer(this); 16 ThreadState::current()->registerPreFinalizer(this);
15 m_resource->addClient(this); 17 m_resource->addClient(this);
16 } 18 }
17 19
18 MockResourceClient::~MockResourceClient() {} 20 MockResourceClient::~MockResourceClient() {}
19 21
20 void MockResourceClient::notifyFinished(Resource*) { 22 void MockResourceClient::notifyFinished(Resource* resource) {
21 ASSERT_FALSE(m_notifyFinishedCalled); 23 ASSERT_FALSE(m_notifyFinishedCalled);
22 m_notifyFinishedCalled = true; 24 m_notifyFinishedCalled = true;
25 m_encodedSizeOnNotifyFinished = resource->encodedSize();
23 } 26 }
24 27
25 void MockResourceClient::removeAsClient() { 28 void MockResourceClient::removeAsClient() {
26 m_resource->removeClient(this); 29 m_resource->removeClient(this);
27 m_resource = nullptr; 30 m_resource = nullptr;
28 } 31 }
29 32
30 void MockResourceClient::dispose() { 33 void MockResourceClient::dispose() {
31 if (m_resource) { 34 if (m_resource) {
32 m_resource->removeClient(this); 35 m_resource->removeClient(this);
33 m_resource = nullptr; 36 m_resource = nullptr;
34 } 37 }
35 } 38 }
36 39
37 DEFINE_TRACE(MockResourceClient) { 40 DEFINE_TRACE(MockResourceClient) {
38 visitor->trace(m_resource); 41 visitor->trace(m_resource);
39 ResourceClient::trace(visitor); 42 ResourceClient::trace(visitor);
40 } 43 }
41 44
42 MockImageResourceClient::MockImageResourceClient(ImageResource* resource) 45 MockImageResourceClient::MockImageResourceClient(ImageResource* resource)
43 : MockResourceClient(resource), 46 : MockResourceClient(resource),
44 m_imageChangedCount(0), 47 m_imageChangedCount(0),
45 m_imageNotifyFinishedCount(0) { 48 m_encodedSizeOnLastImageChanged(0),
49 m_imageNotifyFinishedCount(0),
50 m_encodedSizeOnImageNotifyFinished(0) {
46 toImageResource(m_resource.get())->addObserver(this); 51 toImageResource(m_resource.get())->addObserver(this);
47 } 52 }
48 53
49 MockImageResourceClient::~MockImageResourceClient() {} 54 MockImageResourceClient::~MockImageResourceClient() {}
50 55
51 void MockImageResourceClient::removeAsClient() { 56 void MockImageResourceClient::removeAsClient() {
52 toImageResource(m_resource.get())->removeObserver(this); 57 toImageResource(m_resource.get())->removeObserver(this);
53 MockResourceClient::removeAsClient(); 58 MockResourceClient::removeAsClient();
54 } 59 }
55 60
56 void MockImageResourceClient::dispose() { 61 void MockImageResourceClient::dispose() {
57 if (m_resource) 62 if (m_resource)
58 toImageResource(m_resource.get())->removeObserver(this); 63 toImageResource(m_resource.get())->removeObserver(this);
59 MockResourceClient::dispose(); 64 MockResourceClient::dispose();
60 } 65 }
61 66
62 void MockImageResourceClient::imageChanged(ImageResource*, const IntRect*) { 67 void MockImageResourceClient::imageChanged(ImageResource* image,
68 const IntRect*) {
63 m_imageChangedCount++; 69 m_imageChangedCount++;
70 m_encodedSizeOnLastImageChanged = image->encodedSize();
64 } 71 }
65 72
66 void MockImageResourceClient::imageNotifyFinished(ImageResource*) { 73 void MockImageResourceClient::imageNotifyFinished(ImageResource* image) {
67 ASSERT_EQ(0, m_imageNotifyFinishedCount); 74 ASSERT_EQ(0, m_imageNotifyFinishedCount);
68 m_imageNotifyFinishedCount++; 75 m_imageNotifyFinishedCount++;
76 m_encodedSizeOnImageNotifyFinished = image->encodedSize();
69 } 77 }
70 78
71 bool MockImageResourceClient::notifyFinishedCalled() const { 79 bool MockImageResourceClient::notifyFinishedCalled() const {
72 EXPECT_EQ(m_notifyFinishedCalled ? 1 : 0, m_imageNotifyFinishedCount); 80 EXPECT_EQ(m_notifyFinishedCalled ? 1 : 0, m_imageNotifyFinishedCount);
73 81
74 return m_notifyFinishedCalled; 82 return m_notifyFinishedCalled;
75 } 83 }
76 84
77 } // namespace blink 85 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MockResourceClients.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698