| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/values.h" |
| 6 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
| 7 #include "chrome/browser/devtools/device/tcp_device_provider.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "components/prefs/pref_service.h" |
| 15 |
| 16 class DevToolsAndroidBridgeTest : public InProcessBrowserTest { |
| 17 }; |
| 18 |
| 19 static void assign_from_callback(scoped_refptr<TCPDeviceProvider>* store, |
| 20 int* invocation_counter, |
| 21 scoped_refptr<TCPDeviceProvider> value) { |
| 22 (*invocation_counter)++; |
| 23 *store = value; |
| 24 } |
| 25 |
| 26 IN_PROC_BROWSER_TEST_F(DevToolsAndroidBridgeTest, UpdatesTargetDiscovery) { |
| 27 Profile* profile = browser()->profile(); |
| 28 |
| 29 PrefService* service = profile->GetPrefs(); |
| 30 service->ClearPref(prefs::kDevToolsTargetDiscoveryConfig); |
| 31 |
| 32 DevToolsAndroidBridge* bridge = |
| 33 DevToolsAndroidBridge::Factory::GetForProfile(profile); |
| 34 |
| 35 scoped_refptr<TCPDeviceProvider> provider; |
| 36 int called = 0; |
| 37 bridge->set_tcp_provider_callback_for_test( |
| 38 base::Bind(assign_from_callback, &provider, &called)); |
| 39 |
| 40 EXPECT_LT(0, called); |
| 41 EXPECT_EQ(nullptr, provider); |
| 42 |
| 43 int invocations = called; |
| 44 base::ListValue list; |
| 45 list.AppendString("somehost:2000"); |
| 46 |
| 47 service->Set(prefs::kDevToolsTargetDiscoveryConfig, list); |
| 48 |
| 49 EXPECT_LT(invocations, called); |
| 50 EXPECT_NE(nullptr, provider); |
| 51 std::set<net::HostPortPair> pairs = provider->get_targets_for_test(); |
| 52 EXPECT_EQ(1UL, pairs.size()); |
| 53 net::HostPortPair pair = *pairs.begin(); |
| 54 EXPECT_EQ(2000, pair.port()); |
| 55 EXPECT_EQ("somehost", pair.HostForURL()); |
| 56 |
| 57 invocations = called; |
| 58 list.Clear(); |
| 59 service->Set(prefs::kDevToolsTargetDiscoveryConfig, list); |
| 60 |
| 61 EXPECT_LT(invocations, called); |
| 62 EXPECT_EQ(nullptr, provider); |
| 63 invocations = called; |
| 64 |
| 65 list.AppendString("b:1"); |
| 66 list.AppendString("c:2"); |
| 67 list.AppendString("<not really a good address."); |
| 68 list.AppendString("d:3"); |
| 69 list.AppendString("c:2"); |
| 70 service->Set(prefs::kDevToolsTargetDiscoveryConfig, list); |
| 71 |
| 72 EXPECT_LT(invocations, called); |
| 73 EXPECT_NE(nullptr, provider); |
| 74 pairs = provider->get_targets_for_test(); |
| 75 EXPECT_EQ(3UL, pairs.size()); |
| 76 for (const net::HostPortPair pair : pairs) { |
| 77 EXPECT_EQ(pair.port(), pair.HostForURL()[0] - 'a'); |
| 78 } |
| 79 } |
| OLD | NEW |