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

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

Powered by Google App Engine
This is Rietveld 408576698