OLD | NEW |
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 Loading... |
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 Loading... |
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 } |
OLD | NEW |