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

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 2252163003: Update Context Client Visibility to use Scoped Pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 4 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 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 mock_context_provider_ptr_ = mock_worker_context_provider.get(); 445 mock_context_provider_ptr_ = mock_worker_context_provider.get();
446 446
447 // Workers are bound on the main thread. 447 // Workers are bound on the main thread.
448 mock_worker_context_provider->BindToCurrentThread(); 448 mock_worker_context_provider->BindToCurrentThread();
449 449
450 // Ensure that our mock calls execute in sequence. 450 // Ensure that our mock calls execute in sequence.
451 ::testing::InSequence s; 451 ::testing::InSequence s;
452 452
453 // At init, visibility is set to true and we will call 453 // At init, visibility is set to true and we will call
454 // SetAggressivelyFreeResources(false). 454 // SetAggressivelyFreeResources(false).
455 EXPECT_CALL(*mock_context_support_ptr_, SetClientVisible(0, true)); 455 EXPECT_CALL(*mock_context_support_ptr_, ClientBecameVisible())
456 .WillOnce(
457 ::testing::Invoke(mock_context_support_ptr_,
458 &MockContextSupport::SuperClientBecameVisible));
456 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) 459 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible())
457 .WillOnce(::testing::Return(true)); 460 .WillOnce(::testing::Return(true));
458 EXPECT_CALL(*mock_context_support_ptr_, 461 EXPECT_CALL(*mock_context_support_ptr_,
459 SetAggressivelyFreeResources(false)); 462 SetAggressivelyFreeResources(false));
460 463
461 return LayerTreeHostTest::CreateDelegatingOutputSurface( 464 return LayerTreeHostTest::CreateDelegatingOutputSurface(
462 std::move(compositor_context_provider), 465 std::move(compositor_context_provider),
463 std::move(mock_worker_context_provider)); 466 std::move(mock_worker_context_provider));
464 } 467 }
465 468
466 void InitializeSettings(LayerTreeSettings* settings) override { 469 void InitializeSettings(LayerTreeSettings* settings) override {
467 settings->gpu_rasterization_enabled = true; 470 settings->gpu_rasterization_enabled = true;
468 settings->gpu_rasterization_forced = true; 471 settings->gpu_rasterization_forced = true;
469 } 472 }
470 473
471 void BeginTest() override {} 474 void BeginTest() override {}
472 475
473 void BeforeVisibilityChange() { 476 void BeforeVisibilityChange() {
474 // Ensure that our initialization expectations have completed. 477 // Ensure that our initialization expectations have completed.
475 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); 478 Mock::VerifyAndClearExpectations(mock_context_support_ptr_);
476 479
477 // Ensure that our mock calls execute in sequence. 480 // Ensure that our mock calls execute in sequence.
478 ::testing::InSequence s; 481 ::testing::InSequence s;
479 482
480 // While running, visibility is set to false, and we will call 483 // While running, visibility is set to false, and we will call
481 // DeleteCachedResources and SetAggressivelyFreeResources(true). 484 // DeleteCachedResources and SetAggressivelyFreeResources(true).
482 EXPECT_CALL(*mock_context_support_ptr_, SetClientVisible(0, false)); 485 EXPECT_CALL(*mock_context_support_ptr_,
486 ClientBecameNotVisible_(::testing::_))
danakj 2016/08/18 21:39:44 just _, add a call to using if needed
ericrk 2016/08/19 17:23:19 Done.
487 .WillOnce(::testing::Invoke(
488 mock_context_support_ptr_,
489 &MockContextSupport::SuperClientBecameNotVisible));
483 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible()) 490 EXPECT_CALL(*mock_context_support_ptr_, AnyClientsVisible())
484 .WillOnce(::testing::Return(false)); 491 .WillOnce(::testing::Return(false));
485 EXPECT_CALL(*mock_context_provider_ptr_, DeleteCachedResources()); 492 EXPECT_CALL(*mock_context_provider_ptr_, DeleteCachedResources());
486 EXPECT_CALL(*mock_context_support_ptr_, SetAggressivelyFreeResources(true)) 493 EXPECT_CALL(*mock_context_support_ptr_, SetAggressivelyFreeResources(true))
487 .WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); })); 494 .WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); }));
488 } 495 }
489 496
490 void AfterTest() override { 497 void AfterTest() override {
491 // Ensure all expectations are satisfied. 498 // Ensure all expectations are satisfied.
492 Mock::VerifyAndClearExpectations(mock_context_support_ptr_); 499 Mock::VerifyAndClearExpectations(mock_context_support_ptr_);
493 Mock::VerifyAndClearExpectations(mock_context_provider_ptr_); 500 Mock::VerifyAndClearExpectations(mock_context_provider_ptr_);
494 } 501 }
495 502
496 private: 503 private:
497 class MockContextProvider : public TestContextProvider { 504 class MockContextProvider : public TestContextProvider {
498 public: 505 public:
499 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support) 506 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support)
500 : TestContextProvider(std::move(support), 507 : TestContextProvider(std::move(support),
501 base::MakeUnique<TestGLES2Interface>(), 508 base::MakeUnique<TestGLES2Interface>(),
502 TestWebGraphicsContext3D::Create()) {} 509 TestWebGraphicsContext3D::Create()) {}
503 510
504 MOCK_METHOD0(DeleteCachedResources, void()); 511 MOCK_METHOD0(DeleteCachedResources, void());
505 512
506 private: 513 private:
507 ~MockContextProvider() = default; 514 ~MockContextProvider() = default;
508 }; 515 };
509 516
510 class MockContextSupport : public TestContextSupport { 517 class MockContextSupport : public TestContextSupport {
511 public: 518 public:
519 using VisibilityToken = std::unique_ptr<ScopedVisibility>;
512 MockContextSupport() {} 520 MockContextSupport() {}
513 MOCK_METHOD1(SetAggressivelyFreeResources, 521 MOCK_METHOD1(SetAggressivelyFreeResources,
514 void(bool aggressively_free_resources)); 522 void(bool aggressively_free_resources));
515 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible)); 523 MOCK_METHOD0(ClientBecameVisible, VisibilityToken());
524 MOCK_METHOD1(ClientBecameNotVisible_,
525 void(VisibilityToken& visibility)); // NOLINT
516 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); 526 MOCK_CONST_METHOD0(AnyClientsVisible, bool());
527
528 // Wrapper to allow mocking w/ move-only type.
529 void ClientBecameNotVisible(VisibilityToken visibility) override {
530 ClientBecameNotVisible_(visibility);
531 }
532
533 // Wrappers to allow forwarding to super class implementation.
534 void SuperClientBecameNotVisible(VisibilityToken& visibility) { // NOLINT
535 TestContextSupport::ClientBecameNotVisible(std::move(visibility));
536 }
537 VisibilityToken SuperClientBecameVisible() {
538 return TestContextSupport::ClientBecameVisible();
539 }
517 }; 540 };
518 541
519 MockContextSupport* mock_context_support_ptr_; 542 MockContextSupport* mock_context_support_ptr_;
520 MockContextProvider* mock_context_provider_ptr_; 543 MockContextProvider* mock_context_provider_ptr_;
521 }; 544 };
522 545
523 // Test if the LTH successfully frees resources on the worker context when 546 // Test if the LTH successfully frees resources on the worker context when
524 // visibility is set to false. 547 // visibility is set to false.
525 class LayerTreeHostFreeWorkerContextResourcesOnInvisible 548 class LayerTreeHostFreeWorkerContextResourcesOnInvisible
526 : public LayerTreeHostFreeWorkerContextResourcesTest { 549 : public LayerTreeHostFreeWorkerContextResourcesTest {
(...skipping 6504 matching lines...) Expand 10 before | Expand all | Expand 10 after
7031 private: 7054 private:
7032 FakeContentLayerClient client_; 7055 FakeContentLayerClient client_;
7033 const gfx::Size viewport_size_; 7056 const gfx::Size viewport_size_;
7034 const gfx::Size large_image_size_; 7057 const gfx::Size large_image_size_;
7035 }; 7058 };
7036 7059
7037 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); 7060 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage);
7038 7061
7039 } // namespace 7062 } // namespace
7040 } // namespace cc 7063 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698