OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/notifications/notification_exceptions_table_model.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
10 #include "chrome/test/base/testing_profile.h" | |
11 #include "content/browser/browser_thread.h" | |
12 #include "grit/generated_resources.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 | |
16 class NotificationExceptionsTableModelTest | |
17 : public ChromeRenderViewHostTestHarness { | |
18 public: | |
19 NotificationExceptionsTableModelTest() | |
20 : ui_thread_(BrowserThread::UI, MessageLoop::current()) { | |
21 } | |
22 | |
23 virtual ~NotificationExceptionsTableModelTest() { | |
24 } | |
25 | |
26 virtual void SetUp() { | |
27 ChromeRenderViewHostTestHarness::SetUp(); | |
28 service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); | |
29 ResetModel(); | |
30 } | |
31 | |
32 virtual void TearDown() { | |
33 model_.reset(NULL); | |
34 ChromeRenderViewHostTestHarness::TearDown(); | |
35 } | |
36 | |
37 virtual void ResetModel() { | |
38 model_.reset(new NotificationExceptionsTableModel(service_)); | |
39 } | |
40 | |
41 virtual void FillData() { | |
42 service_->GrantPermission(GURL("http://e-allowed2.com")); | |
43 service_->GrantPermission(GURL("http://allowed.com")); | |
44 | |
45 service_->DenyPermission(GURL("http://denied2.com")); | |
46 service_->DenyPermission(GURL("http://denied.com")); | |
47 service_->DenyPermission(GURL("http://f-denied3.com")); | |
48 | |
49 ResetModel(); | |
50 } | |
51 | |
52 protected: | |
53 BrowserThread ui_thread_; | |
54 scoped_ptr<NotificationExceptionsTableModel> model_; | |
55 DesktopNotificationService* service_; | |
56 }; | |
57 | |
58 TEST_F(NotificationExceptionsTableModelTest, CanCreate) { | |
59 EXPECT_EQ(0, model_->RowCount()); | |
60 } | |
61 | |
62 TEST_F(NotificationExceptionsTableModelTest, RemoveAll) { | |
63 FillData(); | |
64 HostContentSettingsMap::SettingsForOneType settings; | |
65 service_->GetNotificationsSettings(&settings); | |
66 EXPECT_EQ(5u, settings.size()); | |
67 EXPECT_EQ(5, model_->RowCount()); | |
68 | |
69 model_->RemoveAll(); | |
70 EXPECT_EQ(0, model_->RowCount()); | |
71 | |
72 service_->GetNotificationsSettings(&settings); | |
73 EXPECT_EQ(0u, settings.size()); | |
74 } | |
75 | |
76 TEST_F(NotificationExceptionsTableModelTest, AlphabeticalOrder) { | |
77 FillData(); | |
78 EXPECT_EQ(5, model_->RowCount()); | |
79 | |
80 EXPECT_EQ(ASCIIToUTF16("http://allowed.com:80"), | |
81 model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | |
82 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), | |
83 model_->GetText(0, IDS_EXCEPTIONS_ACTION_HEADER)); | |
84 | |
85 EXPECT_EQ(ASCIIToUTF16("http://denied.com:80"), | |
86 model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | |
87 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), | |
88 model_->GetText(1, IDS_EXCEPTIONS_ACTION_HEADER)); | |
89 | |
90 EXPECT_EQ(ASCIIToUTF16("http://denied2.com:80"), | |
91 model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | |
92 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), | |
93 model_->GetText(2, IDS_EXCEPTIONS_ACTION_HEADER)); | |
94 | |
95 EXPECT_EQ(ASCIIToUTF16("http://e-allowed2.com:80"), | |
96 model_->GetText(3, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | |
97 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), | |
98 model_->GetText(3, IDS_EXCEPTIONS_ACTION_HEADER)); | |
99 | |
100 EXPECT_EQ(ASCIIToUTF16("http://f-denied3.com:80"), | |
101 model_->GetText(4, IDS_EXCEPTIONS_HOSTNAME_HEADER)); | |
102 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), | |
103 model_->GetText(4, IDS_EXCEPTIONS_ACTION_HEADER)); | |
104 } | |
105 | |
106 TEST_F(NotificationExceptionsTableModelTest, RemoveRows) { | |
107 FillData(); | |
108 EXPECT_EQ(5, model_->RowCount()); | |
109 | |
110 { | |
111 RemoveRowsTableModel::Rows rows; | |
112 rows.insert(0); // allowed.com | |
113 rows.insert(3); // e-allowed2.com | |
114 model_->RemoveRows(rows); | |
115 } | |
116 EXPECT_EQ(3, model_->RowCount()); | |
117 | |
118 HostContentSettingsMap::SettingsForOneType settings; | |
119 service_->GetNotificationsSettings(&settings); | |
120 EXPECT_EQ(3u, settings.size()); | |
121 | |
122 { | |
123 RemoveRowsTableModel::Rows rows; | |
124 rows.insert(0); | |
125 rows.insert(1); | |
126 rows.insert(2); | |
127 model_->RemoveRows(rows); | |
128 } | |
129 EXPECT_EQ(0, model_->RowCount()); | |
130 service_->GetNotificationsSettings(&settings); | |
131 EXPECT_EQ(0u, settings.size()); | |
132 } | |
OLD | NEW |