OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <AppKit/AppKit.h> |
| 6 |
| 7 #include "chrome/browser/notifications/notification_interactive_uitest_support.h
" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/test/base/interactive_test_utils.h" |
| 11 #import "ui/base/test/windowed_nsnotification_observer.h" |
| 12 #include "ui/message_center/message_center.h" |
| 13 |
| 14 // Verify that Chrome becomes the active app if a notification opens a popup |
| 15 // when clicked. |
| 16 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestPopupShouldActivateApp) { |
| 17 EXPECT_TRUE(embedded_test_server()->Start()); |
| 18 |
| 19 AllowAllOrigins(); |
| 20 ui_test_utils::NavigateToURL(browser(), GetTestPageURL()); |
| 21 |
| 22 EXPECT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( |
| 23 browser()->window()->GetNativeWindow())); |
| 24 |
| 25 { |
| 26 base::scoped_nsobject<WindowedNSNotificationObserver> observer( |
| 27 [[WindowedNSNotificationObserver alloc] |
| 28 initForNotification:NSApplicationDidResignActiveNotification |
| 29 object:NSApp]); |
| 30 [NSApp hide:nil]; |
| 31 [observer wait]; |
| 32 } |
| 33 EXPECT_FALSE([NSApp isActive]); |
| 34 |
| 35 std::string result = CreateNotification( |
| 36 browser(), true, "", "", "", "", |
| 37 "window.open('', '', 'width=100,height=100').focus();"); |
| 38 EXPECT_NE("-1", result); |
| 39 |
| 40 auto* message_center = message_center::MessageCenter::Get(); |
| 41 message_center::Notification* notification = |
| 42 *message_center->GetVisibleNotifications().begin(); |
| 43 |
| 44 { |
| 45 base::scoped_nsobject<WindowedNSNotificationObserver> observer( |
| 46 [[WindowedNSNotificationObserver alloc] |
| 47 initForNotification:NSApplicationDidBecomeActiveNotification |
| 48 object:NSApp]); |
| 49 message_center->ClickOnNotification(notification->id()); |
| 50 [observer wait]; |
| 51 } |
| 52 EXPECT_TRUE([NSApp isActive]); |
| 53 } |
OLD | NEW |