| OLD | NEW |
| 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 Loading... |
| 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<FakeCanvas2DLayerBridge> create(PassRefPtr<GraphicsContext
3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode, ThreadMode threa
dMode) |
| 64 { |
| 65 return adoptPtr(new FakeCanvas2DLayerBridge(context, canvas, opacityMode
, threadMode)); |
| 66 } |
| 67 protected: |
| 68 FakeCanvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCan
vas* canvas, OpacityMode opacityMode, ThreadMode threadMode) : |
| 69 Canvas2DLayerBridge(context, canvas, opacityMode, threadMode) |
| 70 { } |
| 71 }; |
| 72 |
| 61 } // namespace | 73 } // namespace |
| 62 | 74 |
| 63 class Canvas2DLayerBridgeTest : public Test { | 75 class Canvas2DLayerBridgeTest : public Test { |
| 64 protected: | 76 protected: |
| 65 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode) | 77 void fullLifecycleTest(Canvas2DLayerBridge::ThreadMode threadMode) |
| 66 { | 78 { |
| 67 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic
sContextFromWebContext(adoptPtr(new MockCanvasContext)); | 79 RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphic
sContextFromWebContext(adoptPtr(new MockCanvasContext)); |
| 68 | 80 |
| 69 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte
xt->webContext()); | 81 MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainConte
xt->webContext()); |
| 70 | 82 |
| 71 MockWebTextureUpdater updater; | 83 MockWebTextureUpdater updater; |
| 72 | 84 |
| 73 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); | 85 SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150); |
| 74 SkDeferredCanvas canvas(&device); | 86 SkDeferredCanvas canvas(&device); |
| 75 | 87 |
| 76 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 88 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 77 | 89 |
| 78 OwnPtr<Canvas2DLayerBridge> bridge = Canvas2DLayerBridge::create(mainCon
text.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode); | 90 OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(mai
nContext.release(), &canvas, Canvas2DLayerBridge::NonOpaque, threadMode); |
| 79 | 91 |
| 80 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 92 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 81 | 93 |
| 82 EXPECT_CALL(mainMock, flush()); | 94 EXPECT_CALL(mainMock, flush()); |
| 83 unsigned textureId = bridge->backBufferTexture(); | 95 unsigned textureId = bridge->backBufferTexture(); |
| 84 EXPECT_TRUE(textureId == 0); | 96 EXPECT_TRUE(textureId == 0); |
| 85 | 97 |
| 86 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 98 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 87 | 99 |
| 88 bridge.clear(); | 100 bridge.clear(); |
| 89 | 101 |
| 90 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 102 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 91 ::testing::Mock::VerifyAndClearExpectations(&updater); | 103 ::testing::Mock::VerifyAndClearExpectations(&updater); |
| 92 } | 104 } |
| 93 }; | 105 }; |
| 94 | 106 |
| 95 namespace { | 107 namespace { |
| 96 | 108 |
| 97 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) | 109 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded) |
| 98 { | 110 { |
| 99 fullLifecycleTest(Canvas2DLayerBridge::SingleThread); | 111 fullLifecycleTest(Canvas2DLayerBridge::SingleThread); |
| 100 } | 112 } |
| 101 | 113 |
| 102 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded) | 114 TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleThreaded) |
| 103 { | 115 { |
| 104 fullLifecycleTest(Canvas2DLayerBridge::Threaded); | 116 fullLifecycleTest(Canvas2DLayerBridge::Threaded); |
| 105 } | 117 } |
| 106 | 118 |
| 107 } // namespace | 119 } // namespace |
| OLD | NEW |