summaryrefslogtreecommitdiffstats
path: root/chrome/browser/instant/instant_browsertest.cc
blob: 9d7cc671acce0abb987728717c7f0cf903523905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/instant/instant_loader.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/test_navigation_observer.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_service.h"

#define EXPECT_STR_EQ(ascii, utf16) \
  EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16))

#if defined(OS_LINUX)
// These tests are disabled on linux because of http://crbug.com/80118 .
#define MAYBE_OnChangeEvent DISABLED_OnChangeEvent
#define MAYBE_SetSuggestionsArrayOfStrings DISABLED_SetSuggestionsArrayOfStrings
#define MAYBE_SetSuggestionsEmptyArray DISABLED_SetSuggestionsEmptyArray
#define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson
#define MAYBE_SetSuggestionsInvalidSuggestions \
    DISABLED_SetSuggestionsInvalidSuggestions
#define MAYBE_SetSuggestionsEmptyJson DISABLED_SetSuggestionsEmptyJson
#define MAYBE_SetSuggestionsEmptySuggestions \
    DISABLED_SetSuggestionsEmptySuggestions
#define MAYBE_SetSuggestionsEmptySuggestion \
    DISABLED_SetSuggestionsEmptySuggestion
#define MAYBE_ShowPreviewNonSearch DISABLED_ShowPreviewNonSearch
#define MAYBE_NonSearchToSearch DISABLED_NonSearchToSearch
#define MAYBE_SearchToNonSearch DISABLED_SearchToNonSearch
#define MAYBE_ValidHeight DISABLED_ValidHeight
#define MAYBE_OnSubmitEvent DISABLED_OnSubmitEvent
#define MAYBE_OnCancelEvent DISABLED_OnCancelEvent
#define MAYBE_InstantCompleteNever DISABLED_InstantCompleteNever
#define MAYBE_InstantCompleteDelayed DISABLED_InstantCompleteDelayed
#define MAYBE_DontCrashOnBlockedJS DISABLED_DontCrashOnBlockedJS
#define MAYBE_DontPersistSearchbox DISABLED_DontPersistSearchbox
#define MAYBE_PreloadsInstant DISABLED_PreloadsInstant
#define MAYBE_ExperimentEnabled DISABLED_ExperimentEnabled
#else
#define MAYBE_OnChangeEvent OnChangeEvent
#define MAYBE_SetSuggestionsArrayOfStrings SetSuggestionsArrayOfStrings
#define MAYBE_SetSuggestionsEmptyArray SetSuggestionsEmptyArray
#define MAYBE_SetSuggestionsValidJson SetSuggestionsValidJson
#define MAYBE_SetSuggestionsInvalidSuggestions SetSuggestionsInvalidSuggestions
#define MAYBE_SetSuggestionsEmptyJson SetSuggestionsEmptyJson
#define MAYBE_SetSuggestionsEmptySuggestions SetSuggestionsEmptySuggestions
#define MAYBE_SetSuggestionsEmptySuggestion SetSuggestionsEmptySuggestion
#define MAYBE_ShowPreviewNonSearch ShowPreviewNonSearch
#define MAYBE_NonSearchToSearch NonSearchToSearch
#define MAYBE_SearchToNonSearch SearchToNonSearch
#define MAYBE_ValidHeight ValidHeight
#define MAYBE_OnSubmitEvent OnSubmitEvent
#define MAYBE_OnCancelEvent OnCancelEvent
#define MAYBE_InstantCompleteNever InstantCompleteNever
#define MAYBE_InstantCompleteDelayed InstantCompleteDelayed
#define MAYBE_DontCrashOnBlockedJS DontCrashOnBlockedJS
#define MAYBE_DontPersistSearchbox DontPersistSearchbox
#define MAYBE_PreloadsInstant PreloadsInstant
#define MAYBE_ExperimentEnabled ExperimentEnabled
#endif

