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

Side by Side Diff: chrome/browser/notifications/notification_interactive_uitest.cc

Issue 2081103002: Rename PermissionBubbleManager to PermissionRequestManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 5 months 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
OLDNEW
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 <deque> 5 #include <deque>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/test/simple_test_clock.h" 17 #include "base/test/simple_test_clock.h"
18 #include "base/time/clock.h" 18 #include "base/time/clock.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/infobars/infobar_service.h" 23 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 24 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
25 #include "chrome/browser/notifications/notification.h" 25 #include "chrome/browser/notifications/notification.h"
26 #include "chrome/browser/permissions/permission_request_manager.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_tabstrip.h" 29 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
32 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
34 #include "components/content_settings/core/browser/host_content_settings_map.h" 34 #include "components/content_settings/core/browser/host_content_settings_map.h"
35 #include "components/content_settings/core/common/content_settings.h" 35 #include "components/content_settings/core/common/content_settings.h"
36 #include "components/content_settings/core/common/content_settings_pattern.h" 36 #include "components/content_settings/core/common/content_settings_pattern.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_source.h" 38 #include "content/public/browser/notification_source.h"
39 #include "content/public/browser/notification_types.h" 39 #include "content/public/browser/notification_types.h"
40 #include "content/public/browser/render_view_host.h" 40 #include "content/public/browser/render_view_host.h"
41 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 message_loop_runner_->Quit(); 134 message_loop_runner_->Quit();
135 } 135 }
136 136
137 bool notification_received_; 137 bool notification_received_;
138 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 138 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
139 139
140 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); 140 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver);
141 }; 141 };
142 142
143 // Used to observe the creation of permission prompt without responding. 143 // Used to observe the creation of permission prompt without responding.
144 class PermissionRequestObserver : public PermissionBubbleManager::Observer { 144 class PermissionRequestObserver : public PermissionRequestManager::Observer {
145 public: 145 public:
146 explicit PermissionRequestObserver(content::WebContents* web_contents) 146 explicit PermissionRequestObserver(content::WebContents* web_contents)
147 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)), 147 : request_manager_(
148 PermissionRequestManager::FromWebContents(web_contents)),
148 request_shown_(false), 149 request_shown_(false),
149 message_loop_runner_(new content::MessageLoopRunner) { 150 message_loop_runner_(new content::MessageLoopRunner) {
150 bubble_manager_->AddObserver(this); 151 request_manager_->AddObserver(this);
151 } 152 }
152 ~PermissionRequestObserver() override { 153 ~PermissionRequestObserver() override {
153 // Safe to remove twice if it happens. 154 // Safe to remove twice if it happens.
154 bubble_manager_->RemoveObserver(this); 155 request_manager_->RemoveObserver(this);
155 } 156 }
156 157
157 void Wait() { message_loop_runner_->Run(); } 158 void Wait() { message_loop_runner_->Run(); }
158 159
159 bool request_shown() { return request_shown_; } 160 bool request_shown() { return request_shown_; }
160 161
161 private: 162 private:
162 // PermissionBubbleManager::Observer 163 // PermissionRequestManager::Observer
163 void OnBubbleAdded() override { 164 void OnBubbleAdded() override {
164 request_shown_ = true; 165 request_shown_ = true;
165 bubble_manager_->RemoveObserver(this); 166 request_manager_->RemoveObserver(this);
166 message_loop_runner_->Quit(); 167 message_loop_runner_->Quit();
167 } 168 }
168 169
169 PermissionBubbleManager* bubble_manager_; 170 PermissionRequestManager* request_manager_;
170 bool request_shown_; 171 bool request_shown_;
171 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 172 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
172 173
173 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); 174 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
174 }; 175 };
175 176
176 } // namespace 177 } // namespace
177 178
178 class NotificationsTest : public InProcessBrowserTest { 179 class NotificationsTest : public InProcessBrowserTest {
179 public: 180 public:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 220 }
220 221
221 content::WebContents* GetActiveWebContents(Browser* browser) { 222 content::WebContents* GetActiveWebContents(Browser* browser) {
222 return browser->tab_strip_model()->GetActiveWebContents(); 223 return browser->tab_strip_model()->GetActiveWebContents();
223 } 224 }
224 225
225 private: 226 private:
226 void DropOriginPreference(const GURL& origin); 227 void DropOriginPreference(const GURL& origin);
227 std::string RequestAndRespondToPermission( 228 std::string RequestAndRespondToPermission(
228 Browser* browser, 229 Browser* browser,
229 PermissionBubbleManager::AutoResponseType bubble_response); 230 PermissionRequestManager::AutoResponseType bubble_response);
230 }; 231 };
231 232
232 int NotificationsTest::GetNotificationCount() { 233 int NotificationsTest::GetNotificationCount() {
233 return message_center::MessageCenter::Get()->NotificationCount(); 234 return message_center::MessageCenter::Get()->NotificationCount();
234 } 235 }
235 236
236 int NotificationsTest::GetNotificationPopupCount() { 237 int NotificationsTest::GetNotificationPopupCount() {
237 return message_center::MessageCenter::Get()->GetPopupNotifications().size(); 238 return message_center::MessageCenter::Get()->GetPopupNotifications().size();
238 } 239 }
239 240
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 std::string NotificationsTest::CreateSimpleNotification( 297 std::string NotificationsTest::CreateSimpleNotification(
297 Browser* browser, 298 Browser* browser,
298 bool wait_for_new_balloon) { 299 bool wait_for_new_balloon) {
299 return CreateNotification( 300 return CreateNotification(
300 browser, wait_for_new_balloon, 301 browser, wait_for_new_balloon,
301 "no_such_file.png", "My Title", "My Body", ""); 302 "no_such_file.png", "My Title", "My Body", "");
302 } 303 }
303 304
304 std::string NotificationsTest::RequestAndRespondToPermission( 305 std::string NotificationsTest::RequestAndRespondToPermission(
305 Browser* browser, 306 Browser* browser,
306 PermissionBubbleManager::AutoResponseType bubble_response) { 307 PermissionRequestManager::AutoResponseType bubble_response) {
307 std::string result; 308 std::string result;
308 content::WebContents* web_contents = GetActiveWebContents(browser); 309 content::WebContents* web_contents = GetActiveWebContents(browser);
309 PermissionBubbleManager::FromWebContents(web_contents) 310 PermissionRequestManager::FromWebContents(web_contents)
310 ->set_auto_response_for_test(bubble_response); 311 ->set_auto_response_for_test(bubble_response);
311 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 312 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
312 web_contents, "requestPermission();", &result)); 313 web_contents, "requestPermission();", &result));
313 return result; 314 return result;
314 } 315 }
315 316
316 bool NotificationsTest::RequestAndAcceptPermission(Browser* browser) { 317 bool NotificationsTest::RequestAndAcceptPermission(Browser* browser) {
317 std::string result = RequestAndRespondToPermission( 318 std::string result = RequestAndRespondToPermission(
318 browser, PermissionBubbleManager::ACCEPT_ALL); 319 browser, PermissionRequestManager::ACCEPT_ALL);
319 return "request-callback-granted" == result; 320 return "request-callback-granted" == result;
320 } 321 }
321 322
322 bool NotificationsTest::RequestAndDenyPermission(Browser* browser) { 323 bool NotificationsTest::RequestAndDenyPermission(Browser* browser) {
323 std::string result = 324 std::string result = RequestAndRespondToPermission(
324 RequestAndRespondToPermission(browser, PermissionBubbleManager::DENY_ALL); 325 browser, PermissionRequestManager::DENY_ALL);
325 return "request-callback-denied" == result; 326 return "request-callback-denied" == result;
326 } 327 }
327 328
328 bool NotificationsTest::RequestAndDismissPermission(Browser* browser) { 329 bool NotificationsTest::RequestAndDismissPermission(Browser* browser) {
329 std::string result = 330 std::string result =
330 RequestAndRespondToPermission(browser, PermissionBubbleManager::DISMISS); 331 RequestAndRespondToPermission(browser, PermissionRequestManager::DISMISS);
331 return "request-callback-default" == result; 332 return "request-callback-default" == result;
332 } 333 }
333 334
334 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { 335 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) {
335 content::WebContents* web_contents = GetActiveWebContents(browser); 336 content::WebContents* web_contents = GetActiveWebContents(browser);
336 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); 337 ui_test_utils::NavigateToURL(browser, GetTestPageURL());
337 PermissionRequestObserver observer(web_contents); 338 PermissionRequestObserver observer(web_contents);
338 std::string result; 339 std::string result;
339 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 340 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
340 web_contents, "requestPermissionAndRespond();", &result)); 341 web_contents, "requestPermissionAndRespond();", &result));
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 true); // by_user 876 true); // by_user
876 877
877 ASSERT_EQ(0, GetNotificationCount()); 878 ASSERT_EQ(0, GetNotificationCount());
878 879
879 // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did 880 // Calling WebContents::IsCrashed() will return FALSE here, even if the WC did
880 // crash. Work around this timing issue by creating another notification, 881 // crash. Work around this timing issue by creating another notification,
881 // which requires interaction with the renderer process. 882 // which requires interaction with the renderer process.
882 result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat"); 883 result = CreateNotification(browser(), true, "", "Title1", "Body1", "chat");
883 EXPECT_NE("-1", result); 884 EXPECT_NE("-1", result);
884 } 885 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698