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: chrome/browser/geolocation/network_location_provider_unittest.cc

Issue 3091005: Rename GetStringAsUTF16() to GetString() (and overload), etc. (Closed)
Patch Set: Created 10 years, 4 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/geolocation/network_location_provider.h" 5 #include "chrome/browser/geolocation/network_location_provider.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 static void ParseRequest(const std::string& request_data, 170 static void ParseRequest(const std::string& request_data,
171 WifiData* wifi_data_out, 171 WifiData* wifi_data_out,
172 int* max_age_out, 172 int* max_age_out,
173 std::string* access_token_out) { 173 std::string* access_token_out) {
174 CHECK(wifi_data_out && max_age_out && access_token_out); 174 CHECK(wifi_data_out && max_age_out && access_token_out);
175 scoped_ptr<Value> value(base::JSONReader::Read(request_data, false)); 175 scoped_ptr<Value> value(base::JSONReader::Read(request_data, false));
176 EXPECT_TRUE(value != NULL); 176 EXPECT_TRUE(value != NULL);
177 EXPECT_EQ(Value::TYPE_DICTIONARY, value->GetType()); 177 EXPECT_EQ(Value::TYPE_DICTIONARY, value->GetType());
178 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.get()); 178 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.get());
179 std::string attr_value; 179 std::string attr_value;
180 EXPECT_TRUE(dictionary->GetString(L"version", &attr_value)); 180 EXPECT_TRUE(dictionary->GetString("version", &attr_value));
181 EXPECT_EQ(attr_value, "1.1.0"); 181 EXPECT_EQ(attr_value, "1.1.0");
182 EXPECT_TRUE(dictionary->GetString(L"host", &attr_value)); 182 EXPECT_TRUE(dictionary->GetString("host", &attr_value));
183 EXPECT_EQ(attr_value, kTestHost); 183 EXPECT_EQ(attr_value, kTestHost);
184 // Everything else is optional. 184 // Everything else is optional.
185 ListValue* wifi_aps; 185 ListValue* wifi_aps;
186 *max_age_out = kint32min; 186 *max_age_out = kint32min;
187 if (dictionary->GetList(L"wifi_towers", &wifi_aps)) { 187 if (dictionary->GetList("wifi_towers", &wifi_aps)) {
188 int i = 0; 188 int i = 0;
189 for (ListValue::const_iterator it = wifi_aps->begin(); 189 for (ListValue::const_iterator it = wifi_aps->begin();
190 it < wifi_aps->end(); ++it, ++i) { 190 it < wifi_aps->end(); ++it, ++i) {
191 EXPECT_EQ(Value::TYPE_DICTIONARY, (*it)->GetType()); 191 EXPECT_EQ(Value::TYPE_DICTIONARY, (*it)->GetType());
192 DictionaryValue* ap = static_cast<DictionaryValue*>(*it); 192 DictionaryValue* ap = static_cast<DictionaryValue*>(*it);
193 AccessPointData data; 193 AccessPointData data;
194 ap->GetStringAsUTF16(L"mac_address", &data.mac_address); 194 ap->GetString("mac_address", &data.mac_address);
195 ap->GetInteger(L"signal_strength", &data.radio_signal_strength); 195 ap->GetInteger("signal_strength", &data.radio_signal_strength);
196 int age = kint32min; 196 int age = kint32min;
197 ap->GetInteger(L"age", &age); 197 ap->GetInteger("age", &age);
198 if (age > *max_age_out) 198 if (age > *max_age_out)
199 *max_age_out = age; 199 *max_age_out = age;
200 ap->GetInteger(L"channel", &data.channel); 200 ap->GetInteger("channel", &data.channel);
201 ap->GetInteger(L"signal_to_noise", &data.signal_to_noise); 201 ap->GetInteger("signal_to_noise", &data.signal_to_noise);
202 ap->GetStringAsUTF16(L"ssid", &data.ssid); 202 ap->GetString("ssid", &data.ssid);
203 wifi_data_out->access_point_data.insert(data); 203 wifi_data_out->access_point_data.insert(data);
204 } 204 }
205 } else { 205 } else {
206 wifi_data_out->access_point_data.clear(); 206 wifi_data_out->access_point_data.clear();
207 } 207 }
208 if (!dictionary->GetString(L"access_token", access_token_out)) 208 if (!dictionary->GetString("access_token", access_token_out))
209 access_token_out->clear(); 209 access_token_out->clear();
210 } 210 }
211 211
212 static void CheckEmptyRequestIsValid(const std::string& request_data) { 212 static void CheckEmptyRequestIsValid(const std::string& request_data) {
213 WifiData wifi_aps; 213 WifiData wifi_aps;
214 std::string access_token; 214 std::string access_token;
215 int max_age; 215 int max_age;
216 ParseRequest(request_data, &wifi_aps, &max_age, &access_token); 216 ParseRequest(request_data, &wifi_aps, &max_age, &access_token);
217 EXPECT_EQ(kint32min, max_age); 217 EXPECT_EQ(kint32min, max_age);
218 EXPECT_EQ(0, static_cast<int>(wifi_aps.access_point_data.size())); 218 EXPECT_EQ(0, static_cast<int>(wifi_aps.access_point_data.size()));
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 provider->OnPermissionGranted(GURL(kTestHostUrl)); 468 provider->OnPermissionGranted(GURL(kTestHostUrl));
469 469
470 fetcher = get_url_fetcher_and_advance_id(); 470 fetcher = get_url_fetcher_and_advance_id();
471 ASSERT_TRUE(fetcher != NULL); 471 ASSERT_TRUE(fetcher != NULL);
472 472
473 EXPECT_EQ(test_server_url_, fetcher->original_url()); 473 EXPECT_EQ(test_server_url_, fetcher->original_url());
474 474
475 CheckRequestIsValid(fetcher->upload_data(), kScanCount, 475 CheckRequestIsValid(fetcher->upload_data(), kScanCount,
476 REFERENCE_ACCESS_TOKEN); 476 REFERENCE_ACCESS_TOKEN);
477 } 477 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/access_token_store.cc ('k') | chrome/browser/geolocation/network_location_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698