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

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: 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..e483000d4c3a73a41ab6df782ad58b2489fd0955 100644
--- a/content/browser/device_orientation/provider_unittest.cc
+++ b/content/browser/device_orientation/provider_unittest.cc
@@ -16,18 +16,20 @@ 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);
Orientation expected = expectations_queue_.front();
expectations_queue_.pop();
@@ -103,10 +105,11 @@ class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> {
: orientation_factory_(orientation_factory) { }
// From DataFetcher. Called by the Provider.
- virtual bool GetOrientation(Orientation* orientation) {
+ virtual bool GetDeviceData(DeviceData* device_data) {
base::AutoLock auto_lock(orientation_factory_->lock_);
if (orientation_factory_->is_failing_)
return false;
+ Orientation* orientation = static_cast<Orientation*>(device_data);
*orientation = orientation_factory_->orientation_;
return true;
}
@@ -132,7 +135,7 @@ class FailingDataFetcher : public DataFetcher {
}
// From DataFetcher.
- virtual bool GetOrientation(Orientation* orientation) {
+ virtual bool GetDeviceData(DeviceData* device_data) {
return false;
}
@@ -184,10 +187,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 +220,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 +252,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 +306,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 +336,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 +375,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 +424,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