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

Side by Side Diff: chrome/browser/content_settings/permission_queue_controller_unittest.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/content_settings/permission_queue_controller.h" 5 #include "chrome/browser/content_settings/permission_queue_controller.h"
6 6
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/content_settings/permission_request_id.h" 9 #include "chrome/browser/content_settings/permission_request_id.h"
10 #include "chrome/browser/infobars/infobar.h"
11 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/common/content_settings_types.h" 11 #include "chrome/common/content_settings_types.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/mock_render_process_host.h" 15 #include "content/public/test/mock_render_process_host.h"
19 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
20 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
21 18
22 19
23 // PermissionQueueControllerTests --------------------------------------------- 20 // PermissionQueueControllerTests ---------------------------------------------
24 21
25 class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness, 22 class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness {
26 public content::NotificationObserver {
27 protected: 23 protected:
28 PermissionQueueControllerTests() { 24 PermissionQueueControllerTests() {}
29 registrar_.Add(this,
30 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
31 content::NotificationService::AllSources());
32 }
33 virtual ~PermissionQueueControllerTests() {} 25 virtual ~PermissionQueueControllerTests() {}
34 26
35 PermissionRequestID RequestID(int bridge_id) { 27 PermissionRequestID RequestID(int bridge_id) {
36 return PermissionRequestID( 28 return PermissionRequestID(
37 web_contents()->GetRenderProcessHost()->GetID(), 29 web_contents()->GetRenderProcessHost()->GetID(),
38 web_contents()->GetRenderViewHost()->GetRoutingID(), 30 web_contents()->GetRenderViewHost()->GetRoutingID(),
39 bridge_id); 31 bridge_id);
40 } 32 }
41 33
42 private: 34 private:
43 // ChromeRenderViewHostTestHarness: 35 // ChromeRenderViewHostTestHarness:
44 virtual void SetUp() OVERRIDE { 36 virtual void SetUp() OVERRIDE {
45 ChromeRenderViewHostTestHarness::SetUp(); 37 ChromeRenderViewHostTestHarness::SetUp();
46 InfoBarService::CreateForWebContents(web_contents()); 38 InfoBarService::CreateForWebContents(web_contents());
47 } 39 }
48 40
49 // content::NotificationObserver:
50 virtual void Observe(int type,
51 const content::NotificationSource& source,
52 const content::NotificationDetails& details) OVERRIDE {
53 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
54 // Delete the removed infobar. In normal Chrome code, this would be handled
55 // by the InfoBarContainer. It's safe to do this even if the queue
56 // controller Observe() function has not yet been called; see comments in
57 // PermissionQueueController::Observe().
58 // TODO(pkasting): This will no longer be necessary once the InfoBarService
59 // truly owns infobars.
60 delete content::Details<InfoBar::RemovedDetails>(details)->first;
61 }
62
63 content::NotificationRegistrar registrar_;
64
65 DISALLOW_COPY_AND_ASSIGN(PermissionQueueControllerTests); 41 DISALLOW_COPY_AND_ASSIGN(PermissionQueueControllerTests);
66 }; 42 };
67 43
68 44
69 // ObservationCountingQueueController ----------------------------------------- 45 // ObservationCountingQueueController -----------------------------------------
70 46
71 class ObservationCountingQueueController : public PermissionQueueController { 47 class ObservationCountingQueueController : public PermissionQueueController {
72 public: 48 public:
73 explicit ObservationCountingQueueController(Profile* profile); 49 explicit ObservationCountingQueueController(Profile* profile);
74 virtual ~ObservationCountingQueueController(); 50 virtual ~ObservationCountingQueueController();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // test checks that in the case where the controller should remain registered 94 // test checks that in the case where the controller should remain registered
119 // for notifications, it gets notified exactly once." 95 // for notifications, it gets notified exactly once."
120 ObservationCountingQueueController queue_controller(profile()); 96 ObservationCountingQueueController queue_controller(profile());
121 GURL url("http://www.example.com/geolocation"); 97 GURL url("http://www.example.com/geolocation");
122 base::Callback<void(bool)> callback; 98 base::Callback<void(bool)> callback;
123 queue_controller.CreateInfoBarRequest(RequestID(0), url, url, callback); 99 queue_controller.CreateInfoBarRequest(RequestID(0), url, url, callback);
124 queue_controller.CreateInfoBarRequest(RequestID(1), url, url, callback); 100 queue_controller.CreateInfoBarRequest(RequestID(1), url, url, callback);
125 queue_controller.CancelInfoBarRequest(RequestID(0)); 101 queue_controller.CancelInfoBarRequest(RequestID(0));
126 EXPECT_EQ(1, queue_controller.call_count()); 102 EXPECT_EQ(1, queue_controller.call_count());
127 }; 103 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698