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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp

Issue 1736333002: Fix a race condition in canvas hibernation when visibility is toggled repeatedly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698