Index: chrome/renderer/chrome_content_renderer_client_unittest.cc |
diff --git a/chrome/renderer/chrome_content_renderer_client_unittest.cc b/chrome/renderer/chrome_content_renderer_client_unittest.cc |
index b099eea5a6f62b857835b5b26ae3dbcf6e51cbd3..029f18671d0de7566ab05726f47450d5553639bf 100644 |
--- a/chrome/renderer/chrome_content_renderer_client_unittest.cc |
+++ b/chrome/renderer/chrome_content_renderer_client_unittest.cc |
@@ -342,4 +342,34 @@ TEST_F(ChromeContentRendererClientTest, IsRequestOSFileHandleAllowedForURL) { |
GURL("filesystem:http://192.168.0.1/foo"))); |
} |
+TEST_F(ChromeContentRendererClientTest, SetOriginForSuggestionRequest) { |
+ ChromeContentRendererClient client; |
+ // The origin parameter should be set from top_url. |
+ EXPECT_EQ(GURL("chrome-search://suggestion/result.js?" |
+ "origin=http://sanity.example.com"), |
+ client.SetOriginForSuggestionRequest( |
+ GURL("chrome-search://suggestion/result.js"), |
+ GURL("http://sanity.example.com"))); |
+ // Any existing &origin parameter should be replaced by origin=top_url. |
+ EXPECT_EQ(GURL("chrome-search://suggestion/result.js?" |
+ "origin=http://evil.example.com"), |
+ client.SetOriginForSuggestionRequest( |
+ GURL("chrome-search://suggestion/result.js?" |
+ "origin=http://good.example.com/"), |
+ GURL("http://evil.example.com"))); |
+ // Multiple &origin parameters should also be replaced by origin=top_url. |
+ EXPECT_EQ(GURL("chrome-search://suggestion/result.js?" |
+ "origin=http://evil.example.com"), |
+ client.SetOriginForSuggestionRequest( |
+ GURL("chrome-search://suggestion/result.js?" |
+ "origin=http://good.example.com/&" |
+ "origin=http://better.example.com"), |
+ GURL("http://evil.example.com"))); |
+ // A malformed top_url should result in an empty origin. |
+ EXPECT_EQ(GURL("chrome-search://suggestion/result.js?origin="), |
+ client.SetOriginForSuggestionRequest( |
+ GURL("chrome-search://suggestion/result.js"), |
+ GURL("\"<script>alert('evil')</script>"))); |
+} |
+ |
} // namespace chrome |