Index: content/browser/device_orientation/provider_unittest.cc |
diff --git a/content/browser/device_orientation/provider_unittest.cc b/content/browser/device_orientation/provider_unittest.cc |
index be49dfde9cb38265dacdb7f187ac33b570882ccc..eaf9739c619c34e86cb09b37e6646300cf7367f8 100644 |
--- a/content/browser/device_orientation/provider_unittest.cc |
+++ b/content/browser/device_orientation/provider_unittest.cc |
@@ -7,6 +7,7 @@ |
#include "base/message_loop.h" |
#include "base/synchronization/lock.h" |
#include "content/browser/device_orientation/data_fetcher.h" |
+#include "content/browser/device_orientation/device_data.h" |
#include "content/browser/device_orientation/orientation.h" |
#include "content/browser/device_orientation/provider.h" |
#include "content/browser/device_orientation/provider_impl.h" |
@@ -16,34 +17,44 @@ namespace device_orientation { |
namespace { |
// Class for checking expectations on orientation updates from the Provider. |
-class UpdateChecker : public Provider::Observer { |
+class OrientationUpdateChecker : public Provider::Observer { |
public: |
- explicit UpdateChecker(int* expectations_count_ptr) |
- : expectations_count_ptr_(expectations_count_ptr) { |
+ explicit OrientationUpdateChecker(int* expectations_count_ptr) |
+ : Observer(DeviceData::kTypeOrientation), |
+ expectations_count_ptr_(expectations_count_ptr) { |
} |
- virtual ~UpdateChecker() {} |
+ virtual ~OrientationUpdateChecker() {} |
// From Provider::Observer. |
- virtual void OnOrientationUpdate(const Orientation& orientation) { |
+ virtual void OnDeviceDataUpdate(const DeviceData* device_data, |
+ DeviceData::Type device_data_type) { |
ASSERT_FALSE(expectations_queue_.empty()); |
+ const Orientation* orientation = static_cast<const Orientation*>( |
+ device_data); |
+ const Orientation empty_orientation; |
+ if (orientation == NULL && device_data_type == DeviceData::kTypeOrientation) |
+ orientation = &empty_orientation; |
+ else |
+ ASSERT_FALSE(orientation == NULL); |
+ |
Orientation expected = expectations_queue_.front(); |
expectations_queue_.pop(); |
- EXPECT_EQ(expected.can_provide_alpha(), orientation.can_provide_alpha()); |
- EXPECT_EQ(expected.can_provide_beta(), orientation.can_provide_beta()); |
- EXPECT_EQ(expected.can_provide_gamma(), orientation.can_provide_gamma()); |
+ EXPECT_EQ(expected.can_provide_alpha(), orientation->can_provide_alpha()); |
+ EXPECT_EQ(expected.can_provide_beta(), orientation->can_provide_beta()); |
+ EXPECT_EQ(expected.can_provide_gamma(), orientation->can_provide_gamma()); |
EXPECT_EQ(expected.can_provide_absolute(), |
- orientation.can_provide_absolute()); |
+ orientation->can_provide_absolute()); |
if (expected.can_provide_alpha()) |
- EXPECT_EQ(expected.alpha(), orientation.alpha()); |
+ EXPECT_EQ(expected.alpha(), orientation->alpha()); |
if (expected.can_provide_beta()) |
- EXPECT_EQ(expected.beta(), orientation.beta()); |
+ EXPECT_EQ(expected.beta(), orientation->beta()); |
if (expected.can_provide_gamma()) |
- EXPECT_EQ(expected.gamma(), orientation.gamma()); |
+ EXPECT_EQ(expected.gamma(), orientation->gamma()); |
if (expected.can_provide_absolute()) |
- EXPECT_EQ(expected.absolute(), orientation.absolute()); |
+ EXPECT_EQ(expected.absolute(), orientation->absolute()); |
--(*expectations_count_ptr_); |
@@ -103,12 +114,13 @@ class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { |
: orientation_factory_(orientation_factory) { } |
// From DataFetcher. Called by the Provider. |
- virtual bool GetOrientation(Orientation* orientation) { |
+ virtual DeviceData* GetDeviceData(DeviceData::Type device_data_type) { |
base::AutoLock auto_lock(orientation_factory_->lock_); |
if (orientation_factory_->is_failing_) |
- return false; |
+ return NULL; |
+ scoped_ptr<Orientation> orientation(new Orientation()); |
*orientation = orientation_factory_->orientation_; |
- return true; |
+ return orientation.release(); |
} |
private: |
@@ -132,8 +144,8 @@ class FailingDataFetcher : public DataFetcher { |
} |
// From DataFetcher. |
- virtual bool GetOrientation(Orientation* orientation) { |
- return false; |
+ virtual DeviceData* GetDeviceData(DeviceData::Type device_data_type) { |
+ return NULL; |
} |
private: |
@@ -184,16 +196,16 @@ class DeviceOrientationProviderTest : public testing::Test { |
TEST_F(DeviceOrientationProviderTest, FailingTest) { |
Init(FailingDataFetcher::Create); |
- scoped_ptr<UpdateChecker> checker_a( |
- new UpdateChecker(&pending_expectations_)); |
- scoped_ptr<UpdateChecker> checker_b( |
- new UpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker_a( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker_b( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
- checker_a->AddExpectation(Orientation::Empty()); |
+ checker_a->AddExpectation(Orientation()); |
provider_->AddObserver(checker_a.get()); |
MessageLoop::current()->Run(); |
- checker_b->AddExpectation(Orientation::Empty()); |
+ checker_b->AddExpectation(Orientation()); |
provider_->AddObserver(checker_b.get()); |
MessageLoop::current()->Run(); |
} |
@@ -217,7 +229,8 @@ TEST_F(DeviceOrientationProviderTest, BasicPushTest) { |
test_orientation.set_gamma(3); |
test_orientation.set_absolute(true); |
- scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
checker->AddExpectation(test_orientation); |
orientation_factory->SetOrientation(test_orientation); |
provider_->AddObserver(checker.get()); |
@@ -248,12 +261,12 @@ TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { |
test_orientations[2].set_gamma(9); |
// can't provide absolute |
- scoped_ptr<UpdateChecker> checker_a( |
- new UpdateChecker(&pending_expectations_)); |
- scoped_ptr<UpdateChecker> checker_b( |
- new UpdateChecker(&pending_expectations_)); |
- scoped_ptr<UpdateChecker> checker_c( |
- new UpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker_a( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker_b( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker_c( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
checker_a->AddExpectation(test_orientations[0]); |
orientation_factory->SetOrientation(test_orientations[0]); |
@@ -302,7 +315,8 @@ TEST_F(DeviceOrientationProviderTest, MAYBE_ObserverNotRemoved) { |
test_orientation2.set_gamma(6); |
test_orientation2.set_absolute(false); |
- scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); |
+ scoped_ptr<OrientationUpdateChecker> checker( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
checker->AddExpectation(test_orientation); |
orientation_factory->SetOrientation(test_orientation); |
provider_->AddObserver(checker.get()); |
@@ -331,9 +345,9 @@ TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
test_orientation.set_gamma(3); |
test_orientation.set_absolute(true); |
- scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( |
+ scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
&pending_expectations_)); |
- scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( |
+ scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
&pending_expectations_)); |
orientation_factory->SetOrientation(test_orientation); |
@@ -341,11 +355,11 @@ TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
provider_->AddObserver(checker_a.get()); |
MessageLoop::current()->Run(); |
- checker_a->AddExpectation(Orientation::Empty()); |
+ checker_a->AddExpectation(Orientation()); |
orientation_factory->SetFailing(true); |
MessageLoop::current()->Run(); |
- checker_b->AddExpectation(Orientation::Empty()); |
+ checker_b->AddExpectation(Orientation()); |
provider_->AddObserver(checker_b.get()); |
MessageLoop::current()->Run(); |
@@ -370,9 +384,9 @@ TEST_F(DeviceOrientationProviderTest, StartStopStart) { |
test_orientation2.set_gamma(6); |
test_orientation2.set_absolute(false); |
- scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( |
+ scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
&pending_expectations_)); |
- scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( |
+ scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
&pending_expectations_)); |
checker_a->AddExpectation(test_orientation); |
@@ -419,9 +433,9 @@ TEST_F(DeviceOrientationProviderTest, SignificantlyDifferent) { |
third_orientation.set_gamma(kGamma + kSignificantDifference); |
// can't provide absolute |
- scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( |
+ scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
&pending_expectations_)); |
- scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( |
+ scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
&pending_expectations_)); |