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

Unified Diff: third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp

Issue 2087293003: [DevTools] Network.emulateNetworkConditions now affects NetworkStateNotifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments Created 4 years, 6 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
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..3a33be33b2f2f4c6d268fcb4c5309f76b427d8a7 100644
--- a/third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp
+++ b/third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp
@@ -278,4 +278,68 @@ 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());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698