Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(941)

Unified Diff: content/browser/device_orientation/provider_unittest.cc

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moves construction of DeviceData objects out of ProviderImpl Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..828e29986d2a091d03ed43ab575c98c8e918d095 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,40 @@ 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)
+ explicit OrientationUpdateChecker(int* expectations_count_ptr)
: 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) {
ASSERT_FALSE(expectations_queue_.empty());
+ const Orientation* orientation = static_cast<const Orientation*>(
+ device_data);
+ const Orientation empty_orientation;
+ if (orientation == NULL)
+ orientation = &empty_orientation;
+
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 +110,14 @@ 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::DeviceDataType 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 +141,9 @@ class FailingDataFetcher : public DataFetcher {
}
// From DataFetcher.
- virtual bool GetOrientation(Orientation* orientation) {
- return false;
+ virtual DeviceData* GetDeviceData(
+ DeviceData::DeviceDataType device_data_type) {
+ return NULL;
}
private:
@@ -184,10 +194,10 @@ 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());
provider_->AddObserver(checker_a.get());
@@ -217,7 +227,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 +259,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 +313,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 +343,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);
@@ -370,9 +382,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 +431,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_));

Powered by Google App Engine
This is Rietveld 408576698