OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device_orientation_event_pump.h" | 5 #include "device_orientation_event_pump.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 class DeviceOrientationEventPumpTest : public testing::Test { | 74 class DeviceOrientationEventPumpTest : public testing::Test { |
75 public: | 75 public: |
76 DeviceOrientationEventPumpTest() = default; | 76 DeviceOrientationEventPumpTest() = default; |
77 | 77 |
78 protected: | 78 protected: |
79 void SetUp() override { | 79 void SetUp() override { |
80 listener_.reset(new MockDeviceOrientationListener); | 80 listener_.reset(new MockDeviceOrientationListener); |
81 orientation_pump_.reset(new DeviceOrientationEventPumpForTesting); | 81 orientation_pump_.reset(new DeviceOrientationEventPumpForTesting); |
82 shared_memory_ = mojo::SharedBufferHandle::Create( | 82 shared_memory_ = mojo::SharedBufferHandle::Create( |
83 sizeof(DeviceOrientationHardwareBuffer)); | 83 sizeof(device::DeviceOrientationHardwareBuffer)); |
84 mapping_ = shared_memory_->Map(sizeof(DeviceOrientationHardwareBuffer)); | 84 mapping_ = |
| 85 shared_memory_->Map(sizeof(device::DeviceOrientationHardwareBuffer)); |
85 ASSERT_TRUE(mapping_); | 86 ASSERT_TRUE(mapping_); |
86 memset(buffer(), 0, sizeof(DeviceOrientationHardwareBuffer)); | 87 memset(buffer(), 0, sizeof(device::DeviceOrientationHardwareBuffer)); |
87 } | 88 } |
88 | 89 |
89 void InitBuffer() { | 90 void InitBuffer() { |
90 blink::WebDeviceOrientationData& data = buffer()->data; | 91 blink::WebDeviceOrientationData& data = buffer()->data; |
91 data.alpha = 1; | 92 data.alpha = 1; |
92 data.hasAlpha = true; | 93 data.hasAlpha = true; |
93 data.beta = 2; | 94 data.beta = 2; |
94 data.hasBeta = true; | 95 data.hasBeta = true; |
95 data.gamma = 3; | 96 data.gamma = 3; |
96 data.hasGamma = true; | 97 data.hasGamma = true; |
97 data.allAvailableSensorsAreActive = true; | 98 data.allAvailableSensorsAreActive = true; |
98 } | 99 } |
99 | 100 |
100 void InitBufferNoData() { | 101 void InitBufferNoData() { |
101 blink::WebDeviceOrientationData& data = buffer()->data; | 102 blink::WebDeviceOrientationData& data = buffer()->data; |
102 data.allAvailableSensorsAreActive = true; | 103 data.allAvailableSensorsAreActive = true; |
103 } | 104 } |
104 | 105 |
105 MockDeviceOrientationListener* listener() { return listener_.get(); } | 106 MockDeviceOrientationListener* listener() { return listener_.get(); } |
106 DeviceOrientationEventPumpForTesting* orientation_pump() { | 107 DeviceOrientationEventPumpForTesting* orientation_pump() { |
107 return orientation_pump_.get(); | 108 return orientation_pump_.get(); |
108 } | 109 } |
109 mojo::ScopedSharedBufferHandle handle() { | 110 mojo::ScopedSharedBufferHandle handle() { |
110 return shared_memory_->Clone( | 111 return shared_memory_->Clone( |
111 mojo::SharedBufferHandle::AccessMode::READ_ONLY); | 112 mojo::SharedBufferHandle::AccessMode::READ_ONLY); |
112 } | 113 } |
113 DeviceOrientationHardwareBuffer* buffer() { | 114 device::DeviceOrientationHardwareBuffer* buffer() { |
114 return reinterpret_cast<DeviceOrientationHardwareBuffer*>(mapping_.get()); | 115 return reinterpret_cast<device::DeviceOrientationHardwareBuffer*>( |
| 116 mapping_.get()); |
115 } | 117 } |
116 | 118 |
117 private: | 119 private: |
118 base::MessageLoop loop_; | 120 base::MessageLoop loop_; |
119 std::unique_ptr<MockDeviceOrientationListener> listener_; | 121 std::unique_ptr<MockDeviceOrientationListener> listener_; |
120 std::unique_ptr<DeviceOrientationEventPumpForTesting> orientation_pump_; | 122 std::unique_ptr<DeviceOrientationEventPumpForTesting> orientation_pump_; |
121 mojo::ScopedSharedBufferHandle shared_memory_; | 123 mojo::ScopedSharedBufferHandle shared_memory_; |
122 mojo::ScopedSharedBufferMapping mapping_; | 124 mojo::ScopedSharedBufferMapping mapping_; |
123 | 125 |
124 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest); | 126 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 FROM_HERE, base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, | 208 FROM_HERE, base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, |
207 base::Unretained(orientation_pump()))); | 209 base::Unretained(orientation_pump()))); |
208 base::RunLoop().Run(); | 210 base::RunLoop().Run(); |
209 | 211 |
210 EXPECT_TRUE(listener()->did_change_device_orientation()); | 212 EXPECT_TRUE(listener()->did_change_device_orientation()); |
211 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, | 213 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, |
212 static_cast<double>(received_data.alpha)); | 214 static_cast<double>(received_data.alpha)); |
213 } | 215 } |
214 | 216 |
215 } // namespace content | 217 } // namespace content |
OLD | NEW |