| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/page/NetworkStateNotifier.h" | 32 #include "core/page/NetworkStateNotifier.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/testing/UnitTestHelpers.h" |
| 35 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 36 #include "public/platform/WebConnectionType.h" | 37 #include "public/platform/WebConnectionType.h" |
| 37 #include "public/platform/WebThread.h" | 38 #include "public/platform/WebThread.h" |
| 38 #include "wtf/Functional.h" | 39 #include "wtf/Functional.h" |
| 39 #include <gtest/gtest.h> | 40 #include <gtest/gtest.h> |
| 40 | 41 |
| 41 namespace blink { | 42 namespace blink { |
| 42 | 43 |
| 43 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { | 44 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { |
| 44 public: | 45 public: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 { | 72 { |
| 72 m_closure = closure; | 73 m_closure = closure; |
| 73 } | 74 } |
| 74 | 75 |
| 75 private: | 76 private: |
| 76 OwnPtr<Closure> m_closure; | 77 OwnPtr<Closure> m_closure; |
| 77 blink::WebConnectionType m_observedType; | 78 blink::WebConnectionType m_observedType; |
| 78 int m_callbackCount; | 79 int m_callbackCount; |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 class ExitTask | 82 class NetworkStateNotifierTest : public ::testing::Test { |
| 82 : public blink::WebThread::Task { | |
| 83 public: | |
| 84 ExitTask(blink::WebThread* thread) | |
| 85 : m_thread(thread) | |
| 86 { | |
| 87 } | |
| 88 virtual void run() override | |
| 89 { | |
| 90 m_thread->exitRunLoop(); | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 blink::WebThread* m_thread; | |
| 95 }; | |
| 96 | |
| 97 class NetworkStateNotifierTest : public testing::Test { | |
| 98 public: | 83 public: |
| 99 NetworkStateNotifierTest() | 84 NetworkStateNotifierTest() |
| 100 : m_document(Document::create()) | 85 : m_document(Document::create()) |
| 101 , m_document2(Document::create()) | 86 , m_document2(Document::create()) |
| 102 { | 87 { |
| 103 } | 88 } |
| 104 | 89 |
| 105 ExecutionContext* executionContext() | 90 ExecutionContext* executionContext() |
| 106 { | 91 { |
| 107 return m_document.get(); | 92 return m_document.get(); |
| 108 } | 93 } |
| 109 | 94 |
| 110 ExecutionContext* executionContext2() | 95 ExecutionContext* executionContext2() |
| 111 { | 96 { |
| 112 return m_document2.get(); | 97 return m_document2.get(); |
| 113 } | 98 } |
| 114 | 99 |
| 115 protected: | 100 protected: |
| 116 void setType(blink::WebConnectionType type) | 101 void setType(blink::WebConnectionType type) |
| 117 { | 102 { |
| 118 m_notifier.setWebConnectionType(type); | 103 m_notifier.setWebConnectionType(type); |
| 119 | 104 testing::runPendingTasks(); |
| 120 blink::WebThread* thread = blink::Platform::current()->currentThread(); | |
| 121 thread->postTask(FROM_HERE, new ExitTask(thread)); | |
| 122 thread->enterRunLoop(); | |
| 123 } | 105 } |
| 124 | 106 |
| 125 void addObserverOnNotification(StateObserver* observer, StateObserver* obser
verToAdd) | 107 void addObserverOnNotification(StateObserver* observer, StateObserver* obser
verToAdd) |
| 126 { | 108 { |
| 127 observer->setNotificationCallback(bind(&NetworkStateNotifier::addObserve
r, &m_notifier, observerToAdd, executionContext())); | 109 observer->setNotificationCallback(bind(&NetworkStateNotifier::addObserve
r, &m_notifier, observerToAdd, executionContext())); |
| 128 } | 110 } |
| 129 | 111 |
| 130 void removeObserverOnNotification(StateObserver* observer, StateObserver* ob
serverToRemove) | 112 void removeObserverOnNotification(StateObserver* observer, StateObserver* ob
serverToRemove) |
| 131 { | 113 { |
| 132 observer->setNotificationCallback(bind(&NetworkStateNotifier::removeObse
rver, &m_notifier, observerToRemove, executionContext())); | 114 observer->setNotificationCallback(bind(&NetworkStateNotifier::removeObse
rver, &m_notifier, observerToRemove, executionContext())); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 m_notifier.addObserver(&observer2, executionContext2()); | 253 m_notifier.addObserver(&observer2, executionContext2()); |
| 272 m_notifier.removeObserver(&observer1, executionContext()); | 254 m_notifier.removeObserver(&observer1, executionContext()); |
| 273 m_notifier.removeObserver(&observer2, executionContext2()); | 255 m_notifier.removeObserver(&observer2, executionContext2()); |
| 274 | 256 |
| 275 setType(blink::ConnectionTypeBluetooth); | 257 setType(blink::ConnectionTypeBluetooth); |
| 276 EXPECT_EQ(observer1.observedType(), blink::ConnectionTypeNone); | 258 EXPECT_EQ(observer1.observedType(), blink::ConnectionTypeNone); |
| 277 EXPECT_EQ(observer2.observedType(), blink::ConnectionTypeNone); | 259 EXPECT_EQ(observer2.observedType(), blink::ConnectionTypeNone); |
| 278 } | 260 } |
| 279 | 261 |
| 280 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |