| 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 "base/test/test_mock_time_task_runner.h" | 8 #include "base/test/test_mock_time_task_runner.h" |
| 9 #include "cc/test/test_context_provider.h" | 9 #include "cc/test/test_context_provider.h" |
| 10 #include "cc/test/test_context_support.h" | 10 #include "cc/test/test_context_support.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 auto visibility_1 = cache_controller.ClientBecameVisible(); | 47 auto visibility_1 = cache_controller.ClientBecameVisible(); |
| 48 Mock::VerifyAndClearExpectations(&context_support); | 48 Mock::VerifyAndClearExpectations(&context_support); |
| 49 auto visibility_2 = cache_controller.ClientBecameVisible(); | 49 auto visibility_2 = cache_controller.ClientBecameVisible(); |
| 50 | 50 |
| 51 cache_controller.ClientBecameNotVisible(std::move(visibility_1)); | 51 cache_controller.ClientBecameNotVisible(std::move(visibility_1)); |
| 52 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 52 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 53 cache_controller.ClientBecameNotVisible(std::move(visibility_2)); | 53 cache_controller.ClientBecameNotVisible(std::move(visibility_2)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 TEST(ContextCacheControllerTest, ScopedBusyWhileVisible) { | 56 TEST(ContextCacheControllerTest, ScopedBusyWhileVisible) { |
| 57 // TODO(ericrk): Temporarily disabling this to investigate whether this | |
| 58 // code regressed scroll latency on Android. crbug.com/664181 | |
| 59 #if defined(OS_ANDROID) | |
| 60 return; | |
| 61 #endif | |
| 62 StrictMock<MockContextSupport> context_support; | 57 StrictMock<MockContextSupport> context_support; |
| 63 auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner); | 58 auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner); |
| 64 ContextCacheController cache_controller(&context_support, task_runner); | 59 ContextCacheController cache_controller(&context_support, task_runner); |
| 65 | 60 |
| 66 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); | 61 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); |
| 67 auto visibility = cache_controller.ClientBecameVisible(); | 62 auto visibility = cache_controller.ClientBecameVisible(); |
| 68 Mock::VerifyAndClearExpectations(&context_support); | 63 Mock::VerifyAndClearExpectations(&context_support); |
| 69 | 64 |
| 70 // Now that we're visible, ensure that going idle triggers a delayed cleanup. | 65 // Now that we're visible, ensure that going idle triggers a delayed cleanup. |
| 71 auto busy = cache_controller.ClientBecameBusy(); | 66 auto busy = cache_controller.ClientBecameBusy(); |
| 72 cache_controller.ClientBecameNotBusy(std::move(busy)); | 67 cache_controller.ClientBecameNotBusy(std::move(busy)); |
| 73 | 68 |
| 74 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 69 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 75 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); | 70 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); |
| 76 task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5)); | 71 task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5)); |
| 77 Mock::VerifyAndClearExpectations(&context_support); | 72 Mock::VerifyAndClearExpectations(&context_support); |
| 78 | 73 |
| 79 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 74 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 80 cache_controller.ClientBecameNotVisible(std::move(visibility)); | 75 cache_controller.ClientBecameNotVisible(std::move(visibility)); |
| 81 } | 76 } |
| 82 | 77 |
| 83 TEST(ContextCacheControllerTest, ScopedBusyWhileNotVisible) { | 78 TEST(ContextCacheControllerTest, ScopedBusyWhileNotVisible) { |
| 84 // TODO(ericrk): Temporarily disabling this to investigate whether this | |
| 85 // code regressed scroll latency on Android. crbug.com/664181 | |
| 86 #if defined(OS_ANDROID) | |
| 87 return; | |
| 88 #endif | |
| 89 StrictMock<MockContextSupport> context_support; | 79 StrictMock<MockContextSupport> context_support; |
| 90 auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner); | 80 auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner); |
| 91 ContextCacheController cache_controller(&context_support, task_runner); | 81 ContextCacheController cache_controller(&context_support, task_runner); |
| 92 | 82 |
| 93 auto busy = cache_controller.ClientBecameBusy(); | 83 auto busy = cache_controller.ClientBecameBusy(); |
| 94 | 84 |
| 95 // We are not visible, so becoming busy should not trigger an idle callback. | 85 // We are not visible, so becoming busy should not trigger an idle callback. |
| 96 cache_controller.ClientBecameNotBusy(std::move(busy)); | 86 cache_controller.ClientBecameNotBusy(std::move(busy)); |
| 97 task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5)); | 87 task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5)); |
| 98 } | 88 } |
| 99 | 89 |
| 100 TEST(ContextCacheControllerTest, ScopedBusyMulitpleWhileVisible) { | 90 TEST(ContextCacheControllerTest, ScopedBusyMulitpleWhileVisible) { |
| 101 // TODO(ericrk): Temporarily disabling this to investigate whether this | |
| 102 // code regressed scroll latency on Android. crbug.com/664181 | |
| 103 #if defined(OS_ANDROID) | |
| 104 return; | |
| 105 #endif | |
| 106 StrictMock<MockContextSupport> context_support; | 91 StrictMock<MockContextSupport> context_support; |
| 107 auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner); | 92 auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner); |
| 108 ContextCacheController cache_controller(&context_support, task_runner); | 93 ContextCacheController cache_controller(&context_support, task_runner); |
| 109 | 94 |
| 110 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); | 95 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); |
| 111 auto visible = cache_controller.ClientBecameVisible(); | 96 auto visible = cache_controller.ClientBecameVisible(); |
| 112 Mock::VerifyAndClearExpectations(&context_support); | 97 Mock::VerifyAndClearExpectations(&context_support); |
| 113 | 98 |
| 114 auto busy_1 = cache_controller.ClientBecameBusy(); | 99 auto busy_1 = cache_controller.ClientBecameBusy(); |
| 115 cache_controller.ClientBecameNotBusy(std::move(busy_1)); | 100 cache_controller.ClientBecameNotBusy(std::move(busy_1)); |
| 116 auto busy_2 = cache_controller.ClientBecameBusy(); | 101 auto busy_2 = cache_controller.ClientBecameBusy(); |
| 117 cache_controller.ClientBecameNotBusy(std::move(busy_2)); | 102 cache_controller.ClientBecameNotBusy(std::move(busy_2)); |
| 118 | 103 |
| 119 // When we fast forward, only one cleanup should happen. | 104 // When we fast forward, only one cleanup should happen. |
| 120 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 105 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 121 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); | 106 EXPECT_CALL(context_support, SetAggressivelyFreeResources(false)); |
| 122 task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5)); | 107 task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5)); |
| 123 Mock::VerifyAndClearExpectations(&context_support); | 108 Mock::VerifyAndClearExpectations(&context_support); |
| 124 | 109 |
| 125 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); | 110 EXPECT_CALL(context_support, SetAggressivelyFreeResources(true)); |
| 126 cache_controller.ClientBecameNotVisible(std::move(visible)); | 111 cache_controller.ClientBecameNotVisible(std::move(visible)); |
| 127 } | 112 } |
| 128 | 113 |
| 129 } // namespace | 114 } // namespace |
| 130 } // namespace cc | 115 } // namespace cc |
| OLD | NEW |