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

Side by Side Diff: ios/chrome/browser/geolocation/location_manager_unittest.mm

Issue 1103293002: [iOS] Upstream iOS geolocation code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 8 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/geolocation/location_manager.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h"
9 #import "ios/chrome/browser/geolocation/location_manager+Testing.h"
10 #import "ios/public/provider/chrome/browser/geolocation_updater_provider.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/gtest_mac.h"
13 #include "testing/platform_test.h"
14 #import "third_party/ocmock/OCMock/OCMock.h"
15 #import "third_party/ocmock/gtest_support.h"
16
17 namespace {
18
19 class LocationManagerTest : public PlatformTest {
20 public:
21 LocationManagerTest() {}
22
23 protected:
24 void SetUp() override {
25 PlatformTest::SetUp();
26
27 mock_geolocation_updater_.reset(
28 [[OCMockObject mockForProtocol:@protocol(GeolocationUpdater)] retain]);
29
30 // Set up LocationManager with a mock GeolocationUpdater.
31 location_manager_.reset([[LocationManager alloc] init]);
32 [location_manager_ setGeolocationUpdater:mock_geolocation_updater_.get()];
33 }
34
35 void TearDown() override {
36 [location_manager_ setGeolocationUpdater:nil];
37
38 PlatformTest::TearDown();
39 }
40
41 base::scoped_nsobject<id> mock_geolocation_updater_;
42 base::scoped_nsobject<LocationManager> location_manager_;
43 };
44
45 // Verifies that -[LocationManager startUpdatingLocation] calls
46 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater does not yet have
47 // a current location.
48 TEST_F(LocationManagerTest, StartUpdatingLocationNilCurrentLocation) {
49 [[[mock_geolocation_updater_ expect] andReturn:nil] currentLocation];
50
51 // Also expect the call to -[GeolocationUpdater isEnabled];
52 BOOL no = NO;
53 [[[mock_geolocation_updater_ expect]
54 andReturnValue:OCMOCK_VALUE(no)] isEnabled];
55 [[mock_geolocation_updater_ expect] requestWhenInUseAuthorization];
56 [[mock_geolocation_updater_ expect] setEnabled:YES];
57
58 [location_manager_ startUpdatingLocation];
59 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get());
60 }
61
62 // Verifies that -[LocationManager startUpdatingLocation] calls
63 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater
64 // |currentLocation| is stale.
65 TEST_F(LocationManagerTest, StartUpdatingLocationStaleCurrentLocation) {
66 // Set up to return a stale mock CLLocation from -[GeolocationUpdater
67 // currentLocation].
68 base::scoped_nsobject<id> mock_location(
69 [[OCMockObject mockForClass:[CLLocation class]] retain]);
70 BOOL yes = YES;
71 [[[mock_location expect] andReturnValue:OCMOCK_VALUE(yes)] cr_shouldRefresh];
72
73 [[[mock_geolocation_updater_ expect]
74 andReturn:mock_location.get()] currentLocation];
75
76 // Also expect the call to -[GeolocationUpdater isEnabled];
77 BOOL no = NO;
78 [[[mock_geolocation_updater_ expect]
79 andReturnValue:OCMOCK_VALUE(no)] isEnabled];
80 [[mock_geolocation_updater_ expect] requestWhenInUseAuthorization];
81 [[mock_geolocation_updater_ expect] setEnabled:YES];
82
83 [location_manager_ startUpdatingLocation];
84 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get());
85 EXPECT_OCMOCK_VERIFY(mock_location.get());
86 }
87
88 // Verifies that -[LocationManager startUpdatingLocation] does not call
89 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater's
90 // |currentLocation| is fresh.
91 TEST_F(LocationManagerTest, StartUpdatingLocationFreshCurrentLocation) {
92 // Set up to return a fresh mock CLLocation from -[GeolocationUpdater
93 // currentLocation].
94 base::scoped_nsobject<id> mock_location(
95 [[OCMockObject mockForClass:[CLLocation class]] retain]);
96 BOOL no = NO;
97 [[[mock_location expect] andReturnValue:OCMOCK_VALUE(no)] cr_shouldRefresh];
98
99 [[[mock_geolocation_updater_ expect]
100 andReturn:mock_location.get()] currentLocation];
101
102 [location_manager_ startUpdatingLocation];
103 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get());
104 EXPECT_OCMOCK_VERIFY(mock_location.get());
105 }
106
107 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/geolocation/location_manager+Testing.h ('k') | ios/chrome/browser/geolocation/omnibox_geolocation_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698