OLD | NEW |
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 #ifndef CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ |
6 #define CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.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" | 12 #include "googleurl/src/gurl.h" |
21 #include "net/test/test_server.h" | 13 #include "net/test/test_server.h" |
22 | 14 |
| 15 class Browser; |
23 class InstantController; | 16 class InstantController; |
24 class InstantModel; | 17 class InstantService; |
25 class OmniboxView; | 18 class OmniboxView; |
| 19 struct TemplateURLData; |
26 | 20 |
27 namespace content { | 21 namespace content { |
28 class WebContents; | 22 class WebContents; |
29 }; | 23 } |
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 | 24 |
50 // This utility class is meant to be used in a "mix-in" fashion, giving the | 25 // This utility class is meant to be used in a "mix-in" fashion, giving the |
51 // derived test class additional Instant-related functionality. | 26 // derived test class additional Instant-related functionality. |
52 class InstantTestBase { | 27 class InstantTestBase { |
53 protected: | 28 public: |
54 InstantTestBase() | 29 InstantTestBase(); |
55 : https_test_server_( | 30 virtual ~InstantTestBase(); |
56 net::TestServer::TYPE_HTTPS, | |
57 net::BaseTestServer::SSLOptions(), | |
58 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { | |
59 } | |
60 virtual ~InstantTestBase() {} | |
61 | 31 |
62 protected: | 32 // Accessors for common objects. These objects are meant for use by derived |
63 void SetupInstant(Browser* browser); | 33 // classes. InstantTestBase doesn't itself use them. |
64 void Init(const GURL& instant_url); | 34 net::TestServer* https_test_server() { return &https_test_server_; } |
| 35 const GURL& instant_url() const { return instant_url_; } |
| 36 void set_instant_url(const GURL& url) { instant_url_ = url; } |
65 | 37 |
66 InstantController* instant() { | 38 // Call this as soon as possible. It's used by many of the other methods in |
67 return browser_->instant_controller()->instant(); | 39 // this class, including SetupDefaultSearchProvider() and instant(). If you |
68 } | 40 // create a new browser window and want those other methods to point to it, |
| 41 // call set_browser() first with the new Browser object. |
| 42 void set_browser(Browser* browser) { browser_ = browser; } |
69 | 43 |
70 OmniboxView* omnibox() { | 44 // Initializes the user profile dir so that Instant is disabled. Returns true |
71 return browser_->window()->GetLocationBar()->GetLocationEntry(); | 45 // on success. Call this from InProcessBrowserTest::SetUpUserDataDirectory() |
72 } | 46 // to ensure that Instant doesn't try to activate on browser startup. To |
| 47 // re-enable Instant later, call SetupDefaultSearchProvider(). |
| 48 bool DisableInstantOnStartup(); |
73 | 49 |
74 const GURL& instant_url() const { return instant_url_; } | 50 // Sets up the default search engine. NOTE: |template_data| must have a valid |
| 51 // Instant URL for this to work. In particular, InstantTestBase doesn't fill |
| 52 // it in using |instant_url_|. |
| 53 void SetupDefaultSearchProvider(const TemplateURLData& template_data); |
75 | 54 |
76 net::TestServer& https_test_server() { return https_test_server_; } | 55 InstantService* service() const; |
77 | 56 InstantController* instant() const; |
78 void KillInstantRenderView(); | 57 OmniboxView* omnibox() const; |
79 | 58 |
80 void FocusOmnibox(); | 59 void FocusOmnibox(); |
| 60 void WaitForInstantSupport(); |
81 void FocusOmniboxAndWaitForInstantSupport(); | 61 void FocusOmniboxAndWaitForInstantSupport(); |
82 void FocusOmniboxAndWaitForInstantExtendedSupport(); | |
83 | 62 |
84 void SetOmniboxText(const std::string& text); | 63 void SetOmniboxText(const std::string& text); |
| 64 void WaitForOverlayToShow(); |
| 65 void WaitForOverlayToHide(); |
85 void SetOmniboxTextAndWaitForOverlayToShow(const std::string& text); | 66 void SetOmniboxTextAndWaitForOverlayToShow(const std::string& text); |
86 | 67 |
87 bool GetBoolFromJS(content::WebContents* contents, | 68 bool GetBoolFromJS(content::WebContents* contents, |
88 const std::string& script, | 69 const std::string& script, |
89 bool* result) WARN_UNUSED_RESULT; | 70 bool* result) WARN_UNUSED_RESULT; |
90 bool GetIntFromJS(content::WebContents* contents, | 71 bool GetIntFromJS(content::WebContents* contents, |
91 const std::string& script, | 72 const std::string& script, |
92 int* result) WARN_UNUSED_RESULT; | 73 int* result) WARN_UNUSED_RESULT; |
93 bool GetStringFromJS(content::WebContents* contents, | 74 bool GetStringFromJS(content::WebContents* contents, |
94 const std::string& script, | 75 const std::string& script, |
95 std::string* result) WARN_UNUSED_RESULT; | 76 std::string* result) WARN_UNUSED_RESULT; |
96 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT; | |
97 bool CheckVisibilityIs(content::WebContents* contents, | 77 bool CheckVisibilityIs(content::WebContents* contents, |
98 bool expected) WARN_UNUSED_RESULT; | 78 bool expected) WARN_UNUSED_RESULT; |
99 bool HasUserInputInProgress(); | |
100 bool HasTemporaryText(); | |
101 | 79 |
102 // Loads a named image from url |image| from the given |rvh| host. |loaded| | 80 void KillOverlayRenderView(); |
103 // returns whether the image was able to load without error. | 81 |
104 // The method returns true if the JavaScript executed cleanly. | 82 // Loads |image_url| in the context of |contents|. |loaded| contains whether |
105 bool LoadImage(content::RenderViewHost* rvh, | 83 // the image was able to load without error. The method returns true if the |
106 const std::string& image, | 84 // JavaScript executed cleanly. |
107 bool* loaded); | 85 bool LoadImage(content::WebContents* contents, |
| 86 const std::string& image_url, |
| 87 bool* loaded) WARN_UNUSED_RESULT; |
108 | 88 |
109 private: | 89 private: |
| 90 net::TestServer https_test_server_; |
110 GURL instant_url_; | 91 GURL instant_url_; |
111 | |
112 Browser* browser_; | 92 Browser* browser_; |
113 | 93 |
114 // HTTPS Testing server, started on demand. | |
115 net::TestServer https_test_server_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(InstantTestBase); | 94 DISALLOW_COPY_AND_ASSIGN(InstantTestBase); |
118 }; | 95 }; |
119 | 96 |
120 #endif // CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ | 97 #endif // CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ |
OLD | NEW |