Index: content/browser/device_orientation/provider_unittest.cc |
=================================================================== |
--- content/browser/device_orientation/provider_unittest.cc (revision 148849) |
+++ content/browser/device_orientation/provider_unittest.cc (working copy) |
@@ -70,10 +70,18 @@ |
public: |
MockOrientationFactory() |
: is_failing_(false) { |
- EXPECT_FALSE(instance_); |
- instance_ = this; |
} |
+ static void SetCurInstance(MockOrientationFactory* instance) { |
+ if (instance) { |
+ EXPECT_FALSE(instance_); |
+ } |
+ else { |
+ EXPECT_TRUE(instance_); |
+ } |
+ instance_ = instance; |
+ } |
+ |
static DataFetcher* CreateDataFetcher() { |
EXPECT_TRUE(instance_); |
return new MockDataFetcher(instance_); |
@@ -93,7 +101,6 @@ |
friend class base::RefCounted<MockOrientationFactory>; |
~MockOrientationFactory() { |
- instance_ = NULL; |
} |
// Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. |
@@ -210,6 +217,7 @@ |
TEST_F(DeviceOrientationProviderTest, BasicPushTest) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
+ MockOrientationFactory::SetCurInstance(orientation_factory.get()); |
Init(MockOrientationFactory::CreateDataFetcher); |
Orientation test_orientation; |
test_orientation.set_alpha(1); |
@@ -224,11 +232,13 @@ |
MessageLoop::current()->Run(); |
provider_->RemoveObserver(checker.get()); |
+ MockOrientationFactory::SetCurInstance(NULL); |
} |
TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
+ MockOrientationFactory::SetCurInstance(orientation_factory.get()); |
Init(MockOrientationFactory::CreateDataFetcher); |
Orientation test_orientations[] = {Orientation(), Orientation(), |
@@ -277,6 +287,7 @@ |
provider_->RemoveObserver(checker_b.get()); |
provider_->RemoveObserver(checker_c.get()); |
+ MockOrientationFactory::SetCurInstance(NULL); |
} |
#if defined(OS_LINUX) || defined(OS_WIN) |
@@ -289,6 +300,7 @@ |
TEST_F(DeviceOrientationProviderTest, MAYBE_ObserverNotRemoved) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
+ MockOrientationFactory::SetCurInstance(orientation_factory.get()); |
Init(MockOrientationFactory::CreateDataFetcher); |
Orientation test_orientation; |
test_orientation.set_alpha(1); |
@@ -313,6 +325,7 @@ |
MessageLoop::current()->Run(); |
// Note that checker is not removed. This should not be a problem. |
+ MockOrientationFactory::SetCurInstance(NULL); |
hans
2012/07/30 12:56:40
maybe insert a blank line before this, so it doesn
|
} |
#if defined(OS_WIN) |
@@ -324,6 +337,7 @@ |
TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
+ MockOrientationFactory::SetCurInstance(orientation_factory.get()); |
Init(MockOrientationFactory::CreateDataFetcher); |
Orientation test_orientation; |
test_orientation.set_alpha(1); |
@@ -351,11 +365,13 @@ |
provider_->RemoveObserver(checker_a.get()); |
provider_->RemoveObserver(checker_b.get()); |
+ MockOrientationFactory::SetCurInstance(NULL); |
} |
TEST_F(DeviceOrientationProviderTest, StartStopStart) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
+ MockOrientationFactory::SetCurInstance(orientation_factory.get()); |
Init(MockOrientationFactory::CreateDataFetcher); |
Orientation test_orientation; |
@@ -388,11 +404,13 @@ |
MessageLoop::current()->Run(); |
provider_->RemoveObserver(checker_b.get()); |
+ MockOrientationFactory::SetCurInstance(NULL); |
} |
TEST_F(DeviceOrientationProviderTest, SignificantlyDifferent) { |
scoped_refptr<MockOrientationFactory> orientation_factory( |
new MockOrientationFactory()); |
+ MockOrientationFactory::SetCurInstance(orientation_factory.get()); |
Init(MockOrientationFactory::CreateDataFetcher); |
// Values that should be well below or above the implementation's |
@@ -443,6 +461,7 @@ |
provider_->RemoveObserver(checker_a.get()); |
provider_->RemoveObserver(checker_b.get()); |
+ MockOrientationFactory::SetCurInstance(NULL); |
} |
} // namespace |