OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ | |
6 #define CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/run_loop.h" | |
13 #include "chrome/browser/instant/instant_controller.h" | |
14 #include "chrome/browser/instant/instant_overlay_model_observer.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/omnibox/location_bar.h" | |
19 #include "chrome/common/search_types.h" | |
20 #include "googleurl/src/gurl.h" | |
21 #include "net/test/test_server.h" | |
22 | |
23 class InstantController; | |
24 class InstantModel; | |
25 class OmniboxView; | |
26 | |
27 namespace content { | |
28 class WebContents; | |
29 }; | |
30 | |
31 class InstantTestModelObserver : public InstantOverlayModelObserver { | |
32 public: | |
33 InstantTestModelObserver(InstantOverlayModel* model, | |
34 chrome::search::Mode::Type desired_mode_type); | |
35 ~InstantTestModelObserver(); | |
36 | |
37 void WaitForDesiredOverlayState(); | |
38 | |
39 // Overridden from InstantOverlayModelObserver: | |
40 virtual void OverlayStateChanged(const InstantOverlayModel& model) OVERRIDE; | |
41 | |
42 private: | |
43 InstantOverlayModel* const model_; | |
44 const chrome::search::Mode::Type desired_mode_type_; | |
45 base::RunLoop run_loop_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver); | |
48 }; | |
49 | |
50 // This utility class is meant to be used in a "mix-in" fashion, giving the | |
51 // derived test class additional Instant-related functionality. | |
52 class InstantTestBase { | |
53 protected: | |
54 InstantTestBase() | |
55 : https_test_server_( | |
56 net::TestServer::TYPE_HTTPS, | |
57 net::BaseTestServer::SSLOptions(), | |
58 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { | |
59 } | |
60 virtual ~InstantTestBase() {} | |
61 | |
62 protected: | |
63 void SetupInstant(Browser* browser); | |
64 void Init(const GURL& instant_url); | |
65 | |
66 void set_browser(Browser* browser) { | |
67 browser_ = browser; | |
68 } | |
69 | |
70 InstantController* instant() { | |
71 return browser_->instant_controller()->instant(); | |
72 } | |
73 | |
74 OmniboxView* omnibox() { | |
75 return browser_->window()->GetLocationBar()->GetLocationEntry(); | |
76 } | |
77 | |
78 const GURL& instant_url() const { return instant_url_; } | |
79 | |
80 net::TestServer& https_test_server() { return https_test_server_; } | |
81 | |
82 void KillInstantRenderView(); | |
83 | |
84 void FocusOmnibox(); | |
85 void FocusOmniboxAndWaitForInstantSupport(); | |
86 void FocusOmniboxAndWaitForInstantExtendedSupport(); | |
87 | |
88 void SetOmniboxText(const std::string& text); | |
89 void SetOmniboxTextAndWaitForOverlayToShow(const std::string& text); | |
90 void SetOmniboxTextAndWaitForSuggestion(const std::string& text); | |
91 | |
92 bool GetBoolFromJS(content::WebContents* contents, | |
93 const std::string& script, | |
94 bool* result) WARN_UNUSED_RESULT; | |
95 bool GetIntFromJS(content::WebContents* contents, | |
96 const std::string& script, | |
97 int* result) WARN_UNUSED_RESULT; | |
98 bool GetStringFromJS(content::WebContents* contents, | |
99 const std::string& script, | |
100 std::string* result) WARN_UNUSED_RESULT; | |
101 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT; | |
102 bool CheckVisibilityIs(content::WebContents* contents, | |
103 bool expected) WARN_UNUSED_RESULT; | |
104 bool HasUserInputInProgress(); | |
105 bool HasTemporaryText(); | |
106 | |
107 // Loads a named image from url |image| from the given |rvh| host. |loaded| | |
108 // returns whether the image was able to load without error. | |
109 // The method returns true if the JavaScript executed cleanly. | |
110 bool LoadImage(content::RenderViewHost* rvh, | |
111 const std::string& image, | |
112 bool* loaded); | |
113 | |
114 private: | |
115 GURL instant_url_; | |
116 | |
117 Browser* browser_; | |
118 | |
119 // HTTPS Testing server, started on demand. | |
120 net::TestServer https_test_server_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(InstantTestBase); | |
123 }; | |
124 | |
125 #endif // CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ | |
OLD | NEW |