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

Side by Side Diff: components/wifi/wifi_test.cc

Issue 64683014: Mac OS X-specific implementation of Networking Private API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made networkingPrivateApi available on OS X. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/wifi/wifi_service_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <iostream> 6 #include <iostream>
7 #include <string> 7 #include <string>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) { 66 WiFiTest::Result WiFiTest::Main(int argc, const char* argv[]) {
67 if (!ParseCommandLine(argc, argv)) { 67 if (!ParseCommandLine(argc, argv)) {
68 fprintf(stderr, 68 fprintf(stderr,
69 "usage: %s [--list]" 69 "usage: %s [--list]"
70 " [--get_properties]" 70 " [--get_properties]"
71 " [--connect]" 71 " [--connect]"
72 " [--disconnect]" 72 " [--disconnect]"
73 " [--network_guid=<network_guid>]" 73 " [--network_guid=<network_guid>]"
74 " [--frequency=0|2400|5000]" 74 " [--frequency=0|2400|5000]"
75 " [--password=<password>]"
75 " [<network_guid>]\n", 76 " [<network_guid>]\n",
76 argv[0]); 77 argv[0]);
77 return RESULT_WRONG_USAGE; 78 return RESULT_WRONG_USAGE;
78 } 79 }
79 80
80 base::MessageLoopForIO loop; 81 base::MessageLoopForIO loop;
81 result_ = RESULT_PENDING; 82 result_ = RESULT_PENDING;
82 83
83 return result_; 84 return result_;
84 } 85 }
85 86
86 bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { 87 bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) {
87 CommandLine::Init(argc, argv); 88 CommandLine::Init(argc, argv);
88 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 89 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
89 std::string network_guid = 90 std::string network_guid =
90 parsed_command_line.GetSwitchValueASCII("network_guid"); 91 parsed_command_line.GetSwitchValueASCII("network_guid");
92 std::string password =
93 parsed_command_line.GetSwitchValueASCII("password");
91 94
92 if (parsed_command_line.GetArgs().size() == 1) { 95 if (parsed_command_line.GetArgs().size() == 1) {
93 #if defined(OS_WIN) 96 #if defined(OS_WIN)
94 network_guid = WideToASCII(parsed_command_line.GetArgs()[0]); 97 network_guid = WideToASCII(parsed_command_line.GetArgs()[0]);
95 #else 98 #else
96 network_guid = parsed_command_line.GetArgs()[0]; 99 network_guid = parsed_command_line.GetArgs()[0];
97 #endif 100 #endif
98 } 101 }
99 102
100 #if defined(OS_WIN) 103 #if defined(OS_WIN)
101 if (parsed_command_line.HasSwitch("debug")) 104 if (parsed_command_line.HasSwitch("debug"))
102 MessageBoxA(NULL, __FUNCTION__, "Debug Me!", MB_OK); 105 MessageBoxA(NULL, __FUNCTION__, "Debug Me!", MB_OK);
103 #endif 106 #endif
104 107
105 #if defined(OS_WIN) 108 #if defined(OS_WIN) || defined(OS_MACOSX)
106 scoped_ptr<WiFiService> wifi_service(WiFiService::Create()); 109 scoped_ptr<WiFiService> wifi_service(WiFiService::Create());
107 #else 110 #else
108 scoped_ptr<WiFiService> wifi_service(WiFiService::CreateForTest()); 111 scoped_ptr<WiFiService> wifi_service(WiFiService::CreateForTest());
109 #endif 112 #endif
110 113
111 wifi_service->Initialize(NULL); 114 wifi_service->Initialize(NULL);
112 115
113 if (parsed_command_line.HasSwitch("list")) { 116 if (parsed_command_line.HasSwitch("list")) {
114 ListValue network_list; 117 ListValue network_list;
115 wifi_service->GetVisibleNetworks(&network_list); 118 wifi_service->GetVisibleNetworks(&network_list);
116 std::cout << network_list; 119 std::cout << network_list;
117 return true; 120 return true;
118 } 121 }
119 122
120 if (parsed_command_line.HasSwitch("get_properties")) { 123 if (parsed_command_line.HasSwitch("get_properties")) {
121 if (network_guid.length() > 0) { 124 if (network_guid.length() > 0) {
122 DictionaryValue properties; 125 DictionaryValue properties;
123 std::string error; 126 std::string error;
124 wifi_service->GetProperties(network_guid, &properties, &error); 127 wifi_service->GetProperties(network_guid, &properties, &error);
125 std::cout << error << ":\n" << properties; 128 std::cout << error << ":\n" << properties;
126 return true; 129 return true;
127 } 130 }
128 } 131 }
129 132
133 if (parsed_command_line.HasSwitch("password")) {
134 if (network_guid.length() > 0) {
135 std::string error;
136 scoped_ptr<DictionaryValue> properties(new DictionaryValue());
137 properties->SetString("WiFi.Passphrase", password);
138 wifi_service->SetProperties(network_guid, properties.Pass(), &error);
139 // fall through to connect.
140 }
141 }
142
130 if (parsed_command_line.HasSwitch("connect")) { 143 if (parsed_command_line.HasSwitch("connect")) {
131 if (network_guid.length() > 0) { 144 if (network_guid.length() > 0) {
132 std::string error; 145 std::string error;
133 wifi_service->StartConnect(network_guid, &error); 146 wifi_service->StartConnect(network_guid, &error);
134 std::cout << error; 147 std::cout << error;
135 return true; 148 return true;
136 } 149 }
137 } 150 }
138 151
139 if (parsed_command_line.HasSwitch("disconnect")) { 152 if (parsed_command_line.HasSwitch("disconnect")) {
140 if (network_guid.length() > 0) { 153 if (network_guid.length() > 0) {
141 std::string error; 154 std::string error;
142 wifi_service->StartDisconnect(network_guid, &error); 155 wifi_service->StartDisconnect(network_guid, &error);
143 std::cout << error; 156 std::cout << error;
144 return true; 157 return true;
145 } 158 }
146 } 159 }
147 160
148 return false; 161 return false;
149 } 162 }
150 163
151 } // namespace wifi 164 } // namespace wifi
152 165
153 int main(int argc, const char* argv[]) { 166 int main(int argc, const char* argv[]) {
154 wifi::WiFiTest wifi_test; 167 wifi::WiFiTest wifi_test;
155 return wifi_test.Main(argc, argv); 168 return wifi_test.Main(argc, argv);
156 } 169 }
OLDNEW
« no previous file with comments | « components/wifi/wifi_service_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698