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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_manager_notifications_browsertest.cc

Issue 14020002: chromeos: Move chrome/browser/chromeos/extensions/file_browser* to chrome/browser/chromeos/file_man… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort Created 7 years, 8 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 "chrome/browser/chromeos/extensions/file_browser_notifications.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_notificat ions.h"
6 6
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/notifications/notification.h" 11 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h" 12 #include "chrome/browser/notifications/notification_ui_manager.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 class FileBrowserNotificationsTest : public InProcessBrowserTest { 21 class FileManagerNotificationsTest : public InProcessBrowserTest {
22 public: 22 public:
23 FileBrowserNotificationsTest() {} 23 FileManagerNotificationsTest() {}
24 24
25 virtual void CleanUpOnMainThread() OVERRIDE { 25 virtual void CleanUpOnMainThread() OVERRIDE {
26 notifications_.reset(); 26 notifications_.reset();
27 } 27 }
28 28
29 protected: 29 protected:
30 // This must be initialized late in test startup. 30 // This must be initialized late in test startup.
31 void InitNotifications() { 31 void InitNotifications() {
32 Profile* profile = browser()->profile(); 32 Profile* profile = browser()->profile();
33 notifications_.reset(new FileBrowserNotifications(profile)); 33 notifications_.reset(new FileManagerNotifications(profile));
34 } 34 }
35 35
36 bool FindNotification(const std::string& id) { 36 bool FindNotification(const std::string& id) {
37 return notifications_->HasNotificationForTest(id); 37 return notifications_->HasNotificationForTest(id);
38 } 38 }
39 39
40 scoped_ptr<FileBrowserNotifications> notifications_; 40 scoped_ptr<FileManagerNotifications> notifications_;
41 }; 41 };
42 42
43 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, TestBasic) { 43 IN_PROC_BROWSER_TEST_F(FileManagerNotificationsTest, TestBasic) {
44 InitNotifications(); 44 InitNotifications();
45 // Showing a notification adds a new notification. 45 // Showing a notification adds a new notification.
46 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); 46 notifications_->ShowNotification(FileManagerNotifications::DEVICE, "path");
47 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); 47 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest());
48 EXPECT_TRUE(FindNotification("Device_path")); 48 EXPECT_TRUE(FindNotification("Device_path"));
49 49
50 // Updating the same notification maintains the same count. 50 // Updating the same notification maintains the same count.
51 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); 51 notifications_->ShowNotification(FileManagerNotifications::DEVICE, "path");
52 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); 52 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest());
53 EXPECT_TRUE(FindNotification("Device_path")); 53 EXPECT_TRUE(FindNotification("Device_path"));
54 54
55 // A new notification increases the count. 55 // A new notification increases the count.
56 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, 56 notifications_->ShowNotification(FileManagerNotifications::DEVICE_FAIL,
57 "path"); 57 "path");
58 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); 58 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest());
59 EXPECT_TRUE(FindNotification("DeviceFail_path")); 59 EXPECT_TRUE(FindNotification("DeviceFail_path"));
60 EXPECT_TRUE(FindNotification("Device_path")); 60 EXPECT_TRUE(FindNotification("Device_path"));
61 61
62 // Hiding a notification removes it from our data. 62 // Hiding a notification removes it from our data.
63 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, 63 notifications_->HideNotification(FileManagerNotifications::DEVICE_FAIL,
64 "path"); 64 "path");
65 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); 65 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest());
66 EXPECT_FALSE(FindNotification("DeviceFail_path")); 66 EXPECT_FALSE(FindNotification("DeviceFail_path"));
67 EXPECT_TRUE(FindNotification("Device_path")); 67 EXPECT_TRUE(FindNotification("Device_path"));
68 }; 68 };
69 69
70 // Note: Delayed tests use a delay time of 0 so that tasks wille execute 70 // Note: Delayed tests use a delay time of 0 so that tasks wille execute
71 // when RunAllPendingInMessageLoop() is called. 71 // when RunAllPendingInMessageLoop() is called.
72 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { 72 IN_PROC_BROWSER_TEST_F(FileManagerNotificationsTest, ShowDelayedTest) {
73 InitNotifications(); 73 InitNotifications();
74 // Adding a delayed notification does not create a notification. 74 // Adding a delayed notification does not create a notification.
75 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, 75 notifications_->ShowNotificationDelayed(FileManagerNotifications::DEVICE,
76 "path", 76 "path",
77 base::TimeDelta::FromSeconds(0)); 77 base::TimeDelta::FromSeconds(0));
78 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); 78 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest());
79 EXPECT_FALSE(FindNotification("Device_path")); 79 EXPECT_FALSE(FindNotification("Device_path"));
80 80
81 // Running the message loop should create the notification. 81 // Running the message loop should create the notification.
82 content::RunAllPendingInMessageLoop(); 82 content::RunAllPendingInMessageLoop();
83 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); 83 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest());
84 EXPECT_TRUE(FindNotification("Device_path")); 84 EXPECT_TRUE(FindNotification("Device_path"));
85 85
86 // Showing a notification both immediately and delayed results in one 86 // Showing a notification both immediately and delayed results in one
87 // additional notification. 87 // additional notification.
88 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, 88 notifications_->ShowNotificationDelayed(FileManagerNotifications::DEVICE_FAIL,
89 "path", 89 "path",
90 base::TimeDelta::FromSeconds(0)); 90 base::TimeDelta::FromSeconds(0));
91 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, 91 notifications_->ShowNotification(FileManagerNotifications::DEVICE_FAIL,
92 "path"); 92 "path");
93 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); 93 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest());
94 EXPECT_TRUE(FindNotification("DeviceFail_path")); 94 EXPECT_TRUE(FindNotification("DeviceFail_path"));
95 95
96 // When the delayed notification is processed, it's an update, so we still 96 // When the delayed notification is processed, it's an update, so we still
97 // only have two notifications. 97 // only have two notifications.
98 content::RunAllPendingInMessageLoop(); 98 content::RunAllPendingInMessageLoop();
99 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); 99 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest());
100 EXPECT_TRUE(FindNotification("DeviceFail_path")); 100 EXPECT_TRUE(FindNotification("DeviceFail_path"));
101 101
102 // If we schedule a show for later, then hide before it becomes visible, 102 // If we schedule a show for later, then hide before it becomes visible,
103 // the notification should not be added. 103 // the notification should not be added.
104 notifications_->ShowNotificationDelayed(FileBrowserNotifications::FORMAT_FAIL, 104 notifications_->ShowNotificationDelayed(FileManagerNotifications::FORMAT_FAIL,
105 "path", 105 "path",
106 base::TimeDelta::FromSeconds(0)); 106 base::TimeDelta::FromSeconds(0));
107 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, 107 notifications_->HideNotification(FileManagerNotifications::FORMAT_FAIL,
108 "path"); 108 "path");
109 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); 109 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest());
110 EXPECT_TRUE(FindNotification("Device_path")); 110 EXPECT_TRUE(FindNotification("Device_path"));
111 EXPECT_TRUE(FindNotification("DeviceFail_path")); 111 EXPECT_TRUE(FindNotification("DeviceFail_path"));
112 EXPECT_FALSE(FindNotification("Format_path")); 112 EXPECT_FALSE(FindNotification("Format_path"));
113 113
114 // Even after processing messages, no new notification should be added. 114 // Even after processing messages, no new notification should be added.
115 content::RunAllPendingInMessageLoop(); 115 content::RunAllPendingInMessageLoop();
116 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); 116 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest());
117 EXPECT_TRUE(FindNotification("Device_path")); 117 EXPECT_TRUE(FindNotification("Device_path"));
118 EXPECT_TRUE(FindNotification("DeviceFail_path")); 118 EXPECT_TRUE(FindNotification("DeviceFail_path"));
119 EXPECT_FALSE(FindNotification("Format_path")); 119 EXPECT_FALSE(FindNotification("Format_path"));
120 } 120 }
121 121
122 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { 122 IN_PROC_BROWSER_TEST_F(FileManagerNotificationsTest, HideDelayedTest) {
123 InitNotifications(); 123 InitNotifications();
124 // Showing now, and scheduling a hide for later, results in one notification. 124 // Showing now, and scheduling a hide for later, results in one notification.
125 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); 125 notifications_->ShowNotification(FileManagerNotifications::DEVICE, "path");
126 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, 126 notifications_->HideNotificationDelayed(FileManagerNotifications::DEVICE,
127 "path", 127 "path",
128 base::TimeDelta::FromSeconds(0)); 128 base::TimeDelta::FromSeconds(0));
129 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); 129 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest());
130 EXPECT_TRUE(FindNotification("Device_path")); 130 EXPECT_TRUE(FindNotification("Device_path"));
131 131
132 // Running pending messges should remove the notification. 132 // Running pending messges should remove the notification.
133 content::RunAllPendingInMessageLoop(); 133 content::RunAllPendingInMessageLoop();
134 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); 134 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest());
135 135
136 // Immediate show then hide results in no notification. 136 // Immediate show then hide results in no notification.
137 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, 137 notifications_->ShowNotification(FileManagerNotifications::DEVICE_FAIL,
138 "path"); 138 "path");
139 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, 139 notifications_->HideNotification(FileManagerNotifications::DEVICE_FAIL,
140 "path"); 140 "path");
141 content::RunAllPendingInMessageLoop(); 141 content::RunAllPendingInMessageLoop();
142 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); 142 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest());
143 143
144 // Delayed hide for a notification that doesn't exist does nothing. 144 // Delayed hide for a notification that doesn't exist does nothing.
145 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, 145 notifications_->HideNotificationDelayed(FileManagerNotifications::DEVICE_FAIL,
146 "path", 146 "path",
147 base::TimeDelta::FromSeconds(0)); 147 base::TimeDelta::FromSeconds(0));
148 content::RunAllPendingInMessageLoop(); 148 content::RunAllPendingInMessageLoop();
149 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); 149 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest());
150 } 150 }
151 151
152 // Tests that showing two notifications with the same notification ids and 152 // Tests that showing two notifications with the same notification ids and
153 // different messages results in showing the second notification's message. 153 // different messages results in showing the second notification's message.
154 // This situation can be encountered while showing notifications for 154 // This situation can be encountered while showing notifications for
155 // MountCompletedEvent. 155 // MountCompletedEvent.
156 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, IdenticalNotificationIds) { 156 IN_PROC_BROWSER_TEST_F(FileManagerNotificationsTest, IdenticalNotificationIds) {
157 InitNotifications(); 157 InitNotifications();
158 notifications_->RegisterDevice("path"); 158 notifications_->RegisterDevice("path");
159 159
160 notifications_->ManageNotificationsOnMountCompleted("path", "", false, false, 160 notifications_->ManageNotificationsOnMountCompleted("path", "", false, false,
161 false); 161 false);
162 content::RunAllPendingInMessageLoop(); 162 content::RunAllPendingInMessageLoop();
163 163
164 EXPECT_EQ( 164 EXPECT_EQ(
165 l10n_util::GetStringUTF16(IDS_DEVICE_UNKNOWN_DEFAULT_MESSAGE), 165 l10n_util::GetStringUTF16(IDS_DEVICE_UNKNOWN_DEFAULT_MESSAGE),
166 notifications_->GetNotificationMessageForTest("DeviceFail_path")); 166 notifications_->GetNotificationMessageForTest("DeviceFail_path"));
167 167
168 notifications_->ManageNotificationsOnMountCompleted("path", "", false, false, 168 notifications_->ManageNotificationsOnMountCompleted("path", "", false, false,
169 false); 169 false);
170 content::RunAllPendingInMessageLoop(); 170 content::RunAllPendingInMessageLoop();
171 171
172 EXPECT_EQ( 172 EXPECT_EQ(
173 l10n_util::GetStringUTF16(IDS_MULTIPART_DEVICE_UNSUPPORTED_DEFAULT_MESSAGE), 173 l10n_util::GetStringUTF16(IDS_MULTIPART_DEVICE_UNSUPPORTED_DEFAULT_MESSAGE),
174 notifications_->GetNotificationMessageForTest("DeviceFail_path")); 174 notifications_->GetNotificationMessageForTest("DeviceFail_path"));
175 175
176 notifications_->UnregisterDevice("path"); 176 notifications_->UnregisterDevice("path");
177 } 177 }
178 178
179 } // namespace chromeos. 179 } // namespace chromeos.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698