#if defined(OS_MACOSX) || defined(OS_LINUX)
// Showing as flaky on Mac and Linux.
// http://crbug.com/70860
#define MAYBE_SearchServerDoesntSupportInstant \
    DISABLED_SearchServerDoesntSupportInstant
#define MAYBE_NonSearchToSearchDoesntSupportInstant \
    DISABLED_NonSearchToSearchDoesntSupportInstant
#else
#define MAYBE_SearchServerDoesntSupportInstant \
    SearchServerDoesntSupportInstant
#define MAYBE_NonSearchToSearchDoesntSupportInstant \
    NonSearchToSearchDoesntSupportInstant
#endif


class InstantTest : public InProcessBrowserTest {
 public:
  InstantTest()
      : location_bar_(NULL),
        preview_(NULL),
        template_url_id_(0) {
    set_show_window(true);
    EnableDOMAutomation();
  }

  void EnableInstant() {
    InstantController::Enable(browser()->profile());
  }

  void SetupInstantProvider(const std::string& page) {
    TemplateURLService* model =
        TemplateURLServiceFactory::GetForProfile(browser()->profile());
    ASSERT_TRUE(model);

    ui_test_utils::WindowedNotificationObserver service_loaded_observer(
        chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
        content::NotificationService::AllSources());
    if (!model->loaded()) {
      model->Load();
      service_loaded_observer.Wait();
    }
    ASSERT_TRUE(model->loaded());

    // TemplateURLService takes ownership of this.
    TemplateURL* template_url = new TemplateURL();

    std::string url = StringPrintf(
        "http://%s:%d/files/instant/%s?q={searchTerms}",
        test_server()->host_port_pair().host().c_str(),
        test_server()->host_port_pair().port(),
        page.c_str());
    template_url->SetURL(url, 0, 0);
    template_url->SetInstantURL(url, 0, 0);
    template_url->set_keyword(ASCIIToUTF16("foo"));
    template_url->set_short_name(ASCIIToUTF16("foo"));

    model->Add(template_url);
    model->SetDefaultSearchProvider(template_url);
    template_url_id_ = template_url->id();
  }

  void FindLocationBar() {
    if (location_bar_)
      return;
    location_bar_ = browser()->window()->GetLocationBar();
    ASSERT_TRUE(location_bar_);
  }

  // Type a character to get instant to trigger.
  void SetupLocationBar() {
    FindLocationBar();
    // "a" triggers the "about:" provider.  "b" begins the "bing.com" keyword.
    // "c" might someday trigger a "chrome:" provider.
    location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
  }

  // Waits for preview to be shown.
  void WaitForPreviewToNavigate() {
    InstantController* instant = browser()->instant();
    ASSERT_TRUE(instant);
    TabContentsWrapper* tab = instant->GetPreviewContents();
    ASSERT_TRUE(tab);
    preview_ = tab->tab_contents();
    ASSERT_TRUE(preview_);
    // TODO(gbillock): This should really be moved into calling code. It is
    // still race-prone here.
    TestNavigationObserver observer(content::Source<NavigationController>(
        &preview_->controller()), NULL, 1);
    observer.WaitForObservation();
  }

  // Wait for instant to load and ensure it is in the state we expect.
  void SetupPreview() {
    // Wait for the preview to navigate.
    WaitForPreviewToNavigate();

    ASSERT_FALSE(browser()->instant()->is_displayable());
    ASSERT_TRUE(HasPreview());

    // When the page loads, the initial searchBox values are set and only a
    // resize will have been sent.
    ASSERT_EQ("true 0 0 0 true d false d false 1 1",
              GetSearchStateAsString(preview_, false));
  }

  void SetLocationBarText(const std::string& text) {
    ASSERT_NO_FATAL_FAILURE(FindLocationBar());
    ui_test_utils::WindowedNotificationObserver controller_shown_observer(
        chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
        content::NotificationService::AllSources());
    location_bar_->location_entry()->SetUserText(UTF8ToUTF16(text));
    controller_shown_observer.Wait();
  }

