Index: third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp |
diff --git a/third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp b/third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp |
index 5d189315bfa22feffefca09df1fa178b13c64388..06617ddc2c72730bdd6e09bbae741e9d20f90b74 100644 |
--- a/third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp |
+++ b/third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp |
@@ -98,6 +98,8 @@ public: |
: m_document(Document::create()) |
, m_document2(Document::create()) |
{ |
+ // Initialize connection, so that future calls to setWebConnection issue notifications. |
+ m_notifier.setWebConnection(WebConnectionTypeUnknown, 0.0); |
} |
ExecutionContext* getExecutionContext() |
@@ -278,4 +280,93 @@ TEST_F(NetworkStateNotifierTest, RemoveAllContexts) |
EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeNone, kNoneMaxBandwidthMbps)); |
} |
+TEST_F(NetworkStateNotifierTest, SetOverride) |
+{ |
+ StateObserver observer; |
+ m_notifier.addObserver(&observer, getExecutionContext()); |
+ |
+ m_notifier.setOnLine(true); |
+ setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps)); |
+ EXPECT_TRUE(m_notifier.onLine()); |
+ EXPECT_EQ(WebConnectionTypeBluetooth, m_notifier.connectionType()); |
+ EXPECT_EQ(kBluetoothMaxBandwidthMbps, m_notifier.maxBandwidth()); |
+ |
+ m_notifier.setOverride(true, WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
+ testing::runPendingTasks(); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps)); |
+ EXPECT_TRUE(m_notifier.onLine()); |
+ EXPECT_EQ(WebConnectionTypeEthernet, m_notifier.connectionType()); |
+ EXPECT_EQ(kEthernetMaxBandwidthMbps, m_notifier.maxBandwidth()); |
+ |
+ // When override is active, calls to setOnLine and setConnection are temporary ignored. |
+ m_notifier.setOnLine(false); |
+ setConnection(WebConnectionTypeNone, kNoneMaxBandwidthMbps); |
+ testing::runPendingTasks(); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps)); |
+ EXPECT_TRUE(m_notifier.onLine()); |
+ EXPECT_EQ(WebConnectionTypeEthernet, m_notifier.connectionType()); |
+ EXPECT_EQ(kEthernetMaxBandwidthMbps, m_notifier.maxBandwidth()); |
+ |
+ m_notifier.clearOverride(); |
+ testing::runPendingTasks(); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeNone, kNoneMaxBandwidthMbps)); |
+ EXPECT_FALSE(m_notifier.onLine()); |
+ EXPECT_EQ(WebConnectionTypeNone, m_notifier.connectionType()); |
+ EXPECT_EQ(kNoneMaxBandwidthMbps, m_notifier.maxBandwidth()); |
+ |
+ m_notifier.removeObserver(&observer, getExecutionContext()); |
+} |
+ |
+TEST_F(NetworkStateNotifierTest, NoExtraNotifications) |
+{ |
+ StateObserver observer; |
+ m_notifier.addObserver(&observer, getExecutionContext()); |
+ |
+ setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps)); |
+ EXPECT_EQ(observer.callbackCount(), 1); |
+ |
+ setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
+ EXPECT_EQ(observer.callbackCount(), 1); |
+ |
+ setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps)); |
+ EXPECT_EQ(observer.callbackCount(), 2); |
+ |
+ setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
+ EXPECT_EQ(observer.callbackCount(), 2); |
+ |
+ setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
+ EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps)); |
+ EXPECT_EQ(observer.callbackCount(), 3); |
+ |
+ m_notifier.removeObserver(&observer, getExecutionContext()); |
+} |
+ |
+TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) |
+{ |
+ NetworkStateNotifier notifier; |
+ Persistent<Document> document(Document::create()); |
+ StateObserver observer; |
+ |
+ notifier.addObserver(&observer, document.get()); |
+ testing::runPendingTasks(); |
+ EXPECT_EQ(observer.callbackCount(), 0); |
+ |
+ notifier.setWebConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
+ testing::runPendingTasks(); |
+ EXPECT_EQ(observer.callbackCount(), 0); |
+ |
+ notifier.setWebConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
+ testing::runPendingTasks(); |
+ EXPECT_EQ(observer.callbackCount(), 0); |
+ |
+ notifier.setWebConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
+ testing::runPendingTasks(); |
+ EXPECT_EQ(observer.callbackCount(), 1); |
+ EXPECT_EQ(observer.observedType(), WebConnectionTypeEthernet); |
+ EXPECT_EQ(observer.observedMaxBandwidth(), kEthernetMaxBandwidthMbps); |
+} |
+ |
} // namespace blink |