Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / data / instant_extended.html
blobda831f552850bb19576ace0104b2843676ddac4c
1 <html>
2 <head>
3 <script>
5 var apiHandle;
6 var newTabPageHandle;
7 var savedUserText = null;
8 var suggestionIndex = -1;
9 var suggestions = ["result 1", "result 2", "http://www.google.com"];
10 var suggestion;
11 var suggestionType = 0; // INSTANT_SUGGESTION_SEARCH
12 var behavior = 2; // INSTANT_COMPLETE_NEVER
13 var onMostVisitedChangedCalls = 0;
14 var mostVisitedItemsCount = 0;
15 var firstMostVisitedItemId = 0;
16 var onNativeSuggestionsCalls = 0;
17 var onChangeCalls = 0;
18 var submitCount = 0;
19 var onEscKeyPressedCalls = 0;
20 var onFocusChangedCalls = 0;
21 var onToggleVoiceSearchCalls = 0;
22 var prefetchQuery = '';
23 var isFocused = false;
24 var onvisibilitycalls = 0;
25 var onThemeChangedCalls = 0;
27 function getApiHandle() {
28 if (window.navigator && window.navigator.searchBox)
29 return window.navigator.searchBox;
30 if (window.chrome && window.chrome.searchBox)
31 return window.chrome.searchBox;
32 return null;
35 function getNewTabPageHandle() {
36 if (window.navigator && window.navigator.embeddedSearch &&
37 window.navigator.embeddedSearch.newTabPage)
38 return window.navigator.embeddedSearch.newTabPage;
39 if (window.chrome && window.chrome.embeddedSearch &&
40 window.chrome.embeddedSearch.newTabPage)
41 return window.chrome.embeddedSearch.newTabPage;
42 return null;
45 function handleNativeSuggestions() {
46 onNativeSuggestionsCalls++;
47 // Showing the loader at 100% height.
48 apiHandle.hideBars();
49 apiHandle.showOverlay();
52 function handleSubmit() {
53 location.hash = 'q=' + encodeURIComponent(apiHandle.value);
54 submitCount++;
57 function handleOnChange() {
58 onChangeCalls++;
59 savedUserText = apiHandle.value;
60 suggestionIndex = -1;
61 apiHandle.setAutocompleteText(suggestion, behavior);
64 function nextSuggestion() {
65 if (suggestionIndex < suggestions.length - 1) {
66 suggestionIndex++;
67 apiHandle.setValue(suggestions[suggestionIndex], suggestionType);
71 function previousSuggestion() {
72 if (suggestionIndex != -1) {
73 suggestionIndex--;
74 if (suggestionIndex == -1) {
75 apiHandle.setValue(savedUserText, suggestionType);
76 } else {
77 apiHandle.setValue(suggestions[suggestionIndex], suggestionType);
82 function handleKeyPress(event) {
83 var VKEY_ESCAPE = 0x1B;
84 var VKEY_UP = 0x26;
85 var VKEY_DOWN = 0x28;
87 if (event.keyCode == VKEY_ESCAPE) {
88 onEscKeyPressedCalls++;
89 if (suggestionIndex != -1) {
90 suggestionIndex = -1;
91 apiHandle.setAutocompleteText(suggestion, behavior);
93 } else if (event.keyCode == VKEY_DOWN) {
94 nextSuggestion();
95 } else if (event.keyCode == VKEY_UP) {
96 previousSuggestion();
100 function handleMostVisitedChange() {
101 onMostVisitedChangedCalls++;
102 var items = newTabPageHandle.mostVisited;
103 if (items) {
104 mostVisitedItemsCount = items.length;
105 firstMostVisitedItemId = items[0] ? items[0].rid : 0;
109 document.addEventListener("visibilitychange", function() {
110 onvisibilitycalls++;
111 }, false);
113 function handleFocusChange() {
114 onFocusChangedCalls++;
115 isFocused = apiHandle.isFocused;
118 function handleToggleVoiceSearch() {
119 onToggleVoiceSearchCalls++;
122 function handleSuggestionChange() {
123 prefetchQuery = getApiHandle().suggestion.text;
126 function handleThemeChange() {
127 onThemeChangedCalls++;
130 function setUp() {
131 apiHandle = getApiHandle();
132 if (!apiHandle)
133 return;
135 newTabPageHandle = getNewTabPageHandle();
136 apiHandle.onnativesuggestions = handleNativeSuggestions;
137 apiHandle.onsubmit = handleSubmit;
138 apiHandle.onchange = handleOnChange;
139 apiHandle.onkeypress = handleKeyPress;
140 apiHandle.onfocuschange = handleFocusChange;
141 apiHandle.ontogglevoicesearch = handleToggleVoiceSearch;
142 apiHandle.onsuggestionchange = handleSuggestionChange;
143 newTabPageHandle.onmostvisitedchange = handleMostVisitedChange;
144 newTabPageHandle.onthemechange = handleThemeChange;
145 if (apiHandle.value) {
146 handleNativeSuggestions();
147 handleOnChange();
149 if (newTabPageHandle.mostVisited && newTabPageHandle.mostVisited.length) {
150 handleMostVisitedChange();
152 handleFocusChange();
155 setUp();
157 </script>
159 <meta name="referrer" content="origin" />
161 </head>
162 <body>
163 <h1>Instant</h1>
164 </body>
165 </html>