| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 6 #include "googleurl/src/gurl.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 // A macro, so that the IsRequestorURLInVerifiedSite calls are inside of the |
| 10 // the test, which is marked as a friend of WebstoreInlineInstaller. |
| 11 #define IsVerified(requestor_url, verified_site) \ |
| 12 WebstoreInlineInstaller::IsRequestorURLInVerifiedSite( \ |
| 13 GURL(requestor_url), verified_site) |
| 14 |
| 15 TEST(WebstoreInlineInstallerTest, DomainVerification) { |
| 16 // Exact domain match. |
| 17 EXPECT_TRUE(IsVerified("http://example.com", "example.com")); |
| 18 |
| 19 // The HTTPS scheme is allowed. |
| 20 EXPECT_TRUE(IsVerified("https://example.com", "example.com")); |
| 21 |
| 22 // The file: scheme is not allowed. |
| 23 EXPECT_FALSE(IsVerified("file:///example.com", "example.com")); |
| 24 |
| 25 // Trailing slash in URL. |
| 26 EXPECT_TRUE(IsVerified("http://example.com/", "example.com")); |
| 27 |
| 28 // Page on the domain. |
| 29 EXPECT_TRUE(IsVerified("http://example.com/page.html", "example.com")); |
| 30 |
| 31 // Page on a subdomain. |
| 32 EXPECT_TRUE(IsVerified("http://sub.example.com/page.html", "example.com")); |
| 33 |
| 34 // Root domain when only a subdomain is verified. |
| 35 EXPECT_FALSE(IsVerified("http://example.com/", "sub.example.com")); |
| 36 |
| 37 // Different subdomain when only a subdomain is verified. |
| 38 EXPECT_FALSE(IsVerified("http://www.example.com/", "sub.example.com")); |
| 39 |
| 40 // Port matches. |
| 41 EXPECT_TRUE(IsVerified("http://example.com:123/", "example.com:123")); |
| 42 |
| 43 // Port doesn't match. |
| 44 EXPECT_FALSE(IsVerified("http://example.com:456/", "example.com:123")); |
| 45 |
| 46 // Port is missing in the requestor URL. |
| 47 EXPECT_FALSE(IsVerified("http://example.com/", "example.com:123")); |
| 48 |
| 49 // Port is missing in the verified site (any port matches). |
| 50 EXPECT_TRUE(IsVerified("http://example.com:123/", "example.com")); |
| 51 |
| 52 // Path matches. |
| 53 EXPECT_TRUE(IsVerified("http://example.com/path", "example.com/path")); |
| 54 |
| 55 // Path doesn't match. |
| 56 EXPECT_FALSE(IsVerified("http://example.com/foo", "example.com/path")); |
| 57 |
| 58 // Path is missing. |
| 59 EXPECT_FALSE(IsVerified("http://example.com", "example.com/path")); |
| 60 |
| 61 // Path matches (with trailing slash). |
| 62 EXPECT_TRUE(IsVerified("http://example.com/path/", "example.com/path")); |
| 63 |
| 64 // Path matches (is a file under the path). |
| 65 EXPECT_TRUE(IsVerified( |
| 66 "http://example.com/path/page.html", "example.com/path")); |
| 67 |
| 68 // Path and port match. |
| 69 EXPECT_TRUE(IsVerified( |
| 70 "http://example.com:123/path/page.html", "example.com:123/path")); |
| 71 } |
| OLD | NEW |