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

Unified Diff: components/wifi/wifi_test.cc

Issue 68503019: Windows-specific implementation of Networking Private API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Win64 compilation error. Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/wifi/wifi_test.cc
diff --git a/components/wifi/wifi_test.cc b/components/wifi/wifi_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8fd0aaf9deaee427573166f251d95e046770b9f7
--- /dev/null
+++ b/components/wifi/wifi_test.cc
@@ -0,0 +1,156 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+#include <iostream>
+#include <string>
+
+#include "base/at_exit.h"
+#include "base/bind.h"
+#include "base/cancelable_callback.h"
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
+#include "components/wifi/wifi_service.h"
+
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
+
+namespace wifi {
+
+class WiFiTest {
+ public:
+ WiFiTest() {}
+ ~WiFiTest() {}
+
+ enum Result {
+ RESULT_ERROR = -2,
+ RESULT_WRONG_USAGE = -1,
+ RESULT_OK = 0,
+ RESULT_PENDING = 1,
+ };
+
+ Result Main(int argc, const char* argv[]);
+
+ private:
+ bool ParseCommandLine(int argc, const char* argv[]);
+
+ void Start() {}
+ void Finish(Result result) {
+ DCHECK_NE(RESULT_PENDING, result);
+ result_ = result;
+ if (base::MessageLoop::current())
+ base::MessageLoop::current()->Quit();
+ }
+
+#if defined(OS_MACOSX)
+ // Without this there will be a mem leak on osx.
+ base::mac::ScopedNSAutoreleasePool scoped_pool_;
+#endif
+
+ // Need AtExitManager to support AsWeakPtr (in NetLog).
+ base::AtExitManager exit_manager_;
+
+ Result result_;
+};
+
+WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) {
+ if (!ParseCommandLine(argc, argv)) {
+ fprintf(stderr,
+ "usage: %s [--list]"
+ " [--get_properties]"
+ " [--connect]"
+ " [--disconnect]"
+ " [--network_guid=<network_guid>]"
+ " [--frequency=0|2400|5000]"
+ " [<network_guid>]\n",
+ argv[0]);
+ return RESULT_WRONG_USAGE;
+ }
+
+ base::MessageLoopForIO loop;
+ result_ = RESULT_PENDING;
+
+ return result_;
+}
+
+bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) {
+ CommandLine::Init(argc, argv);
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
+ std::string network_guid =
+ parsed_command_line.GetSwitchValueASCII("network_guid");
+
+ if (parsed_command_line.GetArgs().size() == 1) {
+#if defined(OS_WIN)
+ network_guid = WideToASCII(parsed_command_line.GetArgs()[0]);
+#else
+ network_guid = parsed_command_line.GetArgs()[0];
+#endif
+ }
+
+#if defined(OS_WIN)
+ if (parsed_command_line.HasSwitch("debug"))
+ MessageBoxA(NULL, __FUNCTION__, "Debug Me!", MB_OK);
+#endif
+
+#if defined(OS_WIN)
+ scoped_ptr<WiFiService> wifi_service(WiFiService::Create());
+#else
+ scoped_ptr<WiFiService> wifi_service(WiFiService::CreateForTest());
+#endif
+
+ wifi_service->Initialize(NULL);
+
+ if (parsed_command_line.HasSwitch("list")) {
+ ListValue network_list;
+ wifi_service->GetVisibleNetworks(&network_list);
+ std::cout << network_list;
+ return true;
+ }
+
+ if (parsed_command_line.HasSwitch("get_properties")) {
+ if (network_guid.length() > 0) {
+ DictionaryValue properties;
+ std::string error;
+ wifi_service->GetProperties(network_guid, &properties, &error);
+ std::cout << error << ":\n" << properties;
+ return true;
+ }
+ }
+
+ if (parsed_command_line.HasSwitch("connect")) {
+ if (network_guid.length() > 0) {
+ std::string error;
+ wifi_service->StartConnect(network_guid, &error);
+ std::cout << error;
+ return true;
+ }
+ }
+
+ if (parsed_command_line.HasSwitch("disconnect")) {
+ if (network_guid.length() > 0) {
+ std::string error;
+ wifi_service->StartDisconnect(network_guid, &error);
+ std::cout << error;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+} // namespace wifi
+
+int main(int argc, const char* argv[]) {
+ wifi::WiFiTest wifi_test;
+ return wifi_test.Main(argc, argv);
+}
« no previous file with comments | « components/wifi/wifi_service_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698