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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_apitest.cc

Issue 2750453002: Add DiscoveryNetworkMonitor implementation (Closed)
Patch Set: Respond to mfoltz' comments, add chrome.dial API back with tests Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "chrome/browser/extensions/api/dial/dial_api.h" 7 #include "chrome/browser/extensions/api/dial/dial_api.h"
8 #include "chrome/browser/extensions/api/dial/dial_api_factory.h" 8 #include "chrome/browser/extensions/api/dial/dial_api_factory.h"
9 #include "chrome/browser/extensions/api/dial/dial_registry.h" 9 #include "chrome/browser/extensions/api/dial/dial_registry.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "extensions/common/switches.h" 12 #include "extensions/common/switches.h"
13 #include "extensions/test/extension_test_message_listener.h" 13 #include "extensions/test/extension_test_message_listener.h"
14 #include "extensions/test/result_catcher.h" 14 #include "extensions/test/result_catcher.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 using extensions::Extension; 18 using extensions::Extension;
19 using extensions::ResultCatcher; 19 using extensions::ResultCatcher;
20 using extensions::api::dial::DialDeviceData; 20 using extensions::api::dial::DialDeviceData;
21 using extensions::api::dial::DialDeviceDescriptionData; 21 using extensions::api::dial::DialDeviceDescriptionData;
22 using extensions::api::dial::DialRegistry; 22 using extensions::api::dial::DialRegistry;
23 23
24 namespace { 24 namespace {
25 25
26 std::vector<NetworkInfo> FakeGetNetworkInfo(
27 const std::vector<NetworkInfo>& network_info_list) {
28 return network_info_list;
29 }
30
26 class DialAPITest : public ExtensionApiTest { 31 class DialAPITest : public ExtensionApiTest {
27 public: 32 public:
28 DialAPITest() {} 33 DialAPITest() {}
29 34
30 void SetUpCommandLine(base::CommandLine* command_line) override { 35 void SetUpCommandLine(base::CommandLine* command_line) override {
31 ExtensionApiTest::SetUpCommandLine(command_line); 36 ExtensionApiTest::SetUpCommandLine(command_line);
32 command_line->AppendSwitchASCII( 37 command_line->AppendSwitchASCII(
33 extensions::switches::kWhitelistedExtensionID, 38 extensions::switches::kWhitelistedExtensionID,
34 "ddchlicdkolnonkihahngkmmmjnjlkkf"); 39 "ddchlicdkolnonkihahngkmmmjnjlkkf");
35 } 40 }
41
42 protected:
43 void SetUp() override {
44 net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
45
46 // This will create a NetworkChangeNotifier via BrowserTestBase, so make
47 // sure this is after SetTestNotificationsOnly but before we try to create a
48 // DiscoveryNetworkMonitor.
49 ExtensionApiTest::SetUp();
50 }
51
52 void SetUpOnMainThread() override {
53 // This executes after SetUp() so NetworkChangeNotifier should exist here.
54 auto* discovery_network_monitor =
55 DiscoveryNetworkMonitor::GetInstanceForTest(
56 base::Bind(&FakeGetNetworkInfo, base::ConstRef(fake_network_info)));
57 // See SetUp() in discovery_network_monitor_unittest.cc for an explanation
58 // of this logic.
59 if (should_rebind_to_network_change_monitor) {
60 discovery_network_monitor->RebindNetworkChangeObserverForTest();
61 } else {
62 should_rebind_to_network_change_monitor = true;
63 }
64 ExtensionApiTest::SetUpOnMainThread();
65 }
66
67 bool should_rebind_to_network_change_monitor = false;
68 std::vector<NetworkInfo> fake_network_info;
36 }; 69 };
37 70
38 } // namespace 71 } // namespace
39 72
40 // http://crbug.com/177163 73 // http://crbug.com/177163
41 #if defined(OS_WIN) && !defined(NDEBUG) 74 #if defined(OS_WIN) && !defined(NDEBUG)
42 #define MAYBE_DeviceListEvents DISABLED_DeviceListEvents 75 #define MAYBE_DeviceListEvents DISABLED_DeviceListEvents
43 #else 76 #else
44 #define MAYBE_DeviceListEvents DeviceListEvents 77 #define MAYBE_DeviceListEvents DeviceListEvents
45 #endif 78 #endif
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 base::Time::Now()); 161 base::Time::Now());
129 test_device.set_label("testDevice"); 162 test_device.set_label("testDevice");
130 163
131 DialDeviceDescriptionData test_description("<xml>testDescription</xml>", 164 DialDeviceDescriptionData test_description("<xml>testDescription</xml>",
132 GURL("http://127.0.0.1/apps")); 165 GURL("http://127.0.0.1/apps"));
133 api->SetDeviceForTest(test_device, test_description); 166 api->SetDeviceForTest(test_device, test_description);
134 167
135 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", 168 ASSERT_TRUE(RunExtensionSubtest("dial/experimental",
136 "fetch_device_description.html")); 169 "fetch_device_description.html"));
137 } 170 }
171
172 IN_PROC_BROWSER_TEST_F(DialAPITest, GetNetworkId) {
173 fake_network_info = std::vector<NetworkInfo>{
174 {{0, net::NetworkChangeNotifier::CONNECTION_ETHERNET,
175 std::string("enp0s2"), std::string("ethernet1")}}};
176
177 ASSERT_TRUE(RunExtensionSubtest("dial/experimental", "get_network_id.html"));
178
179 ResultCatcher catcher;
180 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
181 }
182
183 IN_PROC_BROWSER_TEST_F(DialAPITest, NetworkIdChanged) {
184 ASSERT_TRUE(
185 RunExtensionSubtest("dial/experimental", "network_id_changed.html"));
186
187 ResultCatcher catcher;
188 ExtensionTestMessageListener listener("continue", false);
189
190 fake_network_info = std::vector<NetworkInfo>{
191 {{0, net::NetworkChangeNotifier::CONNECTION_ETHERNET,
192 std::string("enp0s2"), std::string("ethernet1")}}};
193 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
194 net::NetworkChangeNotifier::CONNECTION_ETHERNET);
195 EXPECT_TRUE(listener.WaitUntilSatisfied());
196
197 fake_network_info =
198 std::vector<NetworkInfo>{{{0, net::NetworkChangeNotifier::CONNECTION_WIFI,
199 std::string("wlp0s3"), std::string("wifi1")}}};
200 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
201 net::NetworkChangeNotifier::CONNECTION_WIFI);
202 EXPECT_TRUE(listener.WaitUntilSatisfied());
203
204 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698