| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/content_settings/core/browser/content_settings_usages_state
.h" | 5 #include "components/content_settings/core/browser/content_settings_usages_state
.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 12 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 15 |
| 17 using content::BrowserThread; | |
| 18 | |
| 19 namespace { | 16 namespace { |
| 20 | 17 |
| 21 ContentSettingsUsagesState::CommittedDetails CreateDetailsWithURL( | 18 ContentSettingsUsagesState::CommittedDetails CreateDetailsWithURL( |
| 22 const GURL& url) { | 19 const GURL& url) { |
| 23 ContentSettingsUsagesState::CommittedDetails details; | 20 ContentSettingsUsagesState::CommittedDetails details; |
| 24 details.current_url = url; | 21 details.current_url = url; |
| 25 return details; | 22 return details; |
| 26 } | 23 } |
| 27 | 24 |
| 28 class ContentSettingsUsagesStateTests : public testing::Test { | 25 class ContentSettingsUsagesStateTests : public testing::Test { |
| 29 public: | 26 public: |
| 30 ContentSettingsUsagesStateTests() | 27 ContentSettingsUsagesStateTests() = default; |
| 31 : ui_thread_(BrowserThread::UI, &message_loop_) { | |
| 32 } | |
| 33 | 28 |
| 34 protected: | 29 protected: |
| 35 void ClearOnNewOrigin(ContentSettingsType type) { | 30 void ClearOnNewOrigin(ContentSettingsType type) { |
| 36 TestingProfile profile; | 31 TestingProfile profile; |
| 37 ContentSettingsUsagesState state( | 32 ContentSettingsUsagesState state( |
| 38 HostContentSettingsMapFactory::GetForProfile(&profile), type); | 33 HostContentSettingsMapFactory::GetForProfile(&profile), type); |
| 39 GURL url_0("http://www.example.com"); | 34 GURL url_0("http://www.example.com"); |
| 40 | 35 |
| 41 ContentSettingsUsagesState::CommittedDetails details = | 36 ContentSettingsUsagesState::CommittedDetails details = |
| 42 CreateDetailsWithURL(url_0); | 37 CreateDetailsWithURL(url_0); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 EXPECT_EQ(1U, | 182 EXPECT_EQ(1U, |
| 188 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( | 183 formatted_host_per_state[CONTENT_SETTING_ALLOW].count( |
| 189 url_2.host())); | 184 url_2.host())); |
| 190 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); | 185 EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size()); |
| 191 EXPECT_EQ(1U, | 186 EXPECT_EQ(1U, |
| 192 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( | 187 formatted_host_per_state[CONTENT_SETTING_BLOCK].count( |
| 193 url_1.spec())); | 188 url_1.spec())); |
| 194 } | 189 } |
| 195 | 190 |
| 196 protected: | 191 protected: |
| 197 base::MessageLoop message_loop_; | 192 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 198 content::TestBrowserThread ui_thread_; | |
| 199 }; | 193 }; |
| 200 | 194 |
| 201 TEST_F(ContentSettingsUsagesStateTests, ClearOnNewOriginForGeolocation) { | 195 TEST_F(ContentSettingsUsagesStateTests, ClearOnNewOriginForGeolocation) { |
| 202 ClearOnNewOrigin(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 196 ClearOnNewOrigin(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 203 } | 197 } |
| 204 | 198 |
| 205 TEST_F(ContentSettingsUsagesStateTests, ClearOnNewOriginForMidi) { | 199 TEST_F(ContentSettingsUsagesStateTests, ClearOnNewOriginForMidi) { |
| 206 ClearOnNewOrigin(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 200 ClearOnNewOrigin(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 207 } | 201 } |
| 208 | 202 |
| 209 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForGeolocation) { | 203 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForGeolocation) { |
| 210 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 204 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 211 } | 205 } |
| 212 | 206 |
| 213 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForMidi) { | 207 TEST_F(ContentSettingsUsagesStateTests, ShowPortOnSameHostForMidi) { |
| 214 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 208 ShowPortOnSameHost(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 215 } | 209 } |
| 216 | 210 |
| 217 } // namespace | 211 } // namespace |
| OLD | NEW |