  const string16& GetSuggestion() const {
    return browser()->instant()->loader_->complete_suggested_text_;
  }

  GURL GetCurrentURL() {
    return browser()->instant()->loader_.get() ?
        browser()->instant()->loader_.get()->url() : GURL();
  }

  void SendKey(ui::KeyboardCode key) {
    ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
        browser(), key, false, false, false, false));
  }

  void SetSuggestionsJavascriptArgument(TabContents* tab_contents,
                                        const std::string& argument) {
    std::string script = StringPrintf(
        "window.setSuggestionsArgument = %s;", argument.c_str());
    ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
        tab_contents->render_view_host(),
        std::wstring(),
        UTF8ToWide(script)));
  }

  bool GetStringFromJavascript(TabContents* tab_contents,
                               const std::string& function,
                               std::string* result) {
    std::string script = StringPrintf(
        "window.domAutomationController.send(%s)", function.c_str());
    return ui_test_utils::ExecuteJavaScriptAndExtractString(
        tab_contents->render_view_host(),
        std::wstring(), UTF8ToWide(script), result);
  }

  bool GetIntFromJavascript(TabContents* tab_contents,
                            const std::string& function,
                            int* result) {
    std::string script = StringPrintf(
        "window.domAutomationController.send(%s)", function.c_str());
    return ui_test_utils::ExecuteJavaScriptAndExtractInt(
        tab_contents->render_view_host(),
        std::wstring(), UTF8ToWide(script), result);
  }

  bool GetBoolFromJavascript(TabContents* tab_contents,
                             const std::string& function,
                             bool* result) {
    std::string script = StringPrintf(
        "window.domAutomationController.send(%s)", function.c_str());
    return ui_test_utils::ExecuteJavaScriptAndExtractBool(
        tab_contents->render_view_host(),
        std::wstring(), UTF8ToWide(script), result);
  }

  bool HasPreview() {
    return browser()->instant()->GetPreviewContents() != NULL;
  }

  // Returns the state of the search box as a string. This consists of the
  // following:
  // window.chrome.sv
  // window.onsubmitcalls
  // window.oncancelcalls
  // window.onchangecalls
  // 'true' if window.onresizecalls has been sent, otherwise false.
  // window.beforeLoadSearchBox.value
  // window.beforeLoadSearchBox.verbatim
  // window.chrome.searchBox.value
  // window.chrome.searchBox.verbatim
  // window.chrome.searchBox.selectionStart
  // window.chrome.searchBox.selectionEnd
  // If determining any of the values fails, the value is 'fail'.
  //
  // If |use_last| is true, then the last searchBox values are used instead of
  // the current. Set |use_last| to true when testing OnSubmit/OnCancel.
  std::string GetSearchStateAsString(TabContents* tab_contents,
                                     bool use_last) {
    bool sv = false;
    int onsubmitcalls = 0;
    int oncancelcalls = 0;
    int onchangecalls = 0;
    int onresizecalls = 0;
    int selection_start = 0;
    int selection_end = 0;
    std::string before_load_value;
    bool before_load_verbatim = false;
    std::string value;
    bool verbatim = false;

    if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) ||
        !GetIntFromJavascript(tab_contents, "window.onsubmitcalls",
                              &onsubmitcalls) ||
        !GetIntFromJavascript(tab_contents, "window.oncancelcalls",
                              &oncancelcalls) ||
        !GetIntFromJavascript(tab_contents, "window.onchangecalls",
                              &onchangecalls) ||
        !GetIntFromJavascript(tab_contents, "window.onresizecalls",
                              &onresizecalls) ||
        !GetStringFromJavascript(
            tab_contents, "window.beforeLoadSearchBox.value",
            &before_load_value) ||
        !GetBoolFromJavascript(
            tab_contents, "window.beforeLoadSearchBox.verbatim",
            &before_load_verbatim)) {
      return "fail";
    }

    if (use_last &&
        (!GetStringFromJavascript(tab_contents, "window.lastSearchBox.value",
                                  &value) ||
         !GetBoolFromJavascript(tab_contents, "window.lastSearchBox.verbatim",
                                &verbatim) ||
         !GetIntFromJavascript(tab_contents,
                               "window.lastSearchBox.selectionStart",
                               &selection_start) ||
         !GetIntFromJavascript(tab_contents,
                               "window.lastSearchBox.selectionEnd",
                               &selection_end))) {
      return "fail";
    }

    if (!use_last &&
        (!GetStringFromJavascript(tab_contents, "window.searchBox.value",
                                  &value) ||
         !GetBoolFromJavascript(tab_contents, "window.searchBox.verbatim",
                                &verbatim) ||
         !GetIntFromJavascript(tab_contents,
                               "window.searchBox.selectionStart",
                               &selection_start) ||
         !GetIntFromJavascript(tab_contents,
                               "window.searchBox.selectionEnd",
                               &selection_end))) {
      return "fail";
    }

    return StringPrintf("%s %d %d %d %s %s %s %s %s %d %d",
                        sv ? "true" : "false",
                        onsubmitcalls,
                        oncancelcalls,
                        onchangecalls,
                        onresizecalls ? "true" : "false",
                        before_load_value.c_str(),
                        before_load_verbatim ? "true" : "false",
                        value.c_str(),
                        verbatim ? "true" : "false",
                        selection_start,
                        selection_end);
  }

  void CheckStringValueFromJavascript(
      const std::string& expected,
      const std::string& function,
      TabContents* tab_contents) {
    std::string result;
    ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result));
    ASSERT_EQ(expected, result);
  }

  void CheckBoolValueFromJavascript(
      bool expected,
      const std::string& function,
      TabContents* tab_contents) {
    bool result;
    ASSERT_TRUE(GetBoolFromJavascript(tab_contents, function, &result));
    ASSERT_EQ(expected, result);
  }

  void CheckIntValueFromJavascript(
      int expected,
      const std::string& function,
      TabContents* tab_contents) {
    int result;
    ASSERT_TRUE(GetIntFromJavascript(tab_contents, function, &result));
    ASSERT_EQ(expected, result);
  }

  // Sends a message to the renderer and waits for the response to come back to
  // the browser.
  void WaitForMessageToBeProcessedByRenderer(TabContentsWrapper* tab) {
    ASSERT_NO_FATAL_FAILURE(
        CheckBoolValueFromJavascript(true, "true", tab->tab_contents()));
  }

 protected:
  LocationBar* location_bar_;
  TabContents* preview_;

  // ID of the default search engine's template_url (in the installed model).
  TemplateURLID template_url_id_;
};

