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