| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/content_settings_observer.h" | 5 #include "chrome/renderer/content_settings_observer.h" |
| 6 | 6 |
| 7 #include "chrome/common/url_constants.h" | 7 #include "chrome/common/url_constants.h" |
| 8 #include "content/public/common/url_constants.h" | 8 #include "content/public/common/url_constants.h" |
| 9 #include "extensions/features/features.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 11 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 11 #include "third_party/WebKit/public/platform/WebURL.h" | 12 #include "third_party/WebKit/public/platform/WebURL.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 #if defined(ENABLE_EXTENSIONS) | 15 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 15 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 using blink::WebSecurityOrigin; | 19 using blink::WebSecurityOrigin; |
| 19 | 20 |
| 20 typedef testing::Test ContentSettingsObserverTest; | 21 typedef testing::Test ContentSettingsObserverTest; |
| 21 | 22 |
| 22 TEST_F(ContentSettingsObserverTest, WhitelistedSchemes) { | 23 TEST_F(ContentSettingsObserverTest, WhitelistedSchemes) { |
| 23 std::string end_url = ":something"; | 24 std::string end_url = ":something"; |
| 24 | 25 |
| 25 GURL chrome_ui_url = | 26 GURL chrome_ui_url = |
| 26 GURL(std::string(content::kChromeUIScheme).append(end_url)); | 27 GURL(std::string(content::kChromeUIScheme).append(end_url)); |
| 27 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( | 28 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 28 WebSecurityOrigin::create(chrome_ui_url), | 29 WebSecurityOrigin::create(chrome_ui_url), |
| 29 GURL())); | 30 GURL())); |
| 30 | 31 |
| 31 GURL chrome_dev_tools_url = | 32 GURL chrome_dev_tools_url = |
| 32 GURL(std::string(content::kChromeDevToolsScheme).append(end_url)); | 33 GURL(std::string(content::kChromeDevToolsScheme).append(end_url)); |
| 33 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( | 34 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 34 WebSecurityOrigin::create(chrome_dev_tools_url), | 35 WebSecurityOrigin::create(chrome_dev_tools_url), |
| 35 GURL())); | 36 GURL())); |
| 36 | 37 |
| 37 #if defined(ENABLE_EXTENSIONS) | 38 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 38 GURL extension_url = | 39 GURL extension_url = |
| 39 GURL(std::string(extensions::kExtensionScheme).append(end_url)); | 40 GURL(std::string(extensions::kExtensionScheme).append(end_url)); |
| 40 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( | 41 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 41 WebSecurityOrigin::create(extension_url), | 42 WebSecurityOrigin::create(extension_url), |
| 42 GURL())); | 43 GURL())); |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 GURL file_url("file:///dir/"); | 46 GURL file_url("file:///dir/"); |
| 46 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( | 47 EXPECT_TRUE(ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 47 WebSecurityOrigin::create(file_url), | 48 WebSecurityOrigin::create(file_url), |
| 48 GURL("file:///dir/"))); | 49 GURL("file:///dir/"))); |
| 49 EXPECT_FALSE(ContentSettingsObserver::IsWhitelistedForContentSettings( | 50 EXPECT_FALSE(ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 50 WebSecurityOrigin::create(file_url), | 51 WebSecurityOrigin::create(file_url), |
| 51 GURL("file:///dir/file"))); | 52 GURL("file:///dir/file"))); |
| 52 | 53 |
| 53 GURL http_url = | 54 GURL http_url = |
| 54 GURL("http://server.com/path"); | 55 GURL("http://server.com/path"); |
| 55 EXPECT_FALSE(ContentSettingsObserver::IsWhitelistedForContentSettings( | 56 EXPECT_FALSE(ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 56 WebSecurityOrigin::create(http_url), | 57 WebSecurityOrigin::create(http_url), |
| 57 GURL())); | 58 GURL())); |
| 58 } | 59 } |
| OLD | NEW |