OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/task_manager/task_manager.h" | |
6 | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/extensions/extension_browsertest.h" | |
10 #include "chrome/browser/notifications/desktop_notification_service.h" | |
11 #include "chrome/browser/notifications/notification.h" | |
12 #include "chrome/browser/notifications/notification_test_util.h" | |
13 #include "chrome/browser/notifications/notification_ui_manager.h" | |
14 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | |
15 #include "chrome/browser/ui/browser.h" | |
16 #include "chrome/browser/ui/browser_dialogs.h" | |
17 #include "chrome/browser/ui/browser_window.h" | |
18 #include "chrome/test/base/in_process_browser_test.h" | |
19 #include "chrome/test/base/ui_test_utils.h" | |
20 #include "content/public/common/content_switches.h" | |
21 #include "grit/generated_resources.h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | |
23 #include "ui/base/l10n/l10n_util.h" | |
24 #include "ui/message_center/message_center_switches.h" | |
25 #include "ui/message_center/message_center_util.h" | |
26 | |
27 using task_manager::browsertest_util::WaitForTaskManagerRows; | |
28 | |
29 class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest { | |
30 protected: | |
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
32 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
33 } | |
34 | |
35 // Returns the text we expect to see in the TaskManager for a given | |
36 // notification. | |
37 base::string16 GetTitle(const char* ascii_name) { | |
38 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NOTIFICATION_PREFIX, | |
39 base::ASCIIToUTF16(ascii_name)); | |
40 } | |
41 }; | |
42 | |
43 // TODO(linux_aura) http://crbug.com/163931 | |
44 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) | |
45 #define MAYBE_NoticeNotificationChanges DISABLED_NoticeNotificationChanges | |
46 // Broken on gtk, see http://crbug.com/355442 | |
47 #elif defined(TOOLKIT_GTK) | |
48 #define MAYBE_NoticeNotificationChanges DISABLED_NoticeNotificationChanges | |
49 #else | |
50 #define MAYBE_NoticeNotificationChanges NoticeNotificationChanges | |
51 #endif | |
52 IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest, | |
53 MAYBE_NoticeNotificationChanges) { | |
54 // These tests do not apply with Message Center-only platforms (e.g. Ash) | |
55 // where notifications do not instantiate a new renderer. | |
56 if (message_center::IsRichNotificationEnabled()) | |
57 return; | |
58 | |
59 // Show a notification. | |
60 NotificationUIManager* notifications = | |
61 g_browser_process->notification_ui_manager(); | |
62 | |
63 base::string16 content = DesktopNotificationService::CreateDataUrl( | |
64 GURL(), base::ASCIIToUTF16("Hello World!"), base::string16(), | |
65 blink::WebTextDirectionDefault); | |
66 | |
67 // Show an initial notification before popping up the task manager. | |
68 scoped_refptr<NotificationDelegate> del0(new MockNotificationDelegate("n0")); | |
69 Notification n0( | |
70 GURL(), GURL(content), base::ASCIIToUTF16("Test 0"), base::string16(), | |
71 del0.get()); | |
72 notifications->Add(n0, browser()->profile()); | |
73 | |
74 // Show the task manager. | |
75 chrome::ShowTaskManager(browser()); | |
76 | |
77 // This notification should show up in the task manager. | |
78 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); | |
79 | |
80 scoped_refptr<NotificationDelegate> del1(new MockNotificationDelegate("n1")); | |
81 Notification n1( | |
82 GURL(), GURL(content), base::ASCIIToUTF16("Test 1"), base::string16(), | |
83 del1.get()); | |
84 scoped_refptr<NotificationDelegate> del2(new MockNotificationDelegate("n2")); | |
85 Notification n2( | |
86 GURL(), GURL(content), base::ASCIIToUTF16("Test 2"), base::string16(), | |
87 del2.get()); | |
88 | |
89 // Show two more notifications with the task manager running, then cancel | |
90 // all three notifications. | |
91 notifications->Add(n1, browser()->profile()); | |
92 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); | |
93 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 1"))); | |
94 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 2"))); | |
95 | |
96 notifications->Add(n2, browser()->profile()); | |
97 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); | |
98 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 1"))); | |
99 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2"))); | |
100 | |
101 notifications->CancelById(n1.notification_id()); | |
102 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0"))); | |
103 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1"))); | |
104 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2"))); | |
105 | |
106 notifications->CancelById(n0.notification_id()); | |
107 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 0"))); | |
108 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1"))); | |
109 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2"))); | |
110 | |
111 notifications->CancelById(n2.notification_id()); | |
112 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 0"))); | |
113 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1"))); | |
114 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 2"))); | |
115 } | |
OLD | NEW |