| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/notifications/notification_exceptions_table_model.h" | 5 #include "chrome/browser/notifications/notification_exceptions_table_model.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 scoped_ptr<NotificationExceptionsTableModel> model_; | 53 scoped_ptr<NotificationExceptionsTableModel> model_; |
| 54 DesktopNotificationService* service_; | 54 DesktopNotificationService* service_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 TEST_F(NotificationExceptionsTableModelTest, CanCreate) { | 57 TEST_F(NotificationExceptionsTableModelTest, CanCreate) { |
| 58 EXPECT_EQ(0, model_->RowCount()); | 58 EXPECT_EQ(0, model_->RowCount()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 TEST_F(NotificationExceptionsTableModelTest, RemoveAll) { | 61 TEST_F(NotificationExceptionsTableModelTest, RemoveAll) { |
| 62 FillData(); | 62 FillData(); |
| 63 HostContentSettingsMap::SettingsForOneType settings; | 63 EXPECT_EQ(2u, service_->GetAllowedOrigins().size()); |
| 64 service_->GetNotificationsSettings(&settings); | 64 EXPECT_EQ(3u, service_->GetBlockedOrigins().size()); |
| 65 EXPECT_EQ(5u, settings.size()); | |
| 66 EXPECT_EQ(5, model_->RowCount()); | 65 EXPECT_EQ(5, model_->RowCount()); |
| 67 | 66 |
| 68 model_->RemoveAll(); | 67 model_->RemoveAll(); |
| 69 EXPECT_EQ(0, model_->RowCount()); | 68 EXPECT_EQ(0, model_->RowCount()); |
| 70 | 69 |
| 71 service_->GetNotificationsSettings(&settings); | 70 EXPECT_EQ(0u, service_->GetAllowedOrigins().size()); |
| 72 EXPECT_EQ(0u, settings.size()); | 71 EXPECT_EQ(0u, service_->GetBlockedOrigins().size()); |
| 73 } | 72 } |
| 74 | 73 |
| 75 TEST_F(NotificationExceptionsTableModelTest, AlphabeticalOrder) { | 74 TEST_F(NotificationExceptionsTableModelTest, AlphabeticalOrder) { |
| 76 FillData(); | 75 FillData(); |
| 77 EXPECT_EQ(5, model_->RowCount()); | 76 EXPECT_EQ(5, model_->RowCount()); |
| 78 | 77 |
| 79 EXPECT_EQ(ASCIIToUTF16("http://allowed.com:80"), | 78 EXPECT_EQ(ASCIIToUTF16("allowed.com"), |
| 80 model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | 79 model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER)); |
| 81 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), | 80 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), |
| 82 model_->GetText(0, IDS_EXCEPTIONS_ACTION_HEADER)); | 81 model_->GetText(0, IDS_EXCEPTIONS_ACTION_HEADER)); |
| 83 | 82 |
| 84 EXPECT_EQ(ASCIIToUTF16("http://denied.com:80"), | 83 EXPECT_EQ(ASCIIToUTF16("denied.com"), |
| 85 model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | 84 model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER)); |
| 86 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), | 85 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), |
| 87 model_->GetText(1, IDS_EXCEPTIONS_ACTION_HEADER)); | 86 model_->GetText(1, IDS_EXCEPTIONS_ACTION_HEADER)); |
| 88 | 87 |
| 89 EXPECT_EQ(ASCIIToUTF16("http://denied2.com:80"), | 88 EXPECT_EQ(ASCIIToUTF16("denied2.com"), |
| 90 model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | 89 model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER)); |
| 91 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), | 90 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), |
| 92 model_->GetText(2, IDS_EXCEPTIONS_ACTION_HEADER)); | 91 model_->GetText(2, IDS_EXCEPTIONS_ACTION_HEADER)); |
| 93 | 92 |
| 94 EXPECT_EQ(ASCIIToUTF16("http://e-allowed2.com:80"), | 93 EXPECT_EQ(ASCIIToUTF16("e-allowed2.com"), |
| 95 model_->GetText(3, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | 94 model_->GetText(3, IDS_EXCEPTIONS_HOSTNAME_HEADER)); |
| 96 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), | 95 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), |
| 97 model_->GetText(3, IDS_EXCEPTIONS_ACTION_HEADER)); | 96 model_->GetText(3, IDS_EXCEPTIONS_ACTION_HEADER)); |
| 98 | 97 |
| 99 EXPECT_EQ(ASCIIToUTF16("http://f-denied3.com:80"), | 98 EXPECT_EQ(ASCIIToUTF16("f-denied3.com"), |
| 100 model_->GetText(4, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | 99 model_->GetText(4, IDS_EXCEPTIONS_HOSTNAME_HEADER)); |
| 101 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), | 100 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), |
| 102 model_->GetText(4, IDS_EXCEPTIONS_ACTION_HEADER)); | 101 model_->GetText(4, IDS_EXCEPTIONS_ACTION_HEADER)); |
| 103 } | 102 } |
| 104 | 103 |
| 105 TEST_F(NotificationExceptionsTableModelTest, RemoveRows) { | 104 TEST_F(NotificationExceptionsTableModelTest, RemoveRows) { |
| 106 FillData(); | 105 FillData(); |
| 107 EXPECT_EQ(5, model_->RowCount()); | 106 EXPECT_EQ(5, model_->RowCount()); |
| 108 | 107 |
| 109 { | 108 { |
| 110 RemoveRowsTableModel::Rows rows; | 109 RemoveRowsTableModel::Rows rows; |
| 111 rows.insert(0); // allowed.com | 110 rows.insert(0); // allowed.com |
| 112 rows.insert(3); // e-allowed2.com | 111 rows.insert(3); // e-allowed2.com |
| 113 model_->RemoveRows(rows); | 112 model_->RemoveRows(rows); |
| 114 } | 113 } |
| 115 EXPECT_EQ(3, model_->RowCount()); | 114 EXPECT_EQ(3, model_->RowCount()); |
| 116 | 115 EXPECT_EQ(0u, service_->GetAllowedOrigins().size()); |
| 117 HostContentSettingsMap::SettingsForOneType settings; | 116 EXPECT_EQ(3u, service_->GetBlockedOrigins().size()); |
| 118 service_->GetNotificationsSettings(&settings); | |
| 119 EXPECT_EQ(3u, settings.size()); | |
| 120 | 117 |
| 121 { | 118 { |
| 122 RemoveRowsTableModel::Rows rows; | 119 RemoveRowsTableModel::Rows rows; |
| 123 rows.insert(0); | 120 rows.insert(0); |
| 124 rows.insert(1); | 121 rows.insert(1); |
| 125 rows.insert(2); | 122 rows.insert(2); |
| 126 model_->RemoveRows(rows); | 123 model_->RemoveRows(rows); |
| 127 } | 124 } |
| 128 EXPECT_EQ(0, model_->RowCount()); | 125 EXPECT_EQ(0, model_->RowCount()); |
| 129 service_->GetNotificationsSettings(&settings); | 126 EXPECT_EQ(0u, service_->GetAllowedOrigins().size()); |
| 130 EXPECT_EQ(0u, settings.size()); | 127 EXPECT_EQ(0u, service_->GetBlockedOrigins().size()); |
| 131 } | 128 } |
| OLD | NEW |