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

Side by Side Diff: Source/WebKit/chromium/tests/Canvas2DLayerBridgeTest.cpp

Issue 16032003: Fixing Canvas2DLayerBridge to handle lost graphics contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed unit tests Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 MOCK_METHOD1(deleteTexture, void(unsigned)); 51 MOCK_METHOD1(deleteTexture, void(unsigned));
52 52
53 virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; } 53 virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; }
54 }; 54 };
55 55
56 class MockWebTextureUpdater : public WebTextureUpdater { 56 class MockWebTextureUpdater : public WebTextureUpdater {
57 public: 57 public:
58 MOCK_METHOD3(appendCopy, void(unsigned, unsigned, WebSize)); 58 MOCK_METHOD3(appendCopy, void(unsigned, unsigned, WebSize));
59 }; 59 };
60 60
61 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge {
62 public:
63 static PassOwnPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode, ThreadMode threadMod e)
64 {
65 return adoptPtr(new FakeCanvas2DLayerBridge(context, canvas, opacityMode , threadMode));
66 }
67
68 virtual bool isValid() OVERRIDE
Stephen White 2013/05/28 18:05:43 Now that we have a virtual isValid(), maybe we cou
69 {
70 return true;
71 }
72 protected:
73 FakeCanvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCan vas* canvas, OpacityMode opacityMode, ThreadMode threadMode) :
74 Canvas2DLayerBridge(context, canvas)
75 {
76 init(opacityMode, threadMode);
77 }
78 };
79
61 } // namespace 80 } // namespace
62 81
63 class Canvas2DLayerBridgeTest : public Test { 82 class Canvas2DLayerBridgeTest : public Test {
64 protected: 83 protected:
65 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode) 84 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode)
66 { 85 {
67 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext)); 86 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic sContextFromWebContext(adoptPtr(new MockCanvasContext));
68 87
69 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext()); 88 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte xt->webContext());
70 89
71 MockWebTextureUpdater updater; 90 MockWebTextureUpdater updater;
72 91
73 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); 92 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150);
74 SkDeferredCanvas canvas(&device); 93 SkDeferredCanvas canvas(&device);
75 94
76 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 95 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
77 96
78 OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainCon text.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode); 97 OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(mai nContext.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode);
79 98
80 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 99 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
81 100
82 EXPECT_CALL(mainMock, flush()); 101 EXPECT_CALL(mainMock, flush());
83 unsigned textureId = bridge->backBufferTexture(); 102 unsigned textureId = bridge->backBufferTexture();
84 EXPECT_TRUE(textureId == 0); 103 EXPECT_TRUE(textureId == 0);
85 104
86 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 105 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
87 106
88 bridge.clear(); 107 bridge.clear();
89 108
90 ::testing::Mock::VerifyAndClearExpectations(&mainMock); 109 ::testing::Mock::VerifyAndClearExpectations(&mainMock);
91 ::testing::Mock::VerifyAndClearExpectations(&updater); 110 ::testing::Mock::VerifyAndClearExpectations(&updater);
92 } 111 }
93 }; 112 };
94 113
95 namespace { 114 namespace {
96 115
97 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) 116 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded)
98 { 117 {
99 fullLifecycleTest(Canvas2DLayerBridge::SingleThread); 118 fullLifecycleTest(Canvas2DLayerBridge::SingleThread);
100 } 119 }
101 120
102 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded) 121 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded)
103 { 122 {
104 fullLifecycleTest(Canvas2DLayerBridge::Threaded); 123 fullLifecycleTest(Canvas2DLayerBridge::Threaded);
105 } 124 }
106 125
107 } // namespace 126 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698