// TODO(tonyg): Add the following tests:
// - Test that the search box API is not populated for pages other than the
//   default search provider.
// - Test resize events.

// Verify that the onchange event is dispatched upon typing in the box.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));

  ASSERT_EQ(ASCIIToUTF16("defghi"), location_bar_->location_entry()->GetText());

  // Make sure the url that will get committed when we press enter matches that
  // of the default search provider.
  const TemplateURL* default_turl =
      TemplateURLServiceFactory::GetForProfile(browser()->profile())->
      GetDefaultSearchProvider();
  ASSERT_TRUE(default_turl);
  ASSERT_TRUE(default_turl->url());
  EXPECT_EQ(default_turl->url()->ReplaceSearchTerms(
                *default_turl, ASCIIToUTF16("defghi"), 0, string16()),
            GetCurrentURL().spec());

  // Check that the value is reflected and onchange is called.
  EXPECT_EQ("true 0 0 1 true d false def false 3 3",
            GetSearchStateAsString(preview_, true));
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsArrayOfStrings) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(preview_, "['defgh', 'unused']");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("defgh", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptyArray) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(preview_, "[]");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsValidJson) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(
      preview_,
      "{suggestions:[{value:'defghij'},{value:'unused'}]}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("defghij", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsInvalidSuggestions) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(
      preview_,
      "{suggestions:{value:'defghi'}}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptyJson) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(preview_, "{}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptySuggestions) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(preview_, "{suggestions:[]}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SetSuggestionsEmptySuggestion) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(preview_, "{suggestions:[{}]}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("", GetSuggestion());
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ShowPreviewNonSearch) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  GURL url(test_server()->GetURL("files/instant/empty.html"));
  ASSERT_NO_FATAL_FAILURE(FindLocationBar());
  location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));

  // The preview should not be active or showing.
  ASSERT_FALSE(HasPreview());
  ASSERT_FALSE(browser()->instant()->is_displayable());
  ASSERT_FALSE(browser()->instant()->IsCurrent());
  ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents());
}

