| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Apple Inc. All Rights Reserved. | 3 * Copyright (C) 2012 Apple Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "GeolocationClientMock.h" | 33 #include "GeolocationClientMock.h" |
| 34 | 34 |
| 35 #include "modules/geolocation/GeolocationController.h" | 35 #include "modules/geolocation/GeolocationController.h" |
| 36 #include "modules/geolocation/GeolocationError.h" | 36 #include "modules/geolocation/GeolocationError.h" |
| 37 #include "modules/geolocation/GeolocationPosition.h" | 37 #include "modules/geolocation/GeolocationPosition.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 GeolocationClientMock::GeolocationClientMock() | 41 GeolocationClientMock::GeolocationClientMock() |
| 42 : m_controller(0) | 42 : m_hasError(false) |
| 43 , m_hasError(false) | |
| 44 , m_controllerTimer(this, &GeolocationClientMock::controllerTimerFired) | 43 , m_controllerTimer(this, &GeolocationClientMock::controllerTimerFired) |
| 45 , m_permissionTimer(this, &GeolocationClientMock::permissionTimerFired) | 44 , m_permissionTimer(this, &GeolocationClientMock::permissionTimerFired) |
| 46 , m_isActive(false) | 45 , m_isActive(false) |
| 47 , m_permissionState(PermissionStateUnset) | 46 , m_permissionState(PermissionStateUnset) |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 GeolocationClientMock::~GeolocationClientMock() | 50 GeolocationClientMock::~GeolocationClientMock() |
| 52 { | 51 { |
| 53 ASSERT(!m_isActive); | 52 ASSERT(!m_isActive); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void GeolocationClientMock::setController(GeolocationController *controller) | |
| 57 { | |
| 58 ASSERT(controller && !m_controller); | |
| 59 m_controller = controller; | |
| 60 } | |
| 61 | |
| 62 void GeolocationClientMock::setPosition(PassRefPtrWillBeRawPtr<GeolocationPositi
on> position) | 55 void GeolocationClientMock::setPosition(PassRefPtrWillBeRawPtr<GeolocationPositi
on> position) |
| 63 { | 56 { |
| 64 m_lastPosition = position; | 57 m_lastPosition = position; |
| 65 clearError(); | 58 clearError(); |
| 66 asyncUpdateController(); | 59 asyncUpdateController(); |
| 67 } | 60 } |
| 68 | 61 |
| 69 void GeolocationClientMock::setPositionUnavailableError(const String& errorMessa
ge) | 62 void GeolocationClientMock::setPositionUnavailableError(const String& errorMessa
ge) |
| 70 { | 63 { |
| 71 m_hasError = true; | 64 m_hasError = true; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 93 } | 86 } |
| 94 | 87 |
| 95 void GeolocationClientMock::cancelPermissionRequest(Geolocation* geolocation) | 88 void GeolocationClientMock::cancelPermissionRequest(Geolocation* geolocation) |
| 96 { | 89 { |
| 97 // Called from Geolocation::disconnectFrame() in response to LocalFrame dest
ruction. | 90 // Called from Geolocation::disconnectFrame() in response to LocalFrame dest
ruction. |
| 98 m_pendingPermissions.remove(geolocation); | 91 m_pendingPermissions.remove(geolocation); |
| 99 if (m_pendingPermissions.isEmpty() && m_permissionTimer.isActive()) | 92 if (m_pendingPermissions.isEmpty() && m_permissionTimer.isActive()) |
| 100 m_permissionTimer.stop(); | 93 m_permissionTimer.stop(); |
| 101 } | 94 } |
| 102 | 95 |
| 96 void GeolocationClientMock::controllerForTestAdded(GeolocationController* contro
ller) |
| 97 { |
| 98 m_controllers.add(controller); |
| 99 } |
| 100 |
| 101 void GeolocationClientMock::controllerForTestRemoved(GeolocationController* cont
roller) |
| 102 { |
| 103 m_controllers.remove(controller); |
| 104 } |
| 105 |
| 103 void GeolocationClientMock::asyncUpdatePermission() | 106 void GeolocationClientMock::asyncUpdatePermission() |
| 104 { | 107 { |
| 105 ASSERT(m_permissionState != PermissionStateUnset); | 108 ASSERT(m_permissionState != PermissionStateUnset); |
| 106 if (!m_permissionTimer.isActive()) | 109 if (!m_permissionTimer.isActive()) |
| 107 m_permissionTimer.startOneShot(0, FROM_HERE); | 110 m_permissionTimer.startOneShot(0, FROM_HERE); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void GeolocationClientMock::permissionTimerFired(Timer<GeolocationClientMock>* t
imer) | 113 void GeolocationClientMock::permissionTimerFired(Timer<GeolocationClientMock>* t
imer) |
| 111 { | 114 { |
| 112 ASSERT_UNUSED(timer, timer == &m_permissionTimer); | 115 ASSERT_UNUSED(timer, timer == &m_permissionTimer); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // See https://bugs.webkit.org/show_bug.cgi?id=49438 | 151 // See https://bugs.webkit.org/show_bug.cgi?id=49438 |
| 149 } | 152 } |
| 150 | 153 |
| 151 GeolocationPosition* GeolocationClientMock::lastPosition() | 154 GeolocationPosition* GeolocationClientMock::lastPosition() |
| 152 { | 155 { |
| 153 return m_lastPosition.get(); | 156 return m_lastPosition.get(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 void GeolocationClientMock::asyncUpdateController() | 159 void GeolocationClientMock::asyncUpdateController() |
| 157 { | 160 { |
| 158 ASSERT(m_controller); | |
| 159 if (m_isActive && !m_controllerTimer.isActive()) | 161 if (m_isActive && !m_controllerTimer.isActive()) |
| 160 m_controllerTimer.startOneShot(0, FROM_HERE); | 162 m_controllerTimer.startOneShot(0, FROM_HERE); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void GeolocationClientMock::controllerTimerFired(Timer<GeolocationClientMock>* t
imer) | 165 void GeolocationClientMock::controllerTimerFired(Timer<GeolocationClientMock>* t
imer) |
| 164 { | 166 { |
| 165 ASSERT_UNUSED(timer, timer == &m_controllerTimer); | 167 ASSERT_UNUSED(timer, timer == &m_controllerTimer); |
| 166 ASSERT(m_controller); | |
| 167 | 168 |
| 169 // Make a copy of the set of controllers since it might be modified while it
erating. |
| 170 HashSet<GeolocationController*> controllers = m_controllers; |
| 168 if (m_lastPosition.get()) { | 171 if (m_lastPosition.get()) { |
| 169 ASSERT(!m_hasError); | 172 ASSERT(!m_hasError); |
| 170 m_controller->positionChanged(m_lastPosition.get()); | 173 for (HashSet<GeolocationController*>::iterator it = controllers.begin();
it != controllers.end(); ++it) |
| 174 (*it)->positionChanged(m_lastPosition.get()); |
| 171 } else if (m_hasError) { | 175 } else if (m_hasError) { |
| 172 m_controller->errorOccurred(GeolocationError::create(GeolocationError::P
ositionUnavailable, m_errorMessage).get()); | 176 for (HashSet<GeolocationController*>::iterator it = controllers.begin();
it != controllers.end(); ++it) |
| 177 (*it)->errorOccurred(GeolocationError::create(GeolocationError::Posi
tionUnavailable, m_errorMessage).get()); |
| 173 } | 178 } |
| 174 } | 179 } |
| 175 | 180 |
| 176 void GeolocationClientMock::clearError() | 181 void GeolocationClientMock::clearError() |
| 177 { | 182 { |
| 178 m_hasError = false; | 183 m_hasError = false; |
| 179 m_errorMessage = String(); | 184 m_errorMessage = String(); |
| 180 } | 185 } |
| 181 | 186 |
| 182 } // WebCore | 187 } // WebCore |
| OLD | NEW |