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

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

Issue 11419276: Remove tabstrip wrappers in browser_tabstrip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gtk Created 8 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 (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/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/notifications/balloon_host.h" 21 #include "chrome/browser/notifications/balloon_host.h"
22 #include "chrome/browser/notifications/desktop_notification_service.h" 22 #include "chrome/browser/notifications/desktop_notification_service.h"
23 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 23 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
24 #include "chrome/browser/notifications/notification.h" 24 #include "chrome/browser/notifications/notification.h"
25 #include "chrome/browser/notifications/notification_ui_manager.h" 25 #include "chrome/browser/notifications/notification_ui_manager.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_tabstrip.h" 28 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents.h" 30 #include "chrome/browser/ui/tab_contents/tab_contents.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/content_settings.h" 33 #include "chrome/common/content_settings.h"
33 #include "chrome/common/content_settings_pattern.h" 34 #include "chrome/common/content_settings_pattern.h"
34 #include "chrome/test/base/in_process_browser_test.h" 35 #include "chrome/test/base/in_process_browser_test.h"
35 #include "chrome/test/base/ui_test_utils.h" 36 #include "chrome/test/base/ui_test_utils.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_source.h" 38 #include "content/public/browser/notification_source.h"
38 #include "content/public/browser/notification_types.h" 39 #include "content/public/browser/notification_types.h"
39 #include "content/public/browser/render_view_host.h" 40 #include "content/public/browser/render_view_host.h"
40 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 213
213 void NotificationsTest::CloseBrowserWindow(Browser* browser) { 214 void NotificationsTest::CloseBrowserWindow(Browser* browser) {
214 content::WindowedNotificationObserver observer( 215 content::WindowedNotificationObserver observer(
215 chrome::NOTIFICATION_BROWSER_CLOSED, 216 chrome::NOTIFICATION_BROWSER_CLOSED,
216 content::Source<Browser>(browser)); 217 content::Source<Browser>(browser));
217 browser->window()->Close(); 218 browser->window()->Close();
218 observer.Wait(); 219 observer.Wait();
219 } 220 }
220 221
221 void NotificationsTest::CrashTab(Browser* browser, int index) { 222 void NotificationsTest::CrashTab(Browser* browser, int index) {
222 content::CrashTab(chrome::GetWebContentsAt(browser, index)); 223 content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index));
223 } 224 }
224 225
225 void NotificationsTest::CrashNotification(Balloon* balloon) { 226 void NotificationsTest::CrashNotification(Balloon* balloon) {
226 content::CrashTab(balloon->balloon_view()->GetHost()->web_contents()); 227 content::CrashTab(balloon->balloon_view()->GetHost()->web_contents());
227 } 228 }
228 229
229 void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) { 230 void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) {
230 DesktopNotificationService* service = GetDesktopNotificationService(); 231 DesktopNotificationService* service = GetDesktopNotificationService();
231 service->SetDefaultContentSetting(setting); 232 service->SetDefaultContentSetting(setting);
232 } 233 }
233 234
234 void NotificationsTest::DenyOrigin(const GURL& origin) { 235 void NotificationsTest::DenyOrigin(const GURL& origin) {
235 DropOriginPreference(origin); 236 DropOriginPreference(origin);
236 GetDesktopNotificationService()->DenyPermission(origin); 237 GetDesktopNotificationService()->DenyPermission(origin);
237 } 238 }
238 239
239 void NotificationsTest::AllowOrigin(const GURL& origin) { 240 void NotificationsTest::AllowOrigin(const GURL& origin) {
240 DropOriginPreference(origin); 241 DropOriginPreference(origin);
241 GetDesktopNotificationService()->GrantPermission(origin); 242 GetDesktopNotificationService()->GrantPermission(origin);
242 } 243 }
243 244
244 void NotificationsTest::AllowAllOrigins() { 245 void NotificationsTest::AllowAllOrigins() {
245 GetDesktopNotificationService()->ResetAllOrigins(); 246 GetDesktopNotificationService()->ResetAllOrigins();
246 GetDesktopNotificationService()->SetDefaultContentSetting( 247 GetDesktopNotificationService()->SetDefaultContentSetting(
247 CONTENT_SETTING_ALLOW); 248 CONTENT_SETTING_ALLOW);
248 } 249 }
249 250
250 void NotificationsTest::VerifyInfobar(const Browser* browser, int index) { 251 void NotificationsTest::VerifyInfobar(const Browser* browser, int index) {
251 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents( 252 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
252 chrome::GetWebContentsAt(browser, index)); 253 browser->tab_strip_model()->GetWebContentsAt(index));
253 254
254 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount()); 255 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount());
255 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(0); 256 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(0);
256 ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); 257 ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate();
257 ASSERT_TRUE(confirm_infobar); 258 ASSERT_TRUE(confirm_infobar);
258 int buttons = confirm_infobar->GetButtons(); 259 int buttons = confirm_infobar->GetButtons();
259 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); 260 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK);
260 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL); 261 EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL);
261 } 262 }
262 263
263 std::string NotificationsTest::CreateNotification( 264 std::string NotificationsTest::CreateNotification(
264 Browser* browser, 265 Browser* browser,
265 bool wait_for_new_balloon, 266 bool wait_for_new_balloon,
266 const char* icon, 267 const char* icon,
267 const char* title, 268 const char* title,
268 const char* body, 269 const char* body,
269 const char* replace_id) { 270 const char* replace_id) {
270 std::string script = base::StringPrintf( 271 std::string script = base::StringPrintf(
271 "createNotification('%s', '%s', '%s', '%s');", 272 "createNotification('%s', '%s', '%s', '%s');",
272 icon, title, body, replace_id); 273 icon, title, body, replace_id);
273 274
274 NotificationBalloonChangeObserver observer; 275 NotificationBalloonChangeObserver observer;
275 std::string result; 276 std::string result;
276 bool success = content::ExecuteJavaScriptAndExtractString( 277 bool success = content::ExecuteJavaScriptAndExtractString(
277 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), 278 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
278 L"", 279 L"",
279 UTF8ToWide(script), 280 UTF8ToWide(script),
280 &result); 281 &result);
281 if (success && result != "-1" && wait_for_new_balloon) 282 if (success && result != "-1" && wait_for_new_balloon)
282 success = observer.Wait(); 283 success = observer.Wait();
283 EXPECT_TRUE(success); 284 EXPECT_TRUE(success);
284 285
285 return result; 286 return result;
286 } 287 }
287 288
288 std::string NotificationsTest::CreateSimpleNotification( 289 std::string NotificationsTest::CreateSimpleNotification(
289 Browser* browser, 290 Browser* browser,
290 bool wait_for_new_balloon) { 291 bool wait_for_new_balloon) {
291 return CreateNotification( 292 return CreateNotification(
292 browser, wait_for_new_balloon, 293 browser, wait_for_new_balloon,
293 "no_such_file.png", "My Title", "My Body", ""); 294 "no_such_file.png", "My Title", "My Body", "");
294 } 295 }
295 296
296 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { 297 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) {
297 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents( 298 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
298 chrome::GetActiveWebContents(browser)); 299 browser->tab_strip_model()->GetActiveWebContents());
299 content::WindowedNotificationObserver observer( 300 content::WindowedNotificationObserver observer(
300 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 301 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
301 content::Source<InfoBarTabHelper>(infobar_helper)); 302 content::Source<InfoBarTabHelper>(infobar_helper));
302 std::string result; 303 std::string result;
303 bool success = content::ExecuteJavaScriptAndExtractString( 304 bool success = content::ExecuteJavaScriptAndExtractString(
304 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), 305 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
305 L"", 306 L"",
306 L"requestPermission();", 307 L"requestPermission();",
307 &result); 308 &result);
308 if (!success || result != "1") 309 if (!success || result != "1")
309 return false; 310 return false;
310 observer.Wait(); 311 observer.Wait();
311 return true; 312 return true;
312 } 313 }
313 314
314 bool NotificationsTest::CancelNotification( 315 bool NotificationsTest::CancelNotification(
315 const char* notification_id, 316 const char* notification_id,
316 Browser* browser) { 317 Browser* browser) {
317 std::string script = base::StringPrintf( 318 std::string script = base::StringPrintf(
318 "cancelNotification('%s');", 319 "cancelNotification('%s');",
319 notification_id); 320 notification_id);
320 321
321 NotificationBalloonChangeObserver observer; 322 NotificationBalloonChangeObserver observer;
322 std::string result; 323 std::string result;
323 bool success = content::ExecuteJavaScriptAndExtractString( 324 bool success = content::ExecuteJavaScriptAndExtractString(
324 chrome::GetActiveWebContents(browser)->GetRenderViewHost(), 325 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
325 L"", 326 L"",
326 UTF8ToWide(script), 327 UTF8ToWide(script),
327 &result); 328 &result);
328 if (!success || result != "1") 329 if (!success || result != "1")
329 return false; 330 return false;
330 return observer.Wait(); 331 return observer.Wait();
331 } 332 }
332 333
333 bool NotificationsTest::PerformActionOnInfobar( 334 bool NotificationsTest::PerformActionOnInfobar(
334 Browser* browser, 335 Browser* browser,
335 InfobarAction action, 336 InfobarAction action,
336 int infobar_index, 337 int infobar_index,
337 int tab_index) { 338 int tab_index) {
338 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents( 339 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
339 chrome::GetWebContentsAt(browser, tab_index)); 340 browser->tab_strip_model()->GetWebContentsAt(tab_index));
340 341
341 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt( 342 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(
342 infobar_index); 343 infobar_index);
343 switch (action) { 344 switch (action) {
344 case DISMISS: { 345 case DISMISS: {
345 infobar->InfoBarDismissed(); 346 infobar->InfoBarDismissed();
346 infobar_helper->RemoveInfoBar(infobar); 347 infobar_helper->RemoveInfoBar(infobar);
347 return true; 348 return true;
348 } 349 }
349 case ALLOW: { 350 case ALLOW: {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { 407 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) {
407 ui_test_utils::NavigateToURL( 408 ui_test_utils::NavigateToURL(
408 browser(), 409 browser(),
409 test_server()->GetURL( 410 test_server()->GetURL(
410 "files/notifications/notifications_request_function.html")); 411 "files/notifications/notifications_request_function.html"));
411 412
412 // Request permission by calling request() while eval'ing an inline script; 413 // Request permission by calling request() while eval'ing an inline script;
413 // That's considered a user gesture to webkit, and should produce an infobar. 414 // That's considered a user gesture to webkit, and should produce an infobar.
414 bool result; 415 bool result;
415 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 416 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
416 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 417 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
417 L"", 418 L"",
418 L"window.domAutomationController.send(request());", 419 L"window.domAutomationController.send(request());",
419 &result)); 420 &result));
420 EXPECT_TRUE(result); 421 EXPECT_TRUE(result);
421 422
422 EXPECT_EQ(1U, InfoBarTabHelper::FromWebContents( 423 EXPECT_EQ(1U, InfoBarTabHelper::FromWebContents(
423 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); 424 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount());
424 } 425 }
425 426
426 // If this flakes, use http://crbug.com/62311. 427 // If this flakes, use http://crbug.com/62311.
427 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { 428 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) {
428 // Load a page which just does a request; no user gesture should result 429 // Load a page which just does a request; no user gesture should result
429 // in no infobar. 430 // in no infobar.
430 ui_test_utils::NavigateToURL( 431 ui_test_utils::NavigateToURL(
431 browser(), 432 browser(),
432 test_server()->GetURL( 433 test_server()->GetURL(
433 "files/notifications/notifications_request_inline.html")); 434 "files/notifications/notifications_request_inline.html"));
434 435
435 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( 436 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
436 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); 437 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount());
437 } 438 }
438 439
439 // Disable new testcases on Chrome OS due to failure on creating notification. 440 // Disable new testcases on Chrome OS due to failure on creating notification.
440 #if !defined(OS_CHROMEOS) 441 #if !defined(OS_CHROMEOS)
441 442
442 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { 443 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
443 // Creates a simple notification. 444 // Creates a simple notification.
444 AllowAllOrigins(); 445 AllowAllOrigins();
445 ui_test_utils::NavigateToURL(browser(), test_page_url_); 446 ui_test_utils::NavigateToURL(browser(), test_page_url_);
446 447
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { 553 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) {
553 // Verify that all domains can be allowed to show notifications. 554 // Verify that all domains can be allowed to show notifications.
554 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW); 555 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
555 ui_test_utils::NavigateToURL(browser(), test_page_url_); 556 ui_test_utils::NavigateToURL(browser(), test_page_url_);
556 557
557 std::string result = CreateSimpleNotification(browser(), true); 558 std::string result = CreateSimpleNotification(browser(), true);
558 EXPECT_NE("-1", result); 559 EXPECT_NE("-1", result);
559 560
560 ASSERT_EQ(1, GetNotificationCount()); 561 ASSERT_EQ(1, GetNotificationCount());
561 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( 562 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
562 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); 563 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount());
563 } 564 }
564 565
565 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { 566 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) {
566 // Verify that no domain can show notifications. 567 // Verify that no domain can show notifications.
567 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK); 568 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
568 ui_test_utils::NavigateToURL(browser(), test_page_url_); 569 ui_test_utils::NavigateToURL(browser(), test_page_url_);
569 570
570 std::string result = CreateSimpleNotification(browser(), false); 571 std::string result = CreateSimpleNotification(browser(), false);
571 EXPECT_EQ("-1", result); 572 EXPECT_EQ("-1", result);
572 573
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 EXPECT_EQ("-1", result); 612 EXPECT_EQ("-1", result);
612 613
613 ASSERT_EQ(0, GetNotificationCount()); 614 ASSERT_EQ(0, GetNotificationCount());
614 615
615 AllowOrigin(test_page_url_.GetOrigin()); 616 AllowOrigin(test_page_url_.GetOrigin());
616 result = CreateSimpleNotification(browser(), true); 617 result = CreateSimpleNotification(browser(), true);
617 EXPECT_NE("-1", result); 618 EXPECT_NE("-1", result);
618 619
619 ASSERT_EQ(1, GetNotificationCount()); 620 ASSERT_EQ(1, GetNotificationCount());
620 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( 621 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
621 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); 622 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount());
622 } 623 }
623 624
624 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { 625 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) {
625 // Verify able to create, deny, and close the notification. 626 // Verify able to create, deny, and close the notification.
626 AllowAllOrigins(); 627 AllowAllOrigins();
627 ui_test_utils::NavigateToURL(browser(), test_page_url_); 628 ui_test_utils::NavigateToURL(browser(), test_page_url_);
628 CreateSimpleNotification(browser(), true); 629 CreateSimpleNotification(browser(), true);
629 ASSERT_EQ(1, GetNotificationCount()); 630 ASSERT_EQ(1, GetNotificationCount());
630 631
631 DenyOrigin(test_page_url_.GetOrigin()); 632 DenyOrigin(test_page_url_.GetOrigin());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 ASSERT_TRUE(RequestPermissionAndWait(browser())); 676 ASSERT_TRUE(RequestPermissionAndWait(browser()));
676 } 677 }
677 678
678 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCrashTabWithPermissionInfobar) { 679 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCrashTabWithPermissionInfobar) {
679 // Test crashing the tab with permission infobar doesn't crash Chrome. 680 // Test crashing the tab with permission infobar doesn't crash Chrome.
680 ui_test_utils::NavigateToURLWithDisposition( 681 ui_test_utils::NavigateToURLWithDisposition(
681 browser(), 682 browser(),
682 empty_page_url_, 683 empty_page_url_,
683 NEW_BACKGROUND_TAB, 684 NEW_BACKGROUND_TAB,
684 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 685 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
685 chrome::ActivateTabAt(browser(), 0, true); 686 browser()->tab_strip_model()->ActivateTabAt(0, true);
686 ui_test_utils::NavigateToURL(browser(), test_page_url_); 687 ui_test_utils::NavigateToURL(browser(), test_page_url_);
687 ASSERT_TRUE(RequestPermissionAndWait(browser())); 688 ASSERT_TRUE(RequestPermissionAndWait(browser()));
688 CrashTab(browser(), 0); 689 CrashTab(browser(), 0);
689 } 690 }
690 691
691 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) { 692 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) {
692 // Test killing a notification doesn't crash Chrome. 693 // Test killing a notification doesn't crash Chrome.
693 AllowAllOrigins(); 694 AllowAllOrigins();
694 ui_test_utils::NavigateToURL(browser(), test_page_url_); 695 ui_test_utils::NavigateToURL(browser(), test_page_url_);
695 CreateSimpleNotification(browser(), true); 696 CreateSimpleNotification(browser(), true);
696 ASSERT_EQ(1, GetNotificationCount()); 697 ASSERT_EQ(1, GetNotificationCount());
697 698
698 const std::deque<Balloon*>& balloons = GetActiveBalloons(); 699 const std::deque<Balloon*>& balloons = GetActiveBalloons();
699 ASSERT_EQ(1U, balloons.size()); 700 ASSERT_EQ(1U, balloons.size());
700 CrashNotification(balloons[0]); 701 CrashNotification(balloons[0]);
701 ASSERT_EQ(0, GetNotificationCount()); 702 ASSERT_EQ(0, GetNotificationCount());
702 } 703 }
703 704
704 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) { 705 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) {
705 // Test notifications in incognito window. 706 // Test notifications in incognito window.
706 Browser* browser = CreateIncognitoBrowser(); 707 Browser* browser = CreateIncognitoBrowser();
707 ui_test_utils::NavigateToURL(browser, test_page_url_); 708 ui_test_utils::NavigateToURL(browser, test_page_url_);
708 chrome::ActivateTabAt(browser, 0, true); 709 browser->tab_strip_model()->ActivateTabAt(0, true);
709 ASSERT_TRUE(RequestPermissionAndWait(browser)); 710 ASSERT_TRUE(RequestPermissionAndWait(browser));
710 PerformActionOnInfobar(browser, ALLOW, 0, 0); 711 PerformActionOnInfobar(browser, ALLOW, 0, 0);
711 CreateSimpleNotification(browser, true); 712 CreateSimpleNotification(browser, true);
712 ASSERT_EQ(1, GetNotificationCount()); 713 ASSERT_EQ(1, GetNotificationCount());
713 } 714 }
714 715
715 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) { 716 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseTabWithPermissionInfobar) {
716 // Test that user can close tab when infobar present. 717 // Test that user can close tab when infobar present.
717 ui_test_utils::NavigateToURLWithDisposition( 718 ui_test_utils::NavigateToURLWithDisposition(
718 browser(), 719 browser(),
719 GURL("about:blank"), 720 GURL("about:blank"),
720 NEW_BACKGROUND_TAB, 721 NEW_BACKGROUND_TAB,
721 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 722 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
722 chrome::ActivateTabAt(browser(), 0, true); 723 browser()->tab_strip_model()->ActivateTabAt(0, true);
723 ui_test_utils::NavigateToURL(browser(), test_page_url_); 724 ui_test_utils::NavigateToURL(browser(), test_page_url_);
724 ASSERT_TRUE(RequestPermissionAndWait(browser())); 725 ASSERT_TRUE(RequestPermissionAndWait(browser()));
725 content::WindowedNotificationObserver observer( 726 content::WindowedNotificationObserver observer(
726 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 727 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
727 content::NotificationService::AllSources()); 728 content::NotificationService::AllSources());
728 chrome::CloseWebContents(browser(), chrome::GetWebContentsAt(browser(), 0)); 729 chrome::CloseWebContents(browser(),
730 browser()->tab_strip_model()->GetWebContentsAt(0));
729 observer.Wait(); 731 observer.Wait();
730 } 732 }
731 733
732 IN_PROC_BROWSER_TEST_F( 734 IN_PROC_BROWSER_TEST_F(
733 NotificationsTest, 735 NotificationsTest,
734 TestNavigateAwayWithPermissionInfobar) { 736 TestNavigateAwayWithPermissionInfobar) {
735 // Test navigating away when an infobar is present, 737 // Test navigating away when an infobar is present,
736 // then trying to create a notification from the same page. 738 // then trying to create a notification from the same page.
737 ui_test_utils::NavigateToURLWithDisposition( 739 ui_test_utils::NavigateToURLWithDisposition(
738 browser(), 740 browser(),
739 GURL("about:blank"), 741 GURL("about:blank"),
740 NEW_BACKGROUND_TAB, 742 NEW_BACKGROUND_TAB,
741 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 743 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
742 chrome::ActivateTabAt(browser(), 0, true); 744 browser()->tab_strip_model()->ActivateTabAt(0, true);
743 ui_test_utils::NavigateToURL(browser(), test_page_url_); 745 ui_test_utils::NavigateToURL(browser(), test_page_url_);
744 ASSERT_TRUE(RequestPermissionAndWait(browser())); 746 ASSERT_TRUE(RequestPermissionAndWait(browser()));
745 ui_test_utils::NavigateToURL(browser(), test_page_url_); 747 ui_test_utils::NavigateToURL(browser(), test_page_url_);
746 ASSERT_TRUE(RequestPermissionAndWait(browser())); 748 ASSERT_TRUE(RequestPermissionAndWait(browser()));
747 PerformActionOnInfobar(browser(), ALLOW, 0, 0); 749 PerformActionOnInfobar(browser(), ALLOW, 0, 0);
748 CreateSimpleNotification(browser(), true); 750 CreateSimpleNotification(browser(), true);
749 ASSERT_EQ(1, GetNotificationCount()); 751 ASSERT_EQ(1, GetNotificationCount());
750 } 752 }
751 753
752 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCrashRendererNotificationRemain) { 754 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCrashRendererNotificationRemain) {
753 // Test crashing renderer does not close or crash notification. 755 // Test crashing renderer does not close or crash notification.
754 AllowAllOrigins(); 756 AllowAllOrigins();
755 ui_test_utils::NavigateToURLWithDisposition( 757 ui_test_utils::NavigateToURLWithDisposition(
756 browser(), 758 browser(),
757 GURL("about:blank"), 759 GURL("about:blank"),
758 NEW_BACKGROUND_TAB, 760 NEW_BACKGROUND_TAB,
759 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 761 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
760 chrome::ActivateTabAt(browser(), 0, true); 762 browser()->tab_strip_model()->ActivateTabAt(0, true);
761 ui_test_utils::NavigateToURL(browser(), test_page_url_); 763 ui_test_utils::NavigateToURL(browser(), test_page_url_);
762 CreateSimpleNotification(browser(), true); 764 CreateSimpleNotification(browser(), true);
763 ASSERT_EQ(1, GetNotificationCount()); 765 ASSERT_EQ(1, GetNotificationCount());
764 CrashTab(browser(), 0); 766 CrashTab(browser(), 0);
765 ASSERT_EQ(1, GetNotificationCount()); 767 ASSERT_EQ(1, GetNotificationCount());
766 } 768 }
767 769
768 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) { 770 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) {
769 // Test that we can replace a notification using the replaceId. 771 // Test that we can replace a notification using the replaceId.
770 AllowAllOrigins(); 772 AllowAllOrigins();
(...skipping 13 matching lines...) Expand all
784 const std::deque<Balloon*>& balloons = GetActiveBalloons(); 786 const std::deque<Balloon*>& balloons = GetActiveBalloons();
785 EXPECT_EQ(1U, balloons.size()); 787 EXPECT_EQ(1U, balloons.size());
786 const Notification& notification = balloons[0]->notification(); 788 const Notification& notification = balloons[0]->notification();
787 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); 789 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
788 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); 790 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
789 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); 791 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title());
790 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); 792 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body());
791 } 793 }
792 794
793 #endif // !defined(OS_CHROMEOS) 795 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698