// Transition from non-search to search and make sure everything is shown
// correctly.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NonSearchToSearch) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  GURL url(test_server()->GetURL("files/instant/empty.html"));
  ASSERT_NO_FATAL_FAILURE(FindLocationBar());
  location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
  // The preview not should be active and not showing.
  ASSERT_FALSE(HasPreview());
  ASSERT_FALSE(browser()->instant()->is_displayable());
  ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents());

  // Now type in some search text.
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def"));

  // Wait for the preview to navigate.
  ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate());

  // The controller is still determining if the provider really supports
  // instant.
  TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents();
  ASSERT_TRUE(current_tab);

  // Instant should be active.
  EXPECT_TRUE(HasPreview());
  EXPECT_FALSE(browser()->instant()->is_displayable());

  // Because we're waiting on the page, instant isn't current.
  ASSERT_FALSE(browser()->instant()->IsCurrent());

  // Bounce a message to the renderer so that we know the instant has gotten a
  // response back from the renderer as to whether the page supports instant.
  ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));

  // Reset the user text so that the page is told the text changed. We should be
  // able to nuke this once 66104 is fixed.
  location_bar_->location_entry()->SetUserText(ASCIIToUTF16("defg"));

  // Wait for the renderer to process it.
  ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));

  // We should have gotten a response back from the renderer that resulted in
  // committing.
  ASSERT_TRUE(HasPreview());
  ASSERT_TRUE(browser()->instant()->is_displayable());
  TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents();
  ASSERT_TRUE(new_tab);
  RenderWidgetHostView* new_rwhv =
      new_tab->tab_contents()->GetRenderWidgetHostView();
  ASSERT_TRUE(new_rwhv);
  ASSERT_TRUE(new_rwhv->IsShowing());
}

// Transition from search to non-search and make sure instant isn't displayable.
// See bug http://crbug.com/100368 for details.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchToNonSearch) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  GURL url(test_server()->GetURL("files/instant/empty.html"));
  ASSERT_NO_FATAL_FAILURE(FindLocationBar());

  // Type in some search text.
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def"));

  // Load a non search url. Don't wait for the preview to navigate. It'll still
  // end up loading in the background.
  location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));

  // Wait for the preview to navigate.
  ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate());

  // Send onchange so that the page sends up suggestions.
  TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents();
  ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
      current_tab->tab_contents()->render_view_host(), std::wstring(),
      L"window.chrome.searchBox.onchange();"));
  ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));

  // Instant should be active, but not displaying
  EXPECT_TRUE(HasPreview());
  EXPECT_FALSE(browser()->instant()->is_displayable());
}

