| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 private: | 94 private: |
| 95 RefPtr<Canvas2DLayerBridge> m_layerBridge; | 95 RefPtr<Canvas2DLayerBridge> m_layerBridge; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // anonymous namespace | 98 } // anonymous namespace |
| 99 | 99 |
| 100 class Canvas2DLayerBridgeTest : public Test { | 100 class Canvas2DLayerBridgeTest : public Test { |
| 101 public: | 101 public: |
| 102 PassRefPtr<Canvas2DLayerBridge> makeBridge(std::unique_ptr<FakeWebGraphicsCo
ntext3DProvider> provider, const IntSize& size, Canvas2DLayerBridge::Acceleratio
nMode accelerationMode) | 102 PassRefPtr<Canvas2DLayerBridge> makeBridge(std::unique_ptr<FakeWebGraphicsCo
ntext3DProvider> provider, const IntSize& size, Canvas2DLayerBridge::Acceleratio
nMode accelerationMode) |
| 103 { | 103 { |
| 104 return adoptRef(new Canvas2DLayerBridge(std::move(provider), size, 0, No
nOpaque, accelerationMode, nullptr)); | 104 RefPtr<Canvas2DLayerBridge> bridge = adoptRef(new Canvas2DLayerBridge(st
d::move(provider), size, 0, NonOpaque, accelerationMode, nullptr)); |
| 105 bridge->dontUseIdleSchedulingForTesting(); |
| 106 return bridge.release(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 protected: | 109 protected: |
| 108 void fullLifecycleTest() | 110 void fullLifecycleTest() |
| 109 { | 111 { |
| 110 FakeGLES2Interface gl; | 112 FakeGLES2Interface gl; |
| 111 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = wrap
Unique(new FakeWebGraphicsContext3DProvider(&gl)); | 113 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = wrap
Unique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 112 | 114 |
| 113 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(std::move
(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Disable
Acceleration, nullptr))); | 115 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(std::move
(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::Disable
Acceleration, nullptr))); |
| 114 | 116 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 std::unique_ptr<MockLogger> mockLogger = wrapUnique(new MockLogger); | 457 std::unique_ptr<MockLogger> mockLogger = wrapUnique(new MockLogger); |
| 456 MockLogger* mockLoggerPtr = mockLogger.get(); | 458 MockLogger* mockLoggerPtr = mockLogger.get(); |
| 457 bridge->setLoggerForTesting(std::move(mockLogger)); | 459 bridge->setLoggerForTesting(std::move(mockLogger)); |
| 458 | 460 |
| 459 // Test entering hibernation | 461 // Test entering hibernation |
| 460 std::unique_ptr<WaitableEvent> hibernationStartedEvent = wrapUnique(new Wait
ableEvent()); | 462 std::unique_ptr<WaitableEvent> hibernationStartedEvent = wrapUnique(new Wait
ableEvent()); |
| 461 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); | 463 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); |
| 462 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) | 464 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) |
| 463 .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent:
:signal)); | 465 .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent:
:signal)); |
| 464 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); | 466 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); |
| 465 // Toggle visibility before the idle tasks that enters hibernation gets a | 467 // Toggle visibility before the task that enters hibernation gets a |
| 466 // chance to run. | 468 // chance to run. |
| 467 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false); | 469 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false); |
| 468 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); | 470 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); |
| 469 | 471 |
| 470 hibernationStartedEvent->wait(); | 472 hibernationStartedEvent->wait(); |
| 471 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); | 473 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 472 EXPECT_FALSE(bridge->isAccelerated()); | 474 EXPECT_FALSE(bridge->isAccelerated()); |
| 473 EXPECT_TRUE(bridge->isHibernating()); | 475 EXPECT_TRUE(bridge->isHibernating()); |
| 474 EXPECT_TRUE(bridge->checkSurfaceValid()); | 476 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 475 | 477 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 std::unique_ptr<WaitableEvent> hibernationEndedEvent = wrapUnique(new Waitab
leEvent()); | 811 std::unique_ptr<WaitableEvent> hibernationEndedEvent = wrapUnique(new Waitab
leEvent()); |
| 810 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedNormally)) | 812 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedNormally)) |
| 811 .WillOnce(testing::InvokeWithoutArgs(hibernationEndedEvent.get(), &Waita
bleEvent::signal)); | 813 .WillOnce(testing::InvokeWithoutArgs(hibernationEndedEvent.get(), &Waita
bleEvent::signal)); |
| 812 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false); | 814 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false); |
| 813 hibernationEndedEvent->wait(); | 815 hibernationEndedEvent->wait(); |
| 814 | 816 |
| 815 // Tear down the bridge while hibernating | 817 // Tear down the bridge while hibernating |
| 816 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 818 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 817 } | 819 } |
| 818 | 820 |
| 819 class IdleFenceTask : public WebThread::IdleTask { | |
| 820 public: | |
| 821 IdleFenceTask(WaitableEvent* doneEvent) | |
| 822 : m_doneEvent(doneEvent) | |
| 823 { } | |
| 824 | |
| 825 virtual ~IdleFenceTask() { } | |
| 826 | |
| 827 void run(double /*deadline*/) override | |
| 828 { | |
| 829 m_doneEvent->signal(); | |
| 830 } | |
| 831 | |
| 832 private: | |
| 833 WaitableEvent* m_doneEvent; | |
| 834 }; | |
| 835 | |
| 836 #if CANVAS2D_HIBERNATION_ENABLED | 821 #if CANVAS2D_HIBERNATION_ENABLED |
| 837 TEST_F(Canvas2DLayerBridgeTest, TeardownWhileHibernationIsPending) | 822 TEST_F(Canvas2DLayerBridgeTest, TeardownWhileHibernationIsPending) |
| 838 #else | 823 #else |
| 839 TEST_F(Canvas2DLayerBridgeTest, DISABLED_TeardownWhileHibernationIsPending) | 824 TEST_F(Canvas2DLayerBridgeTest, DISABLED_TeardownWhileHibernationIsPending) |
| 840 #endif | 825 #endif |
| 841 { | 826 { |
| 842 FakeGLES2Interface gl; | 827 FakeGLES2Interface gl; |
| 843 std::unique_ptr<WebThread> testThread = wrapUnique(Platform::current()->crea
teThread("TestThread")); | 828 std::unique_ptr<WebThread> testThread = wrapUnique(Platform::current()->crea
teThread("TestThread")); |
| 844 | 829 |
| 845 // The Canvas2DLayerBridge has to be created on the thread that will use it | 830 // The Canvas2DLayerBridge has to be created on the thread that will use it |
| (...skipping 10 matching lines...) Expand all Loading... |
| 856 std::unique_ptr<WaitableEvent> hibernationScheduledEvent = wrapUnique(new Wa
itableEvent()); | 841 std::unique_ptr<WaitableEvent> hibernationScheduledEvent = wrapUnique(new Wa
itableEvent()); |
| 857 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); | 842 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); |
| 858 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true, h
ibernationScheduledEvent.get()); | 843 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true, h
ibernationScheduledEvent.get()); |
| 859 postDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 844 postDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 860 // In production, we would expect a | 845 // In production, we would expect a |
| 861 // HibernationAbortedDueToDestructionWhileHibernatePending event to be | 846 // HibernationAbortedDueToDestructionWhileHibernatePending event to be |
| 862 // fired, but that signal is lost in the unit test due to no longer having | 847 // fired, but that signal is lost in the unit test due to no longer having |
| 863 // a bridge to hold the mockLogger. | 848 // a bridge to hold the mockLogger. |
| 864 hibernationScheduledEvent->wait(); | 849 hibernationScheduledEvent->wait(); |
| 865 // Once we know the hibernation task is scheduled, we can schedule a fence. | 850 // Once we know the hibernation task is scheduled, we can schedule a fence. |
| 866 // Assuming Idle tasks are guaranteed to run in the order they were | 851 // Assuming tasks are guaranteed to run in the order they were |
| 867 // submitted, this fence will guarantee the attempt to hibernate runs to | 852 // submitted, this fence will guarantee the attempt to hibernate runs to |
| 868 // completion before the thread is destroyed. | 853 // completion before the thread is destroyed. |
| 869 // This test passes by not crashing, which proves that the WeakPtr logic | 854 // This test passes by not crashing, which proves that the WeakPtr logic |
| 870 // is sound. | 855 // is sound. |
| 871 std::unique_ptr<WaitableEvent> fenceEvent = wrapUnique(new WaitableEvent()); | 856 std::unique_ptr<WaitableEvent> fenceEvent = wrapUnique(new WaitableEvent()); |
| 872 testThread->scheduler()->postIdleTask(BLINK_FROM_HERE, new IdleFenceTask(fen
ceEvent.get())); | 857 testThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, WTF::bind(&Waitabl
eEvent::signal, unretained(fenceEvent.get()))); |
| 873 fenceEvent->wait(); | 858 fenceEvent->wait(); |
| 874 } | 859 } |
| 875 | 860 |
| 876 #if CANVAS2D_HIBERNATION_ENABLED | 861 #if CANVAS2D_HIBERNATION_ENABLED |
| 877 TEST_F(Canvas2DLayerBridgeTest, HibernationAbortedDueToPendingTeardown) | 862 TEST_F(Canvas2DLayerBridgeTest, HibernationAbortedDueToPendingTeardown) |
| 878 #else | 863 #else |
| 879 TEST_F(Canvas2DLayerBridgeTest, DISABLED_HibernationAbortedDueToPendingTeardown) | 864 TEST_F(Canvas2DLayerBridgeTest, DISABLED_HibernationAbortedDueToPendingTeardown) |
| 880 #endif | 865 #endif |
| 881 { | 866 { |
| 882 FakeGLES2Interface gl; | 867 FakeGLES2Interface gl; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 1045 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 1061 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback
)); | 1046 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback
)); |
| 1062 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1047 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 1063 | 1048 |
| 1064 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1049 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
| 1065 // without crashing due to thread checks | 1050 // without crashing due to thread checks |
| 1066 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1051 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 1067 } | 1052 } |
| 1068 | 1053 |
| 1069 } // namespace blink | 1054 } // namespace blink |
| OLD | NEW |