Chromium Code Reviews| Index: chrome/browser/extensions/webstore_inline_installer_unittest.cc |
| diff --git a/chrome/browser/extensions/webstore_inline_installer_unittest.cc b/chrome/browser/extensions/webstore_inline_installer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c8333138860493fe615f0a312804424efd05007c |
| --- /dev/null |
| +++ b/chrome/browser/extensions/webstore_inline_installer_unittest.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/webstore_inline_installer.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +// A macro, so that the IsRequestorUrlInVerifiedSite calls are inside of the |
| +// the test, which is marked as a friend of WebstoreInlineInstaller. |
| +#define IsVerified(requestor_url, verified_site) \ |
| + WebstoreInlineInstaller::IsRequestorUrlInVerifiedSite( \ |
| + GURL(requestor_url), verified_site) |
| + |
| +TEST(WebstoreInlineInstallerTest, DomainVerification) { |
| + // Exact domain match. |
| + EXPECT_TRUE(IsVerified("http://example.com", "example.com")); |
| + |
| + // The HTTPS scheme is allowed. |
| + EXPECT_TRUE(IsVerified("https://example.com", "example.com")); |
| + |
| + // The file: scheme is not allowed. |
| + EXPECT_FALSE(IsVerified("file:///example.com", "example.com")); |
| + |
| + // Trailing slash in URL. |
| + EXPECT_TRUE(IsVerified("http://example.com/", "example.com")); |
| + |
| + // Page on the domain. |
| + EXPECT_TRUE(IsVerified("http://example.com/page.html", "example.com")); |
| + |
| + // Page on a subdomain. |
| + EXPECT_TRUE(IsVerified("http://sub.example.com/page.html", "example.com")); |
| + |
| + // Root domain when only a subdomain is verified. |
| + EXPECT_FALSE(IsVerified("http://example.com/", "sub.example.com")); |
| + |
| + // Different subdomain when only a subdomain is verified. |
| + EXPECT_FALSE(IsVerified("http://www.example.com/", "sub.example.com")); |
| + |
| + // Port matches. |
| + EXPECT_TRUE(IsVerified("http://example.com:123/", "example.com:123")); |
| + |
| + // Port doesn't match. |
| + EXPECT_FALSE(IsVerified("http://example.com:456/", "example.com:123")); |
| + |
| + // Port is missing in the requestor URL. |
| + EXPECT_FALSE(IsVerified("http://example.com/", "example.com:123")); |
| + |
| + // Port is missing in the verified site (any port matches). |
| + EXPECT_TRUE(IsVerified("http://example.com:123/", "example.com")); |
| + |
| + // Path matches. |
| + EXPECT_TRUE(IsVerified("http://example.com/path", "example.com/path")); |
| + |
| + // Path matches (with trailing slash). |
| + EXPECT_TRUE(IsVerified("http://example.com/path/", "example.com/path")); |
| + |
| + // Path matches (is a file under the path). |
| + EXPECT_TRUE(IsVerified( |
| + "http://example.com/path/page.html", "example.com/path")); |
| + |
| + // Path and port match. |
| + EXPECT_TRUE(IsVerified( |
| + "http://example.com:123/path/page.html", "example.com:123/path")); |
|
jstritar
2012/01/25 17:40:28
How about one more test for when there's a path th
Mihai Parparita -not on Chrome
2012/01/25 18:11:04
Done.
|
| +} |