// Makes sure that if the server doesn't support the instant API we don't show
// anything.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
  ASSERT_NO_FATAL_FAILURE(FindLocationBar());

  ui_test_utils::WindowedNotificationObserver tab_closed_observer(
      content::NOTIFICATION_TAB_CLOSED,
      content::NotificationService::AllSources());

  location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
  ASSERT_TRUE(browser()->instant());
  // But because we're waiting to determine if the page really supports instant
  // we shouldn't be showing the preview.
  EXPECT_FALSE(browser()->instant()->is_displayable());
  // But instant should still be active.
  EXPECT_TRUE(HasPreview());

  // When the response comes back that the page doesn't support instant the tab
  // should be closed.
  tab_closed_observer.Wait();
  EXPECT_FALSE(browser()->instant()->is_displayable());
  EXPECT_FALSE(HasPreview());
  EXPECT_FALSE(browser()->instant()->IsCurrent());
}

// Verifies that Instant previews aren't shown for crash URLs.
IN_PROC_BROWSER_TEST_F(InstantTest, CrashUrlCancelsInstant) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
  ASSERT_NO_FATAL_FAILURE(FindLocationBar());
  location_bar_->location_entry()->SetUserText(ASCIIToUTF16("chrome://crash"));
  ASSERT_TRUE(browser()->instant());
  EXPECT_FALSE(browser()->instant()->is_displayable());
}

// Verifies transitioning from loading a non-search string to a search string
// with the provider not supporting instant works (meaning we don't display
// anything).
IN_PROC_BROWSER_TEST_F(InstantTest,
                       MAYBE_NonSearchToSearchDoesntSupportInstant) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
  GURL url(test_server()->GetURL("files/instant/empty.html"));
  ASSERT_NO_FATAL_FAILURE(FindLocationBar());
  location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
  // The preview should not be showing or active.
  EXPECT_FALSE(browser()->instant()->is_displayable());
  EXPECT_FALSE(HasPreview());

  ui_test_utils::WindowedNotificationObserver tab_closed_observer(
      content::NOTIFICATION_TAB_CLOSED,
      content::NotificationService::AllSources());

  // Now type in some search text.
  location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));

  // Instant should be active.
  ASSERT_TRUE(HasPreview());
  // Instant should not be current (it's still loading).
  EXPECT_FALSE(browser()->instant()->IsCurrent());

  // When the response comes back that the page doesn't support instant the tab
  // should be closed.
  tab_closed_observer.Wait();
  EXPECT_FALSE(browser()->instant()->is_displayable());
  EXPECT_FALSE(HasPreview());
  EXPECT_FALSE(browser()->instant()->IsCurrent());
  EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents());
}

// Verifies the page was told a non-zero height.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ValidHeight) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));

  int height;

  // searchBox height is not yet set during initial load.
  ASSERT_TRUE(GetIntFromJavascript(preview_,
      "window.beforeLoadSearchBox.height",
      &height));
  EXPECT_EQ(0, height);

  // searchBox height is available by the time the page loads.
  ASSERT_TRUE(GetIntFromJavascript(preview_,
      "window.chrome.searchBox.height",
      &height));
  EXPECT_GT(height, 0);
}

// Verify that the onsubmit event is dispatched upon pressing enter.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnSubmitEvent) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));

  ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));

  // Check that the preview contents have been committed.
  ASSERT_FALSE(browser()->instant()->GetPreviewContents());
  ASSERT_FALSE(HasPreview());
  TabContents* contents = browser()->GetSelectedTabContents();
  ASSERT_TRUE(contents);

  // We should have two entries. One corresponding to the page the user was
  // first on, and one for the search page.
  ASSERT_EQ(2, contents->controller().entry_count());

  // Check that the value is reflected and onsubmit is called.
  EXPECT_EQ("true 1 0 1 true d false defghi true 3 3",
            GetSearchStateAsString(preview_, true));

  // Make sure the searchbox values were reset.
  EXPECT_EQ("true 1 0 1 true d false  false 0 0",
            GetSearchStateAsString(preview_, false));
}

