| 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 <gmock/gmock.h> | |
| 6 #include <gtest/gtest.h> | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" | |
| 12 #include "grit/generated_resources.h" | |
| 13 #include "ui/base/l10n/l10n_util.h" | |
| 14 | |
| 15 using ::testing::_; | |
| 16 using ::testing::InSequence; | |
| 17 using ::testing::Return; | |
| 18 using ::testing::StrEq; | |
| 19 using ::testing::AnyNumber; | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 class MockFileBrowserNotificationsOnMount : public FileBrowserNotifications { | |
| 26 public: | |
| 27 explicit MockFileBrowserNotificationsOnMount(Profile* profile) | |
| 28 : FileBrowserNotifications(profile) { | |
| 29 } | |
| 30 | |
| 31 virtual ~MockFileBrowserNotificationsOnMount() {} | |
| 32 | |
| 33 MOCK_METHOD3(ShowNotificationWithMessage, void(NotificationType, | |
| 34 const std::string&, const string16&)); | |
| 35 MOCK_METHOD2(HideNotification, void(NotificationType, const std::string&)); | |
| 36 }; | |
| 37 | |
| 38 MATCHER_P2(String16Equals, id, label, "") { | |
| 39 return arg == l10n_util::GetStringFUTF16(id, ASCIIToUTF16(label)); | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 TEST(FileBrowserMountNotificationsTest, GoodDevice) { | |
| 45 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 46 new MockFileBrowserNotificationsOnMount(NULL); | |
| 47 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 48 | |
| 49 std::string notification_path("system_path_prefix"); | |
| 50 std::string device_label("label"); | |
| 51 | |
| 52 notifications->RegisterDevice(notification_path); | |
| 53 | |
| 54 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 55 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 56 | |
| 57 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 58 device_label, true, true, false); | |
| 59 }; | |
| 60 | |
| 61 TEST(FileBrowserMountNotificationsTest, GoodDeviceWithBadParent) { | |
| 62 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 63 new MockFileBrowserNotificationsOnMount(NULL); | |
| 64 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 65 | |
| 66 std::string notification_path("system_path_prefix"); | |
| 67 std::string device_label("label"); | |
| 68 | |
| 69 notifications->RegisterDevice(notification_path); | |
| 70 | |
| 71 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 72 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 73 | |
| 74 { | |
| 75 InSequence s; | |
| 76 | |
| 77 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 78 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), _)); | |
| 79 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 80 FileBrowserNotifications::DEVICE_FAIL, | |
| 81 StrEq(notification_path))); | |
| 82 } | |
| 83 | |
| 84 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 85 device_label, true, false, false); | |
| 86 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 87 device_label, false, true, false); | |
| 88 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 89 device_label, false, true, false); | |
| 90 } | |
| 91 | |
| 92 TEST(FileBrowserMountNotificationsTest, UnsupportedDevice) { | |
| 93 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 94 new MockFileBrowserNotificationsOnMount(NULL); | |
| 95 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 96 | |
| 97 std::string notification_path("system_path_prefix"); | |
| 98 std::string device_label("label"); | |
| 99 | |
| 100 notifications->RegisterDevice(notification_path); | |
| 101 | |
| 102 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 103 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 104 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 105 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 106 String16Equals(IDS_DEVICE_UNSUPPORTED_MESSAGE, device_label))); | |
| 107 | |
| 108 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 109 device_label, false, false, true); | |
| 110 } | |
| 111 | |
| 112 TEST(FileBrowserMountNotificationsTest, UnsupportedWithUnknownParent) { | |
| 113 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 114 new MockFileBrowserNotificationsOnMount(NULL); | |
| 115 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 116 | |
| 117 std::string notification_path("system_path_prefix"); | |
| 118 std::string device_label("label"); | |
| 119 | |
| 120 notifications->RegisterDevice(notification_path); | |
| 121 | |
| 122 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 123 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 124 | |
| 125 { | |
| 126 InSequence s; | |
| 127 | |
| 128 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 129 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), _)); | |
| 130 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 131 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path))); | |
| 132 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 133 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 134 String16Equals(IDS_DEVICE_UNSUPPORTED_MESSAGE, | |
| 135 device_label))); | |
| 136 } | |
| 137 | |
| 138 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 139 device_label, true, false, false); | |
| 140 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 141 device_label, false, false, true); | |
| 142 } | |
| 143 | |
| 144 TEST(FileBrowserMountNotificationsTest, MountPartialSuccess) { | |
| 145 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 146 new MockFileBrowserNotificationsOnMount(NULL); | |
| 147 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 148 | |
| 149 std::string notification_path("system_path_prefix"); | |
| 150 std::string device_label("label"); | |
| 151 | |
| 152 notifications->RegisterDevice(notification_path); | |
| 153 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 154 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 155 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 156 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 157 String16Equals(IDS_MULTIPART_DEVICE_UNSUPPORTED_MESSAGE, | |
| 158 device_label))); | |
| 159 | |
| 160 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 161 device_label, false, true, false); | |
| 162 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 163 device_label, false, false, true); | |
| 164 } | |
| 165 | |
| 166 TEST(FileBrowserMountNotificationsTest, Unknown) { | |
| 167 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 168 new MockFileBrowserNotificationsOnMount(NULL); | |
| 169 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 170 | |
| 171 std::string notification_path("system_path_prefix"); | |
| 172 std::string device_label("label"); | |
| 173 | |
| 174 notifications->RegisterDevice(notification_path); | |
| 175 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 176 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 177 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 178 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 179 String16Equals(IDS_DEVICE_UNKNOWN_MESSAGE, device_label))); | |
| 180 | |
| 181 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 182 device_label, false, false, false); | |
| 183 } | |
| 184 | |
| 185 TEST(FileBrowserMountNotificationsTest, MulitpleFail) { | |
| 186 MockFileBrowserNotificationsOnMount* mocked_notifications = | |
| 187 new MockFileBrowserNotificationsOnMount(NULL); | |
| 188 scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications); | |
| 189 | |
| 190 std::string notification_path("system_path_prefix"); | |
| 191 std::string device_label("label"); | |
| 192 | |
| 193 notifications->RegisterDevice(notification_path); | |
| 194 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 195 FileBrowserNotifications::DEVICE, StrEq(notification_path))); | |
| 196 { | |
| 197 InSequence s; | |
| 198 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 199 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 200 String16Equals(IDS_DEVICE_UNKNOWN_MESSAGE, device_label))) | |
| 201 .RetiresOnSaturation(); | |
| 202 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 203 FileBrowserNotifications::DEVICE_FAIL, notification_path)); | |
| 204 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 205 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 206 String16Equals(IDS_DEVICE_UNKNOWN_MESSAGE, device_label))); | |
| 207 EXPECT_CALL(*mocked_notifications, HideNotification( | |
| 208 FileBrowserNotifications::DEVICE_FAIL, notification_path)); | |
| 209 EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage( | |
| 210 FileBrowserNotifications::DEVICE_FAIL, StrEq(notification_path), | |
| 211 String16Equals(IDS_MULTIPART_DEVICE_UNSUPPORTED_MESSAGE, | |
| 212 device_label))); | |
| 213 } | |
| 214 | |
| 215 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 216 device_label, true, false, false); | |
| 217 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 218 device_label, false, false, false); | |
| 219 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 220 device_label, false, false, false); | |
| 221 notifications->ManageNotificationsOnMountCompleted(notification_path, | |
| 222 device_label, false, false, false); | |
| 223 } | |
| 224 | |
| 225 } // namespace chromeos. | |
| OLD | NEW |