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

Side by Side Diff: chrome/browser/task_manager/task_manager_notification_browsertest.cc

Issue 185873003: Task Manager: overhaul & re-enable task manager browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Retry upload Created 6 years, 9 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
« no previous file with comments | « chrome/browser/task_manager/task_manager_browsertest_util.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/notifications/desktop_notification_service.h" 10 #include "chrome/browser/notifications/desktop_notification_service.h"
11 #include "chrome/browser/notifications/notification.h" 11 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/notification_test_util.h" 12 #include "chrome/browser/notifications/notification_test_util.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h" 13 #include "chrome/browser/notifications/notification_ui_manager.h"
14 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" 14 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_dialogs.h" 16 #include "chrome/browser/ui/browser_dialogs.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "grit/generated_resources.h"
21 #include "testing/gtest/include/gtest/gtest.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"
22 #include "ui/message_center/message_center_util.h" 25 #include "ui/message_center/message_center_util.h"
23 26
27 using task_manager::browsertest_util::WaitForTaskManagerRows;
28
24 class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest { 29 class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest {
25 public:
26 TaskManagerModel* model() const {
27 return TaskManager::GetInstance()->model();
28 }
29 protected: 30 protected:
30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
31 ExtensionBrowserTest::SetUpCommandLine(command_line); 32 ExtensionBrowserTest::SetUpCommandLine(command_line);
33 }
32 34
33 // Do not prelaunch the GPU process for these tests because it will show 35 // Returns the text we expect to see in the TaskManager for a given
34 // up in task manager but whether it appears before or after the new tab 36 // notification.
35 // renderer process is not well defined. 37 base::string16 GetTitle(const char* ascii_name) {
36 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); 38 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NOTIFICATION_PREFIX,
39 base::ASCIIToUTF16(ascii_name));
37 } 40 }
38 }; 41 };
39 42
40 // TODO(linux_aura) http://crbug.com/163931 43 // TODO(linux_aura) http://crbug.com/163931
41 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 44 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
42 #define MAYBE_NoticeNotificationChanges DISABLED_NoticeNotificationChanges 45 #define MAYBE_NoticeNotificationChanges DISABLED_NoticeNotificationChanges
43 #else 46 #else
44 #define MAYBE_NoticeNotificationChanges NoticeNotificationChanges 47 #define MAYBE_NoticeNotificationChanges NoticeNotificationChanges
45 #endif 48 #endif
46 IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest, 49 IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
47 MAYBE_NoticeNotificationChanges) { 50 MAYBE_NoticeNotificationChanges) {
48 // These tests do not apply with Message Center platforms 51 // These tests do not apply with Message Center-only platforms (e.g. Ash)
49 // where notifications do not instantiate a new renderer. 52 // where notifications do not instantiate a new renderer.
50 if (message_center::IsRichNotificationEnabled()) 53 if (message_center::IsRichNotificationEnabled())
51 return; 54 return;
52 55
53 EXPECT_EQ(0, model()->ResourceCount());
54
55 // Show the task manager.
56 chrome::ShowTaskManager(browser());
57 // Expect to see the browser and the New Tab Page renderer.
58 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
59
60 // Show a notification. 56 // Show a notification.
61 NotificationUIManager* notifications = 57 NotificationUIManager* notifications =
62 g_browser_process->notification_ui_manager(); 58 g_browser_process->notification_ui_manager();
63 59
64 base::string16 content = DesktopNotificationService::CreateDataUrl( 60 base::string16 content = DesktopNotificationService::CreateDataUrl(
65 GURL(), base::ASCIIToUTF16("Hello World!"), base::string16(), 61 GURL(), base::ASCIIToUTF16("Hello World!"), base::string16(),
66 blink::WebTextDirectionDefault); 62 blink::WebTextDirectionDefault);
67 63
64 // Show an initial notification before popping up the task manager.
65 scoped_refptr<NotificationDelegate> del0(new MockNotificationDelegate("n0"));
66 Notification n0(
67 GURL(), GURL(content), base::ASCIIToUTF16("Test 0"), base::string16(),
68 del0.get());
69 notifications->Add(n0, browser()->profile());
70
71 // Show the task manager.
72 chrome::ShowTaskManager(browser());
73
74 // This notification should show up in the task manager.
75 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0")));
76
68 scoped_refptr<NotificationDelegate> del1(new MockNotificationDelegate("n1")); 77 scoped_refptr<NotificationDelegate> del1(new MockNotificationDelegate("n1"));
69 Notification n1( 78 Notification n1(
70 GURL(), GURL(content), base::ASCIIToUTF16("Test 1"), base::string16(), 79 GURL(), GURL(content), base::ASCIIToUTF16("Test 1"), base::string16(),
71 del1.get()); 80 del1.get());
72 scoped_refptr<NotificationDelegate> del2(new MockNotificationDelegate("n2")); 81 scoped_refptr<NotificationDelegate> del2(new MockNotificationDelegate("n2"));
73 Notification n2( 82 Notification n2(
74 GURL(), GURL(content), base::ASCIIToUTF16("Test 2"), base::string16(), 83 GURL(), GURL(content), base::ASCIIToUTF16("Test 2"), base::string16(),
75 del2.get()); 84 del2.get());
76 85
86 // Show two more notifications with the task manager running, then cancel
87 // all three notifications.
77 notifications->Add(n1, browser()->profile()); 88 notifications->Add(n1, browser()->profile());
78 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 89 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0")));
90 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 1")));
91 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 2")));
92
79 notifications->Add(n2, browser()->profile()); 93 notifications->Add(n2, browser()->profile());
80 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); 94 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0")));
95 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 1")));
96 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2")));
97
81 notifications->CancelById(n1.notification_id()); 98 notifications->CancelById(n1.notification_id());
82 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 99 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 0")));
100 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1")));
101 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2")));
102
103 notifications->CancelById(n0.notification_id());
104 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 0")));
105 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1")));
106 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, GetTitle("Test 2")));
107
83 notifications->CancelById(n2.notification_id()); 108 notifications->CancelById(n2.notification_id());
84 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 109 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 0")));
110 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 1")));
111 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, GetTitle("Test 2")));
85 } 112 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager_browsertest_util.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698