// Verify that the oncancel event is dispatched upon losing focus.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnCancelEvent) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));

  ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
                                                     VIEW_ID_TAB_CONTAINER));

  // Check that the preview contents has been committed.
  ASSERT_FALSE(browser()->instant()->GetPreviewContents());
  ASSERT_FALSE(HasPreview());
  TabContents* contents = browser()->GetSelectedTabContents();
  ASSERT_TRUE(contents);

  // Check that the value is reflected and oncancel is called.
  EXPECT_EQ("true 0 1 1 true d false def false 3 3",
            GetSearchStateAsString(preview_, true));

  // Make sure the searchbox values were reset.
  EXPECT_EQ("true 0 1 1 true d false  false 0 0",
            GetSearchStateAsString(preview_, false));
}

IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_InstantCompleteNever) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(
      preview_,
      "{suggestions:[{value:'defghij'}],complete_behavior:'never'}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("defghij", GetSuggestion());
  AutocompleteEditModel* edit_model = location_bar_->location_entry()->model();
  EXPECT_EQ(INSTANT_COMPLETE_NEVER, edit_model->instant_complete_behavior());
  ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText());
}

// DISABLED http://crbug.com/80118
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_InstantCompleteDelayed) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  SetSuggestionsJavascriptArgument(
      preview_,
      "{suggestions:[{value:'defghij'}],complete_behavior:'delayed'}");
  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  EXPECT_STR_EQ("defghij", GetSuggestion());
  AutocompleteEditModel* edit_model = location_bar_->location_entry()->model();
  EXPECT_EQ(INSTANT_COMPLETE_DELAYED, edit_model->instant_complete_behavior());
  ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText());
}

// Make sure the renderer doesn't crash if javascript is blocked.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontCrashOnBlockedJS) {
  browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
      CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
  ASSERT_TRUE(test_server()->Start());

  ui_test_utils::WindowedNotificationObserver instant_support_observer(
      chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
      content::NotificationService::AllSources());

  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  // Wait for notification that the instant API has been determined.
  instant_support_observer.Wait();
  // As long as we get the notification we're good (the renderer didn't crash).
}

// Makes sure window.chrome.searchbox doesn't persist when a new page is loaded.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontPersistSearchbox) {
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));

  ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
  ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
  ASSERT_NO_FATAL_FAILURE(SetupPreview());

  ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
  ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));

  // Check that the preview contents have been committed.
  ASSERT_FALSE(browser()->instant()->GetPreviewContents());
  ASSERT_FALSE(HasPreview());

  TabContents* contents = browser()->GetSelectedTabContents();
  ASSERT_TRUE(contents);

  // Navigate to a new URL. This should reset the searchbox values.
  ui_test_utils::NavigateToURL(
      browser(),
      GURL(test_server()->GetURL("files/instant/empty.html")));
  bool result;
  ASSERT_TRUE(GetBoolFromJavascript(
                  browser()->GetSelectedTabContents(),
                  "window.chrome.searchBox.value.length == 0",
                  &result));
  EXPECT_TRUE(result);
}

// Tests that instant search is preloaded whenever the omnibox gets focus.
IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_PreloadsInstant) {
  CommandLine::ForCurrentProcess()->AppendSwitch(
      switches::kPreloadInstantSearch);

  // The omnibox gets focus before the test begins. At that time, there's no
  // instant controller (which is only created after EnableInstant()), so no
  // preloading happens. Unfocus the omnibox with ClickOnView(), so that when
  // we focus it again, the controller will preload instant search.
  ASSERT_TRUE(test_server()->Start());
  EnableInstant();
  SetupInstantProvider("search.html");
  ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
  ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);

  // Verify that there is no previews contents.
  EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents());

  ui_test_utils::WindowedNotificationObserver instant_support_observer(
      chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
      content::NotificationService::AllSources());

  // Focusing the omnibox should cause instant to be preloaded.
  FindLocationBar();
  location_bar_->FocusLocation(false);
  TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
  EXPECT_TRUE(tab_contents);

  instant_support_observer.Wait();

  // Instant should have a preview, but not display it.
  EXPECT_TRUE(HasPreview());
  EXPECT_FALSE(browser()->instant()->is_displayable());

  // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper.
  AddBlankTabAndShow(browser());
  EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents());

  // Doing a search should still use the same loader for the preview.
  SetLocationBarText("def");
  EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents());

  // Verify that the preview is in fact showing instant search.
  EXPECT_TRUE(HasPreview());
  EXPECT_TRUE(browser()->instant()->is_displayable());
  EXPECT_TRUE(browser()->instant()->IsCurrent());
}

