Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Side by Side Diff: chrome/browser/notifications/notification_exceptions_table_model_unittest.cc

Issue 2868042: Backend changes for notifications content settings. (Closed)
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 "app/l10n_util.h"
7 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 8 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
8 #include "chrome/test/testing_profile.h" 9 #include "chrome/test/testing_profile.h"
9 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 class NotificationExceptionsTableModelTest 13 class NotificationExceptionsTableModelTest : public RenderViewHostTestHarness {
13 : public RenderViewHostTestHarness {
14 public: 14 public:
15 NotificationExceptionsTableModelTest() 15 NotificationExceptionsTableModelTest()
16 : ui_thread_(ChromeThread::UI, MessageLoop::current()) { 16 : ui_thread_(ChromeThread::UI, MessageLoop::current()) {
17 } 17 }
18 18
19 virtual ~NotificationExceptionsTableModelTest() { 19 virtual ~NotificationExceptionsTableModelTest() {
20 } 20 }
21 21
22 virtual void SetUp() { 22 virtual void SetUp() {
23 RenderViewHostTestHarness::SetUp(); 23 RenderViewHostTestHarness::SetUp();
24 service_ = profile()->GetDesktopNotificationService();
24 ResetModel(); 25 ResetModel();
25 } 26 }
26 27
27 virtual void TearDown() { 28 virtual void TearDown() {
28 model_.reset(NULL); 29 model_.reset(NULL);
29 RenderViewHostTestHarness::TearDown(); 30 RenderViewHostTestHarness::TearDown();
30 } 31 }
31 32
32 virtual void ResetModel() { 33 virtual void ResetModel() {
33 model_.reset(new NotificationExceptionsTableModel( 34 model_.reset(new NotificationExceptionsTableModel(service_));
34 profile()->GetDesktopNotificationService())); 35 }
36
37 virtual void FillData() {
38 service_->GrantPermission(GURL("http://e-allowed2.com"));
39 service_->GrantPermission(GURL("http://allowed.com"));
40
41 service_->DenyPermission(GURL("http://denied2.com"));
42 service_->DenyPermission(GURL("http://denied.com"));
43 service_->DenyPermission(GURL("http://f-denied3.com"));
44
45 ResetModel();
35 } 46 }
36 47
37 protected: 48 protected:
38 ChromeThread ui_thread_; 49 ChromeThread ui_thread_;
39 scoped_ptr<NotificationExceptionsTableModel> model_; 50 scoped_ptr<NotificationExceptionsTableModel> model_;
51 DesktopNotificationService* service_;
40 }; 52 };
41 53
42 TEST_F(NotificationExceptionsTableModelTest, CanCreate) { 54 TEST_F(NotificationExceptionsTableModelTest, CanCreate) {
43 EXPECT_EQ(0, model_->RowCount()); 55 EXPECT_EQ(0, model_->RowCount());
44 } 56 }
57
58 TEST_F(NotificationExceptionsTableModelTest, RemoveAll) {
59 FillData();
60 EXPECT_EQ(2u, service_->GetAllowedOrigins().size());
61 EXPECT_EQ(3u, service_->GetBlockedOrigins().size());
62 EXPECT_EQ(5, model_->RowCount());
63
64 model_->RemoveAll();
65 EXPECT_EQ(0, model_->RowCount());
66
67 EXPECT_EQ(0u, service_->GetAllowedOrigins().size());
68 EXPECT_EQ(0u, service_->GetBlockedOrigins().size());
69 }
70
71 TEST_F(NotificationExceptionsTableModelTest, AlphabeticalOrder) {
72 FillData();
73 EXPECT_EQ(5, model_->RowCount());
74
75 EXPECT_EQ(L"allowed.com",
76 model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER));
77 EXPECT_EQ(l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON),
78 model_->GetText(0, IDS_EXCEPTIONS_ACTION_HEADER));
79
80 EXPECT_EQ(L"denied.com",
81 model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER));
82 EXPECT_EQ(l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON),
83 model_->GetText(1, IDS_EXCEPTIONS_ACTION_HEADER));
84
85 EXPECT_EQ(L"denied2.com",
86 model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER));
87 EXPECT_EQ(l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON),
88 model_->GetText(2, IDS_EXCEPTIONS_ACTION_HEADER));
89
90 EXPECT_EQ(L"e-allowed2.com",
91 model_->GetText(3, IDS_EXCEPTIONS_HOSTNAME_HEADER));
92 EXPECT_EQ(l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON),
93 model_->GetText(3, IDS_EXCEPTIONS_ACTION_HEADER));
94
95 EXPECT_EQ(L"f-denied3.com",
96 model_->GetText(4, IDS_EXCEPTIONS_HOSTNAME_HEADER));
97 EXPECT_EQ(l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON),
98 model_->GetText(4, IDS_EXCEPTIONS_ACTION_HEADER));
99 }
100
101 TEST_F(NotificationExceptionsTableModelTest, RemoveRows) {
102 FillData();
103 EXPECT_EQ(5, model_->RowCount());
104
105 {
106 RemoveRowsTableModel::Rows rows;
107 rows.insert(0); // allowed.com
108 rows.insert(3); // e-allowed2.com
109 model_->RemoveRows(rows);
110 }
111 EXPECT_EQ(3, model_->RowCount());
112 EXPECT_EQ(0u, service_->GetAllowedOrigins().size());
113 EXPECT_EQ(3u, service_->GetBlockedOrigins().size());
114
115 {
116 RemoveRowsTableModel::Rows rows;
117 rows.insert(0);
118 rows.insert(1);
119 rows.insert(2);
120 model_->RemoveRows(rows);
121 }
122 EXPECT_EQ(0, model_->RowCount());
123 EXPECT_EQ(0u, service_->GetAllowedOrigins().size());
124 EXPECT_EQ(0u, service_->GetBlockedOrigins().size());
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698