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 <map> | 5 #include <map> |
6 #include <queue> | 6 #include <queue> |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "content/browser/device_orientation/data_fetcher.h" | 10 #include "content/browser/device_orientation/data_fetcher.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 virtual ~MotionUpdateChecker() {} | 81 virtual ~MotionUpdateChecker() {} |
82 | 82 |
83 // From UpdateChecker. | 83 // From UpdateChecker. |
84 virtual void OnDeviceDataUpdate(const DeviceData* device_data, | 84 virtual void OnDeviceDataUpdate(const DeviceData* device_data, |
85 DeviceData::Type device_data_type) OVERRIDE { | 85 DeviceData::Type device_data_type) OVERRIDE { |
86 ASSERT_FALSE(expectations_queue_.empty()); | 86 ASSERT_FALSE(expectations_queue_.empty()); |
87 ASSERT_EQ(DeviceData::kTypeMotion, device_data_type); | 87 ASSERT_EQ(DeviceData::kTypeMotion, device_data_type); |
88 | 88 |
89 scoped_refptr<const Motion> motion(static_cast<const Motion*>(device_data)); | 89 scoped_refptr<const Motion> motion(static_cast<const Motion*>(device_data)); |
90 if (motion == NULL) | 90 if (motion.get() == NULL) |
91 motion = new Motion(); | 91 motion = new Motion(); |
92 | 92 |
93 scoped_refptr<const Motion> expected(static_cast<const Motion*>( | 93 scoped_refptr<const Motion> expected(static_cast<const Motion*>( |
94 (expectations_queue_.front().get()))); | 94 (expectations_queue_.front().get()))); |
95 expectations_queue_.pop(); | 95 expectations_queue_.pop(); |
96 | 96 |
97 EXPECT_EQ(expected->can_provide_acceleration_x(), | 97 EXPECT_EQ(expected->can_provide_acceleration_x(), |
98 motion->can_provide_acceleration_x()); | 98 motion->can_provide_acceleration_x()); |
99 EXPECT_EQ(expected->can_provide_acceleration_y(), | 99 EXPECT_EQ(expected->can_provide_acceleration_y(), |
100 motion->can_provide_acceleration_y()); | 100 motion->can_provide_acceleration_y()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 virtual ~OrientationUpdateChecker() {} | 165 virtual ~OrientationUpdateChecker() {} |
166 | 166 |
167 // From UpdateChecker. | 167 // From UpdateChecker. |
168 virtual void OnDeviceDataUpdate(const DeviceData* device_data, | 168 virtual void OnDeviceDataUpdate(const DeviceData* device_data, |
169 DeviceData::Type device_data_type) OVERRIDE { | 169 DeviceData::Type device_data_type) OVERRIDE { |
170 ASSERT_FALSE(expectations_queue_.empty()); | 170 ASSERT_FALSE(expectations_queue_.empty()); |
171 ASSERT_EQ(DeviceData::kTypeOrientation, device_data_type); | 171 ASSERT_EQ(DeviceData::kTypeOrientation, device_data_type); |
172 | 172 |
173 scoped_refptr<const Orientation> orientation( | 173 scoped_refptr<const Orientation> orientation( |
174 static_cast<const Orientation*>(device_data)); | 174 static_cast<const Orientation*>(device_data)); |
175 if (orientation == NULL) | 175 if (orientation.get() == NULL) |
176 orientation = new Orientation(); | 176 orientation = new Orientation(); |
177 | 177 |
178 scoped_refptr<const Orientation> expected(static_cast<const Orientation*>( | 178 scoped_refptr<const Orientation> expected(static_cast<const Orientation*>( |
179 (expectations_queue_.front().get()))); | 179 (expectations_queue_.front().get()))); |
180 expectations_queue_.pop(); | 180 expectations_queue_.pop(); |
181 | 181 |
182 EXPECT_EQ(expected->can_provide_alpha(), orientation->can_provide_alpha()); | 182 EXPECT_EQ(expected->can_provide_alpha(), orientation->can_provide_alpha()); |
183 EXPECT_EQ(expected->can_provide_beta(), orientation->can_provide_beta()); | 183 EXPECT_EQ(expected->can_provide_beta(), orientation->can_provide_beta()); |
184 EXPECT_EQ(expected->can_provide_gamma(), orientation->can_provide_gamma()); | 184 EXPECT_EQ(expected->can_provide_gamma(), orientation->can_provide_gamma()); |
185 EXPECT_EQ(expected->can_provide_absolute(), | 185 EXPECT_EQ(expected->can_provide_absolute(), |
(...skipping 23 matching lines...) Expand all Loading... |
209 } | 209 } |
210 | 210 |
211 // From UpdateChecker. | 211 // From UpdateChecker. |
212 virtual void OnDeviceDataUpdate(const DeviceData* device_data, | 212 virtual void OnDeviceDataUpdate(const DeviceData* device_data, |
213 DeviceData::Type device_data_type) OVERRIDE { | 213 DeviceData::Type device_data_type) OVERRIDE { |
214 ASSERT_FALSE(expectations_queue_.empty()); | 214 ASSERT_FALSE(expectations_queue_.empty()); |
215 ASSERT_EQ(DeviceData::kTypeTest, device_data_type); | 215 ASSERT_EQ(DeviceData::kTypeTest, device_data_type); |
216 | 216 |
217 scoped_refptr<const TestData> test_data( | 217 scoped_refptr<const TestData> test_data( |
218 static_cast<const TestData*>(device_data)); | 218 static_cast<const TestData*>(device_data)); |
219 if (test_data == NULL) | 219 if (test_data.get() == NULL) |
220 test_data = new TestData(); | 220 test_data = new TestData(); |
221 | 221 |
222 scoped_refptr<const TestData> expected(static_cast<const TestData*>( | 222 scoped_refptr<const TestData> expected(static_cast<const TestData*>( |
223 (expectations_queue_.front().get()))); | 223 (expectations_queue_.front().get()))); |
224 expectations_queue_.pop(); | 224 expectations_queue_.pop(); |
225 | 225 |
226 EXPECT_EQ(expected->value(), test_data->value()); | 226 EXPECT_EQ(expected->value(), test_data->value()); |
227 | 227 |
228 --(*expectations_count_ptr_); | 228 --(*expectations_count_ptr_); |
229 | 229 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 class MockDataFetcher : public DataFetcher { | 276 class MockDataFetcher : public DataFetcher { |
277 public: | 277 public: |
278 explicit MockDataFetcher(MockDeviceDataFactory* device_data_factory) | 278 explicit MockDataFetcher(MockDeviceDataFactory* device_data_factory) |
279 : device_data_factory_(device_data_factory) { } | 279 : device_data_factory_(device_data_factory) { } |
280 | 280 |
281 // From DataFetcher. Called by the Provider. | 281 // From DataFetcher. Called by the Provider. |
282 virtual const DeviceData* GetDeviceData(DeviceData::Type device_data_type) { | 282 virtual const DeviceData* GetDeviceData(DeviceData::Type device_data_type) { |
283 base::AutoLock auto_lock(device_data_factory_->lock_); | 283 base::AutoLock auto_lock(device_data_factory_->lock_); |
284 if (device_data_factory_->is_failing_) | 284 if (device_data_factory_->is_failing_) |
285 return NULL; | 285 return NULL; |
286 return device_data_factory_->device_data_map_[device_data_type]; | 286 return device_data_factory_->device_data_map_[device_data_type].get(); |
287 } | 287 } |
288 | 288 |
289 private: | 289 private: |
290 scoped_refptr<MockDeviceDataFactory> device_data_factory_; | 290 scoped_refptr<MockDeviceDataFactory> device_data_factory_; |
291 }; | 291 }; |
292 | 292 |
293 static MockDeviceDataFactory* instance_; | 293 static MockDeviceDataFactory* instance_; |
294 std::map<DeviceData::Type, scoped_refptr<const DeviceData> > device_data_map_; | 294 std::map<DeviceData::Type, scoped_refptr<const DeviceData> > device_data_map_; |
295 bool is_failing_; | 295 bool is_failing_; |
296 base::Lock lock_; | 296 base::Lock lock_; |
(...skipping 14 matching lines...) Expand all Loading... |
311 EXPECT_FALSE(Provider::GetInstanceForTests()); | 311 EXPECT_FALSE(Provider::GetInstanceForTests()); |
312 | 312 |
313 // Clean up in any case, so as to not break subsequent test. | 313 // Clean up in any case, so as to not break subsequent test. |
314 Provider::SetInstanceForTests(NULL); | 314 Provider::SetInstanceForTests(NULL); |
315 } | 315 } |
316 | 316 |
317 // Initialize the test fixture with a ProviderImpl that uses the | 317 // Initialize the test fixture with a ProviderImpl that uses the |
318 // DataFetcherFactory factory. | 318 // DataFetcherFactory factory. |
319 void Init(ProviderImpl::DataFetcherFactory factory) { | 319 void Init(ProviderImpl::DataFetcherFactory factory) { |
320 provider_ = new ProviderImpl(factory); | 320 provider_ = new ProviderImpl(factory); |
321 Provider::SetInstanceForTests(provider_); | 321 Provider::SetInstanceForTests(provider_.get()); |
322 } | 322 } |
323 | 323 |
324 protected: | 324 protected: |
325 // Number of pending expectations. | 325 // Number of pending expectations. |
326 int pending_expectations_; | 326 int pending_expectations_; |
327 | 327 |
328 // Provider instance under test. | 328 // Provider instance under test. |
329 scoped_refptr<Provider> provider_; | 329 scoped_refptr<Provider> provider_; |
330 | 330 |
331 // Message loop for the test thread. | 331 // Message loop for the test thread. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 373 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
374 Init(MockDeviceDataFactory::CreateDataFetcher); | 374 Init(MockDeviceDataFactory::CreateDataFetcher); |
375 scoped_refptr<Orientation> test_orientation(new Orientation()); | 375 scoped_refptr<Orientation> test_orientation(new Orientation()); |
376 test_orientation->set_alpha(1); | 376 test_orientation->set_alpha(1); |
377 test_orientation->set_beta(2); | 377 test_orientation->set_beta(2); |
378 test_orientation->set_gamma(3); | 378 test_orientation->set_gamma(3); |
379 test_orientation->set_absolute(true); | 379 test_orientation->set_absolute(true); |
380 | 380 |
381 scoped_ptr<OrientationUpdateChecker> checker( | 381 scoped_ptr<OrientationUpdateChecker> checker( |
382 new OrientationUpdateChecker(&pending_expectations_)); | 382 new OrientationUpdateChecker(&pending_expectations_)); |
383 checker->AddExpectation(test_orientation); | 383 checker->AddExpectation(test_orientation.get()); |
384 device_data_factory->SetDeviceData(test_orientation, | 384 device_data_factory->SetDeviceData(test_orientation.get(), |
385 DeviceData::kTypeOrientation); | 385 DeviceData::kTypeOrientation); |
386 provider_->AddObserver(checker.get()); | 386 provider_->AddObserver(checker.get()); |
387 MessageLoop::current()->Run(); | 387 MessageLoop::current()->Run(); |
388 | 388 |
389 provider_->RemoveObserver(checker.get()); | 389 provider_->RemoveObserver(checker.get()); |
390 MockDeviceDataFactory::SetCurInstance(NULL); | 390 MockDeviceDataFactory::SetCurInstance(NULL); |
391 } | 391 } |
392 | 392 |
393 // Tests multiple observers observing the same type of data. | 393 // Tests multiple observers observing the same type of data. |
394 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { | 394 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { |
395 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 395 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
(...skipping 18 matching lines...) Expand all Loading... |
414 test_orientations[2]->set_gamma(9); | 414 test_orientations[2]->set_gamma(9); |
415 // can't provide absolute | 415 // can't provide absolute |
416 | 416 |
417 scoped_ptr<OrientationUpdateChecker> checker_a( | 417 scoped_ptr<OrientationUpdateChecker> checker_a( |
418 new OrientationUpdateChecker(&pending_expectations_)); | 418 new OrientationUpdateChecker(&pending_expectations_)); |
419 scoped_ptr<OrientationUpdateChecker> checker_b( | 419 scoped_ptr<OrientationUpdateChecker> checker_b( |
420 new OrientationUpdateChecker(&pending_expectations_)); | 420 new OrientationUpdateChecker(&pending_expectations_)); |
421 scoped_ptr<OrientationUpdateChecker> checker_c( | 421 scoped_ptr<OrientationUpdateChecker> checker_c( |
422 new OrientationUpdateChecker(&pending_expectations_)); | 422 new OrientationUpdateChecker(&pending_expectations_)); |
423 | 423 |
424 checker_a->AddExpectation(test_orientations[0]); | 424 checker_a->AddExpectation(test_orientations[0].get()); |
425 device_data_factory->SetDeviceData(test_orientations[0], | 425 device_data_factory->SetDeviceData(test_orientations[0].get(), |
426 DeviceData::kTypeOrientation); | 426 DeviceData::kTypeOrientation); |
427 provider_->AddObserver(checker_a.get()); | 427 provider_->AddObserver(checker_a.get()); |
428 MessageLoop::current()->Run(); | 428 MessageLoop::current()->Run(); |
429 | 429 |
430 checker_a->AddExpectation(test_orientations[1]); | 430 checker_a->AddExpectation(test_orientations[1].get()); |
431 checker_b->AddExpectation(test_orientations[0]); | 431 checker_b->AddExpectation(test_orientations[0].get()); |
432 checker_b->AddExpectation(test_orientations[1]); | 432 checker_b->AddExpectation(test_orientations[1].get()); |
433 device_data_factory->SetDeviceData(test_orientations[1], | 433 device_data_factory->SetDeviceData(test_orientations[1].get(), |
434 DeviceData::kTypeOrientation); | 434 DeviceData::kTypeOrientation); |
435 provider_->AddObserver(checker_b.get()); | 435 provider_->AddObserver(checker_b.get()); |
436 MessageLoop::current()->Run(); | 436 MessageLoop::current()->Run(); |
437 | 437 |
438 provider_->RemoveObserver(checker_a.get()); | 438 provider_->RemoveObserver(checker_a.get()); |
439 checker_b->AddExpectation(test_orientations[2]); | 439 checker_b->AddExpectation(test_orientations[2].get()); |
440 checker_c->AddExpectation(test_orientations[1]); | 440 checker_c->AddExpectation(test_orientations[1].get()); |
441 checker_c->AddExpectation(test_orientations[2]); | 441 checker_c->AddExpectation(test_orientations[2].get()); |
442 device_data_factory->SetDeviceData(test_orientations[2], | 442 device_data_factory->SetDeviceData(test_orientations[2].get(), |
443 DeviceData::kTypeOrientation); | 443 DeviceData::kTypeOrientation); |
444 provider_->AddObserver(checker_c.get()); | 444 provider_->AddObserver(checker_c.get()); |
445 MessageLoop::current()->Run(); | 445 MessageLoop::current()->Run(); |
446 | 446 |
447 provider_->RemoveObserver(checker_b.get()); | 447 provider_->RemoveObserver(checker_b.get()); |
448 provider_->RemoveObserver(checker_c.get()); | 448 provider_->RemoveObserver(checker_c.get()); |
449 MockDeviceDataFactory::SetCurInstance(NULL); | 449 MockDeviceDataFactory::SetCurInstance(NULL); |
450 } | 450 } |
451 | 451 |
452 // Test for when the fetcher cannot provide the first type of data but can | 452 // Test for when the fetcher cannot provide the first type of data but can |
453 // provide the second type. | 453 // provide the second type. |
(...skipping 12 matching lines...) Expand all Loading... |
466 scoped_refptr<Orientation> test_orientation(new Orientation()); | 466 scoped_refptr<Orientation> test_orientation(new Orientation()); |
467 test_orientation->set_alpha(1); | 467 test_orientation->set_alpha(1); |
468 test_orientation->set_beta(2); | 468 test_orientation->set_beta(2); |
469 test_orientation->set_gamma(3); | 469 test_orientation->set_gamma(3); |
470 test_orientation->set_absolute(true); | 470 test_orientation->set_absolute(true); |
471 | 471 |
472 test_data_checker->AddExpectation(new TestData()); | 472 test_data_checker->AddExpectation(new TestData()); |
473 provider_->AddObserver(test_data_checker.get()); | 473 provider_->AddObserver(test_data_checker.get()); |
474 MessageLoop::current()->Run(); | 474 MessageLoop::current()->Run(); |
475 | 475 |
476 orientation_checker->AddExpectation(test_orientation); | 476 orientation_checker->AddExpectation(test_orientation.get()); |
477 device_data_factory->SetDeviceData(test_orientation, | 477 device_data_factory->SetDeviceData(test_orientation.get(), |
478 DeviceData::kTypeOrientation); | 478 DeviceData::kTypeOrientation); |
479 provider_->AddObserver(orientation_checker.get()); | 479 provider_->AddObserver(orientation_checker.get()); |
480 MessageLoop::current()->Run(); | 480 MessageLoop::current()->Run(); |
481 | 481 |
482 provider_->RemoveObserver(test_data_checker.get()); | 482 provider_->RemoveObserver(test_data_checker.get()); |
483 provider_->RemoveObserver(orientation_checker.get()); | 483 provider_->RemoveObserver(orientation_checker.get()); |
484 MockDeviceDataFactory::SetCurInstance(NULL); | 484 MockDeviceDataFactory::SetCurInstance(NULL); |
485 } | 485 } |
486 | 486 |
487 #if defined(OS_LINUX) || defined(OS_WIN) | 487 #if defined(OS_LINUX) || defined(OS_WIN) |
488 // Flakily DCHECKs on Linux. See crbug.com/104950. | 488 // Flakily DCHECKs on Linux. See crbug.com/104950. |
(...skipping 14 matching lines...) Expand all Loading... |
503 test_orientation->set_absolute(true); | 503 test_orientation->set_absolute(true); |
504 | 504 |
505 scoped_refptr<Orientation> test_orientation2(new Orientation()); | 505 scoped_refptr<Orientation> test_orientation2(new Orientation()); |
506 test_orientation2->set_alpha(4); | 506 test_orientation2->set_alpha(4); |
507 test_orientation2->set_beta(5); | 507 test_orientation2->set_beta(5); |
508 test_orientation2->set_gamma(6); | 508 test_orientation2->set_gamma(6); |
509 test_orientation2->set_absolute(false); | 509 test_orientation2->set_absolute(false); |
510 | 510 |
511 scoped_ptr<OrientationUpdateChecker> checker( | 511 scoped_ptr<OrientationUpdateChecker> checker( |
512 new OrientationUpdateChecker(&pending_expectations_)); | 512 new OrientationUpdateChecker(&pending_expectations_)); |
513 checker->AddExpectation(test_orientation); | 513 checker->AddExpectation(test_orientation.get()); |
514 device_data_factory->SetDeviceData(test_orientation, | 514 device_data_factory->SetDeviceData(test_orientation.get(), |
515 DeviceData::kTypeOrientation); | 515 DeviceData::kTypeOrientation); |
516 provider_->AddObserver(checker.get()); | 516 provider_->AddObserver(checker.get()); |
517 MessageLoop::current()->Run(); | 517 MessageLoop::current()->Run(); |
518 | 518 |
519 checker->AddExpectation(test_orientation2); | 519 checker->AddExpectation(test_orientation2.get()); |
520 device_data_factory->SetDeviceData(test_orientation2, | 520 device_data_factory->SetDeviceData(test_orientation2.get(), |
521 DeviceData::kTypeOrientation); | 521 DeviceData::kTypeOrientation); |
522 MessageLoop::current()->Run(); | 522 MessageLoop::current()->Run(); |
523 | 523 |
524 MockDeviceDataFactory::SetCurInstance(NULL); | 524 MockDeviceDataFactory::SetCurInstance(NULL); |
525 | 525 |
526 // Note that checker is not removed. This should not be a problem. | 526 // Note that checker is not removed. This should not be a problem. |
527 } | 527 } |
528 | 528 |
529 #if defined(OS_WIN) | 529 #if defined(OS_WIN) |
530 // FLAKY on Win. See crbug.com/104950. | 530 // FLAKY on Win. See crbug.com/104950. |
531 #define MAYBE_StartFailing DISABLED_StartFailing | 531 #define MAYBE_StartFailing DISABLED_StartFailing |
532 #else | 532 #else |
533 #define MAYBE_StartFailing StartFailing | 533 #define MAYBE_StartFailing StartFailing |
534 #endif | 534 #endif |
535 TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { | 535 TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
536 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 536 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
537 new MockDeviceDataFactory()); | 537 new MockDeviceDataFactory()); |
538 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 538 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
539 Init(MockDeviceDataFactory::CreateDataFetcher); | 539 Init(MockDeviceDataFactory::CreateDataFetcher); |
540 scoped_refptr<Orientation> test_orientation(new Orientation()); | 540 scoped_refptr<Orientation> test_orientation(new Orientation()); |
541 test_orientation->set_alpha(1); | 541 test_orientation->set_alpha(1); |
542 test_orientation->set_beta(2); | 542 test_orientation->set_beta(2); |
543 test_orientation->set_gamma(3); | 543 test_orientation->set_gamma(3); |
544 test_orientation->set_absolute(true); | 544 test_orientation->set_absolute(true); |
545 | 545 |
546 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( | 546 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
547 &pending_expectations_)); | 547 &pending_expectations_)); |
548 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( | 548 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
549 &pending_expectations_)); | 549 &pending_expectations_)); |
550 | 550 |
551 device_data_factory->SetDeviceData(test_orientation, | 551 device_data_factory->SetDeviceData(test_orientation.get(), |
552 DeviceData::kTypeOrientation); | 552 DeviceData::kTypeOrientation); |
553 checker_a->AddExpectation(test_orientation); | 553 checker_a->AddExpectation(test_orientation.get()); |
554 provider_->AddObserver(checker_a.get()); | 554 provider_->AddObserver(checker_a.get()); |
555 MessageLoop::current()->Run(); | 555 MessageLoop::current()->Run(); |
556 | 556 |
557 checker_a->AddExpectation(new Orientation()); | 557 checker_a->AddExpectation(new Orientation()); |
558 device_data_factory->SetFailing(true); | 558 device_data_factory->SetFailing(true); |
559 MessageLoop::current()->Run(); | 559 MessageLoop::current()->Run(); |
560 | 560 |
561 checker_b->AddExpectation(new Orientation()); | 561 checker_b->AddExpectation(new Orientation()); |
562 provider_->AddObserver(checker_b.get()); | 562 provider_->AddObserver(checker_b.get()); |
563 MessageLoop::current()->Run(); | 563 MessageLoop::current()->Run(); |
(...skipping 19 matching lines...) Expand all Loading... |
583 test_orientation2->set_alpha(4); | 583 test_orientation2->set_alpha(4); |
584 test_orientation2->set_beta(5); | 584 test_orientation2->set_beta(5); |
585 test_orientation2->set_gamma(6); | 585 test_orientation2->set_gamma(6); |
586 test_orientation2->set_absolute(false); | 586 test_orientation2->set_absolute(false); |
587 | 587 |
588 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( | 588 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
589 &pending_expectations_)); | 589 &pending_expectations_)); |
590 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( | 590 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
591 &pending_expectations_)); | 591 &pending_expectations_)); |
592 | 592 |
593 checker_a->AddExpectation(test_orientation); | 593 checker_a->AddExpectation(test_orientation.get()); |
594 device_data_factory->SetDeviceData(test_orientation, | 594 device_data_factory->SetDeviceData(test_orientation.get(), |
595 DeviceData::kTypeOrientation); | 595 DeviceData::kTypeOrientation); |
596 provider_->AddObserver(checker_a.get()); | 596 provider_->AddObserver(checker_a.get()); |
597 MessageLoop::current()->Run(); | 597 MessageLoop::current()->Run(); |
598 | 598 |
599 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. | 599 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. |
600 | 600 |
601 checker_b->AddExpectation(test_orientation2); | 601 checker_b->AddExpectation(test_orientation2.get()); |
602 device_data_factory->SetDeviceData(test_orientation2, | 602 device_data_factory->SetDeviceData(test_orientation2.get(), |
603 DeviceData::kTypeOrientation); | 603 DeviceData::kTypeOrientation); |
604 provider_->AddObserver(checker_b.get()); | 604 provider_->AddObserver(checker_b.get()); |
605 MessageLoop::current()->Run(); | 605 MessageLoop::current()->Run(); |
606 | 606 |
607 provider_->RemoveObserver(checker_b.get()); | 607 provider_->RemoveObserver(checker_b.get()); |
608 MockDeviceDataFactory::SetCurInstance(NULL); | 608 MockDeviceDataFactory::SetCurInstance(NULL); |
609 } | 609 } |
610 | 610 |
611 // Tests that Motion events always fire, even if the motion is unchanged. | 611 // Tests that Motion events always fire, even if the motion is unchanged. |
612 TEST_F(DeviceOrientationProviderTest, MotionAlwaysFires) { | 612 TEST_F(DeviceOrientationProviderTest, MotionAlwaysFires) { |
613 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 613 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
614 new MockDeviceDataFactory()); | 614 new MockDeviceDataFactory()); |
615 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 615 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
616 Init(MockDeviceDataFactory::CreateDataFetcher); | 616 Init(MockDeviceDataFactory::CreateDataFetcher); |
617 | 617 |
618 scoped_refptr<Motion> test_motion(new Motion()); | 618 scoped_refptr<Motion> test_motion(new Motion()); |
619 test_motion->set_acceleration_x(1); | 619 test_motion->set_acceleration_x(1); |
620 test_motion->set_acceleration_y(2); | 620 test_motion->set_acceleration_y(2); |
621 test_motion->set_acceleration_z(3); | 621 test_motion->set_acceleration_z(3); |
622 test_motion->set_acceleration_including_gravity_x(4); | 622 test_motion->set_acceleration_including_gravity_x(4); |
623 test_motion->set_acceleration_including_gravity_y(5); | 623 test_motion->set_acceleration_including_gravity_y(5); |
624 test_motion->set_acceleration_including_gravity_z(6); | 624 test_motion->set_acceleration_including_gravity_z(6); |
625 test_motion->set_rotation_rate_alpha(7); | 625 test_motion->set_rotation_rate_alpha(7); |
626 test_motion->set_rotation_rate_beta(8); | 626 test_motion->set_rotation_rate_beta(8); |
627 test_motion->set_rotation_rate_gamma(9); | 627 test_motion->set_rotation_rate_gamma(9); |
628 test_motion->set_interval(10); | 628 test_motion->set_interval(10); |
629 | 629 |
630 scoped_ptr<MotionUpdateChecker> checker(new MotionUpdateChecker( | 630 scoped_ptr<MotionUpdateChecker> checker(new MotionUpdateChecker( |
631 &pending_expectations_)); | 631 &pending_expectations_)); |
632 | 632 |
633 device_data_factory->SetDeviceData(test_motion, DeviceData::kTypeMotion); | 633 device_data_factory-> |
634 checker->AddExpectation(test_motion); | 634 SetDeviceData(test_motion.get(), DeviceData::kTypeMotion); |
| 635 checker->AddExpectation(test_motion.get()); |
635 provider_->AddObserver(checker.get()); | 636 provider_->AddObserver(checker.get()); |
636 MessageLoop::current()->Run(); | 637 MessageLoop::current()->Run(); |
637 | 638 |
638 // The observer should receive the same motion again. | 639 // The observer should receive the same motion again. |
639 device_data_factory->SetDeviceData(test_motion, DeviceData::kTypeMotion); | 640 device_data_factory-> |
640 checker->AddExpectation(test_motion); | 641 SetDeviceData(test_motion.get(), DeviceData::kTypeMotion); |
| 642 checker->AddExpectation(test_motion.get()); |
641 MessageLoop::current()->Run(); | 643 MessageLoop::current()->Run(); |
642 | 644 |
643 provider_->RemoveObserver(checker.get()); | 645 provider_->RemoveObserver(checker.get()); |
644 MockDeviceDataFactory::SetCurInstance(NULL); | 646 MockDeviceDataFactory::SetCurInstance(NULL); |
645 } | 647 } |
646 | 648 |
647 // Tests that Orientation events only fire if the change is significant. | 649 // Tests that Orientation events only fire if the change is significant. |
648 TEST_F(DeviceOrientationProviderTest, OrientationSignificantlyDifferent) { | 650 TEST_F(DeviceOrientationProviderTest, OrientationSignificantlyDifferent) { |
649 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 651 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
650 new MockDeviceDataFactory()); | 652 new MockDeviceDataFactory()); |
(...skipping 22 matching lines...) Expand all Loading... |
673 third_orientation->set_alpha(kAlpha + kSignificantDifference); | 675 third_orientation->set_alpha(kAlpha + kSignificantDifference); |
674 third_orientation->set_beta(kBeta + kSignificantDifference); | 676 third_orientation->set_beta(kBeta + kSignificantDifference); |
675 third_orientation->set_gamma(kGamma + kSignificantDifference); | 677 third_orientation->set_gamma(kGamma + kSignificantDifference); |
676 // can't provide absolute | 678 // can't provide absolute |
677 | 679 |
678 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( | 680 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
679 &pending_expectations_)); | 681 &pending_expectations_)); |
680 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( | 682 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
681 &pending_expectations_)); | 683 &pending_expectations_)); |
682 | 684 |
683 device_data_factory->SetDeviceData(first_orientation, | 685 device_data_factory->SetDeviceData(first_orientation.get(), |
684 DeviceData::kTypeOrientation); | 686 DeviceData::kTypeOrientation); |
685 checker_a->AddExpectation(first_orientation); | 687 checker_a->AddExpectation(first_orientation.get()); |
686 provider_->AddObserver(checker_a.get()); | 688 provider_->AddObserver(checker_a.get()); |
687 MessageLoop::current()->Run(); | 689 MessageLoop::current()->Run(); |
688 | 690 |
689 // The observers should not see this insignificantly different orientation. | 691 // The observers should not see this insignificantly different orientation. |
690 device_data_factory->SetDeviceData(second_orientation, | 692 device_data_factory->SetDeviceData(second_orientation.get(), |
691 DeviceData::kTypeOrientation); | 693 DeviceData::kTypeOrientation); |
692 checker_b->AddExpectation(first_orientation); | 694 checker_b->AddExpectation(first_orientation.get()); |
693 provider_->AddObserver(checker_b.get()); | 695 provider_->AddObserver(checker_b.get()); |
694 MessageLoop::current()->Run(); | 696 MessageLoop::current()->Run(); |
695 | 697 |
696 device_data_factory->SetDeviceData(third_orientation, | 698 device_data_factory->SetDeviceData(third_orientation.get(), |
697 DeviceData::kTypeOrientation); | 699 DeviceData::kTypeOrientation); |
698 checker_a->AddExpectation(third_orientation); | 700 checker_a->AddExpectation(third_orientation.get()); |
699 checker_b->AddExpectation(third_orientation); | 701 checker_b->AddExpectation(third_orientation.get()); |
700 MessageLoop::current()->Run(); | 702 MessageLoop::current()->Run(); |
701 | 703 |
702 provider_->RemoveObserver(checker_a.get()); | 704 provider_->RemoveObserver(checker_a.get()); |
703 provider_->RemoveObserver(checker_b.get()); | 705 provider_->RemoveObserver(checker_b.get()); |
704 MockDeviceDataFactory::SetCurInstance(NULL); | 706 MockDeviceDataFactory::SetCurInstance(NULL); |
705 } | 707 } |
706 | 708 |
707 } // namespace | 709 } // namespace |
708 | 710 |
709 } // namespace content | 711 } // namespace content |
OLD | NEW |