| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/instant/instant_controller.h" | 10 #include "chrome/browser/instant/instant_controller.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
| 34 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 36 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 39 #include "content/public/test/browser_test_utils.h" |
| 39 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 41 | 42 |
| 42 using content::WebContents; | 43 using content::WebContents; |
| 43 | 44 |
| 44 // Tests are flaky on Linux because of http://crbug.com/80118. | 45 // Tests are flaky on Linux because of http://crbug.com/80118. |
| 45 #if defined(OS_LINUX) && !defined(USE_ASH) | 46 #if defined(OS_LINUX) && !defined(USE_ASH) |
| 46 #define MAYBE(TestName) DISABLED_ ## TestName | 47 #define MAYBE(TestName) DISABLED_ ## TestName |
| 47 #elif defined(OS_WIN) | 48 #elif defined(OS_WIN) |
| 48 #define MAYBE(TestName) FLAKY_ ## TestName | 49 #define MAYBE(TestName) FLAKY_ ## TestName |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 bool PressEnter() { | 136 bool PressEnter() { |
| 136 return ui_test_utils::SendKeyPressSync( | 137 return ui_test_utils::SendKeyPressSync( |
| 137 browser(), ui::VKEY_RETURN, false, false, false, false); | 138 browser(), ui::VKEY_RETURN, false, false, false, false); |
| 138 } | 139 } |
| 139 | 140 |
| 140 bool SetSuggestionsJavascriptArgument(const std::string& argument) { | 141 bool SetSuggestionsJavascriptArgument(const std::string& argument) { |
| 141 std::wstring script = UTF8ToWide(base::StringPrintf( | 142 std::wstring script = UTF8ToWide(base::StringPrintf( |
| 142 "window.setSuggestionsArgument = %s;", argument.c_str())); | 143 "window.setSuggestionsArgument = %s;", argument.c_str())); |
| 143 content::RenderViewHost* rvh = | 144 content::RenderViewHost* rvh = |
| 144 preview()->web_contents()->GetRenderViewHost(); | 145 preview()->web_contents()->GetRenderViewHost(); |
| 145 return ui_test_utils::ExecuteJavaScript(rvh, std::wstring(), script); | 146 return content::ExecuteJavaScript(rvh, std::wstring(), script); |
| 146 } | 147 } |
| 147 | 148 |
| 148 std::wstring WrapScript(const std::string& script) { | 149 std::wstring WrapScript(const std::string& script) { |
| 149 return UTF8ToWide(base::StringPrintf( | 150 return UTF8ToWide(base::StringPrintf( |
| 150 "window.domAutomationController.send(%s)", script.c_str())); | 151 "window.domAutomationController.send(%s)", script.c_str())); |
| 151 } | 152 } |
| 152 | 153 |
| 153 bool GetStringFromJavascript(WebContents* tab, | 154 bool GetStringFromJavascript(WebContents* tab, |
| 154 const std::string& script, | 155 const std::string& script, |
| 155 std::string* result) { | 156 std::string* result) { |
| 156 return ui_test_utils::ExecuteJavaScriptAndExtractString( | 157 return content::ExecuteJavaScriptAndExtractString( |
| 157 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); | 158 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); |
| 158 } | 159 } |
| 159 | 160 |
| 160 bool GetIntFromJavascript(WebContents* tab, | 161 bool GetIntFromJavascript(WebContents* tab, |
| 161 const std::string& script, | 162 const std::string& script, |
| 162 int* result) { | 163 int* result) { |
| 163 return ui_test_utils::ExecuteJavaScriptAndExtractInt( | 164 return content::ExecuteJavaScriptAndExtractInt( |
| 164 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); | 165 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool GetBoolFromJavascript(WebContents* tab, | 168 bool GetBoolFromJavascript(WebContents* tab, |
| 168 const std::string& script, | 169 const std::string& script, |
| 169 bool* result) { | 170 bool* result) { |
| 170 return ui_test_utils::ExecuteJavaScriptAndExtractBool( | 171 return content::ExecuteJavaScriptAndExtractBool( |
| 171 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); | 172 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); |
| 172 } | 173 } |
| 173 | 174 |
| 174 bool CheckVisibilityIs(WebContents* tab, bool visible) { | 175 bool CheckVisibilityIs(WebContents* tab, bool visible) { |
| 175 bool hidden = visible; | 176 bool hidden = visible; |
| 176 return GetBoolFromJavascript(tab, "document.webkitHidden", &hidden) && | 177 return GetBoolFromJavascript(tab, "document.webkitHidden", &hidden) && |
| 177 hidden != visible; | 178 hidden != visible; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Returns the state of the search box as a string. This consists of the | 181 // Returns the state of the search box as a string. This consists of the |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 instant_support_observer.Wait(); | 604 instant_support_observer.Wait(); |
| 604 | 605 |
| 605 // We should now have a preview, but it shouldn't be showing yet. | 606 // We should now have a preview, but it shouldn't be showing yet. |
| 606 EXPECT_TRUE(preview()); | 607 EXPECT_TRUE(preview()); |
| 607 EXPECT_FALSE(loader()->ready()); | 608 EXPECT_FALSE(loader()->ready()); |
| 608 EXPECT_FALSE(instant()->is_displayable()); | 609 EXPECT_FALSE(instant()->is_displayable()); |
| 609 EXPECT_FALSE(instant()->IsCurrent()); | 610 EXPECT_FALSE(instant()->IsCurrent()); |
| 610 | 611 |
| 611 // Send onchange so that the page sends up suggestions. See the comments in | 612 // Send onchange so that the page sends up suggestions. See the comments in |
| 612 // NonSearchToSearch for why this is needed. | 613 // NonSearchToSearch for why this is needed. |
| 613 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 614 ASSERT_TRUE(content::ExecuteJavaScript( |
| 614 preview()->web_contents()->GetRenderViewHost(), std::wstring(), | 615 preview()->web_contents()->GetRenderViewHost(), std::wstring(), |
| 615 L"window.chrome.searchBox.onchange();")); | 616 L"window.chrome.searchBox.onchange();")); |
| 616 ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); | 617 ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); |
| 617 | 618 |
| 618 // Instant should be active, but not displaying. | 619 // Instant should be active, but not displaying. |
| 619 EXPECT_TRUE(preview()); | 620 EXPECT_TRUE(preview()); |
| 620 EXPECT_TRUE(loader()->ready()); | 621 EXPECT_TRUE(loader()->ready()); |
| 621 EXPECT_FALSE(instant()->is_displayable()); | 622 EXPECT_FALSE(instant()->is_displayable()); |
| 622 EXPECT_FALSE(instant()->IsCurrent()); | 623 EXPECT_FALSE(instant()->IsCurrent()); |
| 623 } | 624 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 DetermineInstantSupport(); | 836 DetermineInstantSupport(); |
| 836 SearchAndWaitForPreviewToShow(); | 837 SearchAndWaitForPreviewToShow(); |
| 837 | 838 |
| 838 // Now there should be three rows, the third being the instant preview. | 839 // Now there should be three rows, the third being the instant preview. |
| 839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 840 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 840 string16 prefix = l10n_util::GetStringFUTF16( | 841 string16 prefix = l10n_util::GetStringFUTF16( |
| 841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 842 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
| 842 string16 title = task_manager->GetResourceTitle(2); | 843 string16 title = task_manager->GetResourceTitle(2); |
| 843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 844 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
| 844 } | 845 } |
| OLD | NEW |