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