Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: content/renderer/device_sensors/device_light_event_pump_unittest.cc

Issue 470683002: Revert "Refactor code listening to platform events in content/renderer/." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_light_event_pump.h" 5 #include "device_light_event_pump.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "content/common/device_sensors/device_light_hardware_buffer.h" 8 #include "content/common/device_sensors/device_light_hardware_buffer.h"
9 #include "content/public/test/test_utils.h" 9 #include "content/public/test/test_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 21 matching lines...) Expand all
32 32
33 private: 33 private:
34 bool did_change_device_light_; 34 bool did_change_device_light_;
35 DeviceLightData data_; 35 DeviceLightData data_;
36 36
37 DISALLOW_COPY_AND_ASSIGN(MockDeviceLightListener); 37 DISALLOW_COPY_AND_ASSIGN(MockDeviceLightListener);
38 }; 38 };
39 39
40 class DeviceLightEventPumpForTesting : public DeviceLightEventPump { 40 class DeviceLightEventPumpForTesting : public DeviceLightEventPump {
41 public: 41 public:
42 DeviceLightEventPumpForTesting() 42 DeviceLightEventPumpForTesting() {}
43 : DeviceLightEventPump(0) {}
44 virtual ~DeviceLightEventPumpForTesting() {} 43 virtual ~DeviceLightEventPumpForTesting() {}
45 44
46 void OnDidStart(base::SharedMemoryHandle renderer_handle) { 45 void OnDidStart(base::SharedMemoryHandle renderer_handle) {
47 DeviceLightEventPump::OnDidStart(renderer_handle); 46 DeviceLightEventPump::OnDidStart(renderer_handle);
48 } 47 }
49 virtual void SendStartMessage() OVERRIDE { } 48 virtual bool SendStartMessage() OVERRIDE { return true; }
50 virtual void SendStopMessage() OVERRIDE { } 49 virtual bool SendStopMessage() OVERRIDE { return true; }
51 virtual void FireEvent() OVERRIDE { 50 virtual void FireEvent() OVERRIDE {
52 DeviceLightEventPump::FireEvent(); 51 DeviceLightEventPump::FireEvent();
53 Stop(); 52 Stop();
54 base::MessageLoop::current()->QuitWhenIdle(); 53 base::MessageLoop::current()->QuitWhenIdle();
55 } 54 }
56 55
57 private: 56 private:
58 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPumpForTesting); 57 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPumpForTesting);
59 }; 58 };
60 59
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 DeviceLightHardwareBuffer* buffer_; 93 DeviceLightHardwareBuffer* buffer_;
95 94
96 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPumpTest); 95 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPumpTest);
97 }; 96 };
98 97
99 TEST_F(DeviceLightEventPumpTest, DidStartPolling) { 98 TEST_F(DeviceLightEventPumpTest, DidStartPolling) {
100 base::MessageLoopForUI loop; 99 base::MessageLoopForUI loop;
101 100
102 InitBuffer(); 101 InitBuffer();
103 102
104 light_pump()->Start(listener()); 103 light_pump()->SetListener(listener());
105 light_pump()->OnDidStart(handle()); 104 light_pump()->OnDidStart(handle());
106 105
107 base::MessageLoop::current()->Run(); 106 base::MessageLoop::current()->Run();
108 107
109 const DeviceLightData& received_data = listener()->data(); 108 const DeviceLightData& received_data = listener()->data();
110 EXPECT_TRUE(listener()->did_change_device_light()); 109 EXPECT_TRUE(listener()->did_change_device_light());
111 EXPECT_EQ(1, static_cast<double>(received_data.value)); 110 EXPECT_EQ(1, static_cast<double>(received_data.value));
112 } 111 }
113 112
114 TEST_F(DeviceLightEventPumpTest, DidStartPollingValuesEqual) { 113 TEST_F(DeviceLightEventPumpTest, DidStartPollingValuesEqual) {
115 base::MessageLoopForUI loop; 114 base::MessageLoopForUI loop;
116 115
117 InitBuffer(); 116 InitBuffer();
118 117
119 light_pump()->Start(listener()); 118 light_pump()->SetListener(listener());
120 light_pump()->OnDidStart(handle()); 119 light_pump()->OnDidStart(handle());
121 120
122 base::MessageLoop::current()->Run(); 121 base::MessageLoop::current()->Run();
123 122
124 const DeviceLightData& received_data = listener()->data(); 123 const DeviceLightData& received_data = listener()->data();
125 EXPECT_TRUE(listener()->did_change_device_light()); 124 EXPECT_TRUE(listener()->did_change_device_light());
126 EXPECT_EQ(1, static_cast<double>(received_data.value)); 125 EXPECT_EQ(1, static_cast<double>(received_data.value));
127 126
128 double last_seen_data = received_data.value; 127 double last_seen_data = received_data.value;
129 // Set next value to be same as previous value. 128 // Set next value to be same as previous value.
130 buffer()->data.value = 1.0; 129 buffer()->data.value = 1.0;
131 listener()->set_did_change_device_light(false); 130 listener()->set_did_change_device_light(false);
132
133 // Reset the pump's listener.
134 light_pump()->Start(listener());
135
136 base::MessageLoop::current()->PostTask( 131 base::MessageLoop::current()->PostTask(
137 FROM_HERE, 132 FROM_HERE,
138 base::Bind(&DeviceLightEventPumpForTesting::FireEvent, 133 base::Bind(&DeviceLightEventPumpForTesting::FireEvent,
139 base::Unretained(light_pump()))); 134 base::Unretained(light_pump())));
140 base::MessageLoop::current()->Run(); 135 base::MessageLoop::current()->Run();
141 136
142 // No change in device light as present value is same as previous value. 137 // No change in device light as present value is same as previous value.
143 EXPECT_FALSE(listener()->did_change_device_light()); 138 EXPECT_FALSE(listener()->did_change_device_light());
144 EXPECT_EQ(last_seen_data, static_cast<double>(received_data.value)); 139 EXPECT_EQ(last_seen_data, static_cast<double>(received_data.value));
145 } 140 }
146 141
147 } // namespace content 142 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/device_sensors/device_light_event_pump.cc ('k') | content/renderer/device_sensors/device_motion_event_pump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698