| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 15 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 12 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
| 13 #include "chrome/browser/history/top_sites.h" | 17 #include "chrome/browser/history/top_sites.h" |
| 14 #include "chrome/browser/instant/instant_commit_type.h" | 18 #include "chrome/browser/instant/instant_commit_type.h" |
| 15 #include "chrome/browser/instant/instant_ntp.h" | 19 #include "chrome/browser/instant/instant_ntp.h" |
| 16 #include "chrome/browser/instant/instant_overlay.h" | 20 #include "chrome/browser/instant/instant_overlay.h" |
| 17 #include "chrome/browser/instant/instant_service.h" | 21 #include "chrome/browser/instant/instant_service.h" |
| 18 #include "chrome/browser/instant/instant_service_factory.h" | 22 #include "chrome/browser/instant/instant_service_factory.h" |
| (...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 // The page has navigated so there should be no transient entry. | 1088 // The page has navigated so there should be no transient entry. |
| 1085 const content::NavigationEntry* transient_entry = | 1089 const content::NavigationEntry* transient_entry = |
| 1086 active_tab->GetController().GetTransientEntry(); | 1090 active_tab->GetController().GetTransientEntry(); |
| 1087 EXPECT_EQ(NULL, transient_entry); | 1091 EXPECT_EQ(NULL, transient_entry); |
| 1088 | 1092 |
| 1089 // The last committed entry should be the URL the page navigated to. | 1093 // The last committed entry should be the URL the page navigated to. |
| 1090 const content::NavigationEntry* committed_entry = | 1094 const content::NavigationEntry* committed_entry = |
| 1091 active_tab->GetController().GetLastCommittedEntry(); | 1095 active_tab->GetController().GetLastCommittedEntry(); |
| 1092 EXPECT_TRUE(EndsWith(committed_entry->GetURL().spec(), "#q=query", true)); | 1096 EXPECT_TRUE(EndsWith(committed_entry->GetURL().spec(), "#q=query", true)); |
| 1093 } | 1097 } |
| 1098 |
| 1099 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, RestrictedItemReadback) { |
| 1100 // Initialize Instant. |
| 1101 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 1102 FocusOmniboxAndWaitForInstantSupport(); |
| 1103 |
| 1104 // Get a handle to the NTP and the current state of the JS. |
| 1105 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
| 1106 content::WebContents* preview_tab = instant()->ntp()->contents(); |
| 1107 EXPECT_TRUE(preview_tab); |
| 1108 |
| 1109 // Manufacture a few autocomplete results and get them down to the page. |
| 1110 std::vector<InstantAutocompleteResult> autocomplete_results; |
| 1111 for (int i = 0; i < 3; ++i) { |
| 1112 std::string description(base::StringPrintf("Test Description %d", i)); |
| 1113 std::string url(base::StringPrintf("http://www.testurl%d.com", i)); |
| 1114 |
| 1115 InstantAutocompleteResult res; |
| 1116 res.provider = ASCIIToUTF16(AutocompleteProvider::TypeToString( |
| 1117 AutocompleteProvider::TYPE_BUILTIN)); |
| 1118 res.type = ASCIIToUTF16(AutocompleteMatch::TypeToString( |
| 1119 AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)), |
| 1120 res.description = ASCIIToUTF16(description); |
| 1121 res.destination_url = ASCIIToUTF16(url); |
| 1122 res.transition = content::PAGE_TRANSITION_TYPED; |
| 1123 res.relevance = 42 + i; |
| 1124 |
| 1125 autocomplete_results.push_back(res); |
| 1126 } |
| 1127 instant()->overlay()->SendAutocompleteResults(autocomplete_results); |
| 1128 |
| 1129 // Apparently, one needs to access nativeSuggestions before |
| 1130 // apiHandle.setRestrictedValue can work. |
| 1131 EXPECT_TRUE(ExecuteScript("var foo = apiHandle.nativeSuggestions;")); |
| 1132 |
| 1133 const char kQueryString[] = "Hippos go berzerk!"; |
| 1134 |
| 1135 // First set the query text to a non restricted value and ensure it can be |
| 1136 // read back. |
| 1137 std::ostringstream stream; |
| 1138 stream << "apiHandle.setValue('" << kQueryString << "');"; |
| 1139 EXPECT_TRUE(ExecuteScript(stream.str())); |
| 1140 |
| 1141 std::string result; |
| 1142 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), |
| 1143 "apiHandle.value", |
| 1144 &result)); |
| 1145 EXPECT_EQ(kQueryString, result); |
| 1146 |
| 1147 // Set the query text to the first restricted autocomplete item. |
| 1148 int rid = 0; |
| 1149 stream.str(std::string()); |
| 1150 stream << "apiHandle.setRestrictedValue(" << rid << ")"; |
| 1151 EXPECT_TRUE(ExecuteScript(stream.str())); |
| 1152 |
| 1153 // Expect that we now receive the empty string when reading the value back. |
| 1154 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), |
| 1155 "apiHandle.value", |
| 1156 &result)); |
| 1157 EXPECT_EQ("", result); |
| 1158 |
| 1159 // Now set the query text to a non restricted value and ensure that the |
| 1160 // visibility has been reset and the string can again be read back. |
| 1161 stream.str(std::string()); |
| 1162 stream << "apiHandle.setValue('" << kQueryString << "');"; |
| 1163 EXPECT_TRUE(ExecuteScript(stream.str())); |
| 1164 |
| 1165 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), |
| 1166 "apiHandle.value", |
| 1167 &result)); |
| 1168 EXPECT_EQ(kQueryString, result); |
| 1169 } |
| OLD | NEW |