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

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

Issue 10835030: device_orientation::ProviderImpl to stop polling thread asynchronously (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
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
« no previous file with comments | « content/browser/device_orientation/provider_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
@@ -312,6 +324,8 @@
orientation_factory->SetOrientation(test_orientation2);
MessageLoop::current()->Run();
+ MockOrientationFactory::SetCurInstance(NULL);
+
// Note that checker is not removed. This should not be a problem.
}
@@ -324,6 +338,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 +366,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 +405,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 +462,7 @@
provider_->RemoveObserver(checker_a.get());
provider_->RemoveObserver(checker_b.get());
+ MockOrientationFactory::SetCurInstance(NULL);
}
} // namespace
« no previous file with comments | « content/browser/device_orientation/provider_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698