diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 12:37:57 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 12:37:57 +0000 |
commit | a598247f2a78fb8a394c5db79c39ae5cd2101697 (patch) | |
tree | 3668ae29edc3050292219ade6b5c337272ccd06d /chrome/browser/geolocation/network_location_request.cc | |
parent | 6c8493c5bf17929c6cd6815e8dc80c5038cbbd29 (diff) | |
download | chromium_src-a598247f2a78fb8a394c5db79c39ae5cd2101697.zip chromium_src-a598247f2a78fb8a394c5db79c39ae5cd2101697.tar.gz chromium_src-a598247f2a78fb8a394c5db79c39ae5cd2101697.tar.bz2 |
Re-attempt at http://src.chromium.org/viewvc/chrome?view=rev&revision=37989
(asserts tidy up slit out into its own change http://codereview.chromium.org/578013/show)
Add tests for the geolocation network provider.
Also some small tidy up a few other files.
BUG=http://crbug.com/11246
TEST=unit_tests.exe --gtest_filter=NetworkLocationProvider* --gtest_break_on_failure
Review URL: http://codereview.chromium.org/578006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38207 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation/network_location_request.cc')
-rw-r--r-- | chrome/browser/geolocation/network_location_request.cc | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/chrome/browser/geolocation/network_location_request.cc b/chrome/browser/geolocation/network_location_request.cc index 7fff715..65e3f37 100644 --- a/chrome/browser/geolocation/network_location_request.cc +++ b/chrome/browser/geolocation/network_location_request.cc @@ -66,7 +66,6 @@ NetworkLocationRequest::NetworkLocationRequest(URLRequestContextGetter* context, ListenerInterface* listener) : url_context_(context), timestamp_(kint64min), listener_(listener), url_(url), host_name_(host_name) { -// DCHECK(url_context_); DCHECK(listener); } @@ -89,7 +88,7 @@ bool NetworkLocationRequest::MakeRequest(const string16& access_token, timestamp_ = timestamp; url_fetcher_.reset(URLFetcher::Create( - host_name_.size(), // Used for testing + wifi_data.access_point_data.size(), // Used for testing url_, URLFetcher::POST, this)); url_fetcher_->set_upload_data(kMimeApplicationJson, post_body); url_fetcher_->set_request_context(url_context_); @@ -312,20 +311,31 @@ bool ParseServerResponse(const std::string& response_body, response_object->GetStringAsUTF16(kAccessTokenString, access_token); // Get the location - DictionaryValue* location_object; - if (!response_object->GetDictionary(kLocationString, &location_object)) { - Value* value = NULL; - // If the network provider was unable to provide a position fix, it should - // return a 200 with location == null. Otherwise it's an error. - return response_object->Get(kLocationString, &value) - && value && value->IsType(Value::TYPE_NULL); + Value* location_value = NULL; + if (!response_object->Get(kLocationString, &location_value)) { + LOG(INFO) << "ParseServerResponse() : Missing location attribute.\n"; + return false; + } + DCHECK(location_value); + + if (!location_value->IsType(Value::TYPE_DICTIONARY)) { + if (!location_value->IsType(Value::TYPE_NULL)) { + LOG(INFO) << "ParseServerResponse() : Unexpected location type" + << location_value->GetType() << ".\n"; + // If the network provider was unable to provide a position fix, it should + // return a HTTP 200, with "location" : null. Otherwise it's an error. + return false; + } + return true; // Successfully parsed response containing no fix. } - DCHECK(location_object); + DictionaryValue* location_object = + static_cast<DictionaryValue*>(location_value); // latitude and longitude fields are always required. double latitude, longitude; if (!GetAsDouble(*location_object, kLatitudeString, &latitude) || !GetAsDouble(*location_object, kLongitudeString, &longitude)) { + LOG(INFO) << "ParseServerResponse() : location lacks lat and/or long.\n"; return false; } // All error paths covered: now start actually modifying postion. |