| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <queue> | 5 #include <queue> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "content/browser/device_orientation/data_fetcher.h" | 9 #include "content/browser/device_orientation/data_fetcher.h" |
| 10 #include "content/browser/device_orientation/orientation.h" | 10 #include "content/browser/device_orientation/orientation.h" |
| 11 #include "content/browser/device_orientation/provider.h" | 11 #include "content/browser/device_orientation/provider.h" |
| 12 #include "content/browser/device_orientation/provider_impl.h" | 12 #include "content/browser/device_orientation/provider_impl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace device_orientation { | 15 namespace device_orientation { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Class for checking expectations on orientation updates from the Provider. | 18 // Class for checking expectations on orientation updates from the Provider. |
| 19 class UpdateChecker : public Provider::Observer { | 19 class UpdateChecker : public Provider::OrientationObserver { |
| 20 public: | 20 public: |
| 21 explicit UpdateChecker(int* expectations_count_ptr) | 21 explicit UpdateChecker(int* expectations_count_ptr) |
| 22 : expectations_count_ptr_(expectations_count_ptr) { | 22 : expectations_count_ptr_(expectations_count_ptr) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 virtual ~UpdateChecker() {} | 25 virtual ~UpdateChecker() {} |
| 26 | 26 |
| 27 // From Provider::Observer. | 27 // From Provider::OrientationObserver. |
| 28 virtual void OnOrientationUpdate(const Orientation& orientation) { | 28 virtual void OnOrientationUpdate(const Orientation& orientation) { |
| 29 ASSERT_FALSE(expectations_queue_.empty()); | 29 ASSERT_FALSE(expectations_queue_.empty()); |
| 30 | 30 |
| 31 Orientation expected = expectations_queue_.front(); | 31 Orientation expected = expectations_queue_.front(); |
| 32 expectations_queue_.pop(); | 32 expectations_queue_.pop(); |
| 33 | 33 |
| 34 EXPECT_EQ(expected.can_provide_alpha_, orientation.can_provide_alpha_); | 34 EXPECT_EQ(expected.can_provide_alpha_, orientation.can_provide_alpha_); |
| 35 EXPECT_EQ(expected.can_provide_beta_, orientation.can_provide_beta_); | 35 EXPECT_EQ(expected.can_provide_beta_, orientation.can_provide_beta_); |
| 36 EXPECT_EQ(expected.can_provide_gamma_, orientation.can_provide_gamma_); | 36 EXPECT_EQ(expected.can_provide_gamma_, orientation.can_provide_gamma_); |
| 37 EXPECT_EQ(expected.can_provide_absolute_, | 37 EXPECT_EQ(expected.can_provide_absolute_, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 instance_ = NULL; | 96 instance_ = NULL; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. | 99 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. |
| 100 class MockDataFetcher : public DataFetcher { | 100 class MockDataFetcher : public DataFetcher { |
| 101 public: | 101 public: |
| 102 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) | 102 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) |
| 103 : orientation_factory_(orientation_factory) { } | 103 : orientation_factory_(orientation_factory) { } |
| 104 | 104 |
| 105 // From DataFetcher. Called by the Provider. | 105 // From DataFetcher. Called by the Provider. |
| 106 virtual bool GetMotion(Motion *motion) { |
| 107 // TODO(aousterh): implement this once motion has been implemented in the |
| 108 // provider_impl |
| 109 return false; |
| 110 } |
| 111 |
| 106 virtual bool GetOrientation(Orientation* orientation) { | 112 virtual bool GetOrientation(Orientation* orientation) { |
| 107 base::AutoLock auto_lock(orientation_factory_->lock_); | 113 base::AutoLock auto_lock(orientation_factory_->lock_); |
| 108 if (orientation_factory_->is_failing_) | 114 if (orientation_factory_->is_failing_) |
| 109 return false; | 115 return false; |
| 110 *orientation = orientation_factory_->orientation_; | 116 *orientation = orientation_factory_->orientation_; |
| 111 return true; | 117 return true; |
| 112 } | 118 } |
| 113 | 119 |
| 114 private: | 120 private: |
| 115 scoped_refptr<MockOrientationFactory> orientation_factory_; | 121 scoped_refptr<MockOrientationFactory> orientation_factory_; |
| 116 }; | 122 }; |
| 117 | 123 |
| 118 static MockOrientationFactory* instance_; | 124 static MockOrientationFactory* instance_; |
| 119 Orientation orientation_; | 125 Orientation orientation_; |
| 120 bool is_failing_; | 126 bool is_failing_; |
| 121 base::Lock lock_; | 127 base::Lock lock_; |
| 122 }; | 128 }; |
| 123 | 129 |
| 124 MockOrientationFactory* MockOrientationFactory::instance_; | 130 MockOrientationFactory* MockOrientationFactory::instance_; |
| 125 | 131 |
| 126 // Mock DataFetcher that always fails to provide any orientation data. | 132 // Mock DataFetcher that always fails to provide any orientation data. |
| 127 class FailingDataFetcher : public DataFetcher { | 133 class FailingDataFetcher : public DataFetcher { |
| 128 public: | 134 public: |
| 129 // Factory method; passed to and called by the ProviderImpl. | 135 // Factory method; passed to and called by the ProviderImpl. |
| 130 static DataFetcher* Create() { | 136 static DataFetcher* Create() { |
| 131 return new FailingDataFetcher(); | 137 return new FailingDataFetcher(); |
| 132 } | 138 } |
| 133 | 139 |
| 134 // From DataFetcher. | 140 // From DataFetcher. |
| 141 virtual bool GetMotion(Motion* motion) { |
| 142 // TODO(aousterh): implement this once motion has been implemented in the |
| 143 // provider_impl |
| 144 return false; |
| 145 } |
| 135 virtual bool GetOrientation(Orientation* orientation) { | 146 virtual bool GetOrientation(Orientation* orientation) { |
| 136 return false; | 147 return false; |
| 137 } | 148 } |
| 138 | 149 |
| 139 private: | 150 private: |
| 140 FailingDataFetcher() {} | 151 FailingDataFetcher() {} |
| 141 }; | 152 }; |
| 142 | 153 |
| 143 class DeviceOrientationProviderTest : public testing::Test { | 154 class DeviceOrientationProviderTest : public testing::Test { |
| 144 public: | 155 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 194 |
| 184 TEST_F(DeviceOrientationProviderTest, FailingTest) { | 195 TEST_F(DeviceOrientationProviderTest, FailingTest) { |
| 185 Init(FailingDataFetcher::Create); | 196 Init(FailingDataFetcher::Create); |
| 186 | 197 |
| 187 scoped_ptr<UpdateChecker> checker_a( | 198 scoped_ptr<UpdateChecker> checker_a( |
| 188 new UpdateChecker(&pending_expectations_)); | 199 new UpdateChecker(&pending_expectations_)); |
| 189 scoped_ptr<UpdateChecker> checker_b( | 200 scoped_ptr<UpdateChecker> checker_b( |
| 190 new UpdateChecker(&pending_expectations_)); | 201 new UpdateChecker(&pending_expectations_)); |
| 191 | 202 |
| 192 checker_a->AddExpectation(Orientation::Empty()); | 203 checker_a->AddExpectation(Orientation::Empty()); |
| 193 provider_->AddObserver(checker_a.get()); | 204 provider_->AddOrientationObserver(checker_a.get()); |
| 194 MessageLoop::current()->Run(); | 205 MessageLoop::current()->Run(); |
| 195 | 206 |
| 196 checker_b->AddExpectation(Orientation::Empty()); | 207 checker_b->AddExpectation(Orientation::Empty()); |
| 197 provider_->AddObserver(checker_b.get()); | 208 provider_->AddOrientationObserver(checker_b.get()); |
| 198 MessageLoop::current()->Run(); | 209 MessageLoop::current()->Run(); |
| 199 } | 210 } |
| 200 | 211 |
| 201 TEST_F(DeviceOrientationProviderTest, ProviderIsSingleton) { | 212 TEST_F(DeviceOrientationProviderTest, ProviderIsSingleton) { |
| 202 Init(FailingDataFetcher::Create); | 213 Init(FailingDataFetcher::Create); |
| 203 | 214 |
| 204 scoped_refptr<Provider> provider_a(Provider::GetInstance()); | 215 scoped_refptr<Provider> provider_a(Provider::GetInstance()); |
| 205 scoped_refptr<Provider> provider_b(Provider::GetInstance()); | 216 scoped_refptr<Provider> provider_b(Provider::GetInstance()); |
| 206 | 217 |
| 207 EXPECT_EQ(provider_a.get(), provider_b.get()); | 218 EXPECT_EQ(provider_a.get(), provider_b.get()); |
| 208 } | 219 } |
| 209 | 220 |
| 210 TEST_F(DeviceOrientationProviderTest, BasicPushTest) { | 221 TEST_F(DeviceOrientationProviderTest, BasicPushTest) { |
| 211 scoped_refptr<MockOrientationFactory> orientation_factory( | 222 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 212 new MockOrientationFactory()); | 223 new MockOrientationFactory()); |
| 213 Init(MockOrientationFactory::CreateDataFetcher); | 224 Init(MockOrientationFactory::CreateDataFetcher); |
| 214 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); | 225 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); |
| 215 | 226 |
| 216 scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); | 227 scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); |
| 217 checker->AddExpectation(kTestOrientation); | 228 checker->AddExpectation(kTestOrientation); |
| 218 orientation_factory->SetOrientation(kTestOrientation); | 229 orientation_factory->SetOrientation(kTestOrientation); |
| 219 provider_->AddObserver(checker.get()); | 230 provider_->AddOrientationObserver(checker.get()); |
| 220 MessageLoop::current()->Run(); | 231 MessageLoop::current()->Run(); |
| 221 | 232 |
| 222 provider_->RemoveObserver(checker.get()); | 233 provider_->RemoveOrientationObserver(checker.get()); |
| 223 } | 234 } |
| 224 | 235 |
| 225 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { | 236 TEST_F(DeviceOrientationProviderTest, MultipleOrientationObserversPushTest) { |
| 226 scoped_refptr<MockOrientationFactory> orientation_factory( | 237 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 227 new MockOrientationFactory()); | 238 new MockOrientationFactory()); |
| 228 Init(MockOrientationFactory::CreateDataFetcher); | 239 Init(MockOrientationFactory::CreateDataFetcher); |
| 229 const Orientation kTestOrientations[] = { | 240 const Orientation kTestOrientations[] = { |
| 230 Orientation(true, 1, true, 2, true, 3, true, true), | 241 Orientation(true, 1, true, 2, true, 3, true, true), |
| 231 Orientation(true, 4, true, 5, true, 6, true, false), | 242 Orientation(true, 4, true, 5, true, 6, true, false), |
| 232 Orientation(true, 7, true, 8, true, 9, false, true)}; | 243 Orientation(true, 7, true, 8, true, 9, false, true)}; |
| 233 | 244 |
| 234 scoped_ptr<UpdateChecker> checker_a( | 245 scoped_ptr<UpdateChecker> checker_a( |
| 235 new UpdateChecker(&pending_expectations_)); | 246 new UpdateChecker(&pending_expectations_)); |
| 236 scoped_ptr<UpdateChecker> checker_b( | 247 scoped_ptr<UpdateChecker> checker_b( |
| 237 new UpdateChecker(&pending_expectations_)); | 248 new UpdateChecker(&pending_expectations_)); |
| 238 scoped_ptr<UpdateChecker> checker_c( | 249 scoped_ptr<UpdateChecker> checker_c( |
| 239 new UpdateChecker(&pending_expectations_)); | 250 new UpdateChecker(&pending_expectations_)); |
| 240 | 251 |
| 241 checker_a->AddExpectation(kTestOrientations[0]); | 252 checker_a->AddExpectation(kTestOrientations[0]); |
| 242 orientation_factory->SetOrientation(kTestOrientations[0]); | 253 orientation_factory->SetOrientation(kTestOrientations[0]); |
| 243 provider_->AddObserver(checker_a.get()); | 254 provider_->AddOrientationObserver(checker_a.get()); |
| 244 MessageLoop::current()->Run(); | 255 MessageLoop::current()->Run(); |
| 245 | 256 |
| 246 checker_a->AddExpectation(kTestOrientations[1]); | 257 checker_a->AddExpectation(kTestOrientations[1]); |
| 247 checker_b->AddExpectation(kTestOrientations[0]); | 258 checker_b->AddExpectation(kTestOrientations[0]); |
| 248 checker_b->AddExpectation(kTestOrientations[1]); | 259 checker_b->AddExpectation(kTestOrientations[1]); |
| 249 orientation_factory->SetOrientation(kTestOrientations[1]); | 260 orientation_factory->SetOrientation(kTestOrientations[1]); |
| 250 provider_->AddObserver(checker_b.get()); | 261 provider_->AddOrientationObserver(checker_b.get()); |
| 251 MessageLoop::current()->Run(); | 262 MessageLoop::current()->Run(); |
| 252 | 263 |
| 253 provider_->RemoveObserver(checker_a.get()); | 264 provider_->RemoveOrientationObserver(checker_a.get()); |
| 254 checker_b->AddExpectation(kTestOrientations[2]); | 265 checker_b->AddExpectation(kTestOrientations[2]); |
| 255 checker_c->AddExpectation(kTestOrientations[1]); | 266 checker_c->AddExpectation(kTestOrientations[1]); |
| 256 checker_c->AddExpectation(kTestOrientations[2]); | 267 checker_c->AddExpectation(kTestOrientations[2]); |
| 257 orientation_factory->SetOrientation(kTestOrientations[2]); | 268 orientation_factory->SetOrientation(kTestOrientations[2]); |
| 258 provider_->AddObserver(checker_c.get()); | 269 provider_->AddOrientationObserver(checker_c.get()); |
| 259 MessageLoop::current()->Run(); | 270 MessageLoop::current()->Run(); |
| 260 | 271 |
| 261 provider_->RemoveObserver(checker_b.get()); | 272 provider_->RemoveOrientationObserver(checker_b.get()); |
| 262 provider_->RemoveObserver(checker_c.get()); | 273 provider_->RemoveOrientationObserver(checker_c.get()); |
| 263 } | 274 } |
| 264 | 275 |
| 265 #if defined(OS_LINUX) || defined(OS_WIN) | 276 #if defined(OS_LINUX) || defined(OS_WIN) |
| 266 // Flakily DCHECKs on Linux. See crbug.com/104950. | 277 // Flakily DCHECKs on Linux. See crbug.com/104950. |
| 267 // FLAKY on Win. See crbug.com/104950. | 278 // FLAKY on Win. See crbug.com/104950. |
| 268 #define MAYBE_ObserverNotRemoved DISABLED_ObserverNotRemoved | 279 #define MAYBE_OrientationObserverNotRemoved DISABLED_OrientationObserverNotRemov
ed |
| 269 #else | 280 #else |
| 270 #define MAYBE_ObserverNotRemoved ObserverNotRemoved | 281 #define MAYBE_OrientationObserverNotRemoved OrientationObserverNotRemoved |
| 271 #endif | 282 #endif |
| 272 TEST_F(DeviceOrientationProviderTest, MAYBE_ObserverNotRemoved) { | 283 TEST_F(DeviceOrientationProviderTest, MAYBE_OrientationObserverNotRemoved) { |
| 273 scoped_refptr<MockOrientationFactory> orientation_factory( | 284 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 274 new MockOrientationFactory()); | 285 new MockOrientationFactory()); |
| 275 Init(MockOrientationFactory::CreateDataFetcher); | 286 Init(MockOrientationFactory::CreateDataFetcher); |
| 276 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); | 287 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); |
| 277 const Orientation kTestOrientation2(true, 4, true, 5, true, 6, true, false); | 288 const Orientation kTestOrientation2(true, 4, true, 5, true, 6, true, false); |
| 278 | 289 |
| 279 scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); | 290 scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); |
| 280 checker->AddExpectation(kTestOrientation); | 291 checker->AddExpectation(kTestOrientation); |
| 281 orientation_factory->SetOrientation(kTestOrientation); | 292 orientation_factory->SetOrientation(kTestOrientation); |
| 282 provider_->AddObserver(checker.get()); | 293 provider_->AddOrientationObserver(checker.get()); |
| 283 MessageLoop::current()->Run(); | 294 MessageLoop::current()->Run(); |
| 284 | 295 |
| 285 checker->AddExpectation(kTestOrientation2); | 296 checker->AddExpectation(kTestOrientation2); |
| 286 orientation_factory->SetOrientation(kTestOrientation2); | 297 orientation_factory->SetOrientation(kTestOrientation2); |
| 287 MessageLoop::current()->Run(); | 298 MessageLoop::current()->Run(); |
| 288 | 299 |
| 289 // Note that checker is not removed. This should not be a problem. | 300 // Note that checker is not removed. This should not be a problem. |
| 290 } | 301 } |
| 291 | 302 |
| 292 #if defined(OS_WIN) | 303 #if defined(OS_WIN) |
| 293 // FLAKY on Win. See crbug.com/104950. | 304 // FLAKY on Win. See crbug.com/104950. |
| 294 #define MAYBE_StartFailing DISABLED_StartFailing | 305 #define MAYBE_StartFailing DISABLED_StartFailing |
| 295 #else | 306 #else |
| 296 #define MAYBE_StartFailing StartFailing | 307 #define MAYBE_StartFailing StartFailing |
| 297 #endif | 308 #endif |
| 298 TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { | 309 TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
| 299 scoped_refptr<MockOrientationFactory> orientation_factory( | 310 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 300 new MockOrientationFactory()); | 311 new MockOrientationFactory()); |
| 301 Init(MockOrientationFactory::CreateDataFetcher); | 312 Init(MockOrientationFactory::CreateDataFetcher); |
| 302 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); | 313 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); |
| 303 | 314 |
| 304 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( | 315 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( |
| 305 &pending_expectations_)); | 316 &pending_expectations_)); |
| 306 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( | 317 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( |
| 307 &pending_expectations_)); | 318 &pending_expectations_)); |
| 308 | 319 |
| 309 orientation_factory->SetOrientation(kTestOrientation); | 320 orientation_factory->SetOrientation(kTestOrientation); |
| 310 checker_a->AddExpectation(kTestOrientation); | 321 checker_a->AddExpectation(kTestOrientation); |
| 311 provider_->AddObserver(checker_a.get()); | 322 provider_->AddOrientationObserver(checker_a.get()); |
| 312 MessageLoop::current()->Run(); | 323 MessageLoop::current()->Run(); |
| 313 | 324 |
| 314 checker_a->AddExpectation(Orientation::Empty()); | 325 checker_a->AddExpectation(Orientation::Empty()); |
| 315 orientation_factory->SetFailing(true); | 326 orientation_factory->SetFailing(true); |
| 316 MessageLoop::current()->Run(); | 327 MessageLoop::current()->Run(); |
| 317 | 328 |
| 318 checker_b->AddExpectation(Orientation::Empty()); | 329 checker_b->AddExpectation(Orientation::Empty()); |
| 319 provider_->AddObserver(checker_b.get()); | 330 provider_->AddOrientationObserver(checker_b.get()); |
| 320 MessageLoop::current()->Run(); | 331 MessageLoop::current()->Run(); |
| 321 | 332 |
| 322 provider_->RemoveObserver(checker_a.get()); | 333 provider_->RemoveOrientationObserver(checker_a.get()); |
| 323 provider_->RemoveObserver(checker_b.get()); | 334 provider_->RemoveOrientationObserver(checker_b.get()); |
| 324 } | 335 } |
| 325 | 336 |
| 326 TEST_F(DeviceOrientationProviderTest, StartStopStart) { | 337 TEST_F(DeviceOrientationProviderTest, StartStopStart) { |
| 327 scoped_refptr<MockOrientationFactory> orientation_factory( | 338 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 328 new MockOrientationFactory()); | 339 new MockOrientationFactory()); |
| 329 Init(MockOrientationFactory::CreateDataFetcher); | 340 Init(MockOrientationFactory::CreateDataFetcher); |
| 330 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); | 341 const Orientation kTestOrientation(true, 1, true, 2, true, 3, true, true); |
| 331 const Orientation kTestOrientation2(true, 4, true, 5, true, 6, true, false); | 342 const Orientation kTestOrientation2(true, 4, true, 5, true, 6, true, false); |
| 332 | 343 |
| 333 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( | 344 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( |
| 334 &pending_expectations_)); | 345 &pending_expectations_)); |
| 335 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( | 346 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( |
| 336 &pending_expectations_)); | 347 &pending_expectations_)); |
| 337 | 348 |
| 338 checker_a->AddExpectation(kTestOrientation); | 349 checker_a->AddExpectation(kTestOrientation); |
| 339 orientation_factory->SetOrientation(kTestOrientation); | 350 orientation_factory->SetOrientation(kTestOrientation); |
| 340 provider_->AddObserver(checker_a.get()); | 351 provider_->AddOrientationObserver(checker_a.get()); |
| 341 MessageLoop::current()->Run(); | 352 MessageLoop::current()->Run(); |
| 342 | 353 |
| 343 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. | 354 // This stops the Provider. |
| 355 provider_->RemoveOrientationObserver(checker_a.get()); |
| 344 | 356 |
| 345 checker_b->AddExpectation(kTestOrientation2); | 357 checker_b->AddExpectation(kTestOrientation2); |
| 346 orientation_factory->SetOrientation(kTestOrientation2); | 358 orientation_factory->SetOrientation(kTestOrientation2); |
| 347 provider_->AddObserver(checker_b.get()); | 359 provider_->AddOrientationObserver(checker_b.get()); |
| 348 MessageLoop::current()->Run(); | 360 MessageLoop::current()->Run(); |
| 349 | 361 |
| 350 provider_->RemoveObserver(checker_b.get()); | 362 provider_->RemoveOrientationObserver(checker_b.get()); |
| 351 } | 363 } |
| 352 | 364 |
| 353 TEST_F(DeviceOrientationProviderTest, SignificantlyDifferent) { | 365 TEST_F(DeviceOrientationProviderTest, SignificantlyDifferent) { |
| 354 scoped_refptr<MockOrientationFactory> orientation_factory( | 366 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 355 new MockOrientationFactory()); | 367 new MockOrientationFactory()); |
| 356 Init(MockOrientationFactory::CreateDataFetcher); | 368 Init(MockOrientationFactory::CreateDataFetcher); |
| 357 | 369 |
| 358 // Values that should be well below or above the implementation's | 370 // Values that should be well below or above the implementation's |
| 359 // significane threshold. | 371 // significane threshold. |
| 360 const double kInsignificantDifference = 1e-6; | 372 const double kInsignificantDifference = 1e-6; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 375 false, true); | 387 false, true); |
| 376 | 388 |
| 377 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( | 389 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( |
| 378 &pending_expectations_)); | 390 &pending_expectations_)); |
| 379 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( | 391 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( |
| 380 &pending_expectations_)); | 392 &pending_expectations_)); |
| 381 | 393 |
| 382 | 394 |
| 383 orientation_factory->SetOrientation(first_orientation); | 395 orientation_factory->SetOrientation(first_orientation); |
| 384 checker_a->AddExpectation(first_orientation); | 396 checker_a->AddExpectation(first_orientation); |
| 385 provider_->AddObserver(checker_a.get()); | 397 provider_->AddOrientationObserver(checker_a.get()); |
| 386 MessageLoop::current()->Run(); | 398 MessageLoop::current()->Run(); |
| 387 | 399 |
| 388 // The observers should not see this insignificantly different orientation. | 400 // The observers should not see this insignificantly different orientation. |
| 389 orientation_factory->SetOrientation(second_orientation); | 401 orientation_factory->SetOrientation(second_orientation); |
| 390 checker_b->AddExpectation(first_orientation); | 402 checker_b->AddExpectation(first_orientation); |
| 391 provider_->AddObserver(checker_b.get()); | 403 provider_->AddOrientationObserver(checker_b.get()); |
| 392 MessageLoop::current()->Run(); | 404 MessageLoop::current()->Run(); |
| 393 | 405 |
| 394 orientation_factory->SetOrientation(third_orientation); | 406 orientation_factory->SetOrientation(third_orientation); |
| 395 checker_a->AddExpectation(third_orientation); | 407 checker_a->AddExpectation(third_orientation); |
| 396 checker_b->AddExpectation(third_orientation); | 408 checker_b->AddExpectation(third_orientation); |
| 397 MessageLoop::current()->Run(); | 409 MessageLoop::current()->Run(); |
| 398 | 410 |
| 399 provider_->RemoveObserver(checker_a.get()); | 411 provider_->RemoveOrientationObserver(checker_a.get()); |
| 400 provider_->RemoveObserver(checker_b.get()); | 412 provider_->RemoveOrientationObserver(checker_b.get()); |
| 401 } | 413 } |
| 402 | 414 |
| 403 } // namespace | 415 } // namespace |
| 404 | 416 |
| 405 } // namespace device_orientation | 417 } // namespace device_orientation |
| OLD | NEW |