| Index: chrome/browser/extensions/api/dial/dial_apitest.cc
|
| diff --git a/chrome/browser/extensions/api/dial/dial_apitest.cc b/chrome/browser/extensions/api/dial/dial_apitest.cc
|
| index c3698c52b5acce493178bcb19b9b2808166e18d9..96071402c8fe370c73a6580712c657e7ba463a13 100644
|
| --- a/chrome/browser/extensions/api/dial/dial_apitest.cc
|
| +++ b/chrome/browser/extensions/api/dial/dial_apitest.cc
|
| @@ -23,6 +23,11 @@ using extensions::api::dial::DialRegistry;
|
|
|
| namespace {
|
|
|
| +std::vector<NetworkInfo> FakeGetNetworkInfo(
|
| + const std::vector<NetworkInfo>& network_info_list) {
|
| + return network_info_list;
|
| +}
|
| +
|
| class DialAPITest : public ExtensionApiTest {
|
| public:
|
| DialAPITest() {}
|
| @@ -33,6 +38,34 @@ class DialAPITest : public ExtensionApiTest {
|
| extensions::switches::kWhitelistedExtensionID,
|
| "ddchlicdkolnonkihahngkmmmjnjlkkf");
|
| }
|
| +
|
| + protected:
|
| + void SetUp() override {
|
| + net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
|
| +
|
| + // This will create a NetworkChangeNotifier via BrowserTestBase, so make
|
| + // sure this is after SetTestNotificationsOnly but before we try to create a
|
| + // DiscoveryNetworkMonitor.
|
| + ExtensionApiTest::SetUp();
|
| + }
|
| +
|
| + void SetUpOnMainThread() override {
|
| + // This executes after SetUp() so NetworkChangeNotifier should exist here.
|
| + auto* discovery_network_monitor =
|
| + DiscoveryNetworkMonitor::GetInstanceForTest(
|
| + base::Bind(&FakeGetNetworkInfo, base::ConstRef(fake_network_info)));
|
| + // See SetUp() in discovery_network_monitor_unittest.cc for an explanation
|
| + // of this logic.
|
| + if (should_rebind_to_network_change_monitor) {
|
| + discovery_network_monitor->RebindNetworkChangeObserverForTest();
|
| + } else {
|
| + should_rebind_to_network_change_monitor = true;
|
| + }
|
| + ExtensionApiTest::SetUpOnMainThread();
|
| + }
|
| +
|
| + bool should_rebind_to_network_change_monitor = false;
|
| + std::vector<NetworkInfo> fake_network_info;
|
| };
|
|
|
| } // namespace
|
| @@ -135,3 +168,38 @@ IN_PROC_BROWSER_TEST_F(DialAPITest, FetchDeviceDescription) {
|
| ASSERT_TRUE(RunExtensionSubtest("dial/experimental",
|
| "fetch_device_description.html"));
|
| }
|
| +
|
| +IN_PROC_BROWSER_TEST_F(DialAPITest, GetNetworkId) {
|
| + fake_network_info = std::vector<NetworkInfo>{
|
| + {{0, net::NetworkChangeNotifier::CONNECTION_ETHERNET,
|
| + std::string("enp0s2"), std::string("ethernet1")}}};
|
| +
|
| + ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "get_network_id.html"));
|
| +
|
| + ResultCatcher catcher;
|
| + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(DialAPITest, NetworkIdChanged) {
|
| + ASSERT_TRUE(
|
| + RunExtensionSubtest("dial/experimental", "network_id_changed.html"));
|
| +
|
| + ResultCatcher catcher;
|
| + ExtensionTestMessageListener listener("continue", false);
|
| +
|
| + fake_network_info = std::vector<NetworkInfo>{
|
| + {{0, net::NetworkChangeNotifier::CONNECTION_ETHERNET,
|
| + std::string("enp0s2"), std::string("ethernet1")}}};
|
| + net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
|
| + net::NetworkChangeNotifier::CONNECTION_ETHERNET);
|
| + EXPECT_TRUE(listener.WaitUntilSatisfied());
|
| +
|
| + fake_network_info =
|
| + std::vector<NetworkInfo>{{{0, net::NetworkChangeNotifier::CONNECTION_WIFI,
|
| + std::string("wlp0s3"), std::string("wifi1")}}};
|
| + net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
|
| + net::NetworkChangeNotifier::CONNECTION_WIFI);
|
| + EXPECT_TRUE(listener.WaitUntilSatisfied());
|
| +
|
| + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
|
| +}
|
|
|