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

Side by Side Diff: content/renderer/device_orientation/device_orientation_event_pump_unittest.cc

Issue 63253002: Rename WebKit namespace to blink (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 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 "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_orientation/device_orientation_hardware_buffer.h " 9 #include "content/common/device_orientation/device_orientation_hardware_buffer.h "
10 #include "content/public/test/test_utils.h" 10 #include "content/public/test/test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h" 12 #include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 class MockDeviceOrientationListener 16 class MockDeviceOrientationListener
17 : public WebKit::WebDeviceOrientationListener { 17 : public blink::WebDeviceOrientationListener {
18 public: 18 public:
19 MockDeviceOrientationListener(); 19 MockDeviceOrientationListener();
20 virtual ~MockDeviceOrientationListener() { } 20 virtual ~MockDeviceOrientationListener() { }
21 virtual void didChangeDeviceOrientation( 21 virtual void didChangeDeviceOrientation(
22 const WebKit::WebDeviceOrientationData&) OVERRIDE; 22 const blink::WebDeviceOrientationData&) OVERRIDE;
23 void ResetDidChangeOrientation(); 23 void ResetDidChangeOrientation();
24 bool did_change_device_orientation_; 24 bool did_change_device_orientation_;
25 WebKit::WebDeviceOrientationData data_; 25 blink::WebDeviceOrientationData data_;
26 }; 26 };
27 27
28 MockDeviceOrientationListener::MockDeviceOrientationListener() 28 MockDeviceOrientationListener::MockDeviceOrientationListener()
29 : did_change_device_orientation_(false) { 29 : did_change_device_orientation_(false) {
30 memset(&data_, 0, sizeof(data_)); 30 memset(&data_, 0, sizeof(data_));
31 } 31 }
32 32
33 void MockDeviceOrientationListener::didChangeDeviceOrientation( 33 void MockDeviceOrientationListener::didChangeDeviceOrientation(
34 const WebKit::WebDeviceOrientationData& data) { 34 const blink::WebDeviceOrientationData& data) {
35 memcpy(&data_, &data, sizeof(data)); 35 memcpy(&data_, &data, sizeof(data));
36 did_change_device_orientation_ = true; 36 did_change_device_orientation_ = true;
37 } 37 }
38 38
39 void MockDeviceOrientationListener::ResetDidChangeOrientation() { 39 void MockDeviceOrientationListener::ResetDidChangeOrientation() {
40 did_change_device_orientation_ = false; 40 did_change_device_orientation_ = false;
41 } 41 }
42 42
43 class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump { 43 class DeviceOrientationEventPumpForTesting : public DeviceOrientationEventPump {
44 public: 44 public:
(...skipping 23 matching lines...) Expand all
68 virtual void SetUp() OVERRIDE { 68 virtual void SetUp() OVERRIDE {
69 listener_.reset(new MockDeviceOrientationListener); 69 listener_.reset(new MockDeviceOrientationListener);
70 orientation_pump_.reset(new DeviceOrientationEventPumpForTesting); 70 orientation_pump_.reset(new DeviceOrientationEventPumpForTesting);
71 buffer_ = static_cast<DeviceOrientationHardwareBuffer*>( 71 buffer_ = static_cast<DeviceOrientationHardwareBuffer*>(
72 shared_memory_.memory()); 72 shared_memory_.memory());
73 memset(buffer_, 0, sizeof(DeviceOrientationHardwareBuffer)); 73 memset(buffer_, 0, sizeof(DeviceOrientationHardwareBuffer));
74 shared_memory_.ShareToProcess(base::kNullProcessHandle, &handle_); 74 shared_memory_.ShareToProcess(base::kNullProcessHandle, &handle_);
75 } 75 }
76 76
77 void InitBuffer() { 77 void InitBuffer() {
78 WebKit::WebDeviceOrientationData& data = buffer_->data; 78 blink::WebDeviceOrientationData& data = buffer_->data;
79 data.alpha = 1; 79 data.alpha = 1;
80 data.hasAlpha = true; 80 data.hasAlpha = true;
81 data.beta = 2; 81 data.beta = 2;
82 data.hasBeta = true; 82 data.hasBeta = true;
83 data.gamma = 3; 83 data.gamma = 3;
84 data.hasGamma = true; 84 data.hasGamma = true;
85 data.allAvailableSensorsAreActive = true; 85 data.allAvailableSensorsAreActive = true;
86 } 86 }
87 87
88 scoped_ptr<MockDeviceOrientationListener> listener_; 88 scoped_ptr<MockDeviceOrientationListener> listener_;
(...skipping 11 matching lines...) Expand all
100 #endif 100 #endif
101 TEST_F(DeviceOrientationEventPumpTest, MAYBE_DidStartPolling) { 101 TEST_F(DeviceOrientationEventPumpTest, MAYBE_DidStartPolling) {
102 base::MessageLoop loop; 102 base::MessageLoop loop;
103 103
104 InitBuffer(); 104 InitBuffer();
105 orientation_pump_->SetListener(listener_.get()); 105 orientation_pump_->SetListener(listener_.get());
106 orientation_pump_->OnDidStart(handle_); 106 orientation_pump_->OnDidStart(handle_);
107 107
108 base::MessageLoop::current()->Run(); 108 base::MessageLoop::current()->Run();
109 109
110 WebKit::WebDeviceOrientationData& received_data = listener_->data_; 110 blink::WebDeviceOrientationData& received_data = listener_->data_;
111 EXPECT_TRUE(listener_->did_change_device_orientation_); 111 EXPECT_TRUE(listener_->did_change_device_orientation_);
112 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); 112 EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
113 EXPECT_EQ(1, (double)received_data.alpha); 113 EXPECT_EQ(1, (double)received_data.alpha);
114 EXPECT_TRUE(received_data.hasAlpha); 114 EXPECT_TRUE(received_data.hasAlpha);
115 EXPECT_EQ(2, (double)received_data.beta); 115 EXPECT_EQ(2, (double)received_data.beta);
116 EXPECT_TRUE(received_data.hasBeta); 116 EXPECT_TRUE(received_data.hasBeta);
117 EXPECT_EQ(3, (double)received_data.gamma); 117 EXPECT_EQ(3, (double)received_data.gamma);
118 EXPECT_TRUE(received_data.hasGamma); 118 EXPECT_TRUE(received_data.hasGamma);
119 } 119 }
120 120
121 // Always failing in the win try bot. See http://crbug.com/256782. 121 // Always failing in the win try bot. See http://crbug.com/256782.
122 #if defined(OS_WIN) 122 #if defined(OS_WIN)
123 #define MAYBE_UpdateRespectsOrientationThreshold \ 123 #define MAYBE_UpdateRespectsOrientationThreshold \
124 DISABLED_UpdateRespectsOrientationThreshold 124 DISABLED_UpdateRespectsOrientationThreshold
125 #else 125 #else
126 #define MAYBE_UpdateRespectsOrientationThreshold \ 126 #define MAYBE_UpdateRespectsOrientationThreshold \
127 UpdateRespectsOrientationThreshold 127 UpdateRespectsOrientationThreshold
128 #endif 128 #endif
129 TEST_F(DeviceOrientationEventPumpTest, 129 TEST_F(DeviceOrientationEventPumpTest,
130 MAYBE_UpdateRespectsOrientationThreshold) { 130 MAYBE_UpdateRespectsOrientationThreshold) {
131 base::MessageLoop loop; 131 base::MessageLoop loop;
132 132
133 InitBuffer(); 133 InitBuffer();
134 orientation_pump_->SetListener(listener_.get()); 134 orientation_pump_->SetListener(listener_.get());
135 orientation_pump_->OnDidStart(handle_); 135 orientation_pump_->OnDidStart(handle_);
136 136
137 base::MessageLoop::current()->Run(); 137 base::MessageLoop::current()->Run();
138 138
139 WebKit::WebDeviceOrientationData& received_data = listener_->data_; 139 blink::WebDeviceOrientationData& received_data = listener_->data_;
140 EXPECT_TRUE(listener_->did_change_device_orientation_); 140 EXPECT_TRUE(listener_->did_change_device_orientation_);
141 EXPECT_TRUE(received_data.allAvailableSensorsAreActive); 141 EXPECT_TRUE(received_data.allAvailableSensorsAreActive);
142 EXPECT_EQ(1, (double)received_data.alpha); 142 EXPECT_EQ(1, (double)received_data.alpha);
143 EXPECT_TRUE(received_data.hasAlpha); 143 EXPECT_TRUE(received_data.hasAlpha);
144 EXPECT_EQ(2, (double)received_data.beta); 144 EXPECT_EQ(2, (double)received_data.beta);
145 EXPECT_TRUE(received_data.hasBeta); 145 EXPECT_TRUE(received_data.hasBeta);
146 EXPECT_EQ(3, (double)received_data.gamma); 146 EXPECT_EQ(3, (double)received_data.gamma);
147 EXPECT_TRUE(received_data.hasGamma); 147 EXPECT_TRUE(received_data.hasGamma);
148 148
149 buffer_->data.alpha = 149 buffer_->data.alpha =
(...skipping 22 matching lines...) Expand all
172 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent, 172 base::Bind(&DeviceOrientationEventPumpForTesting::FireEvent,
173 base::Unretained(orientation_pump_.get()))); 173 base::Unretained(orientation_pump_.get())));
174 base::MessageLoop::current()->Run(); 174 base::MessageLoop::current()->Run();
175 175
176 EXPECT_TRUE(listener_->did_change_device_orientation_); 176 EXPECT_TRUE(listener_->did_change_device_orientation_);
177 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold, 177 EXPECT_EQ(1 + DeviceOrientationEventPump::kOrientationThreshold,
178 (double)received_data.alpha); 178 (double)received_data.alpha);
179 } 179 }
180 180
181 } // namespace content 181 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/device_orientation/device_orientation_event_pump.cc ('k') | content/renderer/devtools/devtools_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698