OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "InternalsGeolocation.h" | 32 #include "InternalsGeolocation.h" |
33 | 33 |
34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
35 #include "core/page/Page.h" | |
35 #include "core/testing/Internals.h" | 36 #include "core/testing/Internals.h" |
36 #include "modules/geolocation/GeolocationController.h" | 37 #include "modules/geolocation/GeolocationController.h" |
37 #include "modules/geolocation/GeolocationError.h" | 38 #include "modules/geolocation/GeolocationError.h" |
38 #include "modules/geolocation/GeolocationPosition.h" | 39 #include "modules/geolocation/GeolocationPosition.h" |
39 #include "modules/geolocation/testing/GeolocationClientMock.h" | 40 #include "modules/geolocation/testing/GeolocationClientMock.h" |
40 #include "wtf/CurrentTime.h" | 41 #include "wtf/CurrentTime.h" |
41 | 42 |
42 namespace WebCore { | 43 namespace WebCore { |
43 | 44 |
44 void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* docume nt) | 45 void InternalsGeolocation::setGeolocationClientMock(Internals&, Document* docume nt) |
45 { | 46 { |
46 ASSERT(document && document->page()); | 47 ASSERT(document && document->frame()); |
47 GeolocationController* controller = GeolocationController::from(document->pa ge()); | |
48 GeolocationClientMock* client = new GeolocationClientMock(); | 48 GeolocationClientMock* client = new GeolocationClientMock(); |
49 controller->setClientForTest(client); | 49 |
50 client->setController(controller); | 50 for (LocalFrame* childFrame = document->page()->mainFrame(); childFrame; chi ldFrame = childFrame->tree().nextSibling()) |
kenrb
2014/06/04 20:28:49
This loop looks to be entirely redundant, since ch
| |
51 GeolocationController::from(document->frame())->setClientForTest(client) ; | |
51 } | 52 } |
52 | 53 |
53 void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document , double latitude, double longitude, double accuracy) | 54 void InternalsGeolocation::setGeolocationPosition(Internals&, Document* document , double latitude, double longitude, double accuracy) |
54 { | 55 { |
55 ASSERT(document && document->page()); | 56 ASSERT(document && document->frame()); |
56 GeolocationClientMock* client = geolocationClient(document); | 57 GeolocationClientMock* client = geolocationClient(document); |
57 if (!client) | 58 if (!client) |
58 return; | 59 return; |
59 client->setPosition(GeolocationPosition::create(currentTime(), latitude, lon gitude, accuracy)); | 60 client->setPosition(GeolocationPosition::create(currentTime(), latitude, lon gitude, accuracy)); |
60 } | 61 } |
61 | 62 |
62 void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Do cument* document, const String& message) | 63 void InternalsGeolocation::setGeolocationPositionUnavailableError(Internals&, Do cument* document, const String& message) |
63 { | 64 { |
64 ASSERT(document && document->page()); | 65 ASSERT(document && document->frame()); |
65 GeolocationClientMock* client = geolocationClient(document); | 66 GeolocationClientMock* client = geolocationClient(document); |
66 if (!client) | 67 if (!client) |
67 return; | 68 return; |
68 client->setPositionUnavailableError(message); | 69 client->setPositionUnavailableError(message); |
69 } | 70 } |
70 | 71 |
71 void InternalsGeolocation::setGeolocationPermission(Internals&, Document* docume nt, bool allowed) | 72 void InternalsGeolocation::setGeolocationPermission(Internals&, Document* docume nt, bool allowed) |
72 { | 73 { |
73 ASSERT(document && document->page()); | 74 ASSERT(document && document->frame()); |
74 GeolocationClientMock* client = geolocationClient(document); | 75 GeolocationClientMock* client = geolocationClient(document); |
75 if (!client) | 76 if (!client) |
76 return; | 77 return; |
77 client->setPermission(allowed); | 78 client->setPermission(allowed); |
78 } | 79 } |
79 | 80 |
80 int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals &, Document* document) | 81 int InternalsGeolocation::numberOfPendingGeolocationPermissionRequests(Internals &, Document* document) |
81 { | 82 { |
82 ASSERT(document && document->page()); | 83 ASSERT(document && document->frame()); |
83 GeolocationClientMock* client = geolocationClient(document); | 84 GeolocationClientMock* client = geolocationClient(document); |
84 if (!client) | 85 if (!client) |
85 return -1; | 86 return -1; |
86 return client->numberOfPendingPermissionRequests(); | 87 return client->numberOfPendingPermissionRequests(); |
87 } | 88 } |
88 | 89 |
89 GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* documen t) | 90 GeolocationClientMock* InternalsGeolocation::geolocationClient(Document* documen t) |
90 { | 91 { |
91 GeolocationController* controller = GeolocationController::from(document->pa ge()); | 92 GeolocationController* controller = GeolocationController::from(document->fr ame()); |
92 if (!controller->hasClientForTest()) | 93 if (!controller->hasClientForTest()) |
93 return 0; | 94 return 0; |
94 return static_cast<GeolocationClientMock*>(controller->client()); | 95 return static_cast<GeolocationClientMock*>(controller->client()); |
95 } | 96 } |
96 | 97 |
97 } // namespace WebCore | 98 } // namespace WebCore |
OLD | NEW |