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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 void TearDown() override { 44 void TearDown() override {
45 instant_service_->RemoveObserver(instant_service_observer_.get()); 45 instant_service_->RemoveObserver(instant_service_observer_.get());
46 InstantUnitTestBase::TearDown(); 46 InstantUnitTestBase::TearDown();
47 } 47 }
48 48
49 InstantSearchPrerenderer* GetInstantSearchPrerenderer() { 49 InstantSearchPrerenderer* GetInstantSearchPrerenderer() {
50 return instant_service_->instant_search_prerenderer(); 50 return instant_service_->instant_search_prerenderer();
51 } 51 }
52 52
53 std::vector<InstantMostVisitedItem>& most_visited_items() {
54 return instant_service_->most_visited_items_;
55 }
56
57 std::vector<InstantMostVisitedItem>& suggestions_items() {
58 return instant_service_->suggestions_items_;
59 }
60
53 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; 61 scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
54 }; 62 };
55 63
56 class InstantServiceEnabledTest : public InstantServiceTest { 64 class InstantServiceEnabledTest : public InstantServiceTest {
57 protected: 65 protected:
58 void SetUp() override { 66 void SetUp() override {
59 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 67 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
60 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 68 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
61 InstantServiceTest::SetUp(); 69 InstantServiceTest::SetUp();
62 } 70 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 TEST_F(InstantServiceTest, GetSuggestionFromClientSide) { 176 TEST_F(InstantServiceTest, GetSuggestionFromClientSide) {
169 history::MostVisitedURLList url_list; 177 history::MostVisitedURLList url_list;
170 url_list.push_back(history::MostVisitedURL()); 178 url_list.push_back(history::MostVisitedURL());
171 179
172 instant_service_->OnMostVisitedItemsReceived(url_list); 180 instant_service_->OnMostVisitedItemsReceived(url_list);
173 181
174 auto items = instant_service_->most_visited_items_; 182 auto items = instant_service_->most_visited_items_;
175 ASSERT_EQ(1, (int)items.size()); 183 ASSERT_EQ(1, (int)items.size());
176 ASSERT_FALSE(items[0].is_server_side_suggestion); 184 ASSERT_FALSE(items[0].is_server_side_suggestion);
177 } 185 }
186
187 TEST_F(InstantServiceTest, IsValidURLForNavigation) {
188 // chrome:// URLs should never appear in the most visited items list, but even
189 // if it does, deny navigation anyway.
190 InstantMostVisitedItem settings_item;
191 settings_item.url = GURL("chrome://settings");
192 most_visited_items().push_back(settings_item);
193 EXPECT_FALSE(instant_service_->IsValidURLForNavigation(settings_item.url));
194
195 // If a chrome-extension:// URL appears in the most visited items list, allow
196 // navigation to it.
197 InstantMostVisitedItem extension_item;
198 extension_item.url = GURL("chrome-extension://awesome");
199 most_visited_items().push_back(extension_item);
200 EXPECT_TRUE(instant_service_->IsValidURLForNavigation(extension_item.url));
201
202 // The renderer filters out javascript:// URLs so we should never receive a
203 // request to navigate to one. But if we do, deny it.
204 InstantMostVisitedItem js_item;
205 js_item.url = GURL("javascript:'moo'");
206 most_visited_items().push_back(js_item);
207 EXPECT_FALSE(instant_service_->IsValidURLForNavigation(js_item.url));
208
209 // Normal case: a request for a web safe URL in the most visited items should
210 // be allowed.
211 InstantMostVisitedItem example_item;
212 example_item.url = GURL("https://example.com");
213 most_visited_items().push_back(example_item);
214 EXPECT_TRUE(instant_service_->IsValidURLForNavigation(example_item.url));
215
216 // Normal case: a request for a web safe URL in the most visited items should
217 // be allowed as well.
218 InstantMostVisitedItem chromium_item;
219 chromium_item.url = GURL("https://chromium.org");
220 suggestions_items().push_back(chromium_item);
221 EXPECT_TRUE(instant_service_->IsValidURLForNavigation(chromium_item.url));
222
223 // http://chromium.org is web safe, but not in |suggestions_items_| or
224 // |most_visited_items_|, so it should be denied.
225 EXPECT_FALSE(
226 instant_service_->IsValidURLForNavigation(GURL("http://chromium.org")));
227 }
OLDNEW
« 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