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