OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
7 #include "content/browser/device_orientation/data_fetcher_shared_memory.h" | 7 #include "content/browser/device_orientation/data_fetcher_shared_memory.h" |
8 #include "content/browser/device_orientation/device_inertial_sensor_service.h" | 8 #include "content/browser/device_orientation/device_inertial_sensor_service.h" |
| 9 #include "content/common/device_light/device_light_hardware_buffer.h" |
9 #include "content/common/device_orientation/device_motion_hardware_buffer.h" | 10 #include "content/common/device_orientation/device_motion_hardware_buffer.h" |
10 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" | 11 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
14 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
15 #include "content/public/test/content_browser_test_utils.h" | 16 #include "content/public/test/content_browser_test_utils.h" |
16 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 class FakeDataFetcher : public DataFetcherSharedMemory { | 23 class FakeDataFetcher : public DataFetcherSharedMemory { |
23 public: | 24 public: |
24 FakeDataFetcher() | 25 FakeDataFetcher() |
25 : started_orientation_(false, false), | 26 : started_orientation_(false, false), |
26 stopped_orientation_(false, false), | 27 stopped_orientation_(false, false), |
27 started_motion_(false, false), | 28 started_motion_(false, false), |
28 stopped_motion_(false, false) { | 29 stopped_motion_(false, false), |
| 30 started_light_(false, false), |
| 31 stopped_light_(false, false) { |
29 } | 32 } |
30 virtual ~FakeDataFetcher() { } | 33 virtual ~FakeDataFetcher() { } |
31 | 34 |
32 virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { | 35 virtual bool Start(ConsumerType consumer_type, void* buffer) OVERRIDE { |
33 EXPECT_TRUE(buffer); | 36 EXPECT_TRUE(buffer); |
34 | 37 |
35 switch (consumer_type) { | 38 switch (consumer_type) { |
| 39 case CONSUMER_TYPE_LIGHT: |
| 40 UpdateLight(static_cast<DeviceLightHardwareBuffer*>(buffer)); |
| 41 started_light_.Signal(); |
| 42 break; |
36 case CONSUMER_TYPE_MOTION: | 43 case CONSUMER_TYPE_MOTION: |
37 UpdateMotion(static_cast<DeviceMotionHardwareBuffer*>(buffer)); | 44 UpdateMotion(static_cast<DeviceMotionHardwareBuffer*>(buffer)); |
38 started_motion_.Signal(); | 45 started_motion_.Signal(); |
39 break; | 46 break; |
40 case CONSUMER_TYPE_ORIENTATION: | 47 case CONSUMER_TYPE_ORIENTATION: |
41 UpdateOrientation( | 48 UpdateOrientation( |
42 static_cast<DeviceOrientationHardwareBuffer*>(buffer)); | 49 static_cast<DeviceOrientationHardwareBuffer*>(buffer)); |
43 started_orientation_.Signal(); | 50 started_orientation_.Signal(); |
44 break; | 51 break; |
45 default: | 52 default: |
46 return false; | 53 return false; |
47 } | 54 } |
48 return true; | 55 return true; |
49 } | 56 } |
50 | 57 |
51 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { | 58 virtual bool Stop(ConsumerType consumer_type) OVERRIDE { |
52 switch (consumer_type) { | 59 switch (consumer_type) { |
| 60 case CONSUMER_TYPE_LIGHT: |
| 61 stopped_light_.Signal(); |
| 62 break; |
53 case CONSUMER_TYPE_MOTION: | 63 case CONSUMER_TYPE_MOTION: |
54 stopped_motion_.Signal(); | 64 stopped_motion_.Signal(); |
55 break; | 65 break; |
56 case CONSUMER_TYPE_ORIENTATION: | 66 case CONSUMER_TYPE_ORIENTATION: |
57 stopped_orientation_.Signal(); | 67 stopped_orientation_.Signal(); |
58 break; | 68 break; |
59 default: | 69 default: |
60 return false; | 70 return false; |
61 } | 71 } |
62 return true; | 72 return true; |
63 } | 73 } |
64 | 74 |
65 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { | 75 virtual void Fetch(unsigned consumer_bitmask) OVERRIDE { |
66 FAIL() << "fetch should not be called"; | 76 FAIL() << "fetch should not be called"; |
67 } | 77 } |
68 | 78 |
69 virtual FetcherType GetType() const OVERRIDE { | 79 virtual FetcherType GetType() const OVERRIDE { |
70 return FETCHER_TYPE_DEFAULT; | 80 return FETCHER_TYPE_DEFAULT; |
71 } | 81 } |
72 | 82 |
| 83 void UpdateLight(DeviceLightHardwareBuffer* buffer) { |
| 84 buffer->seqlock.WriteBegin(); |
| 85 buffer->data = 100; |
| 86 buffer->seqlock.WriteEnd(); |
| 87 } |
| 88 |
73 void UpdateMotion(DeviceMotionHardwareBuffer* buffer) { | 89 void UpdateMotion(DeviceMotionHardwareBuffer* buffer) { |
74 buffer->seqlock.WriteBegin(); | 90 buffer->seqlock.WriteBegin(); |
75 buffer->data.accelerationX = 1; | 91 buffer->data.accelerationX = 1; |
76 buffer->data.hasAccelerationX = true; | 92 buffer->data.hasAccelerationX = true; |
77 buffer->data.accelerationY = 2; | 93 buffer->data.accelerationY = 2; |
78 buffer->data.hasAccelerationY = true; | 94 buffer->data.hasAccelerationY = true; |
79 buffer->data.accelerationZ = 3; | 95 buffer->data.accelerationZ = 3; |
80 buffer->data.hasAccelerationZ = true; | 96 buffer->data.hasAccelerationZ = true; |
81 | 97 |
82 buffer->data.accelerationIncludingGravityX = 4; | 98 buffer->data.accelerationIncludingGravityX = 4; |
(...skipping 24 matching lines...) Expand all Loading... |
107 buffer->data.gamma = 3; | 123 buffer->data.gamma = 3; |
108 buffer->data.hasGamma = true; | 124 buffer->data.hasGamma = true; |
109 buffer->data.allAvailableSensorsAreActive = true; | 125 buffer->data.allAvailableSensorsAreActive = true; |
110 buffer->seqlock.WriteEnd(); | 126 buffer->seqlock.WriteEnd(); |
111 } | 127 } |
112 | 128 |
113 base::WaitableEvent started_orientation_; | 129 base::WaitableEvent started_orientation_; |
114 base::WaitableEvent stopped_orientation_; | 130 base::WaitableEvent stopped_orientation_; |
115 base::WaitableEvent started_motion_; | 131 base::WaitableEvent started_motion_; |
116 base::WaitableEvent stopped_motion_; | 132 base::WaitableEvent stopped_motion_; |
| 133 base::WaitableEvent started_light_; |
| 134 base::WaitableEvent stopped_light_; |
117 | 135 |
118 private: | 136 private: |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); | 137 DISALLOW_COPY_AND_ASSIGN(FakeDataFetcher); |
121 }; | 138 }; |
122 | 139 |
123 | 140 |
124 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { | 141 class DeviceInertialSensorBrowserTest : public ContentBrowserTest { |
125 public: | 142 public: |
126 DeviceInertialSensorBrowserTest() | 143 DeviceInertialSensorBrowserTest() |
127 : fetcher_(NULL), | 144 : fetcher_(NULL), |
128 io_loop_finished_event_(false, false) { | 145 io_loop_finished_event_(false, false) { |
129 } | 146 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // handler and navigates to #pass. | 185 // handler and navigates to #pass. |
169 GURL test_url = GetTestUrl( | 186 GURL test_url = GetTestUrl( |
170 "device_orientation", "device_motion_test.html"); | 187 "device_orientation", "device_motion_test.html"); |
171 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); | 188 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 2); |
172 | 189 |
173 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); | 190 EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref()); |
174 fetcher_->started_motion_.Wait(); | 191 fetcher_->started_motion_.Wait(); |
175 fetcher_->stopped_motion_.Wait(); | 192 fetcher_->stopped_motion_.Wait(); |
176 } | 193 } |
177 | 194 |
178 } // namespace | 195 } // namespace |
179 | 196 |
180 } // namespace content | 197 } // namespace content |
OLD | NEW |