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

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

Issue 341833004: [WebsiteSettings] Enable permission bubbles by default. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 | Annotate | Revision Log
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/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/test/simple_test_clock.h" 16 #include "base/test/simple_test_clock.h"
17 #include "base/time/clock.h" 17 #include "base/time/clock.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/content_settings/host_content_settings_map.h" 20 #include "chrome/browser/content_settings/host_content_settings_map.h"
21 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 22 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
23 #include "chrome/browser/notifications/notification.h" 23 #include "chrome/browser/notifications/notification.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
29 #include "chrome/common/content_settings.h" 30 #include "chrome/common/content_settings.h"
30 #include "chrome/common/content_settings_pattern.h" 31 #include "chrome/common/content_settings_pattern.h"
31 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
32 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/infobars/core/confirm_infobar_delegate.h" 34 #include "components/infobars/core/confirm_infobar_delegate.h"
34 #include "components/infobars/core/infobar.h" 35 #include "components/infobars/core/infobar.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/notification_types.h" 38 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
40 #include "content/public/test/browser_test_utils.h" 41 #include "content/public/test/browser_test_utils.h"
41 #include "content/public/test/test_utils.h" 42 #include "content/public/test/test_utils.h"
42 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
43 #include "net/test/embedded_test_server/embedded_test_server.h" 44 #include "net/test/embedded_test_server/embedded_test_server.h"
44 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
45 #include "ui/base/window_open_disposition.h" 46 #include "ui/base/window_open_disposition.h"
46 #include "ui/message_center/message_center.h" 47 #include "ui/message_center/message_center.h"
47 #include "ui/message_center/message_center_observer.h" 48 #include "ui/message_center/message_center_observer.h"
48 #include "url/gurl.h" 49 #include "url/gurl.h"
49 50
50 namespace { 51 namespace {
51 52
52 const char kExpectedIconUrl[] = "/notifications/no_such_file.png"; 53 const char kExpectedIconUrl[] = "/notifications/no_such_file.png";
53 54
54 enum InfobarAction { 55 enum PromptAction {
55 DISMISS = 0, 56 DISMISS = 0,
56 ALLOW, 57 ALLOW,
57 DENY, 58 DENY,
58 }; 59 };
59 60
60 class NotificationChangeObserver { 61 class NotificationChangeObserver {
61 public: 62 public:
62 virtual ~NotificationChangeObserver() {} 63 virtual ~NotificationChangeObserver() {}
63 virtual bool Wait() = 0; 64 virtual bool Wait() = 0;
64 }; 65 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (message_loop_runner_.get()) 108 if (message_loop_runner_.get())
108 message_loop_runner_->Quit(); 109 message_loop_runner_->Quit();
109 } 110 }
110 111
111 bool notification_received_; 112 bool notification_received_;
112 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 113 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
113 114
114 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver); 115 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver);
115 }; 116 };
116 117
118 class MockView : public PermissionBubbleView {
119 public:
120 MockView() : shown_(false), can_accept_updates_(true), delegate_(NULL) {}
121 virtual ~MockView() {}
122
123 void Clear() {
124 shown_ = false;
125 can_accept_updates_ = true;
126 delegate_ = NULL;
127 permission_requests_.clear();
128 permission_states_.clear();
129 }
130
131 // PermissionBubbleView:
132 virtual void SetDelegate(Delegate* delegate) OVERRIDE {
133 delegate_ = delegate;
134 }
135
136 virtual void Show(
137 const std::vector<PermissionBubbleRequest*>& requests,
138 const std::vector<bool>& accept_state,
139 bool customization_state_) OVERRIDE {
140 shown_ = true;
141 permission_requests_ = requests;
142 permission_states_ = accept_state;
143 }
144
145 virtual void Hide() OVERRIDE {
146 shown_ = false;
147 }
148
149 virtual bool IsVisible() OVERRIDE {
150 return shown_;
151 }
152
153 virtual bool CanAcceptRequestUpdate() OVERRIDE {
154 return can_accept_updates_;
155 }
156
157 void Accept() {
158 delegate_->Accept();
159 }
160
161 void Deny() {
162 delegate_->Deny();
163 }
164
165 void Close() {
166 delegate_->Closing();
167 }
168
169 bool shown_;
170 bool can_accept_updates_;
171 Delegate* delegate_;
172 std::vector<PermissionBubbleRequest*> permission_requests_;
173 std::vector<bool> permission_states_;
174 };
175
117 } // namespace 176 } // namespace
118 177
119 class NotificationsTest : public InProcessBrowserTest { 178 class NotificationsTest : public InProcessBrowserTest {
120 public: 179 public:
121 NotificationsTest() {} 180 NotificationsTest() {}
122 181
123 protected: 182 protected:
124 int GetNotificationCount(); 183 int GetNotificationCount();
125 int GetNotificationPopupCount(); 184 int GetNotificationPopupCount();
126 185
127 void CloseBrowserWindow(Browser* browser); 186 void CloseBrowserWindow(Browser* browser);
128 void CrashTab(Browser* browser, int index); 187 void CrashTab(Browser* browser, int index);
129 188
130 void DenyOrigin(const GURL& origin); 189 void DenyOrigin(const GURL& origin);
131 void AllowOrigin(const GURL& origin); 190 void AllowOrigin(const GURL& origin);
132 void AllowAllOrigins(); 191 void AllowAllOrigins();
133 void SetDefaultContentSetting(ContentSetting setting); 192 void SetDefaultContentSetting(ContentSetting setting);
134 193
135 void VerifyInfoBar(const Browser* browser, int index); 194 void VerifyPrompt(const Browser* browser, int index);
136 std::string CreateNotification(Browser* browser, 195 std::string CreateNotification(Browser* browser,
137 bool wait_for_new_balloon, 196 bool wait_for_new_balloon,
138 const char* icon, 197 const char* icon,
139 const char* title, 198 const char* title,
140 const char* body, 199 const char* body,
141 const char* replace_id); 200 const char* replace_id);
142 std::string CreateSimpleNotification(Browser* browser, 201 std::string CreateSimpleNotification(Browser* browser,
143 bool wait_for_new_balloon); 202 bool wait_for_new_balloon);
144 bool RequestPermissionAndWait(Browser* browser); 203 bool RequestPermissionAndWait(Browser* browser);
145 bool CancelNotification(const char* notification_id, Browser* browser); 204 bool CancelNotification(const char* notification_id, Browser* browser);
146 bool PerformActionOnInfoBar(Browser* browser, 205 bool PerformAction(Browser* browser,
147 InfobarAction action, 206 PromptAction action,
148 size_t infobar_index, 207 size_t index,
149 int tab_index); 208 int tab_index);
150 void GetPrefsByContentSetting(ContentSetting setting, 209 void GetPrefsByContentSetting(ContentSetting setting,
151 ContentSettingsForOneType* settings); 210 ContentSettingsForOneType* settings);
152 bool CheckOriginInSetting(const ContentSettingsForOneType& settings, 211 bool CheckOriginInSetting(const ContentSettingsForOneType& settings,
153 const GURL& origin); 212 const GURL& origin);
154 213
155 GURL GetTestPageURL() const { 214 GURL GetTestPageURL() const {
156 return embedded_test_server()->GetURL( 215 return embedded_test_server()->GetURL(
157 "/notifications/notification_tester.html"); 216 "/notifications/notification_tester.html");
158 } 217 }
159 218
219 int GetBubblesQueueSize(PermissionBubbleManager* mgr);
220
160 private: 221 private:
161 void DropOriginPreference(const GURL& origin); 222 void DropOriginPreference(const GURL& origin);
223 MockView mock_bubble_view_;
162 }; 224 };
163 225
164 int NotificationsTest::GetNotificationCount() { 226 int NotificationsTest::GetNotificationCount() {
165 return message_center::MessageCenter::Get()->NotificationCount(); 227 return message_center::MessageCenter::Get()->NotificationCount();
166 } 228 }
167 229
168 int NotificationsTest::GetNotificationPopupCount() { 230 int NotificationsTest::GetNotificationPopupCount() {
169 return message_center::MessageCenter::Get()->GetPopupNotifications().size(); 231 return message_center::MessageCenter::Get()->GetPopupNotifications().size();
170 } 232 }
171 233
(...skipping 24 matching lines...) Expand all
196 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType( 258 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType(
197 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 259 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
198 SetDefaultContentSetting(CONTENT_SETTING_ALLOW); 260 SetDefaultContentSetting(CONTENT_SETTING_ALLOW);
199 } 261 }
200 262
201 void NotificationsTest::SetDefaultContentSetting(ContentSetting setting) { 263 void NotificationsTest::SetDefaultContentSetting(ContentSetting setting) {
202 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 264 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
203 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); 265 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
204 } 266 }
205 267
206 void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { 268 void NotificationsTest::VerifyPrompt(const Browser* browser, int index) {
207 InfoBarService* infobar_service = InfoBarService::FromWebContents( 269 if (!PermissionBubbleManager::Enabled()) {
208 browser->tab_strip_model()->GetWebContentsAt(index)); 270 InfoBarService* infobar_service = InfoBarService::FromWebContents(
271 browser->tab_strip_model()->GetWebContentsAt(index));
209 272
210 ASSERT_EQ(1U, infobar_service->infobar_count()); 273 ASSERT_EQ(1U, infobar_service->infobar_count());
211 ConfirmInfoBarDelegate* confirm_infobar = 274 ConfirmInfoBarDelegate* confirm_infobar =
212 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 275 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
213 ASSERT_TRUE(confirm_infobar); 276 ASSERT_TRUE(confirm_infobar);
214 int buttons = confirm_infobar->GetButtons(); 277 int buttons = confirm_infobar->GetButtons();
215 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); 278 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK);
216 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); 279 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL);
280 } else {
281 PermissionBubbleManager* permission_manager =
282 PermissionBubbleManager::FromWebContents(
283 browser->tab_strip_model()->GetWebContentsAt(0));
284 LOG(INFO) << "Get queue size";
285 ASSERT_EQ(1, GetBubblesQueueSize(permission_manager));
286 }
217 } 287 }
218 288
219 std::string NotificationsTest::CreateNotification( 289 std::string NotificationsTest::CreateNotification(
220 Browser* browser, 290 Browser* browser,
221 bool wait_for_new_balloon, 291 bool wait_for_new_balloon,
222 const char* icon, 292 const char* icon,
223 const char* title, 293 const char* title,
224 const char* body, 294 const char* body,
225 const char* replace_id) { 295 const char* replace_id) {
226 std::string script = base::StringPrintf( 296 std::string script = base::StringPrintf(
(...skipping 17 matching lines...) Expand all
244 Browser* browser, 314 Browser* browser,
245 bool wait_for_new_balloon) { 315 bool wait_for_new_balloon) {
246 return CreateNotification( 316 return CreateNotification(
247 browser, wait_for_new_balloon, 317 browser, wait_for_new_balloon,
248 "no_such_file.png", "My Title", "My Body", ""); 318 "no_such_file.png", "My Title", "My Body", "");
249 } 319 }
250 320
251 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { 321 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) {
252 InfoBarService* infobar_service = InfoBarService::FromWebContents( 322 InfoBarService* infobar_service = InfoBarService::FromWebContents(
253 browser->tab_strip_model()->GetActiveWebContents()); 323 browser->tab_strip_model()->GetActiveWebContents());
254 content::WindowedNotificationObserver observer( 324 PermissionBubbleManager* permission_manager =
255 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 325 PermissionBubbleManager::FromWebContents(
256 content::Source<InfoBarService>(infobar_service)); 326 browser->tab_strip_model()->GetWebContentsAt(0));
257 std::string result; 327 permission_manager->SetView(&mock_bubble_view_);
258 bool success = content::ExecuteScriptAndExtractString( 328 if (!PermissionBubbleManager::Enabled()) {
259 browser->tab_strip_model()->GetActiveWebContents(), 329 content::WindowedNotificationObserver observer(
260 "requestPermission();", 330 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
261 &result); 331 content::Source<InfoBarService>(infobar_service));
262 if (!success || result != "1") 332 std::string result;
263 return false; 333 bool success = content::ExecuteScriptAndExtractString(
264 observer.Wait(); 334 browser->tab_strip_model()->GetActiveWebContents(),
265 return true; 335 "requestPermission();",
336 &result);
337 if (!success || result != "1")
338 return false;
339 observer.Wait();
340 return true;
341 } else {
342 std::string result;
343 bool success = content::ExecuteScriptAndExtractString(
344 browser->tab_strip_model()->GetActiveWebContents(),
345 "requestPermission();",
346 &result);
347 if (!success || result != "1")
348 return false;
349 while (!mock_bubble_view_.shown_) {
350 (new content::MessageLoopRunner())->Run();
351 }
352 return true;
353 }
266 } 354 }
267 355
268 bool NotificationsTest::CancelNotification( 356 bool NotificationsTest::CancelNotification(
269 const char* notification_id, 357 const char* notification_id,
270 Browser* browser) { 358 Browser* browser) {
271 std::string script = base::StringPrintf( 359 std::string script = base::StringPrintf(
272 "cancelNotification('%s');", 360 "cancelNotification('%s');",
273 notification_id); 361 notification_id);
274 362
275 MessageCenterChangeObserver observer; 363 MessageCenterChangeObserver observer;
276 std::string result; 364 std::string result;
277 bool success = content::ExecuteScriptAndExtractString( 365 bool success = content::ExecuteScriptAndExtractString(
278 browser->tab_strip_model()->GetActiveWebContents(), 366 browser->tab_strip_model()->GetActiveWebContents(),
279 script, 367 script,
280 &result); 368 &result);
281 if (!success || result != "1") 369 if (!success || result != "1")
282 return false; 370 return false;
283 return observer.Wait(); 371 return observer.Wait();
284 } 372 }
285 373
286 bool NotificationsTest::PerformActionOnInfoBar( 374 bool NotificationsTest::PerformAction(
287 Browser* browser, 375 Browser* browser,
288 InfobarAction action, 376 PromptAction action,
289 size_t infobar_index, 377 size_t index,
290 int tab_index) { 378 int tab_index) {
291 InfoBarService* infobar_service = InfoBarService::FromWebContents( 379 InfoBarService* infobar_service = InfoBarService::FromWebContents(
292 browser->tab_strip_model()->GetWebContentsAt(tab_index)); 380 browser->tab_strip_model()->GetWebContentsAt(tab_index));
293 if (infobar_index >= infobar_service->infobar_count()) { 381 PermissionBubbleManager* permission_manager =
294 ADD_FAILURE(); 382 PermissionBubbleManager::FromWebContents(
295 return false; 383 browser->tab_strip_model()->GetWebContentsAt(0));
384 if (!PermissionBubbleManager::Enabled()) {
385 if (index >= infobar_service->infobar_count()) {
386 ADD_FAILURE();
387 return false;
388 }
389 } else {
390 if (static_cast<int>(index) >= GetBubblesQueueSize(permission_manager)) {
391 ADD_FAILURE();
392 return false;
393 }
296 } 394 }
297 395
298 infobars::InfoBar* infobar = infobar_service->infobar_at(infobar_index); 396 if (!PermissionBubbleManager::Enabled()) {
299 infobars::InfoBarDelegate* infobar_delegate = infobar->delegate(); 397 infobars::InfoBar* infobar = infobar_service->infobar_at(index);
300 switch (action) { 398 infobars::InfoBarDelegate* infobar_delegate = infobar->delegate();
301 case DISMISS: 399 switch (action) {
302 infobar_delegate->InfoBarDismissed(); 400 case DISMISS:
303 infobar_service->RemoveInfoBar(infobar); 401 infobar_delegate->InfoBarDismissed();
304 return true;
305
306 case ALLOW: {
307 ConfirmInfoBarDelegate* confirm_infobar_delegate =
308 infobar_delegate->AsConfirmInfoBarDelegate();
309 if (!confirm_infobar_delegate) {
310 ADD_FAILURE();
311 } else if (confirm_infobar_delegate->Accept()) {
312 infobar_service->RemoveInfoBar(infobar); 402 infobar_service->RemoveInfoBar(infobar);
313 return true; 403 return true;
404
405 case ALLOW: {
406 ConfirmInfoBarDelegate* confirm_infobar_delegate =
407 infobar_delegate->AsConfirmInfoBarDelegate();
408 if (!confirm_infobar_delegate) {
409 ADD_FAILURE();
410 } else if (confirm_infobar_delegate->Accept()) {
411 infobar_service->RemoveInfoBar(infobar);
412 return true;
413 }
414 }
415
416 case DENY: {
417 ConfirmInfoBarDelegate* confirm_infobar_delegate =
418 infobar_delegate->AsConfirmInfoBarDelegate();
419 if (!confirm_infobar_delegate) {
420 ADD_FAILURE();
421 } else if (confirm_infobar_delegate->Cancel()) {
422 infobar_service->RemoveInfoBar(infobar);
423 return true;
424 }
314 } 425 }
315 } 426 }
316 427 } else {
317 case DENY: { 428 switch (action) {
318 ConfirmInfoBarDelegate* confirm_infobar_delegate = 429 case DISMISS:
319 infobar_delegate->AsConfirmInfoBarDelegate(); 430 mock_bubble_view_.Close();
320 if (!confirm_infobar_delegate) {
321 ADD_FAILURE();
322 } else if (confirm_infobar_delegate->Cancel()) {
323 infobar_service->RemoveInfoBar(infobar);
324 return true; 431 return true;
325 } 432 case ALLOW:
433 mock_bubble_view_.Accept();
434 return true;
435 case DENY:
436 mock_bubble_view_.Deny();
437 return true;
326 } 438 }
327 } 439 }
328 440
329 return false; 441 return false;
330 } 442 }
331 443
332 void NotificationsTest::GetPrefsByContentSetting( 444 void NotificationsTest::GetPrefsByContentSetting(
333 ContentSetting setting, 445 ContentSetting setting,
334 ContentSettingsForOneType* settings) { 446 ContentSettingsForOneType* settings) {
335 DesktopNotificationProfileUtil::GetNotificationsSettings( 447 DesktopNotificationProfileUtil::GetNotificationsSettings(
(...skipping 18 matching lines...) Expand all
354 return true; 466 return true;
355 } 467 }
356 return false; 468 return false;
357 } 469 }
358 470
359 void NotificationsTest::DropOriginPreference(const GURL& origin) { 471 void NotificationsTest::DropOriginPreference(const GURL& origin) {
360 DesktopNotificationProfileUtil::ClearSetting(browser()->profile(), 472 DesktopNotificationProfileUtil::ClearSetting(browser()->profile(),
361 ContentSettingsPattern::FromURLNoWildcard(origin)); 473 ContentSettingsPattern::FromURLNoWildcard(origin));
362 } 474 }
363 475
476 int NotificationsTest::GetBubblesQueueSize(
477 PermissionBubbleManager* mgr) {
478 LOG(INFO) << "Have " << mgr->requests_.size();
479 return static_cast<int>(mgr->requests_.size());
480 }
481
364 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. 482 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428.
365 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { 483 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGesture) {
366 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 484 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
367 485
368 ui_test_utils::NavigateToURL( 486 ui_test_utils::NavigateToURL(
369 browser(), 487 browser(),
370 embedded_test_server()->GetURL( 488 embedded_test_server()->GetURL(
371 "/notifications/notifications_request_function.html")); 489 "/notifications/notifications_request_function.html"));
372 490
373 // Request permission by calling request() while eval'ing an inline script; 491 // Request permission by calling request() while eval'ing an inline script;
374 // That's considered a user gesture to webkit, and should produce an infobar. 492 // That's considered a user gesture to webkit, and should produce an infobar.
375 bool result; 493 bool result;
376 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 494 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
377 browser()->tab_strip_model()->GetActiveWebContents(), 495 browser()->tab_strip_model()->GetActiveWebContents(),
378 "window.domAutomationController.send(request());", 496 "window.domAutomationController.send(request());",
379 &result)); 497 &result));
380 EXPECT_TRUE(result); 498 EXPECT_TRUE(result);
381 499
382 InfoBarService* infobar_service = InfoBarService::FromWebContents( 500 InfoBarService* infobar_service = InfoBarService::FromWebContents(
383 browser()->tab_strip_model()->GetWebContentsAt(0)); 501 browser()->tab_strip_model()->GetWebContentsAt(0));
384 EXPECT_EQ(1U, infobar_service->infobar_count()); 502 PermissionBubbleManager* permission_manager =
503 PermissionBubbleManager::FromWebContents(
504 browser()->tab_strip_model()->GetWebContentsAt(0));
505 if (!PermissionBubbleManager::Enabled())
506 EXPECT_EQ(1U, infobar_service->infobar_count());
507 else
508 EXPECT_EQ(1, GetBubblesQueueSize(permission_manager));
385 } 509 }
386 510
387 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { 511 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
388 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 512 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
389 513
390 // Creates a simple notification. 514 // Creates a simple notification.
391 AllowAllOrigins(); 515 AllowAllOrigins();
392 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 516 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
393 517
394 std::string result = CreateSimpleNotification(browser(), true); 518 std::string result = CreateSimpleNotification(browser(), true);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 556 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
433 557
434 std::string note_id = CreateSimpleNotification(browser(), true); 558 std::string note_id = CreateSimpleNotification(browser(), true);
435 EXPECT_NE(note_id, "-1"); 559 EXPECT_NE(note_id, "-1");
436 560
437 ASSERT_EQ(1, GetNotificationCount()); 561 ASSERT_EQ(1, GetNotificationCount());
438 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser())); 562 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser()));
439 ASSERT_EQ(0, GetNotificationCount()); 563 ASSERT_EQ(0, GetNotificationCount());
440 } 564 }
441 565
442 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionInfobarAppears) { 566 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPermissionPromptAppears) {
443 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 567 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
444 568
445 // Requests notification privileges and verifies the infobar appears. 569 // Requests notification privileges and verifies the infobar appears.
446 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 570 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
447 ASSERT_TRUE(RequestPermissionAndWait(browser())); 571 ASSERT_TRUE(RequestPermissionAndWait(browser()));
448 572
449 ASSERT_EQ(0, GetNotificationCount()); 573 ASSERT_EQ(0, GetNotificationCount());
450 ASSERT_NO_FATAL_FAILURE(VerifyInfoBar(browser(), 0)); 574 LOG(INFO) << "VerifyPrompt";
575 ASSERT_NO_FATAL_FAILURE(VerifyPrompt(browser(), 0));
451 } 576 }
452 577
453 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermissionInfobar) { 578 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowOnPermission) {
454 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 579 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
455 580
456 // Tries to create a notification and clicks allow on the infobar. 581 // Tries to create a notification and clicks allow on the infobar.
457 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 582 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
458 // This notification should not be shown because we do not have permission. 583 // This notification should not be shown because we do not have permission.
459 CreateSimpleNotification(browser(), false); 584 CreateSimpleNotification(browser(), false);
460 ASSERT_EQ(0, GetNotificationCount()); 585 ASSERT_EQ(0, GetNotificationCount());
461 586
462 ASSERT_TRUE(RequestPermissionAndWait(browser())); 587 ASSERT_TRUE(RequestPermissionAndWait(browser()));
463 ASSERT_TRUE(PerformActionOnInfoBar(browser(), ALLOW, 0, 0)); 588 ASSERT_TRUE(PerformAction(browser(), ALLOW, 0, 0));
464 589
465 CreateSimpleNotification(browser(), true); 590 CreateSimpleNotification(browser(), true);
466 EXPECT_EQ(1, GetNotificationCount()); 591 EXPECT_EQ(1, GetNotificationCount());
467 } 592 }
468 593
469 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermissionInfobar) { 594 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyOnPermission) {
470 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 595 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
471 596
472 // Test that no notification is created 597 // Test that no notification is created
473 // when Deny is chosen from permission infobar. 598 // when Deny is chosen from permission infobar.
474 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 599 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
475 ASSERT_TRUE(RequestPermissionAndWait(browser())); 600 ASSERT_TRUE(RequestPermissionAndWait(browser()));
476 PerformActionOnInfoBar(browser(), DENY, 0, 0); 601 PerformAction(browser(), DENY, 0, 0);
477 CreateSimpleNotification(browser(), false); 602 CreateSimpleNotification(browser(), false);
478 ASSERT_EQ(0, GetNotificationCount()); 603 ASSERT_EQ(0, GetNotificationCount());
479 ContentSettingsForOneType settings; 604 ContentSettingsForOneType settings;
480 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 605 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings);
481 EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL())); 606 EXPECT_TRUE(CheckOriginInSetting(settings, GetTestPageURL()));
482 } 607 }
483 608
484 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermissionInfobar) { 609 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestClosePermission) {
485 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 610 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
486 611
487 // Test that no notification is created when permission infobar is dismissed. 612 // Test that no notification is created when permission infobar is dismissed.
488 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 613 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
489 ASSERT_TRUE(RequestPermissionAndWait(browser())); 614 ASSERT_TRUE(RequestPermissionAndWait(browser()));
490 PerformActionOnInfoBar(browser(), DISMISS, 0, 0); 615 PerformAction(browser(), DISMISS, 0, 0);
491 CreateSimpleNotification(browser(), false); 616 CreateSimpleNotification(browser(), false);
492 ASSERT_EQ(0, GetNotificationCount()); 617 ASSERT_EQ(0, GetNotificationCount());
493 ContentSettingsForOneType settings; 618 ContentSettingsForOneType settings;
494 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 619 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings);
495 EXPECT_EQ(0U, settings.size()); 620 EXPECT_EQ(0U, settings.size());
496 } 621 }
497 622
498 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { 623 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) {
499 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 624 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
500 625
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 // Crashes on Linux/Win. See http://crbug.com/160657. 730 // Crashes on Linux/Win. See http://crbug.com/160657.
606 IN_PROC_BROWSER_TEST_F( 731 IN_PROC_BROWSER_TEST_F(
607 NotificationsTest, 732 NotificationsTest,
608 DISABLED_TestOriginPrefsNotSavedInIncognito) { 733 DISABLED_TestOriginPrefsNotSavedInIncognito) {
609 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 734 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
610 735
611 // Verify that allow/deny origin preferences are not saved in incognito. 736 // Verify that allow/deny origin preferences are not saved in incognito.
612 Browser* incognito = CreateIncognitoBrowser(); 737 Browser* incognito = CreateIncognitoBrowser();
613 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); 738 ui_test_utils::NavigateToURL(incognito, GetTestPageURL());
614 ASSERT_TRUE(RequestPermissionAndWait(incognito)); 739 ASSERT_TRUE(RequestPermissionAndWait(incognito));
615 PerformActionOnInfoBar(incognito, DENY, 0, 0); 740 PerformAction(incognito, DENY, 0, 0);
616 CloseBrowserWindow(incognito); 741 CloseBrowserWindow(incognito);
617 742
618 incognito = CreateIncognitoBrowser(); 743 incognito = CreateIncognitoBrowser();
619 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); 744 ui_test_utils::NavigateToURL(incognito, GetTestPageURL());
620 ASSERT_TRUE(RequestPermissionAndWait(incognito)); 745 ASSERT_TRUE(RequestPermissionAndWait(incognito));
621 PerformActionOnInfoBar(incognito, ALLOW, 0, 0); 746 PerformAction(incognito, ALLOW, 0, 0);
622 CreateSimpleNotification(incognito, true); 747 CreateSimpleNotification(incognito, true);
623 ASSERT_EQ(1, GetNotificationCount()); 748 ASSERT_EQ(1, GetNotificationCount());
624 CloseBrowserWindow(incognito); 749 CloseBrowserWindow(incognito);
625 750
626 incognito = CreateIncognitoBrowser(); 751 incognito = CreateIncognitoBrowser();
627 ui_test_utils::NavigateToURL(incognito, GetTestPageURL()); 752 ui_test_utils::NavigateToURL(incognito, GetTestPageURL());
628 ASSERT_TRUE(RequestPermissionAndWait(incognito)); 753 ASSERT_TRUE(RequestPermissionAndWait(incognito));
629 754
630 ContentSettingsForOneType settings; 755 ContentSettingsForOneType settings;
631 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings); 756 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, &settings);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 } 792 }
668 793
669 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { 794 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) {
670 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 795 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
671 796
672 // Test notifications in incognito window. 797 // Test notifications in incognito window.
673 Browser* browser = CreateIncognitoBrowser(); 798 Browser* browser = CreateIncognitoBrowser();
674 ui_test_utils::NavigateToURL(browser, GetTestPageURL()); 799 ui_test_utils::NavigateToURL(browser, GetTestPageURL());
675 browser->tab_strip_model()->ActivateTabAt(0, true); 800 browser->tab_strip_model()->ActivateTabAt(0, true);
676 ASSERT_TRUE(RequestPermissionAndWait(browser)); 801 ASSERT_TRUE(RequestPermissionAndWait(browser));
677 PerformActionOnInfoBar(browser, ALLOW, 0, 0); 802 PerformAction(browser, ALLOW, 0, 0);
678 CreateSimpleNotification(browser, true); 803 CreateSimpleNotification(browser, true);
679 ASSERT_EQ(1, GetNotificationCount()); 804 ASSERT_EQ(1, GetNotificationCount());
680 } 805 }
681 806
682 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) { 807 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) {
683 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 808 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
684 809
685 // Test that user can close tab when infobar present. 810 // Test that user can close tab when infobar present.
686 ui_test_utils::NavigateToURLWithDisposition( 811 ui_test_utils::NavigateToURLWithDisposition(
687 browser(), 812 browser(),
688 GURL("about:blank"), 813 GURL("about:blank"),
689 NEW_BACKGROUND_TAB, 814 NEW_BACKGROUND_TAB,
690 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 815 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
691 browser()->tab_strip_model()->ActivateTabAt(0, true); 816 browser()->tab_strip_model()->ActivateTabAt(0, true);
692 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 817 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
693 ASSERT_TRUE(RequestPermissionAndWait(browser())); 818 ASSERT_TRUE(RequestPermissionAndWait(browser()));
694 content::WebContentsDestroyedWatcher destroyed_watcher( 819 content::WebContentsDestroyedWatcher destroyed_watcher(
695 browser()->tab_strip_model()->GetWebContentsAt(0)); 820 browser()->tab_strip_model()->GetWebContentsAt(0));
696 browser()->tab_strip_model()->CloseWebContentsAt(0, 821 browser()->tab_strip_model()->CloseWebContentsAt(0,
697 TabStripModel::CLOSE_NONE); 822 TabStripModel::CLOSE_NONE);
698 destroyed_watcher.Wait(); 823 destroyed_watcher.Wait();
699 } 824 }
700 825
701 IN_PROC_BROWSER_TEST_F( 826 IN_PROC_BROWSER_TEST_F(
702 NotificationsTest, 827 NotificationsTest,
703 TestNavigateAwayWithPermissionInfobar) { 828 TestNavigateAwayWithPermission) {
704 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 829 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
705 830
706 // Test navigating away when an infobar is present, 831 // Test navigating away when an infobar is present,
707 // then trying to create a notification from the same page. 832 // then trying to create a notification from the same page.
708 ui_test_utils::NavigateToURLWithDisposition( 833 ui_test_utils::NavigateToURLWithDisposition(
709 browser(), 834 browser(),
710 GURL("about:blank"), 835 GURL("about:blank"),
711 NEW_BACKGROUND_TAB, 836 NEW_BACKGROUND_TAB,
712 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 837 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
713 browser()->tab_strip_model()->ActivateTabAt(0, true); 838 browser()->tab_strip_model()->ActivateTabAt(0, true);
714 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 839 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
715 ASSERT_TRUE(RequestPermissionAndWait(browser())); 840 ASSERT_TRUE(RequestPermissionAndWait(browser()));
716 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); 841 ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
717 ASSERT_TRUE(RequestPermissionAndWait(browser())); 842 ASSERT_TRUE(RequestPermissionAndWait(browser()));
718 PerformActionOnInfoBar(browser(), ALLOW, 0, 0); 843 PerformAction(browser(), ALLOW, 0, 0);
719 CreateSimpleNotification(browser(), true); 844 CreateSimpleNotification(browser(), true);
720 ASSERT_EQ(1, GetNotificationCount()); 845 ASSERT_EQ(1, GetNotificationCount());
721 } 846 }
722 847
723 // See crbug.com/248470 848 // See crbug.com/248470
724 #if defined(OS_LINUX) 849 #if defined(OS_LINUX)
725 #define MAYBE_TestCrashRendererNotificationRemain \ 850 #define MAYBE_TestCrashRendererNotificationRemain \
726 DISABLED_TestCrashRendererNotificationRemain 851 DISABLED_TestCrashRendererNotificationRemain
727 #else 852 #else
728 #define MAYBE_TestCrashRendererNotificationRemain \ 853 #define MAYBE_TestCrashRendererNotificationRemain \
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 (*notifications.rbegin())->id()); 957 (*notifications.rbegin())->id());
833 958
834 ASSERT_EQ(0, GetNotificationPopupCount()); 959 ASSERT_EQ(0, GetNotificationPopupCount());
835 960
836 result = CreateNotification( 961 result = CreateNotification(
837 browser(), true, "abc.png", "Title2", "Body2", "chat"); 962 browser(), true, "abc.png", "Title2", "Body2", "chat");
838 EXPECT_NE("-1", result); 963 EXPECT_NE("-1", result);
839 964
840 ASSERT_EQ(1, GetNotificationPopupCount()); 965 ASSERT_EQ(1, GetNotificationPopupCount());
841 } 966 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.cc ('k') | chrome/browser/ui/website_settings/permission_bubble_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698