// Tests the INSTANT experiment of the field trial.
class InstantFieldTrialInstantTest : public InstantTest {
 public:
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
                                    switches::kInstantFieldTrialInstant);
  }
};

// Tests that instant is active, even without calling EnableInstant().
IN_PROC_BROWSER_TEST_F(InstantFieldTrialInstantTest, MAYBE_ExperimentEnabled) {
  // Check that instant is enabled, despite not setting the preference.
  Profile* profile = browser()->profile();
  EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
  EXPECT_TRUE(InstantController::IsEnabled(profile));

  ASSERT_TRUE(test_server()->Start());
  SetupInstantProvider("search.html");
  SetupLocationBar();
  SetupPreview();
  SetLocationBarText("def");

  // Check that instant is active and showing a preview.
  EXPECT_TRUE(HasPreview());
  EXPECT_TRUE(browser()->instant()->is_displayable());
  EXPECT_TRUE(browser()->instant()->IsCurrent());
}

// Tests the HIDDEN experiment of the field trial.
class InstantFieldTrialHiddenTest : public InstantTest {
 public:
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
                                    switches::kInstantFieldTrialHidden);
  }
};

// Tests that instant is active, even without calling EnableInstant().
IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_ExperimentEnabled) {
  // Check that instant is enabled, despite not setting the preference.
  Profile* profile = browser()->profile();
  EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
  EXPECT_TRUE(InstantController::IsEnabled(profile));

  ASSERT_TRUE(test_server()->Start());
  SetupInstantProvider("search.html");
  ui_test_utils::WindowedNotificationObserver instant_support_observer(
      chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
      content::NotificationService::AllSources());
  SetupLocationBar();
  WaitForPreviewToNavigate();
  instant_support_observer.Wait();

  // Type into the omnibox, but don't press <Enter> yet.
  location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));

  // Check that instant is active, but the preview is not showing.
  EXPECT_TRUE(HasPreview());
  EXPECT_FALSE(browser()->instant()->is_displayable());
  EXPECT_FALSE(browser()->instant()->IsCurrent());

  TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
  EXPECT_TRUE(tab_contents);

  // Press <Enter> in the omnibox, causing the preview to be committed.
  SendKey(ui::VKEY_RETURN);

  // The preview contents should now be the active tab contents.
  EXPECT_FALSE(browser()->instant()->GetPreviewContents());
  EXPECT_FALSE(HasPreview());
  EXPECT_FALSE(browser()->instant()->is_displayable());
  EXPECT_FALSE(browser()->instant()->IsCurrent());
  EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper());
}

// Tests the SearchToNonSearch scenario under the HIDDEN field trial.
IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_SearchToNonSearch) {
  ASSERT_TRUE(test_server()->Start());
  ui_test_utils::WindowedNotificationObserver instant_support_observer(
      chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
      content::NotificationService::AllSources());

  // Type in some search text.
  SetupInstantProvider("search.html");
  SetupLocationBar();

  // Load a non-search URL; don't wait for the preview to navigate.
  GURL url(test_server()->GetURL("files/instant/empty.html"));
  location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));

  // Wait for the preview to navigate.
  WaitForPreviewToNavigate();
  instant_support_observer.Wait();

  // Instant should be active, but not displayable or committable.
  EXPECT_TRUE(HasPreview());
  EXPECT_FALSE(browser()->instant()->is_displayable());
  EXPECT_FALSE(browser()->instant()->PrepareForCommit());
}