Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: chrome/browser/instant/instant_test_utils.h

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/compiler_specific.h"
10 #include "base/run_loop.h" 12 #include "base/run_loop.h"
11 #include "chrome/browser/instant/instant_controller.h"
12 #include "chrome/browser/instant/instant_model_observer.h" 13 #include "chrome/browser/instant/instant_model_observer.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "googleurl/src/gurl.h"
14 #include "chrome/browser/ui/browser_instant_controller.h" 15 #include "net/test/test_server.h"
15 #include "chrome/browser/ui/browser_window.h" 16
16 #include "chrome/browser/ui/omnibox/location_bar.h" 17 class Browser;
17 #include "chrome/browser/ui/omnibox/omnibox_view.h" 18 class InstantController;
18 #include "chrome/common/search_types.h" 19 class InstantModel;
19 #include "chrome/test/base/in_process_browser_test.h" 20 class InstantService;
21 class OmniboxView;
22 struct TemplateURLData;
23
24 namespace content {
25 class WebContents;
26 }
20 27
21 class InstantTestModelObserver : public InstantModelObserver { 28 class InstantTestModelObserver : public InstantModelObserver {
22 public: 29 public:
23 InstantTestModelObserver(InstantModel* model, 30 InstantTestModelObserver(InstantController* controller,
24 chrome::search::Mode::Type desired_mode_type); 31 const InstantModel* desired_model);
25 ~InstantTestModelObserver(); 32 virtual ~InstantTestModelObserver();
26 33
27 void WaitUntilDesiredPreviewState(); 34 void WaitForDesiredOverlayState();
28
29 // Overridden from InstantModelObserver:
30 virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE;
31 35
32 private: 36 private:
33 InstantModel* const model_; 37 // Overridden from InstantModelObserver:
34 const chrome::search::Mode::Type desired_mode_type_; 38 virtual void OverlayStateChanged(const InstantModel& model) OVERRIDE;
39
40 InstantController* const controller_;
41 const InstantModel* const desired_model_;
35 base::RunLoop run_loop_; 42 base::RunLoop run_loop_;
36 43
37 DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver); 44 DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver);
38 }; 45 };
39 46
40 class InstantTestBase : public InProcessBrowserTest { 47 // This utility class is meant to be used in a "mix-in" fashion, giving the
48 // derived test class additional Instant-related functionality.
49 class InstantTestBase {
41 public: 50 public:
42 InstantTestBase() 51 InstantTestBase();
43 : https_test_server_( 52 virtual ~InstantTestBase();
44 net::TestServer::TYPE_HTTPS,
45 net::BaseTestServer::SSLOptions(),
46 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
47 }
48 53
49 protected: 54 // Accessors for common objects. These objects are meant for use by derived
50 void SetupInstant(); 55 // classes. InstantTestBase doesn't itself use them.
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; }
59 void set_browser(Browser* browser) { browser_ = browser; }
51 60
52 InstantController* instant() { 61 // Initializes the user profile dir so that Instant is disabled. Returns true
53 return browser()->instant_controller()->instant(); 62 // on success. Call this from InProcessBrowserTest::SetUpUserDataDirectory()
54 } 63 // to ensure that Instant doesn't try to activate on browser startup. To
64 // re-enable Instant later, call SetupDefaultSearchProvider().
65 bool DisableInstantOnStartup();
55 66
56 OmniboxView* omnibox() { 67 // Sets up the default search engine. NOTE: |template_data| must have a valid
57 return browser()->window()->GetLocationBar()->GetLocationEntry(); 68 // Instant URL for this to work. In particular, InstantTestBase doesn't fill
58 } 69 // it in using |instant_url_|.
70 void SetupDefaultSearchProvider(const TemplateURLData& template_data);
59 71
60 void KillInstantRenderView(); 72 InstantService* service() const;
73 InstantController* instant() const;
74 OmniboxView* omnibox() const;
61 75
62 void FocusOmnibox(); 76 void FocusOmnibox();
63 void FocusOmniboxAndWaitForInstantSupport(); 77 void FocusOmniboxAndWaitForInstantSupport();
64 78
65 void SetOmniboxText(const std::string& text); 79 void SetOmniboxText(const std::string& text);
66 void SetOmniboxTextAndWaitForInstantToShow(const std::string& text); 80 void SetOmniboxTextAndWaitForOverlayToShow(const std::string& text);
67 81
68 bool GetBoolFromJS(content::WebContents* contents, 82 bool GetBoolFromJS(content::WebContents* contents,
69 const std::string& script, 83 const std::string& script,
70 bool* result) WARN_UNUSED_RESULT; 84 bool* result) WARN_UNUSED_RESULT;
71 bool GetIntFromJS(content::WebContents* contents, 85 bool GetIntFromJS(content::WebContents* contents,
72 const std::string& script, 86 const std::string& script,
73 int* result) WARN_UNUSED_RESULT; 87 int* result) WARN_UNUSED_RESULT;
74 bool GetStringFromJS(content::WebContents* contents, 88 bool GetStringFromJS(content::WebContents* contents,
75 const std::string& script, 89 const std::string& script,
76 std::string* result) WARN_UNUSED_RESULT; 90 std::string* result) WARN_UNUSED_RESULT;
77 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT;
78 bool CheckVisibilityIs(content::WebContents* contents, 91 bool CheckVisibilityIs(content::WebContents* contents,
79 bool expected) WARN_UNUSED_RESULT; 92 bool expected) WARN_UNUSED_RESULT;
80 bool HasUserInputInProgress();
81 bool HasTemporaryText();
82 93
94 void KillOverlayRenderView();
95
96 private:
97 net::TestServer https_test_server_;
83 GURL instant_url_; 98 GURL instant_url_;
99 Browser* browser_;
84 100
85 // HTTPS Testing server, started on demand. 101 DISALLOW_COPY_AND_ASSIGN(InstantTestBase);
86 net::TestServer https_test_server_;
87 }; 102 };
88 103
89 #endif // CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ 104 #endif // CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698