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

Unified Diff: chrome/browser/instant/instant_extended_browsertest.cc

Issue 12319108: Prevent querying of restricted query values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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/instant/instant_controller.h ('k') | chrome/renderer/resources/extensions/searchbox_api.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/instant/instant_extended_browsertest.cc
diff --git a/chrome/browser/instant/instant_extended_browsertest.cc b/chrome/browser/instant/instant_extended_browsertest.cc
index d38d02b65904328581498e6459cac8abefd7c02e..94893504d64ae2219edbcdfe7f16276410482d1f 100644
--- a/chrome/browser/instant/instant_extended_browsertest.cc
+++ b/chrome/browser/instant/instant_extended_browsertest.cc
@@ -6,6 +6,10 @@
#include "base/prefs/pref_service.h"
#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "chrome/browser/autocomplete/autocomplete_provider.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
@@ -1091,3 +1095,75 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_TransientEntryRemoved) {
active_tab->GetController().GetLastCommittedEntry();
EXPECT_TRUE(EndsWith(committed_entry->GetURL().spec(), "#q=query", true));
}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, RestrictedItemReadback) {
+ // Initialize Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // Get a handle to the NTP and the current state of the JS.
+ ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
+ content::WebContents* preview_tab = instant()->ntp()->contents();
+ EXPECT_TRUE(preview_tab);
+
+ // Manufacture a few autocomplete results and get them down to the page.
+ std::vector<InstantAutocompleteResult> autocomplete_results;
+ for (int i = 0; i < 3; ++i) {
+ std::string description(base::StringPrintf("Test Description %d", i));
+ std::string url(base::StringPrintf("http://www.testurl%d.com", i));
+
+ InstantAutocompleteResult res;
+ res.provider = ASCIIToUTF16(AutocompleteProvider::TypeToString(
+ AutocompleteProvider::TYPE_BUILTIN));
+ res.type = ASCIIToUTF16(AutocompleteMatch::TypeToString(
+ AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)),
+ res.description = ASCIIToUTF16(description);
+ res.destination_url = ASCIIToUTF16(url);
+ res.transition = content::PAGE_TRANSITION_TYPED;
+ res.relevance = 42 + i;
+
+ autocomplete_results.push_back(res);
+ }
+ instant()->overlay()->SendAutocompleteResults(autocomplete_results);
+
+ // Apparently, one needs to access nativeSuggestions before
+ // apiHandle.setRestrictedValue can work.
+ EXPECT_TRUE(ExecuteScript("var foo = apiHandle.nativeSuggestions;"));
+
+ const char kQueryString[] = "Hippos go berzerk!";
+
+ // First set the query text to a non restricted value and ensure it can be
+ // read back.
+ std::ostringstream stream;
+ stream << "apiHandle.setValue('" << kQueryString << "');";
+ EXPECT_TRUE(ExecuteScript(stream.str()));
+
+ std::string result;
+ EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
+ "apiHandle.value",
+ &result));
+ EXPECT_EQ(kQueryString, result);
+
+ // Set the query text to the first restricted autocomplete item.
+ int rid = 0;
+ stream.str(std::string());
+ stream << "apiHandle.setRestrictedValue(" << rid << ")";
+ EXPECT_TRUE(ExecuteScript(stream.str()));
+
+ // Expect that we now receive the empty string when reading the value back.
+ EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
+ "apiHandle.value",
+ &result));
+ EXPECT_EQ("", result);
+
+ // Now set the query text to a non restricted value and ensure that the
+ // visibility has been reset and the string can again be read back.
+ stream.str(std::string());
+ stream << "apiHandle.setValue('" << kQueryString << "');";
+ EXPECT_TRUE(ExecuteScript(stream.str()));
+
+ EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
+ "apiHandle.value",
+ &result));
+ EXPECT_EQ(kQueryString, result);
+}
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/renderer/resources/extensions/searchbox_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698