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

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

Issue 102163002: Revert 238283 "Infobar system refactor." (Closed) Base URL: svn://svn.chromium.org/chrome/
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"
10 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/common/content_settings_types.h" 12 #include "chrome/common/content_settings_types.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/mock_render_process_host.h" 18 #include "content/public/test/mock_render_process_host.h"
16 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 21
19 22
20 // PermissionQueueControllerTests --------------------------------------------- 23 // PermissionQueueControllerTests ---------------------------------------------
21 24
22 class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness { 25 class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness,
26 public content::NotificationObserver {
23 protected: 27 protected:
24 PermissionQueueControllerTests() {} 28 PermissionQueueControllerTests() {
29 registrar_.Add(this,
30 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
31 content::NotificationService::AllSources());
32 }
25 virtual ~PermissionQueueControllerTests() {} 33 virtual ~PermissionQueueControllerTests() {}
26 34
27 PermissionRequestID RequestID(int bridge_id) { 35 PermissionRequestID RequestID(int bridge_id) {
28 return PermissionRequestID( 36 return PermissionRequestID(
29 web_contents()->GetRenderProcessHost()->GetID(), 37 web_contents()->GetRenderProcessHost()->GetID(),
30 web_contents()->GetRenderViewHost()->GetRoutingID(), 38 web_contents()->GetRenderViewHost()->GetRoutingID(),
31 bridge_id); 39 bridge_id);
32 } 40 }
33 41
34 private: 42 private:
35 // ChromeRenderViewHostTestHarness: 43 // ChromeRenderViewHostTestHarness:
36 virtual void SetUp() OVERRIDE { 44 virtual void SetUp() OVERRIDE {
37 ChromeRenderViewHostTestHarness::SetUp(); 45 ChromeRenderViewHostTestHarness::SetUp();
38 InfoBarService::CreateForWebContents(web_contents()); 46 InfoBarService::CreateForWebContents(web_contents());
39 } 47 }
40 48
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
41 DISALLOW_COPY_AND_ASSIGN(PermissionQueueControllerTests); 65 DISALLOW_COPY_AND_ASSIGN(PermissionQueueControllerTests);
42 }; 66 };
43 67
44 68
45 // ObservationCountingQueueController ----------------------------------------- 69 // ObservationCountingQueueController -----------------------------------------
46 70
47 class ObservationCountingQueueController : public PermissionQueueController { 71 class ObservationCountingQueueController : public PermissionQueueController {
48 public: 72 public:
49 explicit ObservationCountingQueueController(Profile* profile); 73 explicit ObservationCountingQueueController(Profile* profile);
50 virtual ~ObservationCountingQueueController(); 74 virtual ~ObservationCountingQueueController();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // test checks that in the case where the controller should remain registered 118 // test checks that in the case where the controller should remain registered
95 // for notifications, it gets notified exactly once." 119 // for notifications, it gets notified exactly once."
96 ObservationCountingQueueController queue_controller(profile()); 120 ObservationCountingQueueController queue_controller(profile());
97 GURL url("http://www.example.com/geolocation"); 121 GURL url("http://www.example.com/geolocation");
98 base::Callback<void(bool)> callback; 122 base::Callback<void(bool)> callback;
99 queue_controller.CreateInfoBarRequest(RequestID(0), url, url, callback); 123 queue_controller.CreateInfoBarRequest(RequestID(0), url, url, callback);
100 queue_controller.CreateInfoBarRequest(RequestID(1), url, url, callback); 124 queue_controller.CreateInfoBarRequest(RequestID(1), url, url, callback);
101 queue_controller.CancelInfoBarRequest(RequestID(0)); 125 queue_controller.CancelInfoBarRequest(RequestID(0));
102 EXPECT_EQ(1, queue_controller.call_count()); 126 EXPECT_EQ(1, queue_controller.call_count());
103 }; 127 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698