| 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_UI_SEARCH_INSTANT_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_ |
| 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_instant_controller.h" | |
| 13 #include "chrome/browser/ui/browser_window.h" | |
| 14 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 15 #include "chrome/browser/ui/search/instant_controller.h" | |
| 16 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 17 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 18 #include "url/gurl.h" | |
| 19 | 12 |
| 20 class OmniboxView; | 13 namespace instant_test_utils { |
| 21 | 14 |
| 22 // This utility class is meant to be used in a "mix-in" fashion, giving the | 15 bool GetBoolFromJS(const content::ToRenderFrameHost& adapter, |
| 23 // derived test class additional Instant-related functionality. | 16 const std::string& script, |
| 24 class InstantTestBase { | 17 bool* result) WARN_UNUSED_RESULT; |
| 25 protected: | 18 bool GetIntFromJS(const content::ToRenderFrameHost& adapter, |
| 26 InstantTestBase(); | 19 const std::string& script, |
| 27 virtual ~InstantTestBase(); | 20 int* result) WARN_UNUSED_RESULT; |
| 21 bool GetDoubleFromJS(const content::ToRenderFrameHost& adapter, |
| 22 const std::string& script, |
| 23 double* result) WARN_UNUSED_RESULT; |
| 24 bool GetStringFromJS(const content::ToRenderFrameHost& adapter, |
| 25 const std::string& script, |
| 26 std::string* result) WARN_UNUSED_RESULT; |
| 28 | 27 |
| 29 protected: | 28 } // namespace instant_test_utils |
| 30 void SetupInstant(Browser* browser); | |
| 31 void Init(const GURL& instant_url, const GURL& ntp_url, | |
| 32 bool init_suggestions_url); | |
| 33 | |
| 34 void set_browser(Browser* browser) { | |
| 35 browser_ = browser; | |
| 36 } | |
| 37 | |
| 38 OmniboxView* omnibox() { | |
| 39 return browser_->window()->GetLocationBar()->GetOmniboxView(); | |
| 40 } | |
| 41 | |
| 42 const GURL& instant_url() const { return instant_url_; } | |
| 43 | |
| 44 const GURL& ntp_url() const { return ntp_url_; } | |
| 45 | |
| 46 net::EmbeddedTestServer& https_test_server() { return https_test_server_; } | |
| 47 | |
| 48 void FocusOmnibox(); | |
| 49 | |
| 50 void SetOmniboxText(const std::string& text); | |
| 51 | |
| 52 void PressEnterAndWaitForNavigation(); | |
| 53 void PressEnterAndWaitForFrameLoad(); | |
| 54 | |
| 55 bool GetBoolFromJS(const content::ToRenderFrameHost& adapter, | |
| 56 const std::string& script, | |
| 57 bool* result) WARN_UNUSED_RESULT; | |
| 58 bool GetIntFromJS(const content::ToRenderFrameHost& adapter, | |
| 59 const std::string& script, | |
| 60 int* result) WARN_UNUSED_RESULT; | |
| 61 bool GetDoubleFromJS(const content::ToRenderFrameHost& adapter, | |
| 62 const std::string& script, | |
| 63 double* result) WARN_UNUSED_RESULT; | |
| 64 bool GetStringFromJS(const content::ToRenderFrameHost& adapter, | |
| 65 const std::string& script, | |
| 66 std::string* result) WARN_UNUSED_RESULT; | |
| 67 | |
| 68 std::string GetOmniboxText(); | |
| 69 | |
| 70 // Loads a named image from url |image| from the given |rvh| host. |loaded| | |
| 71 // returns whether the image was able to load without error. | |
| 72 // The method returns true if the JavaScript executed cleanly. | |
| 73 bool LoadImage(content::RenderViewHost* rvh, | |
| 74 const std::string& image, | |
| 75 bool* loaded); | |
| 76 | |
| 77 private: | |
| 78 GURL instant_url_; | |
| 79 GURL ntp_url_; | |
| 80 | |
| 81 Browser* browser_; | |
| 82 | |
| 83 // HTTPS Testing server, started on demand. | |
| 84 net::EmbeddedTestServer https_test_server_; | |
| 85 | |
| 86 // Set to true to initialize suggestions URL in default search provider. | |
| 87 bool init_suggestions_url_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(InstantTestBase); | |
| 90 }; | |
| 91 | 29 |
| 92 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_ | 30 #endif // CHROME_BROWSER_UI_SEARCH_INSTANT_TEST_UTILS_H_ |
| OLD | NEW |