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