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

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

Issue 2515723003: [ObjC ARC] Converts ios/chrome/browser/geolocation:unit_tests to ARC.Automatically generated ARCM… (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #import "ios/chrome/browser/geolocation/location_manager.h" 5 #import "ios/chrome/browser/geolocation/location_manager.h"
6 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 #import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h" 8 #import "ios/chrome/browser/geolocation/CLLocation+OmniboxGeolocation.h"
9 #import "ios/chrome/browser/geolocation/location_manager+Testing.h" 9 #import "ios/chrome/browser/geolocation/location_manager+Testing.h"
10 #import "ios/public/provider/chrome/browser/geolocation_updater_provider.h" 10 #import "ios/public/provider/chrome/browser/geolocation_updater_provider.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/gtest_mac.h" 12 #include "testing/gtest_mac.h"
13 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 #import "third_party/ocmock/OCMock/OCMock.h" 14 #import "third_party/ocmock/OCMock/OCMock.h"
15 #import "third_party/ocmock/gtest_support.h" 15 #import "third_party/ocmock/gtest_support.h"
16 16
17 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support."
19 #endif
20
17 namespace { 21 namespace {
18 22
19 class LocationManagerTest : public PlatformTest { 23 class LocationManagerTest : public PlatformTest {
20 public: 24 public:
21 LocationManagerTest() {} 25 LocationManagerTest() {}
22 26
23 protected: 27 protected:
24 void SetUp() override { 28 void SetUp() override {
25 PlatformTest::SetUp(); 29 PlatformTest::SetUp();
26 30
27 mock_geolocation_updater_.reset( 31 mock_geolocation_updater_.reset(
28 [[OCMockObject mockForProtocol:@protocol(GeolocationUpdater)] retain]); 32 [OCMockObject mockForProtocol:@protocol(GeolocationUpdater)]);
29 33
30 // Set up LocationManager with a mock GeolocationUpdater. 34 // Set up LocationManager with a mock GeolocationUpdater.
31 location_manager_.reset([[LocationManager alloc] init]); 35 location_manager_.reset([[LocationManager alloc] init]);
32 [location_manager_ setGeolocationUpdater:mock_geolocation_updater_.get()]; 36 [location_manager_ setGeolocationUpdater:mock_geolocation_updater_.get()];
33 } 37 }
34 38
35 void TearDown() override { 39 void TearDown() override {
36 [location_manager_ setGeolocationUpdater:nil]; 40 [location_manager_ setGeolocationUpdater:nil];
37 41
38 PlatformTest::TearDown(); 42 PlatformTest::TearDown();
(...skipping 20 matching lines...) Expand all
59 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get()); 63 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get());
60 } 64 }
61 65
62 // Verifies that -[LocationManager startUpdatingLocation] calls 66 // Verifies that -[LocationManager startUpdatingLocation] calls
63 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater 67 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater
64 // |currentLocation| is stale. 68 // |currentLocation| is stale.
65 TEST_F(LocationManagerTest, StartUpdatingLocationStaleCurrentLocation) { 69 TEST_F(LocationManagerTest, StartUpdatingLocationStaleCurrentLocation) {
66 // Set up to return a stale mock CLLocation from -[GeolocationUpdater 70 // Set up to return a stale mock CLLocation from -[GeolocationUpdater
67 // currentLocation]. 71 // currentLocation].
68 base::scoped_nsobject<id> mock_location( 72 base::scoped_nsobject<id> mock_location(
69 [[OCMockObject mockForClass:[CLLocation class]] retain]); 73 [OCMockObject mockForClass:[CLLocation class]]);
70 BOOL yes = YES; 74 BOOL yes = YES;
71 [[[mock_location expect] andReturnValue:OCMOCK_VALUE(yes)] cr_shouldRefresh]; 75 [[[mock_location expect] andReturnValue:OCMOCK_VALUE(yes)] cr_shouldRefresh];
72 76
73 [[[mock_geolocation_updater_ expect] 77 [[[mock_geolocation_updater_ expect]
74 andReturn:mock_location.get()] currentLocation]; 78 andReturn:mock_location.get()] currentLocation];
75 79
76 // Also expect the call to -[GeolocationUpdater isEnabled]; 80 // Also expect the call to -[GeolocationUpdater isEnabled];
77 BOOL no = NO; 81 BOOL no = NO;
78 [[[mock_geolocation_updater_ expect] 82 [[[mock_geolocation_updater_ expect]
79 andReturnValue:OCMOCK_VALUE(no)] isEnabled]; 83 andReturnValue:OCMOCK_VALUE(no)] isEnabled];
80 [[mock_geolocation_updater_ expect] requestWhenInUseAuthorization]; 84 [[mock_geolocation_updater_ expect] requestWhenInUseAuthorization];
81 [[mock_geolocation_updater_ expect] setEnabled:YES]; 85 [[mock_geolocation_updater_ expect] setEnabled:YES];
82 86
83 [location_manager_ startUpdatingLocation]; 87 [location_manager_ startUpdatingLocation];
84 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get()); 88 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get());
85 EXPECT_OCMOCK_VERIFY(mock_location.get()); 89 EXPECT_OCMOCK_VERIFY(mock_location.get());
86 } 90 }
87 91
88 // Verifies that -[LocationManager startUpdatingLocation] does not call 92 // Verifies that -[LocationManager startUpdatingLocation] does not call
89 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater's 93 // -[GeolocationUpdater setEnabled:] when GeolocationUpdater's
90 // |currentLocation| is fresh. 94 // |currentLocation| is fresh.
91 TEST_F(LocationManagerTest, StartUpdatingLocationFreshCurrentLocation) { 95 TEST_F(LocationManagerTest, StartUpdatingLocationFreshCurrentLocation) {
92 // Set up to return a fresh mock CLLocation from -[GeolocationUpdater 96 // Set up to return a fresh mock CLLocation from -[GeolocationUpdater
93 // currentLocation]. 97 // currentLocation].
94 base::scoped_nsobject<id> mock_location( 98 base::scoped_nsobject<id> mock_location(
95 [[OCMockObject mockForClass:[CLLocation class]] retain]); 99 [OCMockObject mockForClass:[CLLocation class]]);
96 BOOL no = NO; 100 BOOL no = NO;
97 [[[mock_location expect] andReturnValue:OCMOCK_VALUE(no)] cr_shouldRefresh]; 101 [[[mock_location expect] andReturnValue:OCMOCK_VALUE(no)] cr_shouldRefresh];
98 102
99 [[[mock_geolocation_updater_ expect] 103 [[[mock_geolocation_updater_ expect]
100 andReturn:mock_location.get()] currentLocation]; 104 andReturn:mock_location.get()] currentLocation];
101 105
102 [location_manager_ startUpdatingLocation]; 106 [location_manager_ startUpdatingLocation];
103 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get()); 107 EXPECT_OCMOCK_VERIFY(mock_geolocation_updater_.get());
104 EXPECT_OCMOCK_VERIFY(mock_location.get()); 108 EXPECT_OCMOCK_VERIFY(mock_location.get());
105 } 109 }
106 110
107 } // namespace 111 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698