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

Side by Side 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: Remove query_state_ from SearchBox. 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 unified diff | Download patch | Annotate | Revision Log
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 <sstream> 5 #include <sstream>
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/stringprintf.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h"
8 #include "chrome/browser/favicon/favicon_tab_helper.h" 12 #include "chrome/browser/favicon/favicon_tab_helper.h"
9 #include "chrome/browser/instant/instant_commit_type.h" 13 #include "chrome/browser/instant/instant_commit_type.h"
10 #include "chrome/browser/instant/instant_ntp.h" 14 #include "chrome/browser/instant/instant_ntp.h"
11 #include "chrome/browser/instant/instant_overlay.h" 15 #include "chrome/browser/instant/instant_overlay.h"
12 #include "chrome/browser/instant/instant_service.h" 16 #include "chrome/browser/instant/instant_service.h"
13 #include "chrome/browser/instant/instant_service_factory.h" 17 #include "chrome/browser/instant/instant_service_factory.h"
14 #include "chrome/browser/instant/instant_tab.h" 18 #include "chrome/browser/instant/instant_tab.h"
15 #include "chrome/browser/instant/instant_test_utils.h" 19 #include "chrome/browser/instant/instant_test_utils.h"
16 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/search/search.h" 21 #include "chrome/browser/ui/search/search.h"
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 omnibox()->model()->OnKillFocus(); 827 omnibox()->model()->OnKillFocus();
824 828
825 // Wait for the overlay to show. 829 // Wait for the overlay to show.
826 observer.Wait(); 830 observer.Wait();
827 831
828 // Confirm that the overlay has been committed. 832 // Confirm that the overlay has been committed.
829 content::WebContents* active_tab = 833 content::WebContents* active_tab =
830 browser()->tab_strip_model()->GetActiveWebContents(); 834 browser()->tab_strip_model()->GetActiveWebContents();
831 EXPECT_EQ(preview_tab, active_tab); 835 EXPECT_EQ(preview_tab, active_tab);
832 } 836 }
837
838 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, RestrictedItemReadback) {
839 content::WindowedNotificationObserver observer(
840 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
841 content::NotificationService::AllSources());
842
843 // Initialize Instant.
844 ASSERT_NO_FATAL_FAILURE(SetupInstant());
845 FocusOmniboxAndWaitForInstantSupport();
846
847 // Get a handle to the NTP and the current state of the JS.
848 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
849 content::WebContents* preview_tab = instant()->ntp()->contents();
850 EXPECT_TRUE(preview_tab);
851 EXPECT_TRUE(UpdateSearchState(preview_tab));
852
853 // Manufacture a few autocomplete results and get them down to the page.
854 std::vector<InstantAutocompleteResult> autocomplete_results;
855 for (int i = 0; i < 3; ++i) {
856 std::string description(base::StringPrintf("Test Description %d", i));
857 std::string url(base::StringPrintf("http://www.testurl%d.com", i));
858
859 InstantAutocompleteResult res;
860 res.provider = ASCIIToUTF16(AutocompleteProvider::TypeToString(
861 AutocompleteProvider::TYPE_BUILTIN));
862 res.type = ASCIIToUTF16(AutocompleteMatch::TypeToString(
863 AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)),
864 res.description = ASCIIToUTF16(description);
865 res.destination_url = ASCIIToUTF16(url);
866 res.transition = content::PAGE_TRANSITION_TYPED;
867 res.relevance = 42 + i;
868
869 autocomplete_results.push_back(res);
870 }
871 instant()->overlay()->SendAutocompleteResults(autocomplete_results);
872
873 const char kQueryString[] = "Hippos go berzerk!";
874
875 // First set the query text to a non restricted value and ensure it can be
876 // read back.
877 std::ostringstream stream;
878 stream << "apiHandle.setValue('" << kQueryString << "');";
879 EXPECT_TRUE(ExecuteScript(stream.str()));
880 observer.Wait();
881
882 std::string result;
883 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(),
884 "apiHandle.value",
885 &result));
886 EXPECT_EQ(kQueryString, result);
887
888 // Set the query text to the first restricted autocomplete item.
889 int rid = 0;
890 stream.str(std::string());
891 stream << "apiHandle.setRestrictedValue(" << rid << ")";
892 EXPECT_TRUE(ExecuteScript(stream.str()));
893 observer.Wait();
894
895 // Expect that we now receive the empty string when reading the value back.
896 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(),
897 "apiHandle.value",
898 &result));
899 EXPECT_EQ("", result);
900
901 // Now set the query text to a non restricted value and ensure that the
902 // visibility has been reset and the string can again be read back.
903 stream.str(std::string());
904 stream << "apiHandle.setValue('" << kQueryString << "');";
905 EXPECT_TRUE(ExecuteScript(stream.str()));
906 observer.Wait();
907
908 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(),
909 "apiHandle.value",
910 &result));
911 EXPECT_EQ(kQueryString, result);
912 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698