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

Side by Side Diff: chrome/browser/extensions/api/networking_cast/networking_cast_apitest.cc

Issue 2726223004: Introduce networking.cast API (Closed)
Patch Set: . Created 3 years, 9 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
(Empty)
1 // Copyright 2017 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 <memory>
6 #include <string>
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/extensions/api/networking_cast/chrome_networking_cast_d elegate.h"
17 #include "chrome/browser/extensions/extension_apitest.h"
18 #include "extensions/browser/api/networking_private/networking_private_delegate. h"
19 #include "extensions/common/api/networking_cast.h"
20 #include "extensions/common/api/networking_private.h"
21 #include "extensions/common/switches.h"
22
23 #if defined(OS_CHROMEOS)
24 #include "chromeos/dbus/dbus_thread_manager.h"
25 #include "chromeos/dbus/shill_device_client.h"
26 #include "chromeos/dbus/shill_service_client.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h"
28 #endif
29
30 using extensions::api::networking_private::VerificationProperties;
31
32 namespace extensions {
33
34 namespace {
35
36 class TestVerifyDelegate : public NetworkingPrivateDelegate::VerifyDelegate {
37 public:
38 TestVerifyDelegate() = default;
39 ~TestVerifyDelegate() override = default;
40
41 void VerifyDestination(const VerificationProperties& properties,
42 const BoolCallback& success_callback,
43 const FailureCallback& failure_callback) override {
44 success_callback.Run(true);
45 }
46
47 void VerifyAndEncryptCredentials(
48 const std::string& guid,
49 const VerificationProperties& properties,
50 const StringCallback& success_callback,
51 const FailureCallback& failure_callback) override {
52 success_callback.Run("encrypted_credentials");
53 }
54
55 void VerifyAndEncryptData(const VerificationProperties& properties,
56 const std::string& data,
57 const StringCallback& success_callback,
58 const FailureCallback& failure_callback) override {
59 success_callback.Run("encrypted_data");
60 }
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(TestVerifyDelegate);
64 };
65
66 } // namespace
67
68 class NetworkingCastApiTest : public ExtensionApiTest {
69 public:
70 NetworkingCastApiTest() = default;
71 ~NetworkingCastApiTest() override = default;
72
73 void SetUpCommandLine(base::CommandLine* command_line) override {
74 ExtensionApiTest::SetUpCommandLine(command_line);
75 // Whitelist the extension ID of the test extension.
76 command_line->AppendSwitchASCII(
77 extensions::switches::kWhitelistedExtensionID,
78 "epcifkihnkjgphfkloaaleeakhpmgdmn");
79 }
80
81 void SetUp() override {
82 networking_cast_delegate_factory_ =
83 base::Bind(&NetworkingCastApiTest::CreateNetworkingCastDelegate,
84 base::Unretained(this));
85 ChromeNetworkingCastDelegate::SetFactoryCallbackForTest(
86 &networking_cast_delegate_factory_);
87
88 ExtensionApiTest::SetUp();
89 }
90
91 void SetUpOnMainThread() override {
92 ExtensionApiTest::SetUpOnMainThread();
93
94 #if defined(OS_CHROMEOS)
95 chromeos::DBusThreadManager* dbus_manager =
96 chromeos::DBusThreadManager::Get();
97 chromeos::ShillDeviceClient::TestInterface* device_test =
98 dbus_manager->GetShillDeviceClient()->GetTestInterface();
99 device_test->ClearDevices();
100 device_test->AddDevice("/device/stub_wifi_device1", shill::kTypeWifi,
101 "stub_wifi_device");
102 device_test->SetTDLSState(shill::kTDLSConnectedState);
103
104 chromeos::ShillServiceClient::TestInterface* service_test =
105 dbus_manager->GetShillServiceClient()->GetTestInterface();
106 service_test->ClearServices();
107 service_test->AddService("stub_wifi", "stub_wifi_guid", "wifi",
108 shill::kTypeWifi, shill::kStateOnline,
109 true /* add_to_visible */);
110 #endif // defined(OS_CHROMEOS)
111 }
112
113 void TearDown() override {
114 ExtensionApiTest::TearDown();
115 ChromeNetworkingCastDelegate::SetFactoryCallbackForTest(nullptr);
116 }
117
118 bool TdlsSupported() {
119 #if defined(OS_CHROMEOS)
120 return true;
121 #else
122 return false;
123 #endif
124 }
125
126 private:
127 std::unique_ptr<ChromeNetworkingCastDelegate> CreateNetworkingCastDelegate() {
128 return std::unique_ptr<ChromeNetworkingCastDelegate>(
129 new ChromeNetworkingCastDelegate(
130 base::MakeUnique<TestVerifyDelegate>()));
131 }
132
133 ChromeNetworkingCastDelegate::FactoryCallback
134 networking_cast_delegate_factory_;
135
136 DISALLOW_COPY_AND_ASSIGN(NetworkingCastApiTest);
137 };
138
139 IN_PROC_BROWSER_TEST_F(NetworkingCastApiTest, Basic) {
140 const std::string arg =
141 base::StringPrintf("{\"tdlsSupported\": %d}", TdlsSupported());
142 EXPECT_TRUE(RunPlatformAppTestWithArg("networking_cast", arg.c_str()))
143 << message_;
144 }
145
146 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698