OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
6 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" | 6 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h" |
7 #include "chrome/browser/geolocation/geolocation_permission_request_id.h" | 7 #include "chrome/browser/geolocation/geolocation_permission_request_id.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
12 #include "content/public/test/mock_render_process_host.h" | 12 #include "content/public/test/mock_render_process_host.h" |
13 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 class GeolocationInfoBarQueueControllerTests | 16 class GeolocationInfoBarQueueControllerTests |
17 : public ChromeRenderViewHostTestHarness { | 17 : public ChromeRenderViewHostTestHarness { |
18 public: | 18 protected: |
19 GeolocationInfoBarQueueControllerTests(); | 19 virtual void SetUp() OVERRIDE { |
| 20 ChromeRenderViewHostTestHarness::SetUp(); |
| 21 InfoBarService::CreateForWebContents(web_contents()); |
| 22 } |
20 | 23 |
21 protected: | 24 GeolocationPermissionRequestID RequestID(int bridge_id) { |
22 GeolocationPermissionRequestID RequestID(int bridge_id); | 25 return GeolocationPermissionRequestID( |
23 | 26 web_contents()->GetRenderProcessHost()->GetID(), |
24 private: | 27 web_contents()->GetRenderViewHost()->GetRoutingID(), |
25 // ChromeRenderViewHostTestHarness: | 28 bridge_id); |
26 virtual void SetUp() OVERRIDE; | 29 } |
27 | |
28 content::TestBrowserThread ui_thread_; | |
29 | |
30 DISALLOW_COPY_AND_ASSIGN(GeolocationInfoBarQueueControllerTests); | |
31 }; | 30 }; |
32 | 31 |
33 GeolocationInfoBarQueueControllerTests::GeolocationInfoBarQueueControllerTests() | |
34 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()) { | |
35 } | |
36 | |
37 GeolocationPermissionRequestID | |
38 GeolocationInfoBarQueueControllerTests::RequestID(int bridge_id) { | |
39 return GeolocationPermissionRequestID( | |
40 web_contents()->GetRenderProcessHost()->GetID(), | |
41 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
42 bridge_id); | |
43 } | |
44 | |
45 void GeolocationInfoBarQueueControllerTests::SetUp() { | |
46 ChromeRenderViewHostTestHarness::SetUp(); | |
47 InfoBarService::CreateForWebContents(web_contents()); | |
48 } | |
49 | |
50 class ObservationCountingQueueController : | 32 class ObservationCountingQueueController : |
51 public GeolocationInfoBarQueueController { | 33 public GeolocationInfoBarQueueController { |
52 public: | 34 public: |
53 explicit ObservationCountingQueueController(Profile* profile); | 35 explicit ObservationCountingQueueController(Profile* profile); |
54 | 36 |
55 int call_count() const { return call_count_; } | 37 int call_count() const { return call_count_; } |
56 | 38 |
57 private: | 39 private: |
58 int call_count_; | 40 int call_count_; |
59 | 41 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 ObservationCountingQueueController infobar_queue_controller(profile()); | 88 ObservationCountingQueueController infobar_queue_controller(profile()); |
107 GURL url("http://www.example.com/geolocation"); | 89 GURL url("http://www.example.com/geolocation"); |
108 base::Callback<void(bool)> callback; | 90 base::Callback<void(bool)> callback; |
109 infobar_queue_controller.CreateInfoBarRequest(RequestID(0), url, url, | 91 infobar_queue_controller.CreateInfoBarRequest(RequestID(0), url, url, |
110 callback); | 92 callback); |
111 infobar_queue_controller.CreateInfoBarRequest(RequestID(1), url, url, | 93 infobar_queue_controller.CreateInfoBarRequest(RequestID(1), url, url, |
112 callback); | 94 callback); |
113 infobar_queue_controller.CancelInfoBarRequest(RequestID(0)); | 95 infobar_queue_controller.CancelInfoBarRequest(RequestID(0)); |
114 EXPECT_EQ(1, infobar_queue_controller.call_count()); | 96 EXPECT_EQ(1, infobar_queue_controller.call_count()); |
115 }; | 97 }; |
OLD | NEW |