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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 EXPECT_FALSE(bridge->isHibernating()); | 495 EXPECT_FALSE(bridge->isHibernating()); |
496 EXPECT_TRUE(bridge->checkSurfaceValid()); | 496 EXPECT_TRUE(bridge->checkSurfaceValid()); |
497 | 497 |
498 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 498 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
499 // without crashing due to thread checks | 499 // without crashing due to thread checks |
500 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 500 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
501 | 501 |
502 ::testing::Mock::VerifyAndClearExpectations(&mainMock); | 502 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
503 } | 503 } |
504 | 504 |
| 505 TEST_F(Canvas2DLayerBridgeTest, HibernationReEntry) |
| 506 { |
| 507 MockCanvasContext mainMock; |
| 508 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T
estThread")); |
| 509 |
| 510 // The Canvas2DLayerBridge has to be created on the thread that will use it |
| 511 // to avoid WeakPtr thread check issues. |
| 512 Canvas2DLayerBridgePtr bridge; |
| 513 postAndWaitCreateBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge, &mai
nMock, this); |
| 514 |
| 515 // Register an alternate Logger for tracking hibernation events |
| 516 OwnPtr<MockLogger> mockLogger = adoptPtr(new MockLogger); |
| 517 MockLogger* mockLoggerPtr = mockLogger.get(); |
| 518 bridge->setLoggerForTesting(mockLogger.release()); |
| 519 |
| 520 // Test entering hibernation |
| 521 OwnPtr<WaitableEvent> hibernationStartedEvent = adoptPtr(new WaitableEvent()
); |
| 522 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); |
| 523 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) |
| 524 .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent:
:signal)); |
| 525 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); |
| 526 // Toggle visibility before the idle tasks that enters hibernation gets a |
| 527 // chance to run. |
| 528 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), false); |
| 529 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); |
| 530 |
| 531 hibernationStartedEvent->wait(); |
| 532 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 533 EXPECT_FALSE(bridge->isAccelerated()); |
| 534 EXPECT_TRUE(bridge->isHibernating()); |
| 535 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 536 |
| 537 // Test exiting hibernation |
| 538 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedNormally)); |
| 539 postAndWaitSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(),
false); |
| 540 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 541 EXPECT_TRUE(bridge->isAccelerated()); |
| 542 EXPECT_FALSE(bridge->isHibernating()); |
| 543 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 544 |
| 545 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
| 546 // without crashing due to thread checks |
| 547 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 548 |
| 549 ::testing::Mock::VerifyAndClearExpectations(&mainMock); |
| 550 |
| 551 } |
| 552 |
505 TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycleWithDeferredRenderingDisable
d) | 553 TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycleWithDeferredRenderingDisable
d) |
506 { | 554 { |
507 MockCanvasContext mainMock; | 555 MockCanvasContext mainMock; |
508 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T
estThread")); | 556 OwnPtr<WebThread> testThread = adoptPtr(Platform::current()->createThread("T
estThread")); |
509 | 557 |
510 // The Canvas2DLayerBridge has to be created on the thread that will use it | 558 // The Canvas2DLayerBridge has to be created on the thread that will use it |
511 // to avoid WeakPtr thread check issues. | 559 // to avoid WeakPtr thread check issues. |
512 Canvas2DLayerBridgePtr bridge; | 560 Canvas2DLayerBridgePtr bridge; |
513 postAndWaitCreateBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge, &mai
nMock, this); | 561 postAndWaitCreateBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge, &mai
nMock, this); |
514 bridge->disableDeferral(DisableDeferralReasonUnknown); | 562 bridge->disableDeferral(DisableDeferralReasonUnknown); |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 WebExternalTextureMailbox mailbox; | 1040 WebExternalTextureMailbox mailbox; |
993 EXPECT_FALSE(bridge->prepareMailbox(&mailbox, 0)); | 1041 EXPECT_FALSE(bridge->prepareMailbox(&mailbox, 0)); |
994 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1042 EXPECT_TRUE(bridge->checkSurfaceValid()); |
995 | 1043 |
996 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1044 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
997 // without crashing due to thread checks | 1045 // without crashing due to thread checks |
998 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1046 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
999 } | 1047 } |
1000 | 1048 |
1001 } // namespace blink | 1049 } // namespace blink |
OLD | NEW |