Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: chrome/browser/search/instant_service_unittest.cc

Issue 1669723002: NTP: don't allow navigateContentWindow to navigate where it pleases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/instant_service.cc ('k') | chrome/browser/ui/search/search_tab_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/instant_service_unittest.cc
diff --git a/chrome/browser/search/instant_service_unittest.cc b/chrome/browser/search/instant_service_unittest.cc
index dcfe926beea6ab1bfe505207a8adff12bd865489..e2836f39a3d1adf79cc1088017ddca592ae91275 100644
--- a/chrome/browser/search/instant_service_unittest.cc
+++ b/chrome/browser/search/instant_service_unittest.cc
@@ -50,6 +50,14 @@ class InstantServiceTest : public InstantUnitTestBase {
return instant_service_->instant_search_prerenderer();
}
+ std::vector<InstantMostVisitedItem>& most_visited_items() {
+ return instant_service_->most_visited_items_;
+ }
+
+ std::vector<InstantMostVisitedItem>& suggestions_items() {
+ return instant_service_->suggestions_items_;
+ }
+
scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
};
@@ -175,3 +183,45 @@ TEST_F(InstantServiceTest, GetSuggestionFromClientSide) {
ASSERT_EQ(1, (int)items.size());
ASSERT_FALSE(items[0].is_server_side_suggestion);
}
+
+TEST_F(InstantServiceTest, IsValidURLForNavigation) {
+ // chrome:// URLs should never appear in the most visited items list, but even
+ // if it does, deny navigation anyway.
+ InstantMostVisitedItem settings_item;
+ settings_item.url = GURL("chrome://settings");
+ most_visited_items().push_back(settings_item);
+ EXPECT_FALSE(instant_service_->IsValidURLForNavigation(settings_item.url));
+
+ // If a chrome-extension:// URL appears in the most visited items list, allow
+ // navigation to it.
+ InstantMostVisitedItem extension_item;
+ extension_item.url = GURL("chrome-extension://awesome");
+ most_visited_items().push_back(extension_item);
+ EXPECT_TRUE(instant_service_->IsValidURLForNavigation(extension_item.url));
+
+ // The renderer filters out javascript:// URLs so we should never receive a
+ // request to navigate to one. But if we do, deny it.
+ InstantMostVisitedItem js_item;
+ js_item.url = GURL("javascript:'moo'");
+ most_visited_items().push_back(js_item);
+ EXPECT_FALSE(instant_service_->IsValidURLForNavigation(js_item.url));
+
+ // Normal case: a request for a web safe URL in the most visited items should
+ // be allowed.
+ InstantMostVisitedItem example_item;
+ example_item.url = GURL("https://example.com");
+ most_visited_items().push_back(example_item);
+ EXPECT_TRUE(instant_service_->IsValidURLForNavigation(example_item.url));
+
+ // Normal case: a request for a web safe URL in the most visited items should
+ // be allowed as well.
+ InstantMostVisitedItem chromium_item;
+ chromium_item.url = GURL("https://chromium.org");
+ suggestions_items().push_back(chromium_item);
+ EXPECT_TRUE(instant_service_->IsValidURLForNavigation(chromium_item.url));
+
+ // http://chromium.org is web safe, but not in |suggestions_items_| or
+ // |most_visited_items_|, so it should be denied.
+ EXPECT_FALSE(
+ instant_service_->IsValidURLForNavigation(GURL("http://chromium.org")));
+}
« no previous file with comments | « chrome/browser/search/instant_service.cc ('k') | chrome/browser/ui/search/search_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698