OLD | NEW |
---|---|
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_browser_notifications.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" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
13 #include "chrome/browser/notifications/notification_ui_manager.h" | 13 #include "chrome/browser/notifications/notification_ui_manager.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" | |
17 #include "ui/base/l10n/l10n_util.h" | |
16 | 18 |
17 namespace chromeos { | 19 namespace chromeos { |
18 | 20 |
19 class FileBrowserNotificationsTest : public InProcessBrowserTest { | 21 class FileBrowserNotificationsTest : public InProcessBrowserTest { |
20 public: | 22 public: |
21 FileBrowserNotificationsTest() {} | 23 FileBrowserNotificationsTest() {} |
22 | 24 |
23 virtual void CleanUpOnMainThread() OVERRIDE { | 25 virtual void CleanUpOnMainThread() OVERRIDE { |
24 notifications_.reset(); | 26 notifications_.reset(); |
25 } | 27 } |
(...skipping 10 matching lines...) Expand all Loading... | |
36 } | 38 } |
37 | 39 |
38 scoped_ptr<FileBrowserNotifications> notifications_; | 40 scoped_ptr<FileBrowserNotifications> notifications_; |
39 }; | 41 }; |
40 | 42 |
41 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, TestBasic) { | 43 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, TestBasic) { |
42 InitNotifications(); | 44 InitNotifications(); |
43 // Showing a notification adds a new notification. | 45 // Showing a notification adds a new notification. |
44 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); | 46 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); |
45 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); | 47 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); |
46 EXPECT_TRUE(FindNotification("Dpath")); | 48 EXPECT_TRUE(FindNotification("Device_path")); |
47 | 49 |
48 // Updating the same notification maintains the same count. | 50 // Updating the same notification maintains the same count. |
49 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); | 51 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); |
50 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); | 52 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); |
51 EXPECT_TRUE(FindNotification("Dpath")); | 53 EXPECT_TRUE(FindNotification("Device_path")); |
52 | 54 |
53 // A new notification increases the count. | 55 // A new notification increases the count. |
54 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 56 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
55 "path"); | 57 "path"); |
56 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); | 58 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); |
57 EXPECT_TRUE(FindNotification("DFpath")); | 59 EXPECT_TRUE(FindNotification("DeviceFail_path")); |
58 EXPECT_TRUE(FindNotification("Dpath")); | 60 EXPECT_TRUE(FindNotification("Device_path")); |
59 | 61 |
60 // Hiding a notification removes it from our data. | 62 // Hiding a notification removes it from our data. |
61 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, | 63 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, |
62 "path"); | 64 "path"); |
63 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); | 65 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); |
64 EXPECT_FALSE(FindNotification("DFpath")); | 66 EXPECT_FALSE(FindNotification("DeviceFail_path")); |
65 EXPECT_TRUE(FindNotification("Dpath")); | 67 EXPECT_TRUE(FindNotification("Device_path")); |
66 }; | 68 }; |
67 | 69 |
68 // 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 |
69 // when RunAllPendingInMessageLoop() is called. | 71 // when RunAllPendingInMessageLoop() is called. |
70 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { | 72 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { |
71 InitNotifications(); | 73 InitNotifications(); |
72 // Adding a delayed notification does not create a notification. | 74 // Adding a delayed notification does not create a notification. |
73 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, | 75 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, |
74 "path", | 76 "path", |
75 base::TimeDelta::FromSeconds(0)); | 77 base::TimeDelta::FromSeconds(0)); |
76 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); | 78 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); |
77 EXPECT_FALSE(FindNotification("Dpath")); | 79 EXPECT_FALSE(FindNotification("Device_path")); |
78 | 80 |
79 // Running the message loop should create the notification. | 81 // Running the message loop should create the notification. |
80 content::RunAllPendingInMessageLoop(); | 82 content::RunAllPendingInMessageLoop(); |
81 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); | 83 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); |
82 EXPECT_TRUE(FindNotification("Dpath")); | 84 EXPECT_TRUE(FindNotification("Device_path")); |
83 | 85 |
84 // Showing a notification both immediately and delayed results in one | 86 // Showing a notification both immediately and delayed results in one |
85 // additional notification. | 87 // additional notification. |
86 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, | 88 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, |
87 "path", | 89 "path", |
88 base::TimeDelta::FromSeconds(0)); | 90 base::TimeDelta::FromSeconds(0)); |
89 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 91 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
90 "path"); | 92 "path"); |
91 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); | 93 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); |
92 EXPECT_TRUE(FindNotification("DFpath")); | 94 EXPECT_TRUE(FindNotification("DeviceFail_path")); |
93 | 95 |
94 // 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 |
95 // only have two notifications. | 97 // only have two notifications. |
96 content::RunAllPendingInMessageLoop(); | 98 content::RunAllPendingInMessageLoop(); |
97 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); | 99 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); |
98 EXPECT_TRUE(FindNotification("DFpath")); | 100 EXPECT_TRUE(FindNotification("DeviceFail_path")); |
99 | 101 |
100 // 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, |
101 // the notification should not be added. | 103 // the notification should not be added. |
102 notifications_->ShowNotificationDelayed(FileBrowserNotifications::FORMAT_FAIL, | 104 notifications_->ShowNotificationDelayed(FileBrowserNotifications::FORMAT_FAIL, |
103 "path", | 105 "path", |
104 base::TimeDelta::FromSeconds(0)); | 106 base::TimeDelta::FromSeconds(0)); |
105 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, | 107 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, |
106 "path"); | 108 "path"); |
107 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); | 109 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); |
108 EXPECT_TRUE(FindNotification("Dpath")); | 110 EXPECT_TRUE(FindNotification("Device_path")); |
109 EXPECT_TRUE(FindNotification("DFpath")); | 111 EXPECT_TRUE(FindNotification("DeviceFail_path")); |
110 EXPECT_FALSE(FindNotification("Fpath")); | 112 EXPECT_FALSE(FindNotification("Format_path")); |
111 | 113 |
112 // Even after processing messages, no new notification should be added. | 114 // Even after processing messages, no new notification should be added. |
113 content::RunAllPendingInMessageLoop(); | 115 content::RunAllPendingInMessageLoop(); |
114 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); | 116 EXPECT_EQ(2u, notifications_->GetNotificationCountForTest()); |
115 EXPECT_TRUE(FindNotification("Dpath")); | 117 EXPECT_TRUE(FindNotification("Device_path")); |
116 EXPECT_TRUE(FindNotification("DFpath")); | 118 EXPECT_TRUE(FindNotification("DeviceFail_path")); |
117 EXPECT_FALSE(FindNotification("Fpath")); | 119 EXPECT_FALSE(FindNotification("Format_path")); |
118 } | 120 } |
119 | 121 |
120 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { | 122 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { |
121 InitNotifications(); | 123 InitNotifications(); |
122 // 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. |
123 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); | 125 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); |
124 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, | 126 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, |
125 "path", | 127 "path", |
126 base::TimeDelta::FromSeconds(0)); | 128 base::TimeDelta::FromSeconds(0)); |
127 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); | 129 EXPECT_EQ(1u, notifications_->GetNotificationCountForTest()); |
128 EXPECT_TRUE(FindNotification("Dpath")); | 130 EXPECT_TRUE(FindNotification("Device_path")); |
129 | 131 |
130 // Running pending messges should remove the notification. | 132 // Running pending messges should remove the notification. |
131 content::RunAllPendingInMessageLoop(); | 133 content::RunAllPendingInMessageLoop(); |
132 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); | 134 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); |
133 | 135 |
134 // Immediate show then hide results in no notification. | 136 // Immediate show then hide results in no notification. |
135 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 137 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
136 "path"); | 138 "path"); |
137 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, | 139 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, |
138 "path"); | 140 "path"); |
139 content::RunAllPendingInMessageLoop(); | 141 content::RunAllPendingInMessageLoop(); |
140 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); | 142 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); |
141 | 143 |
142 // Delayed hide for a notification that doesn't exist does nothing. | 144 // Delayed hide for a notification that doesn't exist does nothing. |
143 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, | 145 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, |
144 "path", | 146 "path", |
145 base::TimeDelta::FromSeconds(0)); | 147 base::TimeDelta::FromSeconds(0)); |
146 content::RunAllPendingInMessageLoop(); | 148 content::RunAllPendingInMessageLoop(); |
147 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); | 149 EXPECT_EQ(0u, notifications_->GetNotificationCountForTest()); |
148 } | 150 } |
149 | 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 nitificaions for | |
stevenjb
2012/11/27 01:20:08
nit: notifications
| |
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 | |
150 } // namespace chromeos. | 179 } // namespace chromeos. |
OLD | NEW |