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

Side by Side Diff: chrome/browser/ui/search/instant_extended_interactive_uitest.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. Created 5 years, 1 month 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
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 #include <sstream> 5 #include <sstream>
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram_base.h" 9 #include "base/metrics/histogram_base.h"
10 #include "base/metrics/histogram_samples.h" 10 #include "base/metrics/histogram_samples.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "content/public/browser/render_process_host.h" 66 #include "content/public/browser/render_process_host.h"
67 #include "content/public/browser/render_view_host.h" 67 #include "content/public/browser/render_view_host.h"
68 #include "content/public/browser/site_instance.h" 68 #include "content/public/browser/site_instance.h"
69 #include "content/public/browser/url_data_source.h" 69 #include "content/public/browser/url_data_source.h"
70 #include "content/public/browser/web_contents.h" 70 #include "content/public/browser/web_contents.h"
71 #include "content/public/common/bindings_policy.h" 71 #include "content/public/common/bindings_policy.h"
72 #include "content/public/test/browser_test_utils.h" 72 #include "content/public/test/browser_test_utils.h"
73 #include "content/public/test/test_utils.h" 73 #include "content/public/test/test_utils.h"
74 #include "net/base/network_change_notifier.h" 74 #include "net/base/network_change_notifier.h"
75 #include "net/http/http_status_code.h" 75 #include "net/http/http_status_code.h"
76 #include "net/test/embedded_test_server/embedded_test_server.h"
76 #include "net/url_request/test_url_fetcher_factory.h" 77 #include "net/url_request/test_url_fetcher_factory.h"
77 #include "net/url_request/url_fetcher_impl.h" 78 #include "net/url_request/url_fetcher_impl.h"
78 #include "net/url_request/url_request_status.h" 79 #include "net/url_request/url_request_status.h"
79 #include "testing/gmock/include/gmock/gmock.h" 80 #include "testing/gmock/include/gmock/gmock.h"
80 #include "third_party/skia/include/core/SkBitmap.h" 81 #include "third_party/skia/include/core/SkBitmap.h"
81 82
82 using base::ASCIIToUTF16; 83 using base::ASCIIToUTF16;
83 using testing::HasSubstr; 84 using testing::HasSubstr;
84 85
85 namespace { 86 namespace {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 submit_count_(0), 140 submit_count_(0),
140 on_esc_key_press_event_calls_(0), 141 on_esc_key_press_event_calls_(0),
141 on_focus_changed_calls_(0), 142 on_focus_changed_calls_(0),
142 is_focused_(false), 143 is_focused_(false),
143 on_toggle_voice_search_calls_(0) { 144 on_toggle_voice_search_calls_(0) {
144 } 145 }
145 protected: 146 protected:
146 void SetUpInProcessBrowserTestFixture() override { 147 void SetUpInProcessBrowserTestFixture() override {
147 search::EnableQueryExtractionForTesting(); 148 search::EnableQueryExtractionForTesting();
148 ASSERT_TRUE(https_test_server().Start()); 149 ASSERT_TRUE(https_test_server().Start());
149 GURL instant_url = https_test_server().GetURL( 150 GURL instant_url =
150 "files/instant_extended.html?strk=1&"); 151 https_test_server().GetURL("/instant_extended.html?strk=1&");
151 GURL ntp_url = https_test_server().GetURL( 152 GURL ntp_url =
152 "files/instant_extended_ntp.html?strk=1&"); 153 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&");
153 InstantTestBase::Init(instant_url, ntp_url, false); 154 InstantTestBase::Init(instant_url, ntp_url, false);
154 } 155 }
155 156
156 int64 GetHistogramCount(const char* name) { 157 int64 GetHistogramCount(const char* name) {
157 base::HistogramBase* histogram = 158 base::HistogramBase* histogram =
158 base::StatisticsRecorder::FindHistogram(name); 159 base::StatisticsRecorder::FindHistogram(name);
159 if (!histogram) { 160 if (!histogram) {
160 // If no histogram is found, it's possible that no values have been 161 // If no histogram is found, it's possible that no values have been
161 // recorded yet. Assume that the value is zero. 162 // recorded yet. Assume that the value is zero.
162 return 0; 163 return 0;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 class InstantExtendedPrefetchTest : public InstantExtendedTest { 255 class InstantExtendedPrefetchTest : public InstantExtendedTest {
255 public: 256 public:
256 InstantExtendedPrefetchTest() 257 InstantExtendedPrefetchTest()
257 : factory_(new net::URLFetcherImplFactory()), 258 : factory_(new net::URLFetcherImplFactory()),
258 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) { 259 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) {
259 } 260 }
260 261
261 void SetUpInProcessBrowserTestFixture() override { 262 void SetUpInProcessBrowserTestFixture() override {
262 search::EnableQueryExtractionForTesting(); 263 search::EnableQueryExtractionForTesting();
263 ASSERT_TRUE(https_test_server().Start()); 264 ASSERT_TRUE(https_test_server().Start());
264 GURL instant_url = https_test_server().GetURL( 265 GURL instant_url =
265 "files/instant_extended.html?strk=1&"); 266 https_test_server().GetURL("/instant_extended.html?strk=1&");
266 GURL ntp_url = https_test_server().GetURL( 267 GURL ntp_url =
267 "files/instant_extended_ntp.html?strk=1&"); 268 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&");
268 InstantTestBase::Init(instant_url, ntp_url, true); 269 InstantTestBase::Init(instant_url, ntp_url, true);
269 } 270 }
270 271
271 void SetUpCommandLine(base::CommandLine* command_line) override { 272 void SetUpCommandLine(base::CommandLine* command_line) override {
272 command_line->AppendSwitchASCII( 273 command_line->AppendSwitchASCII(
273 switches::kForceFieldTrials, 274 switches::kForceFieldTrials,
274 "EmbeddedSearch/Group11 prefetch_results_srp:1/"); 275 "EmbeddedSearch/Group11 prefetch_results_srp:1/");
275 } 276 }
276 277
277 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); } 278 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // Test class used to verify chrome-search: scheme and access policy from the 313 // Test class used to verify chrome-search: scheme and access policy from the
313 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it 314 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it
314 // loads a theme that provides a background image. 315 // loads a theme that provides a background image.
315 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { 316 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase {
316 public: 317 public:
317 InstantPolicyTest() {} 318 InstantPolicyTest() {}
318 319
319 protected: 320 protected:
320 void SetUpInProcessBrowserTestFixture() override { 321 void SetUpInProcessBrowserTestFixture() override {
321 ASSERT_TRUE(https_test_server().Start()); 322 ASSERT_TRUE(https_test_server().Start());
322 GURL instant_url = https_test_server().GetURL( 323 GURL instant_url =
323 "files/instant_extended.html?strk=1&"); 324 https_test_server().GetURL("/instant_extended.html?strk=1&");
324 GURL ntp_url = https_test_server().GetURL( 325 GURL ntp_url =
325 "files/instant_extended_ntp.html?strk=1&"); 326 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&");
326 InstantTestBase::Init(instant_url, ntp_url, false); 327 InstantTestBase::Init(instant_url, ntp_url, false);
327 } 328 }
328 329
329 void InstallThemeSource() { 330 void InstallThemeSource() {
330 ThemeSource* theme = new ThemeSource(profile()); 331 ThemeSource* theme = new ThemeSource(profile());
331 content::URLDataSource::Add(profile(), theme); 332 content::URLDataSource::Add(profile(), theme);
332 } 333 }
333 334
334 void InstallThemeAndVerify(const std::string& theme_dir, 335 void InstallThemeAndVerify(const std::string& theme_dir,
335 const std::string& theme_name) { 336 const std::string& theme_name) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 omnibox()->ShowURL(); 981 omnibox()->ShowURL();
981 EXPECT_FALSE(browser()->toolbar_model()->WouldPerformSearchTermReplacement( 982 EXPECT_FALSE(browser()->toolbar_model()->WouldPerformSearchTermReplacement(
982 false)); 983 false));
983 // Don't bother looking for a specific URL; ensuring we're no longer showing 984 // Don't bother looking for a specific URL; ensuring we're no longer showing
984 // the search terms is sufficient. 985 // the search terms is sufficient.
985 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText()); 986 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText());
986 } 987 }
987 988
988 // Check that clicking on a result sends the correct referrer. 989 // Check that clicking on a result sends the correct referrer.
989 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { 990 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) {
990 ASSERT_TRUE(test_server()->Start()); 991 ASSERT_TRUE(embedded_test_server()->Start());
991 GURL result_url = 992 GURL result_url = embedded_test_server()->GetURL(
992 test_server()->GetURL("files/referrer_policy/referrer-policy-log.html"); 993 "/referrer_policy/referrer-policy-log.html");
993 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 994 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
994 FocusOmnibox(); 995 FocusOmnibox();
995 996
996 // Type a query and press enter to get results. 997 // Type a query and press enter to get results.
997 SetOmniboxText("query"); 998 SetOmniboxText("query");
998 PressEnterAndWaitForFrameLoad(); 999 PressEnterAndWaitForFrameLoad();
999 1000
1000 // Simulate going to a result. 1001 // Simulate going to a result.
1001 content::WebContents* contents = 1002 content::WebContents* contents =
1002 browser()->tab_strip_model()->GetActiveWebContents(); 1003 browser()->tab_strip_model()->GetActiveWebContents();
1003 std::ostringstream stream; 1004 std::ostringstream stream;
1004 stream << "var link = document.createElement('a');"; 1005 stream << "var link = document.createElement('a');";
1005 stream << "link.href = \"" << result_url.spec() << "\";"; 1006 stream << "link.href = \"" << result_url.spec() << "\";";
1006 stream << "document.body.appendChild(link);"; 1007 stream << "document.body.appendChild(link);";
1007 stream << "link.click();"; 1008 stream << "link.click();";
1008 EXPECT_TRUE(content::ExecuteScript(contents, stream.str())); 1009 EXPECT_TRUE(content::ExecuteScript(contents, stream.str()));
1009 1010
1010 content::WaitForLoadStop(contents); 1011 content::WaitForLoadStop(contents);
1011 std::string expected_title = 1012 std::string expected_title =
1012 "Referrer is " + instant_url().GetWithEmptyPath().spec(); 1013 "Referrer is " + instant_url().GetWithEmptyPath().spec();
1013 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle()); 1014 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle());
1014 } 1015 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698