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/orientation.h" | 10 #include "content/browser/device_orientation/orientation.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 private: | 60 private: |
61 // Set up by the test fixture, which then blocks while it is accessed | 61 // Set up by the test fixture, which then blocks while it is accessed |
62 // from OnOrientationUpdate which is executed on the test fixture's | 62 // from OnOrientationUpdate which is executed on the test fixture's |
63 // message_loop_. | 63 // message_loop_. |
64 int* expectations_count_ptr_; | 64 int* expectations_count_ptr_; |
65 std::queue<Orientation> expectations_queue_; | 65 std::queue<Orientation> expectations_queue_; |
66 }; | 66 }; |
67 | 67 |
68 // Class for injecting test orientation data into the Provider. | 68 // Class for injecting test orientation data into the Provider. |
69 class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { | 69 class MockOrientationFactory |
| 70 : public base::RefCountedThreadSafe<MockOrientationFactory> { |
70 public: | 71 public: |
71 MockOrientationFactory() | 72 MockOrientationFactory() |
72 : is_failing_(false) { | 73 : is_failing_(false) { |
73 } | 74 } |
74 | 75 |
75 static void SetCurInstance(MockOrientationFactory* instance) { | 76 static void SetCurInstance(MockOrientationFactory* instance) { |
76 if (instance) { | 77 if (instance) { |
77 EXPECT_FALSE(instance_); | 78 EXPECT_FALSE(instance_); |
78 } | 79 } |
79 else { | 80 else { |
(...skipping 11 matching lines...) Expand all Loading... |
91 base::AutoLock auto_lock(lock_); | 92 base::AutoLock auto_lock(lock_); |
92 orientation_ = orientation; | 93 orientation_ = orientation; |
93 } | 94 } |
94 | 95 |
95 void SetFailing(bool is_failing) { | 96 void SetFailing(bool is_failing) { |
96 base::AutoLock auto_lock(lock_); | 97 base::AutoLock auto_lock(lock_); |
97 is_failing_ = is_failing; | 98 is_failing_ = is_failing; |
98 } | 99 } |
99 | 100 |
100 private: | 101 private: |
101 friend class base::RefCounted<MockOrientationFactory>; | 102 friend class base::RefCountedThreadSafe<MockOrientationFactory>; |
102 | 103 |
103 ~MockOrientationFactory() { | 104 ~MockOrientationFactory() { |
104 } | 105 } |
105 | 106 |
106 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. | 107 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. |
107 class MockDataFetcher : public DataFetcher { | 108 class MockDataFetcher : public DataFetcher { |
108 public: | 109 public: |
109 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) | 110 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) |
110 : orientation_factory_(orientation_factory) { } | 111 : orientation_factory_(orientation_factory) { } |
111 | 112 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 MessageLoop::current()->Run(); | 462 MessageLoop::current()->Run(); |
462 | 463 |
463 provider_->RemoveObserver(checker_a.get()); | 464 provider_->RemoveObserver(checker_a.get()); |
464 provider_->RemoveObserver(checker_b.get()); | 465 provider_->RemoveObserver(checker_b.get()); |
465 MockOrientationFactory::SetCurInstance(NULL); | 466 MockOrientationFactory::SetCurInstance(NULL); |
466 } | 467 } |
467 | 468 |
468 } // namespace | 469 } // namespace |
469 | 470 |
470 } // namespace device_orientation | 471 } // namespace device_orientation |
OLD | NEW |