| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <queue> | 5 #include <queue> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "content/browser/device_orientation/data_fetcher.h" | 9 #include "content/browser/device_orientation/data_fetcher.h" |
| 10 #include "content/browser/device_orientation/device_data.h" |
| 10 #include "content/browser/device_orientation/orientation.h" | 11 #include "content/browser/device_orientation/orientation.h" |
| 11 #include "content/browser/device_orientation/provider.h" | 12 #include "content/browser/device_orientation/provider.h" |
| 12 #include "content/browser/device_orientation/provider_impl.h" | 13 #include "content/browser/device_orientation/provider_impl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace device_orientation { | 16 namespace device_orientation { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Class for checking expectations on orientation updates from the Provider. | 19 // Class for checking expectations on orientation updates from the Provider. |
| 19 class UpdateChecker : public Provider::Observer { | 20 class OrientationUpdateChecker : public Provider::Observer { |
| 20 public: | 21 public: |
| 21 explicit UpdateChecker(int* expectations_count_ptr) | 22 explicit OrientationUpdateChecker(int* expectations_count_ptr) |
| 22 : expectations_count_ptr_(expectations_count_ptr) { | 23 : expectations_count_ptr_(expectations_count_ptr) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 virtual ~UpdateChecker() {} | 26 virtual ~OrientationUpdateChecker() {} |
| 26 | 27 |
| 27 // From Provider::Observer. | 28 // From Provider::Observer. |
| 28 virtual void OnOrientationUpdate(const Orientation& orientation) { | 29 virtual void OnDeviceDataUpdate(const DeviceData* device_data) { |
| 29 ASSERT_FALSE(expectations_queue_.empty()); | 30 ASSERT_FALSE(expectations_queue_.empty()); |
| 30 | 31 |
| 32 const Orientation* orientation = static_cast<const Orientation*>( |
| 33 device_data); |
| 34 const Orientation empty_orientation; |
| 35 if (orientation == NULL) |
| 36 orientation = &empty_orientation; |
| 37 |
| 31 Orientation expected = expectations_queue_.front(); | 38 Orientation expected = expectations_queue_.front(); |
| 32 expectations_queue_.pop(); | 39 expectations_queue_.pop(); |
| 33 | 40 |
| 34 EXPECT_EQ(expected.can_provide_alpha(), orientation.can_provide_alpha()); | 41 EXPECT_EQ(expected.can_provide_alpha(), orientation->can_provide_alpha()); |
| 35 EXPECT_EQ(expected.can_provide_beta(), orientation.can_provide_beta()); | 42 EXPECT_EQ(expected.can_provide_beta(), orientation->can_provide_beta()); |
| 36 EXPECT_EQ(expected.can_provide_gamma(), orientation.can_provide_gamma()); | 43 EXPECT_EQ(expected.can_provide_gamma(), orientation->can_provide_gamma()); |
| 37 EXPECT_EQ(expected.can_provide_absolute(), | 44 EXPECT_EQ(expected.can_provide_absolute(), |
| 38 orientation.can_provide_absolute()); | 45 orientation->can_provide_absolute()); |
| 39 if (expected.can_provide_alpha()) | 46 if (expected.can_provide_alpha()) |
| 40 EXPECT_EQ(expected.alpha(), orientation.alpha()); | 47 EXPECT_EQ(expected.alpha(), orientation->alpha()); |
| 41 if (expected.can_provide_beta()) | 48 if (expected.can_provide_beta()) |
| 42 EXPECT_EQ(expected.beta(), orientation.beta()); | 49 EXPECT_EQ(expected.beta(), orientation->beta()); |
| 43 if (expected.can_provide_gamma()) | 50 if (expected.can_provide_gamma()) |
| 44 EXPECT_EQ(expected.gamma(), orientation.gamma()); | 51 EXPECT_EQ(expected.gamma(), orientation->gamma()); |
| 45 if (expected.can_provide_absolute()) | 52 if (expected.can_provide_absolute()) |
| 46 EXPECT_EQ(expected.absolute(), orientation.absolute()); | 53 EXPECT_EQ(expected.absolute(), orientation->absolute()); |
| 47 | 54 |
| 48 --(*expectations_count_ptr_); | 55 --(*expectations_count_ptr_); |
| 49 | 56 |
| 50 if (*expectations_count_ptr_ == 0) { | 57 if (*expectations_count_ptr_ == 0) { |
| 51 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 58 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 52 } | 59 } |
| 53 } | 60 } |
| 54 | 61 |
| 55 void AddExpectation(const Orientation& orientation) { | 62 void AddExpectation(const Orientation& orientation) { |
| 56 expectations_queue_.push(orientation); | 63 expectations_queue_.push(orientation); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 instance_ = NULL; | 103 instance_ = NULL; |
| 97 } | 104 } |
| 98 | 105 |
| 99 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. | 106 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. |
| 100 class MockDataFetcher : public DataFetcher { | 107 class MockDataFetcher : public DataFetcher { |
| 101 public: | 108 public: |
| 102 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) | 109 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) |
| 103 : orientation_factory_(orientation_factory) { } | 110 : orientation_factory_(orientation_factory) { } |
| 104 | 111 |
| 105 // From DataFetcher. Called by the Provider. | 112 // From DataFetcher. Called by the Provider. |
| 106 virtual bool GetOrientation(Orientation* orientation) { | 113 virtual DeviceData* GetDeviceData( |
| 114 DeviceData::DeviceDataType device_data_type) { |
| 107 base::AutoLock auto_lock(orientation_factory_->lock_); | 115 base::AutoLock auto_lock(orientation_factory_->lock_); |
| 108 if (orientation_factory_->is_failing_) | 116 if (orientation_factory_->is_failing_) |
| 109 return false; | 117 return NULL; |
| 118 scoped_ptr<Orientation> orientation(new Orientation()); |
| 110 *orientation = orientation_factory_->orientation_; | 119 *orientation = orientation_factory_->orientation_; |
| 111 return true; | 120 return orientation.release(); |
| 112 } | 121 } |
| 113 | 122 |
| 114 private: | 123 private: |
| 115 scoped_refptr<MockOrientationFactory> orientation_factory_; | 124 scoped_refptr<MockOrientationFactory> orientation_factory_; |
| 116 }; | 125 }; |
| 117 | 126 |
| 118 static MockOrientationFactory* instance_; | 127 static MockOrientationFactory* instance_; |
| 119 Orientation orientation_; | 128 Orientation orientation_; |
| 120 bool is_failing_; | 129 bool is_failing_; |
| 121 base::Lock lock_; | 130 base::Lock lock_; |
| 122 }; | 131 }; |
| 123 | 132 |
| 124 MockOrientationFactory* MockOrientationFactory::instance_; | 133 MockOrientationFactory* MockOrientationFactory::instance_; |
| 125 | 134 |
| 126 // Mock DataFetcher that always fails to provide any orientation data. | 135 // Mock DataFetcher that always fails to provide any orientation data. |
| 127 class FailingDataFetcher : public DataFetcher { | 136 class FailingDataFetcher : public DataFetcher { |
| 128 public: | 137 public: |
| 129 // Factory method; passed to and called by the ProviderImpl. | 138 // Factory method; passed to and called by the ProviderImpl. |
| 130 static DataFetcher* Create() { | 139 static DataFetcher* Create() { |
| 131 return new FailingDataFetcher(); | 140 return new FailingDataFetcher(); |
| 132 } | 141 } |
| 133 | 142 |
| 134 // From DataFetcher. | 143 // From DataFetcher. |
| 135 virtual bool GetOrientation(Orientation* orientation) { | 144 virtual DeviceData* GetDeviceData( |
| 136 return false; | 145 DeviceData::DeviceDataType device_data_type) { |
| 146 return NULL; |
| 137 } | 147 } |
| 138 | 148 |
| 139 private: | 149 private: |
| 140 FailingDataFetcher() {} | 150 FailingDataFetcher() {} |
| 141 }; | 151 }; |
| 142 | 152 |
| 143 class DeviceOrientationProviderTest : public testing::Test { | 153 class DeviceOrientationProviderTest : public testing::Test { |
| 144 public: | 154 public: |
| 145 DeviceOrientationProviderTest() | 155 DeviceOrientationProviderTest() |
| 146 : pending_expectations_(0) { | 156 : pending_expectations_(0) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 177 // Provider instance under test. | 187 // Provider instance under test. |
| 178 scoped_refptr<Provider> provider_; | 188 scoped_refptr<Provider> provider_; |
| 179 | 189 |
| 180 // Message loop for the test thread. | 190 // Message loop for the test thread. |
| 181 MessageLoop message_loop_; | 191 MessageLoop message_loop_; |
| 182 }; | 192 }; |
| 183 | 193 |
| 184 TEST_F(DeviceOrientationProviderTest, FailingTest) { | 194 TEST_F(DeviceOrientationProviderTest, FailingTest) { |
| 185 Init(FailingDataFetcher::Create); | 195 Init(FailingDataFetcher::Create); |
| 186 | 196 |
| 187 scoped_ptr<UpdateChecker> checker_a( | 197 scoped_ptr<OrientationUpdateChecker> checker_a( |
| 188 new UpdateChecker(&pending_expectations_)); | 198 new OrientationUpdateChecker(&pending_expectations_)); |
| 189 scoped_ptr<UpdateChecker> checker_b( | 199 scoped_ptr<OrientationUpdateChecker> checker_b( |
| 190 new UpdateChecker(&pending_expectations_)); | 200 new OrientationUpdateChecker(&pending_expectations_)); |
| 191 | 201 |
| 192 checker_a->AddExpectation(Orientation::Empty()); | 202 checker_a->AddExpectation(Orientation::Empty()); |
| 193 provider_->AddObserver(checker_a.get()); | 203 provider_->AddObserver(checker_a.get()); |
| 194 MessageLoop::current()->Run(); | 204 MessageLoop::current()->Run(); |
| 195 | 205 |
| 196 checker_b->AddExpectation(Orientation::Empty()); | 206 checker_b->AddExpectation(Orientation::Empty()); |
| 197 provider_->AddObserver(checker_b.get()); | 207 provider_->AddObserver(checker_b.get()); |
| 198 MessageLoop::current()->Run(); | 208 MessageLoop::current()->Run(); |
| 199 } | 209 } |
| 200 | 210 |
| 201 TEST_F(DeviceOrientationProviderTest, ProviderIsSingleton) { | 211 TEST_F(DeviceOrientationProviderTest, ProviderIsSingleton) { |
| 202 Init(FailingDataFetcher::Create); | 212 Init(FailingDataFetcher::Create); |
| 203 | 213 |
| 204 scoped_refptr<Provider> provider_a(Provider::GetInstance()); | 214 scoped_refptr<Provider> provider_a(Provider::GetInstance()); |
| 205 scoped_refptr<Provider> provider_b(Provider::GetInstance()); | 215 scoped_refptr<Provider> provider_b(Provider::GetInstance()); |
| 206 | 216 |
| 207 EXPECT_EQ(provider_a.get(), provider_b.get()); | 217 EXPECT_EQ(provider_a.get(), provider_b.get()); |
| 208 } | 218 } |
| 209 | 219 |
| 210 TEST_F(DeviceOrientationProviderTest, BasicPushTest) { | 220 TEST_F(DeviceOrientationProviderTest, BasicPushTest) { |
| 211 scoped_refptr<MockOrientationFactory> orientation_factory( | 221 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 212 new MockOrientationFactory()); | 222 new MockOrientationFactory()); |
| 213 Init(MockOrientationFactory::CreateDataFetcher); | 223 Init(MockOrientationFactory::CreateDataFetcher); |
| 214 Orientation test_orientation; | 224 Orientation test_orientation; |
| 215 test_orientation.set_alpha(1); | 225 test_orientation.set_alpha(1); |
| 216 test_orientation.set_beta(2); | 226 test_orientation.set_beta(2); |
| 217 test_orientation.set_gamma(3); | 227 test_orientation.set_gamma(3); |
| 218 test_orientation.set_absolute(true); | 228 test_orientation.set_absolute(true); |
| 219 | 229 |
| 220 scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); | 230 scoped_ptr<OrientationUpdateChecker> checker( |
| 231 new OrientationUpdateChecker(&pending_expectations_)); |
| 221 checker->AddExpectation(test_orientation); | 232 checker->AddExpectation(test_orientation); |
| 222 orientation_factory->SetOrientation(test_orientation); | 233 orientation_factory->SetOrientation(test_orientation); |
| 223 provider_->AddObserver(checker.get()); | 234 provider_->AddObserver(checker.get()); |
| 224 MessageLoop::current()->Run(); | 235 MessageLoop::current()->Run(); |
| 225 | 236 |
| 226 provider_->RemoveObserver(checker.get()); | 237 provider_->RemoveObserver(checker.get()); |
| 227 } | 238 } |
| 228 | 239 |
| 229 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { | 240 TEST_F(DeviceOrientationProviderTest, MultipleObserversPushTest) { |
| 230 scoped_refptr<MockOrientationFactory> orientation_factory( | 241 scoped_refptr<MockOrientationFactory> orientation_factory( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 241 test_orientations[1].set_alpha(4); | 252 test_orientations[1].set_alpha(4); |
| 242 test_orientations[1].set_beta(5); | 253 test_orientations[1].set_beta(5); |
| 243 test_orientations[1].set_gamma(6); | 254 test_orientations[1].set_gamma(6); |
| 244 test_orientations[1].set_absolute(false); | 255 test_orientations[1].set_absolute(false); |
| 245 | 256 |
| 246 test_orientations[2].set_alpha(7); | 257 test_orientations[2].set_alpha(7); |
| 247 test_orientations[2].set_beta(8); | 258 test_orientations[2].set_beta(8); |
| 248 test_orientations[2].set_gamma(9); | 259 test_orientations[2].set_gamma(9); |
| 249 // can't provide absolute | 260 // can't provide absolute |
| 250 | 261 |
| 251 scoped_ptr<UpdateChecker> checker_a( | 262 scoped_ptr<OrientationUpdateChecker> checker_a( |
| 252 new UpdateChecker(&pending_expectations_)); | 263 new OrientationUpdateChecker(&pending_expectations_)); |
| 253 scoped_ptr<UpdateChecker> checker_b( | 264 scoped_ptr<OrientationUpdateChecker> checker_b( |
| 254 new UpdateChecker(&pending_expectations_)); | 265 new OrientationUpdateChecker(&pending_expectations_)); |
| 255 scoped_ptr<UpdateChecker> checker_c( | 266 scoped_ptr<OrientationUpdateChecker> checker_c( |
| 256 new UpdateChecker(&pending_expectations_)); | 267 new OrientationUpdateChecker(&pending_expectations_)); |
| 257 | 268 |
| 258 checker_a->AddExpectation(test_orientations[0]); | 269 checker_a->AddExpectation(test_orientations[0]); |
| 259 orientation_factory->SetOrientation(test_orientations[0]); | 270 orientation_factory->SetOrientation(test_orientations[0]); |
| 260 provider_->AddObserver(checker_a.get()); | 271 provider_->AddObserver(checker_a.get()); |
| 261 MessageLoop::current()->Run(); | 272 MessageLoop::current()->Run(); |
| 262 | 273 |
| 263 checker_a->AddExpectation(test_orientations[1]); | 274 checker_a->AddExpectation(test_orientations[1]); |
| 264 checker_b->AddExpectation(test_orientations[0]); | 275 checker_b->AddExpectation(test_orientations[0]); |
| 265 checker_b->AddExpectation(test_orientations[1]); | 276 checker_b->AddExpectation(test_orientations[1]); |
| 266 orientation_factory->SetOrientation(test_orientations[1]); | 277 orientation_factory->SetOrientation(test_orientations[1]); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 295 test_orientation.set_beta(2); | 306 test_orientation.set_beta(2); |
| 296 test_orientation.set_gamma(3); | 307 test_orientation.set_gamma(3); |
| 297 test_orientation.set_absolute(true); | 308 test_orientation.set_absolute(true); |
| 298 | 309 |
| 299 Orientation test_orientation2; | 310 Orientation test_orientation2; |
| 300 test_orientation2.set_alpha(4); | 311 test_orientation2.set_alpha(4); |
| 301 test_orientation2.set_beta(5); | 312 test_orientation2.set_beta(5); |
| 302 test_orientation2.set_gamma(6); | 313 test_orientation2.set_gamma(6); |
| 303 test_orientation2.set_absolute(false); | 314 test_orientation2.set_absolute(false); |
| 304 | 315 |
| 305 scoped_ptr<UpdateChecker> checker(new UpdateChecker(&pending_expectations_)); | 316 scoped_ptr<OrientationUpdateChecker> checker( |
| 317 new OrientationUpdateChecker(&pending_expectations_)); |
| 306 checker->AddExpectation(test_orientation); | 318 checker->AddExpectation(test_orientation); |
| 307 orientation_factory->SetOrientation(test_orientation); | 319 orientation_factory->SetOrientation(test_orientation); |
| 308 provider_->AddObserver(checker.get()); | 320 provider_->AddObserver(checker.get()); |
| 309 MessageLoop::current()->Run(); | 321 MessageLoop::current()->Run(); |
| 310 | 322 |
| 311 checker->AddExpectation(test_orientation2); | 323 checker->AddExpectation(test_orientation2); |
| 312 orientation_factory->SetOrientation(test_orientation2); | 324 orientation_factory->SetOrientation(test_orientation2); |
| 313 MessageLoop::current()->Run(); | 325 MessageLoop::current()->Run(); |
| 314 | 326 |
| 315 // Note that checker is not removed. This should not be a problem. | 327 // Note that checker is not removed. This should not be a problem. |
| 316 } | 328 } |
| 317 | 329 |
| 318 #if defined(OS_WIN) | 330 #if defined(OS_WIN) |
| 319 // FLAKY on Win. See crbug.com/104950. | 331 // FLAKY on Win. See crbug.com/104950. |
| 320 #define MAYBE_StartFailing DISABLED_StartFailing | 332 #define MAYBE_StartFailing DISABLED_StartFailing |
| 321 #else | 333 #else |
| 322 #define MAYBE_StartFailing StartFailing | 334 #define MAYBE_StartFailing StartFailing |
| 323 #endif | 335 #endif |
| 324 TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { | 336 TEST_F(DeviceOrientationProviderTest, MAYBE_StartFailing) { |
| 325 scoped_refptr<MockOrientationFactory> orientation_factory( | 337 scoped_refptr<MockOrientationFactory> orientation_factory( |
| 326 new MockOrientationFactory()); | 338 new MockOrientationFactory()); |
| 327 Init(MockOrientationFactory::CreateDataFetcher); | 339 Init(MockOrientationFactory::CreateDataFetcher); |
| 328 Orientation test_orientation; | 340 Orientation test_orientation; |
| 329 test_orientation.set_alpha(1); | 341 test_orientation.set_alpha(1); |
| 330 test_orientation.set_beta(2); | 342 test_orientation.set_beta(2); |
| 331 test_orientation.set_gamma(3); | 343 test_orientation.set_gamma(3); |
| 332 test_orientation.set_absolute(true); | 344 test_orientation.set_absolute(true); |
| 333 | 345 |
| 334 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( | 346 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
| 335 &pending_expectations_)); | 347 &pending_expectations_)); |
| 336 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( | 348 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
| 337 &pending_expectations_)); | 349 &pending_expectations_)); |
| 338 | 350 |
| 339 orientation_factory->SetOrientation(test_orientation); | 351 orientation_factory->SetOrientation(test_orientation); |
| 340 checker_a->AddExpectation(test_orientation); | 352 checker_a->AddExpectation(test_orientation); |
| 341 provider_->AddObserver(checker_a.get()); | 353 provider_->AddObserver(checker_a.get()); |
| 342 MessageLoop::current()->Run(); | 354 MessageLoop::current()->Run(); |
| 343 | 355 |
| 344 checker_a->AddExpectation(Orientation::Empty()); | 356 checker_a->AddExpectation(Orientation::Empty()); |
| 345 orientation_factory->SetFailing(true); | 357 orientation_factory->SetFailing(true); |
| 346 MessageLoop::current()->Run(); | 358 MessageLoop::current()->Run(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 363 test_orientation.set_beta(2); | 375 test_orientation.set_beta(2); |
| 364 test_orientation.set_gamma(3); | 376 test_orientation.set_gamma(3); |
| 365 test_orientation.set_absolute(true); | 377 test_orientation.set_absolute(true); |
| 366 | 378 |
| 367 Orientation test_orientation2; | 379 Orientation test_orientation2; |
| 368 test_orientation2.set_alpha(4); | 380 test_orientation2.set_alpha(4); |
| 369 test_orientation2.set_beta(5); | 381 test_orientation2.set_beta(5); |
| 370 test_orientation2.set_gamma(6); | 382 test_orientation2.set_gamma(6); |
| 371 test_orientation2.set_absolute(false); | 383 test_orientation2.set_absolute(false); |
| 372 | 384 |
| 373 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( | 385 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
| 374 &pending_expectations_)); | 386 &pending_expectations_)); |
| 375 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( | 387 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
| 376 &pending_expectations_)); | 388 &pending_expectations_)); |
| 377 | 389 |
| 378 checker_a->AddExpectation(test_orientation); | 390 checker_a->AddExpectation(test_orientation); |
| 379 orientation_factory->SetOrientation(test_orientation); | 391 orientation_factory->SetOrientation(test_orientation); |
| 380 provider_->AddObserver(checker_a.get()); | 392 provider_->AddObserver(checker_a.get()); |
| 381 MessageLoop::current()->Run(); | 393 MessageLoop::current()->Run(); |
| 382 | 394 |
| 383 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. | 395 provider_->RemoveObserver(checker_a.get()); // This stops the Provider. |
| 384 | 396 |
| 385 checker_b->AddExpectation(test_orientation2); | 397 checker_b->AddExpectation(test_orientation2); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 412 second_orientation.set_beta(kBeta + kInsignificantDifference); | 424 second_orientation.set_beta(kBeta + kInsignificantDifference); |
| 413 second_orientation.set_gamma(kGamma + kInsignificantDifference); | 425 second_orientation.set_gamma(kGamma + kInsignificantDifference); |
| 414 second_orientation.set_absolute(false); | 426 second_orientation.set_absolute(false); |
| 415 | 427 |
| 416 Orientation third_orientation; | 428 Orientation third_orientation; |
| 417 third_orientation.set_alpha(kAlpha + kSignificantDifference); | 429 third_orientation.set_alpha(kAlpha + kSignificantDifference); |
| 418 third_orientation.set_beta(kBeta + kSignificantDifference); | 430 third_orientation.set_beta(kBeta + kSignificantDifference); |
| 419 third_orientation.set_gamma(kGamma + kSignificantDifference); | 431 third_orientation.set_gamma(kGamma + kSignificantDifference); |
| 420 // can't provide absolute | 432 // can't provide absolute |
| 421 | 433 |
| 422 scoped_ptr<UpdateChecker> checker_a(new UpdateChecker( | 434 scoped_ptr<OrientationUpdateChecker> checker_a(new OrientationUpdateChecker( |
| 423 &pending_expectations_)); | 435 &pending_expectations_)); |
| 424 scoped_ptr<UpdateChecker> checker_b(new UpdateChecker( | 436 scoped_ptr<OrientationUpdateChecker> checker_b(new OrientationUpdateChecker( |
| 425 &pending_expectations_)); | 437 &pending_expectations_)); |
| 426 | 438 |
| 427 | 439 |
| 428 orientation_factory->SetOrientation(first_orientation); | 440 orientation_factory->SetOrientation(first_orientation); |
| 429 checker_a->AddExpectation(first_orientation); | 441 checker_a->AddExpectation(first_orientation); |
| 430 provider_->AddObserver(checker_a.get()); | 442 provider_->AddObserver(checker_a.get()); |
| 431 MessageLoop::current()->Run(); | 443 MessageLoop::current()->Run(); |
| 432 | 444 |
| 433 // The observers should not see this insignificantly different orientation. | 445 // The observers should not see this insignificantly different orientation. |
| 434 orientation_factory->SetOrientation(second_orientation); | 446 orientation_factory->SetOrientation(second_orientation); |
| 435 checker_b->AddExpectation(first_orientation); | 447 checker_b->AddExpectation(first_orientation); |
| 436 provider_->AddObserver(checker_b.get()); | 448 provider_->AddObserver(checker_b.get()); |
| 437 MessageLoop::current()->Run(); | 449 MessageLoop::current()->Run(); |
| 438 | 450 |
| 439 orientation_factory->SetOrientation(third_orientation); | 451 orientation_factory->SetOrientation(third_orientation); |
| 440 checker_a->AddExpectation(third_orientation); | 452 checker_a->AddExpectation(third_orientation); |
| 441 checker_b->AddExpectation(third_orientation); | 453 checker_b->AddExpectation(third_orientation); |
| 442 MessageLoop::current()->Run(); | 454 MessageLoop::current()->Run(); |
| 443 | 455 |
| 444 provider_->RemoveObserver(checker_a.get()); | 456 provider_->RemoveObserver(checker_a.get()); |
| 445 provider_->RemoveObserver(checker_b.get()); | 457 provider_->RemoveObserver(checker_b.get()); |
| 446 } | 458 } |
| 447 | 459 |
| 448 } // namespace | 460 } // namespace |
| 449 | 461 |
| 450 } // namespace device_orientation | 462 } // namespace device_orientation |
| OLD | NEW |