OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "chrome/browser/geolocation/fake_access_token_store.h" | 11 #include "chrome/browser/geolocation/fake_access_token_store.h" |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); | 426 TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); |
427 ASSERT_TRUE(fetcher != NULL); | 427 ASSERT_TRUE(fetcher != NULL); |
428 CheckEmptyRequestIsValid(fetcher->upload_data()); | 428 CheckEmptyRequestIsValid(fetcher->upload_data()); |
429 // Complete the network request with bad position fix. | 429 // Complete the network request with bad position fix. |
430 const char* kNoFixNetworkResponse = | 430 const char* kNoFixNetworkResponse = |
431 "{" | 431 "{" |
432 " \"location\": null," | 432 " \"location\": null," |
433 " \"access_token\": \"" REFERENCE_ACCESS_TOKEN "\"" | 433 " \"access_token\": \"" REFERENCE_ACCESS_TOKEN "\"" |
434 "}"; | 434 "}"; |
435 fetcher->delegate()->OnURLFetchComplete( | 435 fetcher->delegate()->OnURLFetchComplete( |
436 fetcher, test_server_url_, URLRequestStatus(), 200, // OK | 436 fetcher, test_server_url_, net::URLRequestStatus(), 200, // OK |
437 ResponseCookies(), kNoFixNetworkResponse); | 437 ResponseCookies(), kNoFixNetworkResponse); |
438 | 438 |
439 // This should have set the access token anyhow | 439 // This should have set the access token anyhow |
440 EXPECT_EQ(UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), | 440 EXPECT_EQ(UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), |
441 access_token_store_->access_token_set_[test_server_url_]); | 441 access_token_store_->access_token_set_[test_server_url_]); |
442 | 442 |
443 Geoposition position; | 443 Geoposition position; |
444 provider->GetPosition(&position); | 444 provider->GetPosition(&position); |
445 EXPECT_FALSE(position.IsValidFix()); | 445 EXPECT_FALSE(position.IsValidFix()); |
446 | 446 |
(...skipping 13 matching lines...) Expand all Loading... |
460 "{" | 460 "{" |
461 " \"location\": {" | 461 " \"location\": {" |
462 " \"latitude\": 51.0," | 462 " \"latitude\": 51.0," |
463 " \"longitude\": -0.1," | 463 " \"longitude\": -0.1," |
464 " \"altitude\": 30.1," | 464 " \"altitude\": 30.1," |
465 " \"accuracy\": 1200.4," | 465 " \"accuracy\": 1200.4," |
466 " \"altitude_accuracy\": 10.6" | 466 " \"altitude_accuracy\": 10.6" |
467 " }" | 467 " }" |
468 "}"; | 468 "}"; |
469 fetcher->delegate()->OnURLFetchComplete( | 469 fetcher->delegate()->OnURLFetchComplete( |
470 fetcher, test_server_url_, URLRequestStatus(), 200, // OK | 470 fetcher, test_server_url_, net::URLRequestStatus(), 200, // OK |
471 ResponseCookies(), kReferenceNetworkResponse); | 471 ResponseCookies(), kReferenceNetworkResponse); |
472 | 472 |
473 provider->GetPosition(&position); | 473 provider->GetPosition(&position); |
474 EXPECT_EQ(51.0, position.latitude); | 474 EXPECT_EQ(51.0, position.latitude); |
475 EXPECT_EQ(-0.1, position.longitude); | 475 EXPECT_EQ(-0.1, position.longitude); |
476 EXPECT_EQ(30.1, position.altitude); | 476 EXPECT_EQ(30.1, position.altitude); |
477 EXPECT_EQ(1200.4, position.accuracy); | 477 EXPECT_EQ(1200.4, position.accuracy); |
478 EXPECT_EQ(10.6, position.altitude_accuracy); | 478 EXPECT_EQ(10.6, position.altitude_accuracy); |
479 EXPECT_TRUE(position.is_valid_timestamp()); | 479 EXPECT_TRUE(position.is_valid_timestamp()); |
480 EXPECT_TRUE(position.IsValidFix()); | 480 EXPECT_TRUE(position.IsValidFix()); |
(...skipping 17 matching lines...) Expand all Loading... |
498 | 498 |
499 // Now a third scan with more than twice the original amount -> new request. | 499 // Now a third scan with more than twice the original amount -> new request. |
500 const int kThirdScanAps = kFirstScanAps * 2 + 1; | 500 const int kThirdScanAps = kFirstScanAps * 2 + 1; |
501 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kThirdScanAps)); | 501 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kThirdScanAps)); |
502 main_message_loop_.RunAllPending(); | 502 main_message_loop_.RunAllPending(); |
503 fetcher = get_url_fetcher_and_advance_id(); | 503 fetcher = get_url_fetcher_and_advance_id(); |
504 EXPECT_TRUE(fetcher); | 504 EXPECT_TRUE(fetcher); |
505 // ...reply with a network error. | 505 // ...reply with a network error. |
506 fetcher->delegate()->OnURLFetchComplete( | 506 fetcher->delegate()->OnURLFetchComplete( |
507 fetcher, test_server_url_, | 507 fetcher, test_server_url_, |
508 URLRequestStatus(URLRequestStatus::FAILED, -1), | 508 net::URLRequestStatus(net::URLRequestStatus::FAILED, -1), |
509 200, // should be ignored | 509 200, // should be ignored |
510 ResponseCookies(), ""); | 510 ResponseCookies(), ""); |
511 | 511 |
512 // Error means we now no longer have a fix. | 512 // Error means we now no longer have a fix. |
513 provider->GetPosition(&position); | 513 provider->GetPosition(&position); |
514 EXPECT_FALSE(position.is_valid_latlong()); | 514 EXPECT_FALSE(position.is_valid_latlong()); |
515 EXPECT_FALSE(position.IsValidFix()); | 515 EXPECT_FALSE(position.IsValidFix()); |
516 | 516 |
517 // Wifi scan returns to original set: should be serviced from cache. | 517 // Wifi scan returns to original set: should be serviced from cache. |
518 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kFirstScanAps)); | 518 wifi_data_provider_->SetData(CreateReferenceWifiScanData(kFirstScanAps)); |
(...skipping 15 matching lines...) Expand all Loading... |
534 CheckEmptyRequestIsValid(fetcher->upload_data()); | 534 CheckEmptyRequestIsValid(fetcher->upload_data()); |
535 // Complete the network request with bad position fix (using #define so we | 535 // Complete the network request with bad position fix (using #define so we |
536 // can paste this into various other strings below) | 536 // can paste this into various other strings below) |
537 #define REFERENCE_ACCESS_TOKEN "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe" | 537 #define REFERENCE_ACCESS_TOKEN "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe" |
538 const char* kNoFixNetworkResponse = | 538 const char* kNoFixNetworkResponse = |
539 "{" | 539 "{" |
540 " \"location\": null," | 540 " \"location\": null," |
541 " \"access_token\": \"" REFERENCE_ACCESS_TOKEN "\"" | 541 " \"access_token\": \"" REFERENCE_ACCESS_TOKEN "\"" |
542 "}"; | 542 "}"; |
543 fetcher->delegate()->OnURLFetchComplete( | 543 fetcher->delegate()->OnURLFetchComplete( |
544 fetcher, test_server_url_, URLRequestStatus(), 200, // OK | 544 fetcher, test_server_url_, net::URLRequestStatus(), 200, // OK |
545 ResponseCookies(), kNoFixNetworkResponse); | 545 ResponseCookies(), kNoFixNetworkResponse); |
546 | 546 |
547 // This should have set the access token anyhow | 547 // This should have set the access token anyhow |
548 EXPECT_EQ(UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), | 548 EXPECT_EQ(UTF8ToUTF16(REFERENCE_ACCESS_TOKEN), |
549 access_token_store_->access_token_set_[test_server_url_]); | 549 access_token_store_->access_token_set_[test_server_url_]); |
550 | 550 |
551 Geoposition position; | 551 Geoposition position; |
552 provider->GetPosition(&position); | 552 provider->GetPosition(&position); |
553 EXPECT_FALSE(position.IsValidFix()); | 553 EXPECT_FALSE(position.IsValidFix()); |
554 | 554 |
(...skipping 14 matching lines...) Expand all Loading... |
569 "{" | 569 "{" |
570 " \"location\": {" | 570 " \"location\": {" |
571 " \"latitude\": 51.0," | 571 " \"latitude\": 51.0," |
572 " \"longitude\": -0.1," | 572 " \"longitude\": -0.1," |
573 " \"altitude\": 30.1," | 573 " \"altitude\": 30.1," |
574 " \"accuracy\": 1200.4," | 574 " \"accuracy\": 1200.4," |
575 " \"altitude_accuracy\": 10.6" | 575 " \"altitude_accuracy\": 10.6" |
576 " }" | 576 " }" |
577 "}"; | 577 "}"; |
578 fetcher->delegate()->OnURLFetchComplete( | 578 fetcher->delegate()->OnURLFetchComplete( |
579 fetcher, test_server_url_, URLRequestStatus(), 200, // OK | 579 fetcher, test_server_url_, net::URLRequestStatus(), 200, // OK |
580 ResponseCookies(), kReferenceNetworkResponse_1); | 580 ResponseCookies(), kReferenceNetworkResponse_1); |
581 | 581 |
582 provider->GetPosition(&position); | 582 provider->GetPosition(&position); |
583 EXPECT_EQ(51.0, position.latitude); | 583 EXPECT_EQ(51.0, position.latitude); |
584 EXPECT_EQ(-0.1, position.longitude); | 584 EXPECT_EQ(-0.1, position.longitude); |
585 EXPECT_EQ(30.1, position.altitude); | 585 EXPECT_EQ(30.1, position.altitude); |
586 EXPECT_EQ(1200.4, position.accuracy); | 586 EXPECT_EQ(1200.4, position.accuracy); |
587 EXPECT_EQ(10.6, position.altitude_accuracy); | 587 EXPECT_EQ(10.6, position.altitude_accuracy); |
588 EXPECT_TRUE(position.is_valid_timestamp()); | 588 EXPECT_TRUE(position.is_valid_timestamp()); |
589 EXPECT_TRUE(position.IsValidFix()); | 589 EXPECT_TRUE(position.IsValidFix()); |
(...skipping 19 matching lines...) Expand all Loading... |
609 "{" | 609 "{" |
610 " \"location\": {" | 610 " \"location\": {" |
611 " \"latitude\": 51.1," | 611 " \"latitude\": 51.1," |
612 " \"longitude\": -0.1," | 612 " \"longitude\": -0.1," |
613 " \"altitude\": 30.2," | 613 " \"altitude\": 30.2," |
614 " \"accuracy\": 1100.4," | 614 " \"accuracy\": 1100.4," |
615 " \"altitude_accuracy\": 10.6" | 615 " \"altitude_accuracy\": 10.6" |
616 " }" | 616 " }" |
617 "}"; | 617 "}"; |
618 fetcher->delegate()->OnURLFetchComplete( | 618 fetcher->delegate()->OnURLFetchComplete( |
619 fetcher, test_server_url_, URLRequestStatus(), 200, // OK | 619 fetcher, test_server_url_, net::URLRequestStatus(), 200, // OK |
620 ResponseCookies(), kReferenceNetworkResponse_2); | 620 ResponseCookies(), kReferenceNetworkResponse_2); |
621 | 621 |
622 provider->GetPosition(&position); | 622 provider->GetPosition(&position); |
623 EXPECT_EQ(51.1, position.latitude); | 623 EXPECT_EQ(51.1, position.latitude); |
624 EXPECT_EQ(-0.1, position.longitude); | 624 EXPECT_EQ(-0.1, position.longitude); |
625 EXPECT_EQ(30.2, position.altitude); | 625 EXPECT_EQ(30.2, position.altitude); |
626 EXPECT_EQ(1100.4, position.accuracy); | 626 EXPECT_EQ(1100.4, position.accuracy); |
627 EXPECT_EQ(10.6, position.altitude_accuracy); | 627 EXPECT_EQ(10.6, position.altitude_accuracy); |
628 EXPECT_TRUE(position.is_valid_timestamp()); | 628 EXPECT_TRUE(position.is_valid_timestamp()); |
629 EXPECT_TRUE(position.IsValidFix()); | 629 EXPECT_TRUE(position.IsValidFix()); |
(...skipping 12 matching lines...) Expand all Loading... |
642 "{" | 642 "{" |
643 " \"location\": {" | 643 " \"location\": {" |
644 " \"latitude\": 51.3," | 644 " \"latitude\": 51.3," |
645 " \"longitude\": -0.1," | 645 " \"longitude\": -0.1," |
646 " \"altitude\": 30.2," | 646 " \"altitude\": 30.2," |
647 " \"accuracy\": 50.4," | 647 " \"accuracy\": 50.4," |
648 " \"altitude_accuracy\": 10.6" | 648 " \"altitude_accuracy\": 10.6" |
649 " }" | 649 " }" |
650 "}"; | 650 "}"; |
651 fetcher->delegate()->OnURLFetchComplete( | 651 fetcher->delegate()->OnURLFetchComplete( |
652 fetcher, test_server_url_, URLRequestStatus(), 200, // OK | 652 fetcher, test_server_url_, net::URLRequestStatus(), 200, // OK |
653 ResponseCookies(), kReferenceNetworkResponse_3); | 653 ResponseCookies(), kReferenceNetworkResponse_3); |
654 | 654 |
655 provider->GetPosition(&position); | 655 provider->GetPosition(&position); |
656 EXPECT_EQ(51.3, position.latitude); | 656 EXPECT_EQ(51.3, position.latitude); |
657 EXPECT_EQ(-0.1, position.longitude); | 657 EXPECT_EQ(-0.1, position.longitude); |
658 EXPECT_EQ(30.2, position.altitude); | 658 EXPECT_EQ(30.2, position.altitude); |
659 EXPECT_EQ(50.4, position.accuracy); | 659 EXPECT_EQ(50.4, position.accuracy); |
660 EXPECT_EQ(10.6, position.altitude_accuracy); | 660 EXPECT_EQ(10.6, position.altitude_accuracy); |
661 EXPECT_TRUE(position.is_valid_timestamp()); | 661 EXPECT_TRUE(position.is_valid_timestamp()); |
662 EXPECT_TRUE(position.IsValidFix()); | 662 EXPECT_TRUE(position.IsValidFix()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 } else { | 772 } else { |
773 const int evicted = i - kCacheSize; | 773 const int evicted = i - kCacheSize; |
774 EXPECT_FALSE(cache.FindPosition(CreateReferenceRouterData(2), | 774 EXPECT_FALSE(cache.FindPosition(CreateReferenceRouterData(2), |
775 CreateReferenceWifiScanData(evicted))); | 775 CreateReferenceWifiScanData(evicted))); |
776 EXPECT_TRUE(cache.FindPosition(CreateReferenceRouterData(2), | 776 EXPECT_TRUE(cache.FindPosition(CreateReferenceRouterData(2), |
777 CreateReferenceWifiScanData(evicted + 1))); | 777 CreateReferenceWifiScanData(evicted + 1))); |
778 } | 778 } |
779 } | 779 } |
780 } | 780 } |
781 | 781 |
OLD | NEW |