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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 if (expected->can_provide_rotation_rate_gamma()) | 143 if (expected->can_provide_rotation_rate_gamma()) |
144 EXPECT_EQ(expected->rotation_rate_gamma(), | 144 EXPECT_EQ(expected->rotation_rate_gamma(), |
145 motion->rotation_rate_gamma()); | 145 motion->rotation_rate_gamma()); |
146 | 146 |
147 if (expected->can_provide_interval()) | 147 if (expected->can_provide_interval()) |
148 EXPECT_EQ(expected->interval(), motion->interval()); | 148 EXPECT_EQ(expected->interval(), motion->interval()); |
149 | 149 |
150 --(*expectations_count_ptr_); | 150 --(*expectations_count_ptr_); |
151 | 151 |
152 if (*expectations_count_ptr_ == 0) { | 152 if (*expectations_count_ptr_ == 0) { |
153 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 153 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 154 base::MessageLoop::QuitClosure()); |
154 } | 155 } |
155 } | 156 } |
156 }; | 157 }; |
157 | 158 |
158 // Class for checking expectations on orientation updates from the Provider. | 159 // Class for checking expectations on orientation updates from the Provider. |
159 class OrientationUpdateChecker : public UpdateChecker { | 160 class OrientationUpdateChecker : public UpdateChecker { |
160 public: | 161 public: |
161 explicit OrientationUpdateChecker(int* expectations_count_ptr) | 162 explicit OrientationUpdateChecker(int* expectations_count_ptr) |
162 : UpdateChecker(DeviceData::kTypeOrientation, expectations_count_ptr) { | 163 : UpdateChecker(DeviceData::kTypeOrientation, expectations_count_ptr) { |
163 } | 164 } |
(...skipping 25 matching lines...) Expand all Loading... |
189 if (expected->can_provide_beta()) | 190 if (expected->can_provide_beta()) |
190 EXPECT_EQ(expected->beta(), orientation->beta()); | 191 EXPECT_EQ(expected->beta(), orientation->beta()); |
191 if (expected->can_provide_gamma()) | 192 if (expected->can_provide_gamma()) |
192 EXPECT_EQ(expected->gamma(), orientation->gamma()); | 193 EXPECT_EQ(expected->gamma(), orientation->gamma()); |
193 if (expected->can_provide_absolute()) | 194 if (expected->can_provide_absolute()) |
194 EXPECT_EQ(expected->absolute(), orientation->absolute()); | 195 EXPECT_EQ(expected->absolute(), orientation->absolute()); |
195 | 196 |
196 --(*expectations_count_ptr_); | 197 --(*expectations_count_ptr_); |
197 | 198 |
198 if (*expectations_count_ptr_ == 0) { | 199 if (*expectations_count_ptr_ == 0) { |
199 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 200 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 201 base::MessageLoop::QuitClosure()); |
200 } | 202 } |
201 } | 203 } |
202 }; | 204 }; |
203 | 205 |
204 // Class for checking expectations on test_data updates from the Provider. | 206 // Class for checking expectations on test_data updates from the Provider. |
205 class TestDataUpdateChecker : public UpdateChecker { | 207 class TestDataUpdateChecker : public UpdateChecker { |
206 public: | 208 public: |
207 explicit TestDataUpdateChecker(int* expectations_count_ptr) | 209 explicit TestDataUpdateChecker(int* expectations_count_ptr) |
208 : UpdateChecker(DeviceData::kTypeTest, expectations_count_ptr) { | 210 : UpdateChecker(DeviceData::kTypeTest, expectations_count_ptr) { |
209 } | 211 } |
(...skipping 11 matching lines...) Expand all Loading... |
221 | 223 |
222 scoped_refptr<const TestData> expected(static_cast<const TestData*>( | 224 scoped_refptr<const TestData> expected(static_cast<const TestData*>( |
223 (expectations_queue_.front().get()))); | 225 (expectations_queue_.front().get()))); |
224 expectations_queue_.pop(); | 226 expectations_queue_.pop(); |
225 | 227 |
226 EXPECT_EQ(expected->value(), test_data->value()); | 228 EXPECT_EQ(expected->value(), test_data->value()); |
227 | 229 |
228 --(*expectations_count_ptr_); | 230 --(*expectations_count_ptr_); |
229 | 231 |
230 if (*expectations_count_ptr_ == 0) { | 232 if (*expectations_count_ptr_ == 0) { |
231 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 233 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 234 base::MessageLoop::QuitClosure()); |
232 } | 235 } |
233 } | 236 } |
234 }; | 237 }; |
235 | 238 |
236 // Class for injecting test device data into the Provider. | 239 // Class for injecting test device data into the Provider. |
237 class MockDeviceDataFactory | 240 class MockDeviceDataFactory |
238 : public base::RefCountedThreadSafe<MockDeviceDataFactory> { | 241 : public base::RefCountedThreadSafe<MockDeviceDataFactory> { |
239 public: | 242 public: |
240 MockDeviceDataFactory() | 243 MockDeviceDataFactory() |
241 : is_failing_(false) { | 244 : is_failing_(false) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 326 } |
324 | 327 |
325 protected: | 328 protected: |
326 // Number of pending expectations. | 329 // Number of pending expectations. |
327 int pending_expectations_; | 330 int pending_expectations_; |
328 | 331 |
329 // Provider instance under test. | 332 // Provider instance under test. |
330 scoped_refptr<Provider> provider_; | 333 scoped_refptr<Provider> provider_; |
331 | 334 |
332 // Message loop for the test thread. | 335 // Message loop for the test thread. |
333 MessageLoop message_loop_; | 336 base::MessageLoop message_loop_; |
334 }; | 337 }; |
335 | 338 |
336 TEST_F(DeviceOrientationProviderTest, FailingTest) { | 339 TEST_F(DeviceOrientationProviderTest, FailingTest) { |
337 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 340 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
338 new MockDeviceDataFactory()); | 341 new MockDeviceDataFactory()); |
339 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 342 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
340 Init(MockDeviceDataFactory::CreateDataFetcher); | 343 Init(MockDeviceDataFactory::CreateDataFetcher); |
341 | 344 |
342 scoped_ptr<OrientationUpdateChecker> checker_a( | 345 scoped_ptr<OrientationUpdateChecker> checker_a( |
343 new OrientationUpdateChecker(&pending_expectations_)); | 346 new OrientationUpdateChecker(&pending_expectations_)); |
344 scoped_ptr<OrientationUpdateChecker> checker_b( | 347 scoped_ptr<OrientationUpdateChecker> checker_b( |
345 new OrientationUpdateChecker(&pending_expectations_)); | 348 new OrientationUpdateChecker(&pending_expectations_)); |
346 | 349 |
347 checker_a->AddExpectation(new Orientation()); | 350 checker_a->AddExpectation(new Orientation()); |
348 provider_->AddObserver(checker_a.get()); | 351 provider_->AddObserver(checker_a.get()); |
349 MessageLoop::current()->Run(); | 352 base::MessageLoop::current()->Run(); |
350 | 353 |
351 checker_b->AddExpectation(new Orientation()); | 354 checker_b->AddExpectation(new Orientation()); |
352 provider_->AddObserver(checker_b.get()); | 355 provider_->AddObserver(checker_b.get()); |
353 MessageLoop::current()->Run(); | 356 base::MessageLoop::current()->Run(); |
354 | 357 |
355 MockDeviceDataFactory::SetCurInstance(NULL); | 358 MockDeviceDataFactory::SetCurInstance(NULL); |
356 } | 359 } |
357 | 360 |
358 TEST_F(DeviceOrientationProviderTest, ProviderIsSingleton) { | 361 TEST_F(DeviceOrientationProviderTest, ProviderIsSingleton) { |
359 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 362 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
360 new MockDeviceDataFactory()); | 363 new MockDeviceDataFactory()); |
361 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 364 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
362 Init(MockDeviceDataFactory::CreateDataFetcher); | 365 Init(MockDeviceDataFactory::CreateDataFetcher); |
363 | 366 |
(...skipping 14 matching lines...) Expand all Loading... |
378 test_orientation->set_beta(2); | 381 test_orientation->set_beta(2); |
379 test_orientation->set_gamma(3); | 382 test_orientation->set_gamma(3); |
380 test_orientation->set_absolute(true); | 383 test_orientation->set_absolute(true); |
381 | 384 |
382 scoped_ptr<OrientationUpdateChecker> checker( | 385 scoped_ptr<OrientationUpdateChecker> checker( |
383 new OrientationUpdateChecker(&pending_expectations_)); | 386 new OrientationUpdateChecker(&pending_expectations_)); |
384 checker->AddExpectation(test_orientation); | 387 checker->AddExpectation(test_orientation); |
385 device_data_factory->SetDeviceData(test_orientation, | 388 device_data_factory->SetDeviceData(test_orientation, |
386 DeviceData::kTypeOrientation); | 389 DeviceData::kTypeOrientation); |
387 provider_->AddObserver(checker.get()); | 390 provider_->AddObserver(checker.get()); |
388 MessageLoop::current()->Run(); | 391 base::MessageLoop::current()->Run(); |
389 | 392 |
390 provider_->RemoveObserver(checker.get()); | 393 provider_->RemoveObserver(checker.get()); |
391 MockDeviceDataFactory::SetCurInstance(NULL); | 394 MockDeviceDataFactory::SetCurInstance(NULL); |
392 } | 395 } |
393 | 396 |
394 // Tests multiple observers observing the same type of data. | 397 // Tests multiple observers observing the same type of data. |
395 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { | 398 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { |
396 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 399 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
397 new MockDeviceDataFactory()); | 400 new MockDeviceDataFactory()); |
398 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 401 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
(...skipping 20 matching lines...) Expand all Loading... |
419 new OrientationUpdateChecker(&pending_expectations_)); | 422 new OrientationUpdateChecker(&pending_expectations_)); |
420 scoped_ptr<OrientationUpdateChecker> checker_b( | 423 scoped_ptr<OrientationUpdateChecker> checker_b( |
421 new OrientationUpdateChecker(&pending_expectations_)); | 424 new OrientationUpdateChecker(&pending_expectations_)); |
422 scoped_ptr<OrientationUpdateChecker> checker_c( | 425 scoped_ptr<OrientationUpdateChecker> checker_c( |
423 new OrientationUpdateChecker(&pending_expectations_)); | 426 new OrientationUpdateChecker(&pending_expectations_)); |
424 | 427 |
425 checker_a->AddExpectation(test_orientations[0]); | 428 checker_a->AddExpectation(test_orientations[0]); |
426 device_data_factory->SetDeviceData(test_orientations[0], | 429 device_data_factory->SetDeviceData(test_orientations[0], |
427 DeviceData::kTypeOrientation); | 430 DeviceData::kTypeOrientation); |
428 provider_->AddObserver(checker_a.get()); | 431 provider_->AddObserver(checker_a.get()); |
429 MessageLoop::current()->Run(); | 432 base::MessageLoop::current()->Run(); |
430 | 433 |
431 checker_a->AddExpectation(test_orientations[1]); | 434 checker_a->AddExpectation(test_orientations[1]); |
432 checker_b->AddExpectation(test_orientations[0]); | 435 checker_b->AddExpectation(test_orientations[0]); |
433 checker_b->AddExpectation(test_orientations[1]); | 436 checker_b->AddExpectation(test_orientations[1]); |
434 device_data_factory->SetDeviceData(test_orientations[1], | 437 device_data_factory->SetDeviceData(test_orientations[1], |
435 DeviceData::kTypeOrientation); | 438 DeviceData::kTypeOrientation); |
436 provider_->AddObserver(checker_b.get()); | 439 provider_->AddObserver(checker_b.get()); |
437 MessageLoop::current()->Run(); | 440 base::MessageLoop::current()->Run(); |
438 | 441 |
439 provider_->RemoveObserver(checker_a.get()); | 442 provider_->RemoveObserver(checker_a.get()); |
440 checker_b->AddExpectation(test_orientations[2]); | 443 checker_b->AddExpectation(test_orientations[2]); |
441 checker_c->AddExpectation(test_orientations[1]); | 444 checker_c->AddExpectation(test_orientations[1]); |
442 checker_c->AddExpectation(test_orientations[2]); | 445 checker_c->AddExpectation(test_orientations[2]); |
443 device_data_factory->SetDeviceData(test_orientations[2], | 446 device_data_factory->SetDeviceData(test_orientations[2], |
444 DeviceData::kTypeOrientation); | 447 DeviceData::kTypeOrientation); |
445 provider_->AddObserver(checker_c.get()); | 448 provider_->AddObserver(checker_c.get()); |
446 MessageLoop::current()->Run(); | 449 base::MessageLoop::current()->Run(); |
447 | 450 |
448 provider_->RemoveObserver(checker_b.get()); | 451 provider_->RemoveObserver(checker_b.get()); |
449 provider_->RemoveObserver(checker_c.get()); | 452 provider_->RemoveObserver(checker_c.get()); |
450 MockDeviceDataFactory::SetCurInstance(NULL); | 453 MockDeviceDataFactory::SetCurInstance(NULL); |
451 } | 454 } |
452 | 455 |
453 // 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 |
454 // provide the second type. | 457 // provide the second type. |
455 TEST_F(DeviceOrientationProviderTest, FailingFirstDataTypeTest) { | 458 TEST_F(DeviceOrientationProviderTest, FailingFirstDataTypeTest) { |
456 | 459 |
457 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 460 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
458 new MockDeviceDataFactory()); | 461 new MockDeviceDataFactory()); |
459 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 462 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
460 Init(MockDeviceDataFactory::CreateDataFetcher); | 463 Init(MockDeviceDataFactory::CreateDataFetcher); |
461 | 464 |
462 scoped_ptr<TestDataUpdateChecker> test_data_checker( | 465 scoped_ptr<TestDataUpdateChecker> test_data_checker( |
463 new TestDataUpdateChecker(&pending_expectations_)); | 466 new TestDataUpdateChecker(&pending_expectations_)); |
464 scoped_ptr<OrientationUpdateChecker> orientation_checker( | 467 scoped_ptr<OrientationUpdateChecker> orientation_checker( |
465 new OrientationUpdateChecker(&pending_expectations_)); | 468 new OrientationUpdateChecker(&pending_expectations_)); |
466 | 469 |
467 scoped_refptr<Orientation> test_orientation(new Orientation()); | 470 scoped_refptr<Orientation> test_orientation(new Orientation()); |
468 test_orientation->set_alpha(1); | 471 test_orientation->set_alpha(1); |
469 test_orientation->set_beta(2); | 472 test_orientation->set_beta(2); |
470 test_orientation->set_gamma(3); | 473 test_orientation->set_gamma(3); |
471 test_orientation->set_absolute(true); | 474 test_orientation->set_absolute(true); |
472 | 475 |
473 test_data_checker->AddExpectation(new TestData()); | 476 test_data_checker->AddExpectation(new TestData()); |
474 provider_->AddObserver(test_data_checker.get()); | 477 provider_->AddObserver(test_data_checker.get()); |
475 MessageLoop::current()->Run(); | 478 base::MessageLoop::current()->Run(); |
476 | 479 |
477 orientation_checker->AddExpectation(test_orientation); | 480 orientation_checker->AddExpectation(test_orientation); |
478 device_data_factory->SetDeviceData(test_orientation, | 481 device_data_factory->SetDeviceData(test_orientation, |
479 DeviceData::kTypeOrientation); | 482 DeviceData::kTypeOrientation); |
480 provider_->AddObserver(orientation_checker.get()); | 483 provider_->AddObserver(orientation_checker.get()); |
481 MessageLoop::current()->Run(); | 484 base::MessageLoop::current()->Run(); |
482 | 485 |
483 provider_->RemoveObserver(test_data_checker.get()); | 486 provider_->RemoveObserver(test_data_checker.get()); |
484 provider_->RemoveObserver(orientation_checker.get()); | 487 provider_->RemoveObserver(orientation_checker.get()); |
485 MockDeviceDataFactory::SetCurInstance(NULL); | 488 MockDeviceDataFactory::SetCurInstance(NULL); |
486 } | 489 } |
487 | 490 |
488 #if defined(OS_LINUX) || defined(OS_WIN) | 491 #if defined(OS_LINUX) || defined(OS_WIN) |
489 // Flakily DCHECKs on Linux. See crbug.com/104950. | 492 // Flakily DCHECKs on Linux. See crbug.com/104950. |
490 // FLAKY on Win. See crbug.com/104950. | 493 // FLAKY on Win. See crbug.com/104950. |
491 #define MAYBE_ObserverNotRemoved DISABLED_ObserverNotRemoved | 494 #define MAYBE_ObserverNotRemoved DISABLED_ObserverNotRemoved |
(...skipping 16 matching lines...) Expand all Loading... |
508 test_orientation2->set_beta(5); | 511 test_orientation2->set_beta(5); |
509 test_orientation2->set_gamma(6); | 512 test_orientation2->set_gamma(6); |
510 test_orientation2->set_absolute(false); | 513 test_orientation2->set_absolute(false); |
511 | 514 |
512 scoped_ptr<OrientationUpdateChecker> checker( | 515 scoped_ptr<OrientationUpdateChecker> checker( |
513 new OrientationUpdateChecker(&pending_expectations_)); | 516 new OrientationUpdateChecker(&pending_expectations_)); |
514 checker->AddExpectation(test_orientation); | 517 checker->AddExpectation(test_orientation); |
515 device_data_factory->SetDeviceData(test_orientation, | 518 device_data_factory->SetDeviceData(test_orientation, |
516 DeviceData::kTypeOrientation); | 519 DeviceData::kTypeOrientation); |
517 provider_->AddObserver(checker.get()); | 520 provider_->AddObserver(checker.get()); |
518 MessageLoop::current()->Run(); | 521 base::MessageLoop::current()->Run(); |
519 | 522 |
520 checker->AddExpectation(test_orientation2); | 523 checker->AddExpectation(test_orientation2); |
521 device_data_factory->SetDeviceData(test_orientation2, | 524 device_data_factory->SetDeviceData(test_orientation2, |
522 DeviceData::kTypeOrientation); | 525 DeviceData::kTypeOrientation); |
523 MessageLoop::current()->Run(); | 526 base::MessageLoop::current()->Run(); |
524 | 527 |
525 MockDeviceDataFactory::SetCurInstance(NULL); | 528 MockDeviceDataFactory::SetCurInstance(NULL); |
526 | 529 |
527 // 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. |
528 } | 531 } |
529 | 532 |
530 #if defined(OS_WIN) | 533 #if defined(OS_WIN) |
531 // FLAKY on Win. See crbug.com/104950. | 534 // FLAKY on Win. See crbug.com/104950. |
532 #define MAYBE_StartFailing DISABLED_StartFailing | 535 #define MAYBE_StartFailing DISABLED_StartFailing |
533 #else | 536 #else |
(...skipping 12 matching lines...) Expand all Loading... |
546 | 549 |
547 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( | 550 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
548 &pending_expectations_)); | 551 &pending_expectations_)); |
549 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( | 552 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
550 &pending_expectations_)); | 553 &pending_expectations_)); |
551 | 554 |
552 device_data_factory->SetDeviceData(test_orientation, | 555 device_data_factory->SetDeviceData(test_orientation, |
553 DeviceData::kTypeOrientation); | 556 DeviceData::kTypeOrientation); |
554 checker_a->AddExpectation(test_orientation); | 557 checker_a->AddExpectation(test_orientation); |
555 provider_->AddObserver(checker_a.get()); | 558 provider_->AddObserver(checker_a.get()); |
556 MessageLoop::current()->Run(); | 559 base::MessageLoop::current()->Run(); |
557 | 560 |
558 checker_a->AddExpectation(new Orientation()); | 561 checker_a->AddExpectation(new Orientation()); |
559 device_data_factory->SetFailing(true); | 562 device_data_factory->SetFailing(true); |
560 MessageLoop::current()->Run(); | 563 base::MessageLoop::current()->Run(); |
561 | 564 |
562 checker_b->AddExpectation(new Orientation()); | 565 checker_b->AddExpectation(new Orientation()); |
563 provider_->AddObserver(checker_b.get()); | 566 provider_->AddObserver(checker_b.get()); |
564 MessageLoop::current()->Run(); | 567 base::MessageLoop::current()->Run(); |
565 | 568 |
566 provider_->RemoveObserver(checker_a.get()); | 569 provider_->RemoveObserver(checker_a.get()); |
567 provider_->RemoveObserver(checker_b.get()); | 570 provider_->RemoveObserver(checker_b.get()); |
568 MockDeviceDataFactory::SetCurInstance(NULL); | 571 MockDeviceDataFactory::SetCurInstance(NULL); |
569 } | 572 } |
570 | 573 |
571 TEST_F(DeviceOrientationProviderTest, StartStopStart) { | 574 TEST_F(DeviceOrientationProviderTest, StartStopStart) { |
572 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 575 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
573 new MockDeviceDataFactory()); | 576 new MockDeviceDataFactory()); |
574 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 577 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
(...skipping 13 matching lines...) Expand all Loading... |
588 | 591 |
589 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( | 592 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
590 &pending_expectations_)); | 593 &pending_expectations_)); |
591 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( | 594 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
592 &pending_expectations_)); | 595 &pending_expectations_)); |
593 | 596 |
594 checker_a->AddExpectation(test_orientation); | 597 checker_a->AddExpectation(test_orientation); |
595 device_data_factory->SetDeviceData(test_orientation, | 598 device_data_factory->SetDeviceData(test_orientation, |
596 DeviceData::kTypeOrientation); | 599 DeviceData::kTypeOrientation); |
597 provider_->AddObserver(checker_a.get()); | 600 provider_->AddObserver(checker_a.get()); |
598 MessageLoop::current()->Run(); | 601 base::MessageLoop::current()->Run(); |
599 | 602 |
600 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. | 603 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. |
601 | 604 |
602 checker_b->AddExpectation(test_orientation2); | 605 checker_b->AddExpectation(test_orientation2); |
603 device_data_factory->SetDeviceData(test_orientation2, | 606 device_data_factory->SetDeviceData(test_orientation2, |
604 DeviceData::kTypeOrientation); | 607 DeviceData::kTypeOrientation); |
605 provider_->AddObserver(checker_b.get()); | 608 provider_->AddObserver(checker_b.get()); |
606 MessageLoop::current()->Run(); | 609 base::MessageLoop::current()->Run(); |
607 | 610 |
608 provider_->RemoveObserver(checker_b.get()); | 611 provider_->RemoveObserver(checker_b.get()); |
609 MockDeviceDataFactory::SetCurInstance(NULL); | 612 MockDeviceDataFactory::SetCurInstance(NULL); |
610 } | 613 } |
611 | 614 |
612 // 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. |
613 TEST_F(DeviceOrientationProviderTest, FLAKY_MotionAlwaysFires) { | 616 TEST_F(DeviceOrientationProviderTest, FLAKY_MotionAlwaysFires) { |
614 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 617 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
615 new MockDeviceDataFactory()); | 618 new MockDeviceDataFactory()); |
616 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 619 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
627 test_motion->set_rotation_rate_beta(8); | 630 test_motion->set_rotation_rate_beta(8); |
628 test_motion->set_rotation_rate_gamma(9); | 631 test_motion->set_rotation_rate_gamma(9); |
629 test_motion->set_interval(10); | 632 test_motion->set_interval(10); |
630 | 633 |
631 scoped_ptr<MotionUpdateChecker> checker(new MotionUpdateChecker( | 634 scoped_ptr<MotionUpdateChecker> checker(new MotionUpdateChecker( |
632 &pending_expectations_)); | 635 &pending_expectations_)); |
633 | 636 |
634 device_data_factory->SetDeviceData(test_motion, DeviceData::kTypeMotion); | 637 device_data_factory->SetDeviceData(test_motion, DeviceData::kTypeMotion); |
635 checker->AddExpectation(test_motion); | 638 checker->AddExpectation(test_motion); |
636 provider_->AddObserver(checker.get()); | 639 provider_->AddObserver(checker.get()); |
637 MessageLoop::current()->Run(); | 640 base::MessageLoop::current()->Run(); |
638 | 641 |
639 // The observer should receive the same motion again. | 642 // The observer should receive the same motion again. |
640 device_data_factory->SetDeviceData(test_motion, DeviceData::kTypeMotion); | 643 device_data_factory->SetDeviceData(test_motion, DeviceData::kTypeMotion); |
641 checker->AddExpectation(test_motion); | 644 checker->AddExpectation(test_motion); |
642 MessageLoop::current()->Run(); | 645 base::MessageLoop::current()->Run(); |
643 | 646 |
644 provider_->RemoveObserver(checker.get()); | 647 provider_->RemoveObserver(checker.get()); |
645 MockDeviceDataFactory::SetCurInstance(NULL); | 648 MockDeviceDataFactory::SetCurInstance(NULL); |
646 } | 649 } |
647 | 650 |
648 // Tests that Orientation events only fire if the change is significant. | 651 // Tests that Orientation events only fire if the change is significant. |
649 TEST_F(DeviceOrientationProviderTest, OrientationSignificantlyDifferent) { | 652 TEST_F(DeviceOrientationProviderTest, OrientationSignificantlyDifferent) { |
650 scoped_refptr<MockDeviceDataFactory> device_data_factory( | 653 scoped_refptr<MockDeviceDataFactory> device_data_factory( |
651 new MockDeviceDataFactory()); | 654 new MockDeviceDataFactory()); |
652 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); | 655 MockDeviceDataFactory::SetCurInstance(device_data_factory.get()); |
(...skipping 25 matching lines...) Expand all Loading... |
678 | 681 |
679 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( | 682 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
680 &pending_expectations_)); | 683 &pending_expectations_)); |
681 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( | 684 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
682 &pending_expectations_)); | 685 &pending_expectations_)); |
683 | 686 |
684 device_data_factory->SetDeviceData(first_orientation, | 687 device_data_factory->SetDeviceData(first_orientation, |
685 DeviceData::kTypeOrientation); | 688 DeviceData::kTypeOrientation); |
686 checker_a->AddExpectation(first_orientation); | 689 checker_a->AddExpectation(first_orientation); |
687 provider_->AddObserver(checker_a.get()); | 690 provider_->AddObserver(checker_a.get()); |
688 MessageLoop::current()->Run(); | 691 base::MessageLoop::current()->Run(); |
689 | 692 |
690 // The observers should not see this insignificantly different orientation. | 693 // The observers should not see this insignificantly different orientation. |
691 device_data_factory->SetDeviceData(second_orientation, | 694 device_data_factory->SetDeviceData(second_orientation, |
692 DeviceData::kTypeOrientation); | 695 DeviceData::kTypeOrientation); |
693 checker_b->AddExpectation(first_orientation); | 696 checker_b->AddExpectation(first_orientation); |
694 provider_->AddObserver(checker_b.get()); | 697 provider_->AddObserver(checker_b.get()); |
695 MessageLoop::current()->Run(); | 698 base::MessageLoop::current()->Run(); |
696 | 699 |
697 device_data_factory->SetDeviceData(third_orientation, | 700 device_data_factory->SetDeviceData(third_orientation, |
698 DeviceData::kTypeOrientation); | 701 DeviceData::kTypeOrientation); |
699 checker_a->AddExpectation(third_orientation); | 702 checker_a->AddExpectation(third_orientation); |
700 checker_b->AddExpectation(third_orientation); | 703 checker_b->AddExpectation(third_orientation); |
701 MessageLoop::current()->Run(); | 704 base::MessageLoop::current()->Run(); |
702 | 705 |
703 provider_->RemoveObserver(checker_a.get()); | 706 provider_->RemoveObserver(checker_a.get()); |
704 provider_->RemoveObserver(checker_b.get()); | 707 provider_->RemoveObserver(checker_b.get()); |
705 MockDeviceDataFactory::SetCurInstance(NULL); | 708 MockDeviceDataFactory::SetCurInstance(NULL); |
706 } | 709 } |
707 | 710 |
708 } // namespace | 711 } // namespace |
709 | 712 |
710 } // namespace content | 713 } // namespace content |
OLD | NEW |