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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | 9 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
10 #include "content/public/test/test_utils.h" | 10 #include "content/public/test/test_utils.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 class DeviceOrientationEventPumpTest : public testing::Test { | 67 class DeviceOrientationEventPumpTest : public testing::Test { |
68 public: | 68 public: |
69 DeviceOrientationEventPumpTest() { | 69 DeviceOrientationEventPumpTest() { |
70 EXPECT_TRUE(shared_memory_.CreateAndMapAnonymous( | 70 EXPECT_TRUE(shared_memory_.CreateAndMapAnonymous( |
71 sizeof(DeviceOrientationHardwareBuffer))); | 71 sizeof(DeviceOrientationHardwareBuffer))); |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 virtual void SetUp() OVERRIDE { | 75 virtual void SetUp() OVERRIDE { |
| 76 const DeviceOrientationHardwareBuffer* null_buffer = NULL; |
76 listener_.reset(new MockDeviceOrientationListener); | 77 listener_.reset(new MockDeviceOrientationListener); |
77 orientation_pump_.reset(new DeviceOrientationEventPumpForTesting); | 78 orientation_pump_.reset(new DeviceOrientationEventPumpForTesting); |
78 buffer_ = static_cast<DeviceOrientationHardwareBuffer*>( | 79 buffer_ = static_cast<DeviceOrientationHardwareBuffer*>( |
79 shared_memory_.memory()); | 80 shared_memory_.memory()); |
| 81 ASSERT_NE(null_buffer, buffer_); |
80 memset(buffer_, 0, sizeof(DeviceOrientationHardwareBuffer)); | 82 memset(buffer_, 0, sizeof(DeviceOrientationHardwareBuffer)); |
81 shared_memory_.ShareToProcess(base::kNullProcessHandle, &handle_); | 83 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), |
| 84 &handle_)); |
82 } | 85 } |
83 | 86 |
84 void InitBuffer() { | 87 void InitBuffer() { |
85 blink::WebDeviceOrientationData& data = buffer_->data; | 88 blink::WebDeviceOrientationData& data = buffer_->data; |
86 data.alpha = 1; | 89 data.alpha = 1; |
87 data.hasAlpha = true; | 90 data.hasAlpha = true; |
88 data.beta = 2; | 91 data.beta = 2; |
89 data.hasBeta = true; | 92 data.hasBeta = true; |
90 data.gamma = 3; | 93 data.gamma = 3; |
91 data.hasGamma = true; | 94 data.hasGamma = true; |
(...skipping 15 matching lines...) Expand all Loading... |
107 private: | 110 private: |
108 scoped_ptr<MockDeviceOrientationListener> listener_; | 111 scoped_ptr<MockDeviceOrientationListener> listener_; |
109 scoped_ptr<DeviceOrientationEventPumpForTesting> orientation_pump_; | 112 scoped_ptr<DeviceOrientationEventPumpForTesting> orientation_pump_; |
110 base::SharedMemoryHandle handle_; | 113 base::SharedMemoryHandle handle_; |
111 base::SharedMemory shared_memory_; | 114 base::SharedMemory shared_memory_; |
112 DeviceOrientationHardwareBuffer* buffer_; | 115 DeviceOrientationHardwareBuffer* buffer_; |
113 | 116 |
114 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest); | 117 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpTest); |
115 }; | 118 }; |
116 | 119 |
117 // Always failing in the win try bot. See http://crbug.com/256782. | 120 TEST_F(DeviceOrientationEventPumpTest, DidStartPolling) { |
118 #if defined(OS_WIN) | |
119 #define MAYBE_DidStartPolling DISABLED_DidStartPolling | |
120 #else | |
121 #define MAYBE_DidStartPolling DidStartPolling | |
122 #endif | |
123 TEST_F(DeviceOrientationEventPumpTest, MAYBE_DidStartPolling) { | |
124 base::MessageLoop loop; | 121 base::MessageLoop loop; |
125 | 122 |
126 InitBuffer(); | 123 InitBuffer(); |
127 orientation_pump()->SetListener(listener()); | 124 orientation_pump()->SetListener(listener()); |
128 orientation_pump()->OnDidStart(handle()); | 125 orientation_pump()->OnDidStart(handle()); |
129 | 126 |
130 base::MessageLoop::current()->Run(); | 127 base::MessageLoop::current()->Run(); |
131 | 128 |
132 const blink::WebDeviceOrientationData& received_data = listener()->data(); | 129 const blink::WebDeviceOrientationData& received_data = listener()->data(); |
133 EXPECT_TRUE(listener()->did_change_device_orientation()); | 130 EXPECT_TRUE(listener()->did_change_device_orientation()); |
134 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); | 131 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); |
135 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); | 132 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); |
136 EXPECT_TRUE(received_data.hasAlpha); | 133 EXPECT_TRUE(received_data.hasAlpha); |
137 EXPECT_EQ(2, static_cast<double>(received_data.beta)); | 134 EXPECT_EQ(2, static_cast<double>(received_data.beta)); |
138 EXPECT_TRUE(received_data.hasBeta); | 135 EXPECT_TRUE(received_data.hasBeta); |
139 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); | 136 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); |
140 EXPECT_TRUE(received_data.hasGamma); | 137 EXPECT_TRUE(received_data.hasGamma); |
141 } | 138 } |
142 | 139 |
143 // Always failing in the win try bot. See http://crbug.com/256782. | 140 TEST_F(DeviceOrientationEventPumpTest, FireAllNullEvent) { |
144 #if defined(OS_WIN) | |
145 #define MAYBE_FireAllNullEvent DISABLED_FireAllNullEvent | |
146 #else | |
147 #define MAYBE_FireAllNullEvent FireAllNullEvent | |
148 #endif | |
149 TEST_F(DeviceOrientationEventPumpTest, MAYBE_FireAllNullEvent) { | |
150 base::MessageLoop loop; | 141 base::MessageLoop loop; |
151 | 142 |
152 InitBufferNoData(); | 143 InitBufferNoData(); |
153 orientation_pump()->SetListener(listener()); | 144 orientation_pump()->SetListener(listener()); |
154 orientation_pump()->OnDidStart(handle()); | 145 orientation_pump()->OnDidStart(handle()); |
155 | 146 |
156 base::MessageLoop::current()->Run(); | 147 base::MessageLoop::current()->Run(); |
157 | 148 |
158 const blink::WebDeviceOrientationData& received_data = listener()->data(); | 149 const blink::WebDeviceOrientationData& received_data = listener()->data(); |
159 EXPECT_TRUE(listener()->did_change_device_orientation()); | 150 EXPECT_TRUE(listener()->did_change_device_orientation()); |
160 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); | 151 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); |
161 EXPECT_FALSE(received_data.hasAlpha); | 152 EXPECT_FALSE(received_data.hasAlpha); |
162 EXPECT_FALSE(received_data.hasBeta); | 153 EXPECT_FALSE(received_data.hasBeta); |
163 EXPECT_FALSE(received_data.hasGamma); | 154 EXPECT_FALSE(received_data.hasGamma); |
164 } | 155 } |
165 | 156 |
166 // Always failing in the win try bot. See http://crbug.com/256782. | 157 TEST_F(DeviceOrientationEventPumpTest, UpdateRespectsOrientationThreshold) { |
167 #if defined(OS_WIN) | |
168 #define MAYBE_UpdateRespectsOrientationThreshold \ | |
169 DISABLED_UpdateRespectsOrientationThreshold | |
170 #else | |
171 #define MAYBE_UpdateRespectsOrientationThreshold \ | |
172 UpdateRespectsOrientationThreshold | |
173 #endif | |
174 TEST_F(DeviceOrientationEventPumpTest, | |
175 MAYBE_UpdateRespectsOrientationThreshold) { | |
176 base::MessageLoop loop; | 158 base::MessageLoop loop; |
177 | 159 |
178 InitBuffer(); | 160 InitBuffer(); |
179 orientation_pump()->SetListener(listener()); | 161 orientation_pump()->SetListener(listener()); |
180 orientation_pump()->OnDidStart(handle()); | 162 orientation_pump()->OnDidStart(handle()); |
181 | 163 |
182 base::MessageLoop::current()->Run(); | 164 base::MessageLoop::current()->Run(); |
183 | 165 |
184 const blink::WebDeviceOrientationData& received_data = listener()->data(); | 166 const blink::WebDeviceOrientationData& received_data = listener()->data(); |
185 EXPECT_TRUE(listener()->did_change_device_orientation()); | 167 EXPECT_TRUE(listener()->did_change_device_orientation()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, | 199 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, |
218 base::Unretained(orientation_pump()))); | 200 base::Unretained(orientation_pump()))); |
219 base::MessageLoop::current()->Run(); | 201 base::MessageLoop::current()->Run(); |
220 | 202 |
221 EXPECT_TRUE(listener()->did_change_device_orientation()); | 203 EXPECT_TRUE(listener()->did_change_device_orientation()); |
222 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, | 204 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, |
223 static_cast<double>(received_data.alpha)); | 205 static_cast<double>(received_data.alpha)); |
224 } | 206 } |
225 | 207 |
226 } // namespace content | 208 } // namespace content |
OLD | NEW |