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

Side by Side Diff: chrome/browser/geolocation/geolocation_exceptions_table_model_unittest.cc

Issue 4192012: Convert implicit scoped_refptr constructor calls to explicit ones, part 1 (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: fix presubmit Created 10 years, 1 month 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 | Annotate | Revision Log
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/geolocation/geolocation_exceptions_table_model.h" 5 #include "chrome/browser/geolocation/geolocation_exceptions_table_model.h"
6 6
7 #include "chrome/browser/browser_thread.h" 7 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 8 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
9 #include "chrome/common/content_settings_helper.h" 9 #include "chrome/common/content_settings_helper.h"
10 #include "chrome/test/testing_profile.h" 10 #include "chrome/test/testing_profile.h"
(...skipping 22 matching lines...) Expand all
33 model_.reset(NULL); 33 model_.reset(NULL);
34 RenderViewHostTestHarness::TearDown(); 34 RenderViewHostTestHarness::TearDown();
35 } 35 }
36 36
37 virtual void ResetModel() { 37 virtual void ResetModel() {
38 model_.reset(new GeolocationExceptionsTableModel( 38 model_.reset(new GeolocationExceptionsTableModel(
39 profile()->GetGeolocationContentSettingsMap())); 39 profile()->GetGeolocationContentSettingsMap()));
40 } 40 }
41 41
42 void CreateAllowedSamples() { 42 void CreateAllowedSamples() {
43 scoped_refptr<GeolocationContentSettingsMap> map = 43 scoped_refptr<GeolocationContentSettingsMap> map(
44 profile()->GetGeolocationContentSettingsMap(); 44 profile()->GetGeolocationContentSettingsMap());
45 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW); 45 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW);
46 map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW); 46 map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW);
47 map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_ALLOW); 47 map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_ALLOW);
48 ResetModel(); 48 ResetModel();
49 EXPECT_EQ(3, model_->RowCount()); 49 EXPECT_EQ(3, model_->RowCount());
50 } 50 }
51 51
52 protected: 52 protected:
53 BrowserThread ui_thread_; 53 BrowserThread ui_thread_;
54 scoped_ptr<GeolocationExceptionsTableModel> model_; 54 scoped_ptr<GeolocationExceptionsTableModel> model_;
55 }; 55 };
56 56
57 TEST_F(GeolocationExceptionsTableModelTest, CanRemoveException) { 57 TEST_F(GeolocationExceptionsTableModelTest, CanRemoveException) {
58 EXPECT_EQ(0, model_->RowCount()); 58 EXPECT_EQ(0, model_->RowCount());
59 59
60 scoped_refptr<GeolocationContentSettingsMap> map = 60 scoped_refptr<GeolocationContentSettingsMap> map(
61 profile()->GetGeolocationContentSettingsMap(); 61 profile()->GetGeolocationContentSettingsMap());
62 62
63 // Ensure a single entry can be removed. 63 // Ensure a single entry can be removed.
64 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW); 64 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW);
65 ResetModel(); 65 ResetModel();
66 EXPECT_EQ(1, model_->RowCount()); 66 EXPECT_EQ(1, model_->RowCount());
67 GeolocationExceptionsTableModel::Rows rows; 67 GeolocationExceptionsTableModel::Rows rows;
68 rows.insert(0U); 68 rows.insert(0U);
69 EXPECT_TRUE(model_->CanRemoveRows(rows)); 69 EXPECT_TRUE(model_->CanRemoveRows(rows));
70 70
71 71
72 // Ensure an entry with children can't be removed. 72 // Ensure an entry with children can't be removed.
73 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_DEFAULT); 73 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_DEFAULT);
74 map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW); 74 map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW);
75 map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_BLOCK); 75 map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_BLOCK);
76 ResetModel(); 76 ResetModel();
77 EXPECT_EQ(3, model_->RowCount()); 77 EXPECT_EQ(3, model_->RowCount());
78 EXPECT_FALSE(model_->CanRemoveRows(rows)); 78 EXPECT_FALSE(model_->CanRemoveRows(rows));
79 79
80 // Ensure it can be removed if removing all children. 80 // Ensure it can be removed if removing all children.
81 rows.clear(); 81 rows.clear();
82 rows.insert(1U); 82 rows.insert(1U);
83 rows.insert(2U); 83 rows.insert(2U);
84 EXPECT_TRUE(model_->CanRemoveRows(rows)); 84 EXPECT_TRUE(model_->CanRemoveRows(rows));
85 } 85 }
86 86
87 TEST_F(GeolocationExceptionsTableModelTest, RemoveExceptions) { 87 TEST_F(GeolocationExceptionsTableModelTest, RemoveExceptions) {
88 CreateAllowedSamples(); 88 CreateAllowedSamples();
89 scoped_refptr<GeolocationContentSettingsMap> map = 89 scoped_refptr<GeolocationContentSettingsMap> map(
90 profile()->GetGeolocationContentSettingsMap(); 90 profile()->GetGeolocationContentSettingsMap());
91 91
92 // Test removing parent exception. 92 // Test removing parent exception.
93 GeolocationExceptionsTableModel::Rows rows; 93 GeolocationExceptionsTableModel::Rows rows;
94 rows.insert(0U); 94 rows.insert(0U);
95 model_->RemoveRows(rows); 95 model_->RemoveRows(rows);
96 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); 96 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0));
97 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl1)); 97 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl1));
98 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl2)); 98 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl2));
99 99
100 ResetModel(); 100 ResetModel();
101 EXPECT_EQ(3, model_->RowCount()); 101 EXPECT_EQ(3, model_->RowCount());
102 102
103 // Test removing remaining children. 103 // Test removing remaining children.
104 rows.clear(); 104 rows.clear();
105 rows.insert(1U); 105 rows.insert(1U);
106 rows.insert(2U); 106 rows.insert(2U);
107 model_->RemoveRows(rows); 107 model_->RemoveRows(rows);
108 EXPECT_EQ(0, model_->RowCount()); 108 EXPECT_EQ(0, model_->RowCount());
109 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); 109 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0));
110 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1)); 110 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1));
111 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2)); 111 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2));
112 } 112 }
113 113
114 TEST_F(GeolocationExceptionsTableModelTest, RemoveAll) { 114 TEST_F(GeolocationExceptionsTableModelTest, RemoveAll) {
115 CreateAllowedSamples(); 115 CreateAllowedSamples();
116 scoped_refptr<GeolocationContentSettingsMap> map = 116 scoped_refptr<GeolocationContentSettingsMap> map(
117 profile()->GetGeolocationContentSettingsMap(); 117 profile()->GetGeolocationContentSettingsMap());
118 118
119 model_->RemoveAll(); 119 model_->RemoveAll();
120 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); 120 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0));
121 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1)); 121 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1));
122 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2)); 122 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2));
123 EXPECT_EQ(0, model_->RowCount()); 123 EXPECT_EQ(0, model_->RowCount());
124 } 124 }
125 125
126 TEST_F(GeolocationExceptionsTableModelTest, GetText) { 126 TEST_F(GeolocationExceptionsTableModelTest, GetText) {
127 CreateAllowedSamples(); 127 CreateAllowedSamples();
128 128
129 // Ensure the parent doesn't have any indentation. 129 // Ensure the parent doesn't have any indentation.
130 std::wstring text(model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER)); 130 std::wstring text(model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER));
131 EXPECT_EQ(content_settings_helper::OriginToWString(kUrl0), text); 131 EXPECT_EQ(content_settings_helper::OriginToWString(kUrl0), text);
132 132
133 // Ensure there's some indentation on the children nodes. 133 // Ensure there's some indentation on the children nodes.
134 text = model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER); 134 text = model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER);
135 EXPECT_NE(content_settings_helper::OriginToWString(kUrl1), text); 135 EXPECT_NE(content_settings_helper::OriginToWString(kUrl1), text);
136 EXPECT_NE(std::wstring::npos, 136 EXPECT_NE(std::wstring::npos,
137 text.find(content_settings_helper::OriginToWString(kUrl1))); 137 text.find(content_settings_helper::OriginToWString(kUrl1)));
138 138
139 text = model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER); 139 text = model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER);
140 EXPECT_NE(content_settings_helper::OriginToWString(kUrl2), text); 140 EXPECT_NE(content_settings_helper::OriginToWString(kUrl2), text);
141 EXPECT_NE(std::wstring::npos, 141 EXPECT_NE(std::wstring::npos,
142 text.find(content_settings_helper::OriginToWString(kUrl2))); 142 text.find(content_settings_helper::OriginToWString(kUrl2)));
143 } 143 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/access_token_store_browsertest.cc ('k') | chrome/browser/host_content_settings_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698