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