1 // Copyright (c) 2010 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.
5 #include "chrome/browser/notifications/notification_exceptions_table_model.h"
7 #include "base/utf_string_conversions.h"
8 #include "chrome/test/testing_profile.h"
9 #include "content/browser/browser_thread.h"
10 #include "content/browser/renderer_host/test_render_view_host.h"
11 #include "grit/generated_resources.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/l10n/l10n_util.h"
15 class NotificationExceptionsTableModelTest
: public RenderViewHostTestHarness
{
17 NotificationExceptionsTableModelTest()
18 : ui_thread_(BrowserThread::UI
, MessageLoop::current()) {
21 virtual ~NotificationExceptionsTableModelTest() {
24 virtual void SetUp() {
25 RenderViewHostTestHarness::SetUp();
26 service_
= profile()->GetDesktopNotificationService();
30 virtual void TearDown() {
32 RenderViewHostTestHarness::TearDown();
35 virtual void ResetModel() {
36 model_
.reset(new NotificationExceptionsTableModel(service_
));
39 virtual void FillData() {
40 service_
->GrantPermission(GURL("http://e-allowed2.com"));
41 service_
->GrantPermission(GURL("http://allowed.com"));
43 service_
->DenyPermission(GURL("http://denied2.com"));
44 service_
->DenyPermission(GURL("http://denied.com"));
45 service_
->DenyPermission(GURL("http://f-denied3.com"));
51 BrowserThread ui_thread_
;
52 scoped_ptr
<NotificationExceptionsTableModel
> model_
;
53 DesktopNotificationService
* service_
;
56 TEST_F(NotificationExceptionsTableModelTest
, CanCreate
) {
57 EXPECT_EQ(0, model_
->RowCount());
60 TEST_F(NotificationExceptionsTableModelTest
, RemoveAll
) {
62 EXPECT_EQ(2u, service_
->GetAllowedOrigins().size());
63 EXPECT_EQ(3u, service_
->GetBlockedOrigins().size());
64 EXPECT_EQ(5, model_
->RowCount());
67 EXPECT_EQ(0, model_
->RowCount());
69 EXPECT_EQ(0u, service_
->GetAllowedOrigins().size());
70 EXPECT_EQ(0u, service_
->GetBlockedOrigins().size());
73 TEST_F(NotificationExceptionsTableModelTest
, AlphabeticalOrder
) {
75 EXPECT_EQ(5, model_
->RowCount());
77 EXPECT_EQ(ASCIIToUTF16("allowed.com"),
78 model_
->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER
));
79 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON
),
80 model_
->GetText(0, IDS_EXCEPTIONS_ACTION_HEADER
));
82 EXPECT_EQ(ASCIIToUTF16("denied.com"),
83 model_
->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER
));
84 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON
),
85 model_
->GetText(1, IDS_EXCEPTIONS_ACTION_HEADER
));
87 EXPECT_EQ(ASCIIToUTF16("denied2.com"),
88 model_
->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER
));
89 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON
),
90 model_
->GetText(2, IDS_EXCEPTIONS_ACTION_HEADER
));
92 EXPECT_EQ(ASCIIToUTF16("e-allowed2.com"),
93 model_
->GetText(3, IDS_EXCEPTIONS_HOSTNAME_HEADER
));
94 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON
),
95 model_
->GetText(3, IDS_EXCEPTIONS_ACTION_HEADER
));
97 EXPECT_EQ(ASCIIToUTF16("f-denied3.com"),
98 model_
->GetText(4, IDS_EXCEPTIONS_HOSTNAME_HEADER
));
99 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON
),
100 model_
->GetText(4, IDS_EXCEPTIONS_ACTION_HEADER
));
103 TEST_F(NotificationExceptionsTableModelTest
, RemoveRows
) {
105 EXPECT_EQ(5, model_
->RowCount());
108 RemoveRowsTableModel::Rows rows
;
109 rows
.insert(0); // allowed.com
110 rows
.insert(3); // e-allowed2.com
111 model_
->RemoveRows(rows
);
113 EXPECT_EQ(3, model_
->RowCount());
114 EXPECT_EQ(0u, service_
->GetAllowedOrigins().size());
115 EXPECT_EQ(3u, service_
->GetBlockedOrigins().size());
118 RemoveRowsTableModel::Rows rows
;
122 model_
->RemoveRows(rows
);
124 EXPECT_EQ(0, model_
->RowCount());
125 EXPECT_EQ(0u, service_
->GetAllowedOrigins().size());
126 EXPECT_EQ(0u, service_
->GetBlockedOrigins().size());