| OLD | NEW |
| 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/renderer_host/test/test_render_view_host.h" | 7 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 8 #include "chrome/test/testing_profile.h" | 8 #include "chrome/test/testing_profile.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 scoped_refptr<GeolocationContentSettingsMap> map = | 65 scoped_refptr<GeolocationContentSettingsMap> map = |
| 66 profile()->GetGeolocationContentSettingsMap(); | 66 profile()->GetGeolocationContentSettingsMap(); |
| 67 | 67 |
| 68 // Ensure a single entry can be removed. | 68 // Ensure a single entry can be removed. |
| 69 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW); | 69 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_ALLOW); |
| 70 ResetModel(); | 70 ResetModel(); |
| 71 EXPECT_EQ(1, model_->RowCount()); | 71 EXPECT_EQ(1, model_->RowCount()); |
| 72 GeolocationExceptionsTableModel::Rows rows; | 72 GeolocationExceptionsTableModel::Rows rows; |
| 73 rows.insert(0U); | 73 rows.insert(0U); |
| 74 EXPECT_TRUE(model_->CanRemoveExceptions(rows)); | 74 EXPECT_TRUE(model_->CanRemoveRows(rows)); |
| 75 | 75 |
| 76 | 76 |
| 77 // Ensure an entry with children can't be removed. | 77 // Ensure an entry with children can't be removed. |
| 78 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_DEFAULT); | 78 map->SetContentSetting(kUrl0, kUrl0, CONTENT_SETTING_DEFAULT); |
| 79 map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW); | 79 map->SetContentSetting(kUrl0, kUrl1, CONTENT_SETTING_ALLOW); |
| 80 map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_BLOCK); | 80 map->SetContentSetting(kUrl0, kUrl2, CONTENT_SETTING_BLOCK); |
| 81 ResetModel(); | 81 ResetModel(); |
| 82 EXPECT_EQ(3, model_->RowCount()); | 82 EXPECT_EQ(3, model_->RowCount()); |
| 83 EXPECT_FALSE(model_->CanRemoveExceptions(rows)); | 83 EXPECT_FALSE(model_->CanRemoveRows(rows)); |
| 84 | 84 |
| 85 // Ensure it can be removed if removing all children. | 85 // Ensure it can be removed if removing all children. |
| 86 rows.clear(); | 86 rows.clear(); |
| 87 rows.insert(1U); | 87 rows.insert(1U); |
| 88 rows.insert(2U); | 88 rows.insert(2U); |
| 89 EXPECT_TRUE(model_->CanRemoveExceptions(rows)); | 89 EXPECT_TRUE(model_->CanRemoveRows(rows)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TEST_F(GeolocationExceptionsTableModelTest, RemoveExceptions) { | 92 TEST_F(GeolocationExceptionsTableModelTest, RemoveExceptions) { |
| 93 CreateAllowedSamples(); | 93 CreateAllowedSamples(); |
| 94 scoped_refptr<GeolocationContentSettingsMap> map = | 94 scoped_refptr<GeolocationContentSettingsMap> map = |
| 95 profile()->GetGeolocationContentSettingsMap(); | 95 profile()->GetGeolocationContentSettingsMap(); |
| 96 | 96 |
| 97 // Test removing parent exception. | 97 // Test removing parent exception. |
| 98 GeolocationExceptionsTableModel::Rows rows; | 98 GeolocationExceptionsTableModel::Rows rows; |
| 99 rows.insert(0U); | 99 rows.insert(0U); |
| 100 model_->RemoveExceptions(rows); | 100 model_->RemoveRows(rows); |
| 101 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); | 101 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); |
| 102 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl1)); | 102 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl1)); |
| 103 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl2)); | 103 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetContentSetting(kUrl0, kUrl2)); |
| 104 | 104 |
| 105 ResetModel(); | 105 ResetModel(); |
| 106 EXPECT_EQ(3, model_->RowCount()); | 106 EXPECT_EQ(3, model_->RowCount()); |
| 107 | 107 |
| 108 // Test removing remaining children. | 108 // Test removing remaining children. |
| 109 rows.clear(); | 109 rows.clear(); |
| 110 rows.insert(1U); | 110 rows.insert(1U); |
| 111 rows.insert(2U); | 111 rows.insert(2U); |
| 112 model_->RemoveExceptions(rows); | 112 model_->RemoveRows(rows); |
| 113 EXPECT_EQ(0, model_->RowCount()); | 113 EXPECT_EQ(0, model_->RowCount()); |
| 114 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); | 114 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl0)); |
| 115 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1)); | 115 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl1)); |
| 116 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2)); | 116 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(kUrl0, kUrl2)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(GeolocationExceptionsTableModelTest, RemoveAll) { | 119 TEST_F(GeolocationExceptionsTableModelTest, RemoveAll) { |
| 120 CreateAllowedSamples(); | 120 CreateAllowedSamples(); |
| 121 scoped_refptr<GeolocationContentSettingsMap> map = | 121 scoped_refptr<GeolocationContentSettingsMap> map = |
| 122 profile()->GetGeolocationContentSettingsMap(); | 122 profile()->GetGeolocationContentSettingsMap(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 | 137 |
| 138 // Ensure there's some indentation on the children nodes. | 138 // Ensure there's some indentation on the children nodes. |
| 139 text = model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER); | 139 text = model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER); |
| 140 EXPECT_NE(OriginToWString(kUrl1), text); | 140 EXPECT_NE(OriginToWString(kUrl1), text); |
| 141 EXPECT_NE(std::wstring::npos, text.find(OriginToWString(kUrl1))); | 141 EXPECT_NE(std::wstring::npos, text.find(OriginToWString(kUrl1))); |
| 142 | 142 |
| 143 text = model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER); | 143 text = model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER); |
| 144 EXPECT_NE(OriginToWString(kUrl2), text); | 144 EXPECT_NE(OriginToWString(kUrl2), text); |
| 145 EXPECT_NE(std::wstring::npos, text.find(OriginToWString(kUrl2))); | 145 EXPECT_NE(std::wstring::npos, text.find(OriginToWString(kUrl2))); |
| 146 } | 146 } |
| OLD | NEW |