| 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 #include "chrome/browser/instant/instant_test_utils.h" | 5 #include "chrome/browser/instant/instant_test_utils.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | |
| 13 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/interactive_test_utils.h" | 14 #include "chrome/test/base/interactive_test_utils.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/notification_service.h" | |
| 18 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/result_codes.h" | 18 #include "content/public/common/result_codes.h" |
| 21 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 22 | 20 |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| 25 std::string WrapScript(const std::string& script) { | 23 std::string WrapScript(const std::string& script) { |
| 26 return "domAutomationController.send(" + script + ")"; | 24 return "domAutomationController.send(" + script + ")"; |
| 27 } | 25 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void InstantTestBase::FocusOmnibox() { | 86 void InstantTestBase::FocusOmnibox() { |
| 89 // If the omnibox already has focus, just notify Instant. | 87 // If the omnibox already has focus, just notify Instant. |
| 90 if (omnibox()->model()->has_focus()) { | 88 if (omnibox()->model()->has_focus()) { |
| 91 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, | 89 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, |
| 92 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); | 90 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); |
| 93 } else { | 91 } else { |
| 94 browser()->window()->GetLocationBar()->FocusLocation(false); | 92 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 95 } | 93 } |
| 96 } | 94 } |
| 97 | 95 |
| 98 void InstantTestBase::FocusOmniboxAndWaitForInstantSupport() { | |
| 99 content::WindowedNotificationObserver observer( | |
| 100 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | |
| 101 content::NotificationService::AllSources()); | |
| 102 FocusOmnibox(); | |
| 103 observer.Wait(); | |
| 104 } | |
| 105 | |
| 106 void InstantTestBase::SetOmniboxText(const std::string& text) { | 96 void InstantTestBase::SetOmniboxText(const std::string& text) { |
| 107 FocusOmnibox(); | 97 FocusOmnibox(); |
| 108 omnibox()->SetUserText(UTF8ToUTF16(text)); | 98 omnibox()->SetUserText(UTF8ToUTF16(text)); |
| 109 } | 99 } |
| 110 | 100 |
| 111 void InstantTestBase::SetOmniboxTextAndWaitForInstantToShow( | 101 void InstantTestBase::SetOmniboxTextAndWaitForInstantToShow( |
| 112 const std::string& text) { | 102 const std::string& text) { |
| 113 InstantTestModelObserver observer( | 103 InstantTestModelObserver observer( |
| 114 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); | 104 instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); |
| 115 SetOmniboxText(text); | 105 SetOmniboxText(text); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 142 } | 132 } |
| 143 | 133 |
| 144 bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents, | 134 bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents, |
| 145 bool expected) { | 135 bool expected) { |
| 146 bool actual = !expected; // Purposely start with a mis-match. | 136 bool actual = !expected; // Purposely start with a mis-match. |
| 147 // We can only use ASSERT_*() in a method that returns void, hence this | 137 // We can only use ASSERT_*() in a method that returns void, hence this |
| 148 // convoluted check. | 138 // convoluted check. |
| 149 return GetBoolFromJS(contents, "!document.webkitHidden", &actual) && | 139 return GetBoolFromJS(contents, "!document.webkitHidden", &actual) && |
| 150 actual == expected; | 140 actual == expected; |
| 151 } | 141 } |
| OLD | NEW |