| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 bool did_change_device_orientation_; | 41 bool did_change_device_orientation_; |
| 42 blink::WebDeviceOrientationData data_; | 42 blink::WebDeviceOrientationData data_; |
| 43 | 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(MockDeviceOrientationListener); | 44 DISALLOW_COPY_AND_ASSIGN(MockDeviceOrientationListener); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump { | 47 class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump { |
| 48 public: | 48 public: |
| 49 DeviceOrientationEventPumpForTesting() { } | 49 DeviceOrientationEventPumpForTesting() |
| 50 : DeviceOrientationEventPump(0) { } |
| 50 virtual ~DeviceOrientationEventPumpForTesting() { } | 51 virtual ~DeviceOrientationEventPumpForTesting() { } |
| 51 | 52 |
| 52 void OnDidStart(base::SharedMemoryHandle renderer_handle) { | 53 void OnDidStart(base::SharedMemoryHandle renderer_handle) { |
| 53 DeviceOrientationEventPump::OnDidStart(renderer_handle); | 54 DeviceOrientationEventPump::OnDidStart(renderer_handle); |
| 54 } | 55 } |
| 55 virtual bool SendStartMessage() OVERRIDE { return true; } | 56 virtual void SendStartMessage() OVERRIDE { } |
| 56 virtual bool SendStopMessage() OVERRIDE { return true; } | 57 virtual void SendStopMessage() OVERRIDE { } |
| 57 virtual void FireEvent() OVERRIDE { | 58 virtual void FireEvent() OVERRIDE { |
| 58 DeviceOrientationEventPump::FireEvent(); | 59 DeviceOrientationEventPump::FireEvent(); |
| 59 Stop(); | 60 Stop(); |
| 60 base::MessageLoop::current()->QuitWhenIdle(); | 61 base::MessageLoop::current()->QuitWhenIdle(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpForTesting); | 65 DISALLOW_COPY_AND_ASSIGN(DeviceOrientationEventPumpForTesting); |
| 65 }; | 66 }; |
| 66 | 67 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // Always failing in the win try bot. See http://crbug.com/256782. | 118 // Always failing in the win try bot. See http://crbug.com/256782. |
| 118 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 119 #define MAYBE_DidStartPolling DISABLED_DidStartPolling | 120 #define MAYBE_DidStartPolling DISABLED_DidStartPolling |
| 120 #else | 121 #else |
| 121 #define MAYBE_DidStartPolling DidStartPolling | 122 #define MAYBE_DidStartPolling DidStartPolling |
| 122 #endif | 123 #endif |
| 123 TEST_F(DeviceOrientationEventPumpTest, MAYBE_DidStartPolling) { | 124 TEST_F(DeviceOrientationEventPumpTest, MAYBE_DidStartPolling) { |
| 124 base::MessageLoop loop; | 125 base::MessageLoop loop; |
| 125 | 126 |
| 126 InitBuffer(); | 127 InitBuffer(); |
| 127 orientation_pump()->SetListener(listener()); | 128 orientation_pump()->Start(listener()); |
| 128 orientation_pump()->OnDidStart(handle()); | 129 orientation_pump()->OnDidStart(handle()); |
| 129 | 130 |
| 130 base::MessageLoop::current()->Run(); | 131 base::MessageLoop::current()->Run(); |
| 131 | 132 |
| 132 const blink::WebDeviceOrientationData& received_data = listener()->data(); | 133 const blink::WebDeviceOrientationData& received_data = listener()->data(); |
| 133 EXPECT_TRUE(listener()->did_change_device_orientation()); | 134 EXPECT_TRUE(listener()->did_change_device_orientation()); |
| 134 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); | 135 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); |
| 135 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); | 136 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); |
| 136 EXPECT_TRUE(received_data.hasAlpha); | 137 EXPECT_TRUE(received_data.hasAlpha); |
| 137 EXPECT_EQ(2, static_cast<double>(received_data.beta)); | 138 EXPECT_EQ(2, static_cast<double>(received_data.beta)); |
| 138 EXPECT_TRUE(received_data.hasBeta); | 139 EXPECT_TRUE(received_data.hasBeta); |
| 139 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); | 140 EXPECT_EQ(3, static_cast<double>(received_data.gamma)); |
| 140 EXPECT_TRUE(received_data.hasGamma); | 141 EXPECT_TRUE(received_data.hasGamma); |
| 141 } | 142 } |
| 142 | 143 |
| 143 // Always failing in the win try bot. See http://crbug.com/256782. | 144 // Always failing in the win try bot. See http://crbug.com/256782. |
| 144 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
| 145 #define MAYBE_FireAllNullEvent DISABLED_FireAllNullEvent | 146 #define MAYBE_FireAllNullEvent DISABLED_FireAllNullEvent |
| 146 #else | 147 #else |
| 147 #define MAYBE_FireAllNullEvent FireAllNullEvent | 148 #define MAYBE_FireAllNullEvent FireAllNullEvent |
| 148 #endif | 149 #endif |
| 149 TEST_F(DeviceOrientationEventPumpTest, MAYBE_FireAllNullEvent) { | 150 TEST_F(DeviceOrientationEventPumpTest, MAYBE_FireAllNullEvent) { |
| 150 base::MessageLoop loop; | 151 base::MessageLoop loop; |
| 151 | 152 |
| 152 InitBufferNoData(); | 153 InitBufferNoData(); |
| 153 orientation_pump()->SetListener(listener()); | 154 orientation_pump()->Start(listener()); |
| 154 orientation_pump()->OnDidStart(handle()); | 155 orientation_pump()->OnDidStart(handle()); |
| 155 | 156 |
| 156 base::MessageLoop::current()->Run(); | 157 base::MessageLoop::current()->Run(); |
| 157 | 158 |
| 158 const blink::WebDeviceOrientationData& received_data = listener()->data(); | 159 const blink::WebDeviceOrientationData& received_data = listener()->data(); |
| 159 EXPECT_TRUE(listener()->did_change_device_orientation()); | 160 EXPECT_TRUE(listener()->did_change_device_orientation()); |
| 160 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); | 161 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); |
| 161 EXPECT_FALSE(received_data.hasAlpha); | 162 EXPECT_FALSE(received_data.hasAlpha); |
| 162 EXPECT_FALSE(received_data.hasBeta); | 163 EXPECT_FALSE(received_data.hasBeta); |
| 163 EXPECT_FALSE(received_data.hasGamma); | 164 EXPECT_FALSE(received_data.hasGamma); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Always failing in the win try bot. See http://crbug.com/256782. | 167 // Always failing in the win try bot. See http://crbug.com/256782. |
| 167 #if defined(OS_WIN) | 168 #if defined(OS_WIN) |
| 168 #define MAYBE_UpdateRespectsOrientationThreshold \ | 169 #define MAYBE_UpdateRespectsOrientationThreshold \ |
| 169 DISABLED_UpdateRespectsOrientationThreshold | 170 DISABLED_UpdateRespectsOrientationThreshold |
| 170 #else | 171 #else |
| 171 #define MAYBE_UpdateRespectsOrientationThreshold \ | 172 #define MAYBE_UpdateRespectsOrientationThreshold \ |
| 172 UpdateRespectsOrientationThreshold | 173 UpdateRespectsOrientationThreshold |
| 173 #endif | 174 #endif |
| 174 TEST_F(DeviceOrientationEventPumpTest, | 175 TEST_F(DeviceOrientationEventPumpTest, |
| 175 MAYBE_UpdateRespectsOrientationThreshold) { | 176 MAYBE_UpdateRespectsOrientationThreshold) { |
| 176 base::MessageLoop loop; | 177 base::MessageLoop loop; |
| 177 | 178 |
| 178 InitBuffer(); | 179 InitBuffer(); |
| 179 orientation_pump()->SetListener(listener()); | 180 orientation_pump()->Start(listener()); |
| 180 orientation_pump()->OnDidStart(handle()); | 181 orientation_pump()->OnDidStart(handle()); |
| 181 | 182 |
| 182 base::MessageLoop::current()->Run(); | 183 base::MessageLoop::current()->Run(); |
| 183 | 184 |
| 184 const blink::WebDeviceOrientationData& received_data = listener()->data(); | 185 const blink::WebDeviceOrientationData& received_data = listener()->data(); |
| 185 EXPECT_TRUE(listener()->did_change_device_orientation()); | 186 EXPECT_TRUE(listener()->did_change_device_orientation()); |
| 186 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); | 187 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); |
| 187 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); | 188 EXPECT_EQ(1, static_cast<double>(received_data.alpha)); |
| 188 EXPECT_TRUE(received_data.hasAlpha); | 189 EXPECT_TRUE(received_data.hasAlpha); |
| 189 EXPECT_EQ(2, static_cast<double>(received_data.beta)); | 190 EXPECT_EQ(2, static_cast<double>(received_data.beta)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 217 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, | 218 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, |
| 218 base::Unretained(orientation_pump()))); | 219 base::Unretained(orientation_pump()))); |
| 219 base::MessageLoop::current()->Run(); | 220 base::MessageLoop::current()->Run(); |
| 220 | 221 |
| 221 EXPECT_TRUE(listener()->did_change_device_orientation()); | 222 EXPECT_TRUE(listener()->did_change_device_orientation()); |
| 222 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, | 223 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, |
| 223 static_cast<double>(received_data.alpha)); | 224 static_cast<double>(received_data.alpha)); |
| 224 } | 225 } |
| 225 | 226 |
| 226 } // namespace content | 227 } // namespace content |
| OLD | NEW |