| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/output/context_cache_controller.h" | 5 #include "cc/output/context_cache_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "cc/test/test_context_provider.h" | 8 #include "cc/test/test_context_provider.h" |
| 9 #include "cc/test/test_context_support.h" | 9 #include "cc/test/test_context_support.h" |
| 10 #include "cc/test/test_web_graphics_context_3d.h" | 10 #include "cc/test/test_web_graphics_context_3d.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace { | 15 namespace { |
| 16 using ::testing::Mock; | 16 using ::testing::Mock; |
| 17 using ::testing::StrictMock; | 17 using ::testing::StrictMock; |
| 18 | 18 |
| 19 class MockContextSupport : public TestContextSupport { | 19 class MockContextSupport : public TestContextSupport { |
| 20 public: | 20 public: |
| 21 MockContextSupport() {} | 21 MockContextSupport() {} |
| 22 MOCK_METHOD1(SetAggressivelyFreeResources, | 22 MOCK_METHOD1(SetAggressivelyFreeResources, |
| 23 void(bool aggressively_free_resources)); | 23 void(bool aggressively_free_resources)); |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 TEST(ContextCacheControllerTest, ScopedVisibilityBasic) { | 26 TEST(ContextCacheControllerTest, ScopedVisibilityBasic) { |
| 27 StrictMock<MockContextSupport> context_support; | 27 StrictMock<MockContextSupport> context_support; |
| 28 ContextCacheController cache_controller(&context_support); | 28 ContextCacheController cache_controller(&context_support, nullptr); |
| 29 | 29 |
| 30 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); | 30 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); |
| 31 std::unique_ptr<ContextCacheController::ScopedVisibility> visibility = | 31 std::unique_ptr<ContextCacheController::ScopedVisibility> visibility = |
| 32 cache_controller.ClientBecameVisible(); | 32 cache_controller.ClientBecameVisible(); |
| 33 Mock::VerifyAndClearExpectations(&context_support); | 33 Mock::VerifyAndClearExpectations(&context_support); |
| 34 | 34 |
| 35 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 35 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 36 cache_controller.ClientBecameNotVisible(std::move(visibility)); | 36 cache_controller.ClientBecameNotVisible(std::move(visibility)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 TEST(ContextCacheControllerTest, ScopedVisibilityMulti) { | 39 TEST(ContextCacheControllerTest, ScopedVisibilityMulti) { |
| 40 StrictMock<MockContextSupport> context_support; | 40 StrictMock<MockContextSupport> context_support; |
| 41 ContextCacheController cache_controller(&context_support); | 41 ContextCacheController cache_controller(&context_support, nullptr); |
| 42 | 42 |
| 43 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); | 43 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); |
| 44 std::unique_ptr<ContextCacheController::ScopedVisibility> visibility_1 = | 44 std::unique_ptr<ContextCacheController::ScopedVisibility> visibility_1 = |
| 45 cache_controller.ClientBecameVisible(); | 45 cache_controller.ClientBecameVisible(); |
| 46 Mock::VerifyAndClearExpectations(&context_support); | 46 Mock::VerifyAndClearExpectations(&context_support); |
| 47 std::unique_ptr<ContextCacheController::ScopedVisibility> visibility_2 = | 47 std::unique_ptr<ContextCacheController::ScopedVisibility> visibility_2 = |
| 48 cache_controller.ClientBecameVisible(); | 48 cache_controller.ClientBecameVisible(); |
| 49 | 49 |
| 50 cache_controller.ClientBecameNotVisible(std::move(visibility_1)); | 50 cache_controller.ClientBecameNotVisible(std::move(visibility_1)); |
| 51 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 51 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 52 cache_controller.ClientBecameNotVisible(std::move(visibility_2)); | 52 cache_controller.ClientBecameNotVisible(std::move(visibility_2)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 } // namespace cc | 56 } // namespace cc |
| OLD | NEW |