OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/blimp/synced_property_remote.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace cc { | |
10 namespace { | |
11 | |
12 TEST(SyncedPropertyRemoteTest, BasicDeltaTracking) { | |
13 SyncedPropertyRemote<ScaleGroup> synced_float; | |
14 | |
15 // Set up the initial value. | |
16 float initial_state = 0.5f; | |
17 synced_float.PushFromEngineMainThread(initial_state); | |
18 EXPECT_EQ(synced_float.EngineMain(), initial_state); | |
19 | |
20 // Apply a delta from the impl thread. | |
21 float delta_from_impl = 0.2f; | |
22 synced_float.UpdateDeltaFromImplThread(initial_state * delta_from_impl); | |
23 EXPECT_EQ(synced_float.DeltaNotAppliedOnEngine(), delta_from_impl); | |
24 EXPECT_EQ(synced_float.EngineMain(), initial_state); | |
25 | |
26 // Pull a state update for the engine. | |
27 float delta_to_send = synced_float.PullDeltaForEngineUpdate(); | |
28 EXPECT_EQ(delta_to_send, delta_from_impl); | |
29 | |
30 // The initial delta should still be reported as unapplied. | |
31 EXPECT_EQ(synced_float.DeltaNotAppliedOnEngine(), delta_from_impl); | |
32 | |
33 // Now send some more delta from impl. It should be included in the unapplied | |
34 // delta. | |
35 float second_delta_from_impl = 0.3f; | |
36 synced_float.UpdateDeltaFromImplThread(synced_float.EngineMain() * | |
37 second_delta_from_impl); | |
38 float third_delta_from_impl = 0.4f; | |
39 synced_float.UpdateDeltaFromImplThread(synced_float.EngineMain() * | |
40 third_delta_from_impl); | |
41 | |
42 float expected_total_delta = | |
43 delta_from_impl * second_delta_from_impl * third_delta_from_impl; | |
44 EXPECT_EQ(synced_float.DeltaNotAppliedOnEngine(), expected_total_delta); | |
45 | |
46 // Inform that the delta was applied on the engine and make sure it is | |
47 // pre-emptively applied on the client. | |
48 synced_float.DidApplySentDeltaOnEngine(); | |
49 EXPECT_EQ(synced_float.EngineMain(), initial_state * delta_from_impl); | |
50 | |
51 // Now pull another delta, it should be now the accumulated delta. | |
52 EXPECT_EQ(synced_float.PullDeltaForEngineUpdate(), | |
53 second_delta_from_impl * third_delta_from_impl); | |
54 } | |
55 | |
56 } // namespace | |
57 } // namespace cc | |
OLD | NEW |