Support SizeClassIdiom on iOS7.
[chromium-blink-merge.git] / chrome / browser / ui / search / instant_test_utils.h
blob1a63cc6847495ab4ca0e7e402ae3b592e35a38c8
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_
6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/metrics/field_trial.h"
13 #include "base/run_loop.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_instant_controller.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/location_bar/location_bar.h"
19 #include "chrome/browser/ui/search/instant_controller.h"
20 #include "chrome/common/search_types.h"
21 #include "net/test/spawned_test_server/spawned_test_server.h"
22 #include "url/gurl.h"
24 class BrowserInstantController;
25 class InstantController;
26 class InstantModel;
27 class OmniboxView;
29 namespace content {
30 class WebContents;
33 // This utility class is meant to be used in a "mix-in" fashion, giving the
34 // derived test class additional Instant-related functionality.
35 class InstantTestBase {
36 protected:
37 InstantTestBase();
38 virtual ~InstantTestBase();
40 protected:
41 void SetupInstant(Browser* browser);
42 void Init(const GURL& instant_url, const GURL& ntp_url,
43 bool init_suggestions_url);
45 void SetInstantURL(const std::string& url);
47 void set_browser(Browser* browser) {
48 browser_ = browser;
51 BrowserInstantController* browser_instant() {
52 return browser_->instant_controller();
55 InstantController* instant() {
56 return browser_->instant_controller()->instant();
59 OmniboxView* omnibox() {
60 return browser_->window()->GetLocationBar()->GetOmniboxView();
63 const GURL& instant_url() const { return instant_url_; }
65 const GURL& ntp_url() const { return ntp_url_; }
67 net::SpawnedTestServer& https_test_server() { return https_test_server_; }
69 void KillInstantRenderView();
71 void FocusOmnibox();
73 void SetOmniboxText(const std::string& text);
75 void PressEnterAndWaitForNavigation();
76 void PressEnterAndWaitForFrameLoad();
78 bool GetBoolFromJS(content::WebContents* contents,
79 const std::string& script,
80 bool* result) WARN_UNUSED_RESULT;
81 bool GetIntFromJS(content::WebContents* contents,
82 const std::string& script,
83 int* result) WARN_UNUSED_RESULT;
84 bool GetStringFromJS(content::WebContents* contents,
85 const std::string& script,
86 std::string* result) WARN_UNUSED_RESULT;
87 bool CheckVisibilityIs(content::WebContents* contents,
88 bool expected) WARN_UNUSED_RESULT;
90 std::string GetOmniboxText();
92 // Loads a named image from url |image| from the given |rvh| host. |loaded|
93 // returns whether the image was able to load without error.
94 // The method returns true if the JavaScript executed cleanly.
95 bool LoadImage(content::RenderViewHost* rvh,
96 const std::string& image,
97 bool* loaded);
99 // Returns the omnibox's inline autocompletion (shown in blue highlight).
100 base::string16 GetBlueText();
102 private:
103 GURL instant_url_;
104 GURL ntp_url_;
106 Browser* browser_;
108 // HTTPS Testing server, started on demand.
109 net::SpawnedTestServer https_test_server_;
111 // Set to true to initialize suggestions URL in default search provider.
112 bool init_suggestions_url_;
114 DISALLOW_COPY_AND_ASSIGN(InstantTestBase);
117 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_