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..ffeb0fcf9929d267b069936471faa8d4ffaf4d7e 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,43 @@ 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()); |
- Orientation expected = expectations_queue_.front(); |
+ scoped_refptr<const Orientation> orientation( |
+ static_cast<const Orientation*>(device_data)); |
+ if (orientation == NULL && device_data_type == DeviceData::kTypeOrientation) |
+ orientation = new Orientation(); |
+ else |
+ ASSERT_FALSE(orientation == NULL); |
+ |
+ scoped_refptr<const 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_absolute(), |
- orientation.can_provide_absolute()); |
- if (expected.can_provide_alpha()) |
- EXPECT_EQ(expected.alpha(), orientation.alpha()); |
- if (expected.can_provide_beta()) |
- EXPECT_EQ(expected.beta(), orientation.beta()); |
- if (expected.can_provide_gamma()) |
- EXPECT_EQ(expected.gamma(), orientation.gamma()); |
- if (expected.can_provide_absolute()) |
- EXPECT_EQ(expected.absolute(), orientation.absolute()); |
+ 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()); |
+ if (expected->can_provide_alpha()) |
+ EXPECT_EQ(expected->alpha(), orientation->alpha()); |
+ if (expected->can_provide_beta()) |
+ EXPECT_EQ(expected->beta(), orientation->beta()); |
+ if (expected->can_provide_gamma()) |
+ EXPECT_EQ(expected->gamma(), orientation->gamma()); |
+ if (expected->can_provide_absolute()) |
+ EXPECT_EQ(expected->absolute(), orientation->absolute()); |
--(*expectations_count_ptr_); |
@@ -52,8 +62,9 @@ class UpdateChecker : public Provider::Observer { |
} |
} |
- void AddExpectation(const Orientation& orientation) { |
- expectations_queue_.push(orientation); |
+ void AddExpectation(const Orientation* orientation) { |
+ scoped_refptr<const Orientation> expected_orientation(orientation); |
+ expectations_queue_.push(expected_orientation); |
++(*expectations_count_ptr_); |
} |
@@ -62,7 +73,7 @@ class UpdateChecker : public Provider::Observer { |
// from OnOrientationUpdate which is executed on the test fixture's |
// message_loop_. |
int* expectations_count_ptr_; |
- std::queue<Orientation> expectations_queue_; |
+ std::queue<scoped_refptr<const Orientation> > expectations_queue_; |
}; |
// Class for injecting test orientation data into the Provider. |
@@ -79,7 +90,7 @@ class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { |
return new MockDataFetcher(instance_); |
} |
- void SetOrientation(const Orientation& orientation) { |
+ void SetOrientation(const Orientation* orientation) { |
base::AutoLock auto_lock(lock_); |
orientation_ = orientation; |
} |
@@ -103,12 +114,11 @@ class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { |
: orientation_factory_(orientation_factory) { } |
// From DataFetcher. Called by the Provider. |
- virtual bool GetOrientation(Orientation* orientation) { |
+ virtual const DeviceData* GetDeviceData(DeviceData::Type device_data_type) { |
base::AutoLock auto_lock(orientation_factory_->lock_); |
if (orientation_factory_->is_failing_) |
- return false; |
- *orientation = orientation_factory_->orientation_; |
- return true; |
+ return NULL; |
+ return orientation_factory_->orientation_; |
} |
private: |
@@ -116,7 +126,7 @@ class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { |
}; |
static MockOrientationFactory* instance_; |
- Orientation orientation_; |
+ scoped_refptr<const Orientation> orientation_; |
bool is_failing_; |
base::Lock lock_; |
}; |
@@ -132,8 +142,8 @@ class FailingDataFetcher : public DataFetcher { |
} |
// From DataFetcher. |
- virtual bool GetOrientation(Orientation* orientation) { |
- return false; |
+ virtual const DeviceData* GetDeviceData(DeviceData::Type device_data_type) { |
+ return NULL; |
} |
private: |
@@ -184,16 +194,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(new Orientation()); |
provider_->AddObserver(checker_a.get()); |
MessageLoop::current()->Run(); |
- checker_b->AddExpectation(Orientation::Empty()); |
+ checker_b->AddExpectation(new Orientation()); |
provider_->AddObserver(checker_b.get()); |
MessageLoop::current()->Run(); |
} |
@@ -211,13 +221,14 @@ TEST_F(DeviceOrientationProviderTest, BasicPushTest) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
Init(MockOrientationFactory::CreateDataFetcher); |
- Orientation test_orientation; |
- test_orientation.set_alpha(1); |
- test_orientation.set_beta(2); |
- test_orientation.set_gamma(3); |
- test_orientation.set_absolute(true); |
- |
- scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); |
+ scoped_refptr<Orientation> test_orientation(new Orientation()); |
+ test_orientation->set_alpha(1); |
+ test_orientation->set_beta(2); |
+ test_orientation->set_gamma(3); |
+ test_orientation->set_absolute(true); |
+ |
+ scoped_ptr<OrientationUpdateChecker> checker( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
checker->AddExpectation(test_orientation); |
orientation_factory->SetOrientation(test_orientation); |
provider_->AddObserver(checker.get()); |
@@ -231,29 +242,29 @@ TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { |
new MockOrientationFactory()); |
Init(MockOrientationFactory::CreateDataFetcher); |
- Orientation test_orientations[] = {Orientation(), Orientation(), |
- Orientation()}; |
- test_orientations[0].set_alpha(1); |
- test_orientations[0].set_beta(2); |
- test_orientations[0].set_gamma(3); |
- test_orientations[0].set_absolute(true); |
- |
- test_orientations[1].set_alpha(4); |
- test_orientations[1].set_beta(5); |
- test_orientations[1].set_gamma(6); |
- test_orientations[1].set_absolute(false); |
- |
- test_orientations[2].set_alpha(7); |
- test_orientations[2].set_beta(8); |
- test_orientations[2].set_gamma(9); |
+ scoped_refptr<Orientation> test_orientations[] = {new Orientation(), |
+ new Orientation(), new Orientation()}; |
+ test_orientations[0]->set_alpha(1); |
+ test_orientations[0]->set_beta(2); |
+ test_orientations[0]->set_gamma(3); |
+ test_orientations[0]->set_absolute(true); |
+ |
+ test_orientations[1]->set_alpha(4); |
+ test_orientations[1]->set_beta(5); |
+ test_orientations[1]->set_gamma(6); |
+ test_orientations[1]->set_absolute(false); |
+ |
+ test_orientations[2]->set_alpha(7); |
+ test_orientations[2]->set_beta(8); |
+ 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]); |
@@ -290,19 +301,20 @@ TEST_F(DeviceOrientationProviderTest, MAYBE_ObserverNotRemoved) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
Init(MockOrientationFactory::CreateDataFetcher); |
- Orientation test_orientation; |
- test_orientation.set_alpha(1); |
- test_orientation.set_beta(2); |
- test_orientation.set_gamma(3); |
- test_orientation.set_absolute(true); |
- |
- Orientation test_orientation2; |
- test_orientation2.set_alpha(4); |
- test_orientation2.set_beta(5); |
- test_orientation2.set_gamma(6); |
- test_orientation2.set_absolute(false); |
- |
- scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); |
+ scoped_refptr<Orientation> test_orientation(new Orientation()); |
+ test_orientation->set_alpha(1); |
+ test_orientation->set_beta(2); |
+ test_orientation->set_gamma(3); |
+ test_orientation->set_absolute(true); |
+ |
+ scoped_refptr<Orientation> test_orientation2(new Orientation()); |
+ test_orientation2->set_alpha(4); |
+ test_orientation2->set_beta(5); |
+ test_orientation2->set_gamma(6); |
+ test_orientation2->set_absolute(false); |
+ |
+ scoped_ptr<OrientationUpdateChecker> checker( |
+ new OrientationUpdateChecker(&pending_expectations_)); |
checker->AddExpectation(test_orientation); |
orientation_factory->SetOrientation(test_orientation); |
provider_->AddObserver(checker.get()); |
@@ -325,15 +337,15 @@ TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
Init(MockOrientationFactory::CreateDataFetcher); |
- Orientation test_orientation; |
- test_orientation.set_alpha(1); |
- test_orientation.set_beta(2); |
- test_orientation.set_gamma(3); |
- test_orientation.set_absolute(true); |
+ scoped_refptr<Orientation> test_orientation(new Orientation()); |
+ test_orientation->set_alpha(1); |
+ test_orientation->set_beta(2); |
+ 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 +353,11 @@ TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
provider_->AddObserver(checker_a.get()); |
MessageLoop::current()->Run(); |
- checker_a->AddExpectation(Orientation::Empty()); |
+ checker_a->AddExpectation(new Orientation()); |
orientation_factory->SetFailing(true); |
MessageLoop::current()->Run(); |
- checker_b->AddExpectation(Orientation::Empty()); |
+ checker_b->AddExpectation(new Orientation()); |
provider_->AddObserver(checker_b.get()); |
MessageLoop::current()->Run(); |
@@ -358,21 +370,21 @@ TEST_F(DeviceOrientationProviderTest, StartStopStart) { |
new MockOrientationFactory()); |
Init(MockOrientationFactory::CreateDataFetcher); |
- Orientation test_orientation; |
- test_orientation.set_alpha(1); |
- test_orientation.set_beta(2); |
- test_orientation.set_gamma(3); |
- test_orientation.set_absolute(true); |
+ scoped_refptr<Orientation> test_orientation(new Orientation()); |
+ test_orientation->set_alpha(1); |
+ test_orientation->set_beta(2); |
+ test_orientation->set_gamma(3); |
+ test_orientation->set_absolute(true); |
- Orientation test_orientation2; |
- test_orientation2.set_alpha(4); |
- test_orientation2.set_beta(5); |
- test_orientation2.set_gamma(6); |
- test_orientation2.set_absolute(false); |
+ scoped_refptr<Orientation> test_orientation2(new Orientation()); |
+ test_orientation2->set_alpha(4); |
+ test_orientation2->set_beta(5); |
+ 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); |
@@ -401,30 +413,29 @@ TEST_F(DeviceOrientationProviderTest, SignificantlyDifferent) { |
const double kSignificantDifference = 30; |
const double kAlpha = 4, kBeta = 5, kGamma = 6; |
- Orientation first_orientation; |
- first_orientation.set_alpha(kAlpha); |
- first_orientation.set_beta(kBeta); |
- first_orientation.set_gamma(kGamma); |
- first_orientation.set_absolute(true); |
- |
- Orientation second_orientation; |
- second_orientation.set_alpha(kAlpha + kInsignificantDifference); |
- second_orientation.set_beta(kBeta + kInsignificantDifference); |
- second_orientation.set_gamma(kGamma + kInsignificantDifference); |
- second_orientation.set_absolute(false); |
- |
- Orientation third_orientation; |
- third_orientation.set_alpha(kAlpha + kSignificantDifference); |
- third_orientation.set_beta(kBeta + kSignificantDifference); |
- third_orientation.set_gamma(kGamma + kSignificantDifference); |
+ scoped_refptr<Orientation> first_orientation(new Orientation()); |
+ first_orientation->set_alpha(kAlpha); |
+ first_orientation->set_beta(kBeta); |
+ first_orientation->set_gamma(kGamma); |
+ first_orientation->set_absolute(true); |
+ |
+ scoped_refptr<Orientation> second_orientation(new Orientation()); |
+ second_orientation->set_alpha(kAlpha + kInsignificantDifference); |
+ second_orientation->set_beta(kBeta + kInsignificantDifference); |
+ second_orientation->set_gamma(kGamma + kInsignificantDifference); |
+ second_orientation->set_absolute(false); |
+ |
+ scoped_refptr<Orientation> third_orientation(new Orientation()); |
+ third_orientation->set_alpha(kAlpha + kSignificantDifference); |
+ third_orientation->set_beta(kBeta + kSignificantDifference); |
+ 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_)); |
- |
orientation_factory->SetOrientation(first_orientation); |
checker_a->AddExpectation(first_orientation); |
provider_->AddObserver(checker_a.get()); |