OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/html/canvas/CanvasRenderingContext2D.h" | 7 #include "core/html/canvas/CanvasRenderingContext2D.h" |
8 | 8 |
9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
10 #include "core/html/HTMLDocument.h" | 10 #include "core/html/HTMLDocument.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 public: | 146 public: |
147 MockImageBufferSurfaceForOverwriteTesting(const IntSize& size, OpacityMode m
ode) : UnacceleratedImageBufferSurface(size, mode) { } | 147 MockImageBufferSurfaceForOverwriteTesting(const IntSize& size, OpacityMode m
ode) : UnacceleratedImageBufferSurface(size, mode) { } |
148 virtual ~MockImageBufferSurfaceForOverwriteTesting() { } | 148 virtual ~MockImageBufferSurfaceForOverwriteTesting() { } |
149 bool isRecording() const override { return true; } // otherwise overwrites a
re not tracked | 149 bool isRecording() const override { return true; } // otherwise overwrites a
re not tracked |
150 | 150 |
151 MOCK_METHOD0(willOverwriteCanvas, void()); | 151 MOCK_METHOD0(willOverwriteCanvas, void()); |
152 }; | 152 }; |
153 | 153 |
154 //============================================================================ | 154 //============================================================================ |
155 | 155 |
156 class MockCanvasObserver : public CanvasObserver { | 156 class MockCanvasObserver : public NoBaseWillBeGarbageCollectedFinalized<MockCanv
asObserver>, public CanvasObserver { |
| 157 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockCanvasObserver); |
157 public: | 158 public: |
| 159 static PassOwnPtrWillBeRawPtr<MockCanvasObserver> create() |
| 160 { |
| 161 return adoptPtrWillBeNoop(new MockCanvasObserver); |
| 162 } |
| 163 |
158 virtual ~MockCanvasObserver() { } | 164 virtual ~MockCanvasObserver() { } |
159 MOCK_METHOD2(canvasChanged, void(HTMLCanvasElement*, const FloatRect&)); | 165 MOCK_METHOD2(canvasChanged, void(HTMLCanvasElement*, const FloatRect&)); |
160 MOCK_METHOD1(canvasResized, void(HTMLCanvasElement*)); | 166 MOCK_METHOD1(canvasResized, void(HTMLCanvasElement*)); |
161 #if !ENABLE(OILPAN) | 167 #if !ENABLE(OILPAN) |
162 void canvasDestroyed(HTMLCanvasElement*) override { }; | 168 void canvasDestroyed(HTMLCanvasElement*) override { }; |
163 #endif | 169 #endif |
164 }; | 170 }; |
165 | 171 |
166 //============================================================================ | 172 //============================================================================ |
167 | 173 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 1; ++i) { | 538 for (int i = 0; i < ExpensiveCanvasHeuristicParameters::ExpensiveRecordingSt
ackDepth - 1; ++i) { |
533 context2d()->save(); | 539 context2d()->save(); |
534 context2d()->translate(1.0f, 0.0f); | 540 context2d()->translate(1.0f, 0.0f); |
535 } | 541 } |
536 canvasElement().doDeferredPaintInvalidation(); // To close the current frame | 542 canvasElement().doDeferredPaintInvalidation(); // To close the current frame |
537 } | 543 } |
538 | 544 |
539 TEST_F(CanvasRenderingContext2DTest, CanvasObserver) | 545 TEST_F(CanvasRenderingContext2DTest, CanvasObserver) |
540 { | 546 { |
541 createContext(NonOpaque); | 547 createContext(NonOpaque); |
542 MockCanvasObserver observer; | 548 OwnPtrWillBeRawPtr<MockCanvasObserver> observer = MockCanvasObserver::create
(); |
543 canvasElement().addObserver(&observer); | 549 canvasElement().addObserver(observer.get()); |
544 | 550 |
545 // The canvasChanged notification must be immediate, and not deferred until
paint time | 551 // The canvasChanged notification must be immediate, and not deferred until
paint time |
546 // because offscreen canvases, which are not painted, also need to emit noti
fications. | 552 // because offscreen canvases, which are not painted, also need to emit noti
fications. |
547 EXPECT_CALL(observer, canvasChanged(&canvasElement(), FloatRect(0, 0, 1, 1))
).Times(1); | 553 EXPECT_CALL(*observer, canvasChanged(&canvasElement(), FloatRect(0, 0, 1, 1)
)).Times(1); |
548 context2d()->fillRect(0, 0, 1, 1); | 554 context2d()->fillRect(0, 0, 1, 1); |
549 Mock::VerifyAndClearExpectations(&observer); | 555 Mock::VerifyAndClearExpectations(observer.get()); |
550 | 556 |
551 canvasElement().removeObserver(&observer); | 557 canvasElement().removeObserver(observer.get()); |
552 } | 558 } |
553 | 559 |
554 } // unnamed namespace | 560 } // unnamed namespace |
OLD | NEW |