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