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

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: Rebase. 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 on_change_calls_(0), 139 on_change_calls_(0),
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 144
144 protected: 145 protected:
145 void SetUpInProcessBrowserTestFixture() override { 146 void SetUpInProcessBrowserTestFixture() override {
146 search::EnableQueryExtractionForTesting(); 147 search::EnableQueryExtractionForTesting();
147 ASSERT_TRUE(https_test_server().Start()); 148 ASSERT_TRUE(https_test_server().Start());
148 GURL instant_url = https_test_server().GetURL( 149 GURL instant_url =
149 "files/instant_extended.html?strk=1&"); 150 https_test_server().GetURL("/instant_extended.html?strk=1&");
150 GURL ntp_url = https_test_server().GetURL( 151 GURL ntp_url =
151 "files/instant_extended_ntp.html?strk=1&"); 152 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&");
152 InstantTestBase::Init(instant_url, ntp_url, false); 153 InstantTestBase::Init(instant_url, ntp_url, false);
153 } 154 }
154 155
155 int64 GetHistogramCount(const char* name) { 156 int64 GetHistogramCount(const char* name) {
156 base::HistogramBase* histogram = 157 base::HistogramBase* histogram =
157 base::StatisticsRecorder::FindHistogram(name); 158 base::StatisticsRecorder::FindHistogram(name);
158 if (!histogram) { 159 if (!histogram) {
159 // If no histogram is found, it's possible that no values have been 160 // If no histogram is found, it's possible that no values have been
160 // recorded yet. Assume that the value is zero. 161 // recorded yet. Assume that the value is zero.
161 return 0; 162 return 0;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 class InstantExtendedPrefetchTest : public InstantExtendedTest { 251 class InstantExtendedPrefetchTest : public InstantExtendedTest {
251 public: 252 public:
252 InstantExtendedPrefetchTest() 253 InstantExtendedPrefetchTest()
253 : factory_(new net::URLFetcherImplFactory()), 254 : factory_(new net::URLFetcherImplFactory()),
254 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) { 255 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) {
255 } 256 }
256 257
257 void SetUpInProcessBrowserTestFixture() override { 258 void SetUpInProcessBrowserTestFixture() override {
258 search::EnableQueryExtractionForTesting(); 259 search::EnableQueryExtractionForTesting();
259 ASSERT_TRUE(https_test_server().Start()); 260 ASSERT_TRUE(https_test_server().Start());
260 GURL instant_url = https_test_server().GetURL( 261 GURL instant_url =
261 "files/instant_extended.html?strk=1&"); 262 https_test_server().GetURL("/instant_extended.html?strk=1&");
262 GURL ntp_url = https_test_server().GetURL( 263 GURL ntp_url =
263 "files/instant_extended_ntp.html?strk=1&"); 264 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&");
264 InstantTestBase::Init(instant_url, ntp_url, true); 265 InstantTestBase::Init(instant_url, ntp_url, true);
265 } 266 }
266 267
267 void SetUpCommandLine(base::CommandLine* command_line) override { 268 void SetUpCommandLine(base::CommandLine* command_line) override {
268 command_line->AppendSwitchASCII( 269 command_line->AppendSwitchASCII(
269 switches::kForceFieldTrials, 270 switches::kForceFieldTrials,
270 "EmbeddedSearch/Group11 prefetch_results_srp:1/"); 271 "EmbeddedSearch/Group11 prefetch_results_srp:1/");
271 } 272 }
272 273
273 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); } 274 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // Test class used to verify chrome-search: scheme and access policy from the 309 // Test class used to verify chrome-search: scheme and access policy from the
309 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it 310 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it
310 // loads a theme that provides a background image. 311 // loads a theme that provides a background image.
311 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { 312 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase {
312 public: 313 public:
313 InstantPolicyTest() {} 314 InstantPolicyTest() {}
314 315
315 protected: 316 protected:
316 void SetUpInProcessBrowserTestFixture() override { 317 void SetUpInProcessBrowserTestFixture() override {
317 ASSERT_TRUE(https_test_server().Start()); 318 ASSERT_TRUE(https_test_server().Start());
318 GURL instant_url = https_test_server().GetURL( 319 GURL instant_url =
319 "files/instant_extended.html?strk=1&"); 320 https_test_server().GetURL("/instant_extended.html?strk=1&");
320 GURL ntp_url = https_test_server().GetURL( 321 GURL ntp_url =
321 "files/instant_extended_ntp.html?strk=1&"); 322 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&");
322 InstantTestBase::Init(instant_url, ntp_url, false); 323 InstantTestBase::Init(instant_url, ntp_url, false);
323 } 324 }
324 325
325 void InstallThemeSource() { 326 void InstallThemeSource() {
326 ThemeSource* theme = new ThemeSource(profile()); 327 ThemeSource* theme = new ThemeSource(profile());
327 content::URLDataSource::Add(profile(), theme); 328 content::URLDataSource::Add(profile(), theme);
328 } 329 }
329 330
330 void InstallThemeAndVerify(const std::string& theme_dir, 331 void InstallThemeAndVerify(const std::string& theme_dir,
331 const std::string& theme_name) { 332 const std::string& theme_name) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 omnibox()->ShowURL(); 977 omnibox()->ShowURL();
977 EXPECT_FALSE(browser()->toolbar_model()->WouldPerformSearchTermReplacement( 978 EXPECT_FALSE(browser()->toolbar_model()->WouldPerformSearchTermReplacement(
978 false)); 979 false));
979 // Don't bother looking for a specific URL; ensuring we're no longer showing 980 // Don't bother looking for a specific URL; ensuring we're no longer showing
980 // the search terms is sufficient. 981 // the search terms is sufficient.
981 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText()); 982 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText());
982 } 983 }
983 984
984 // Check that clicking on a result sends the correct referrer. 985 // Check that clicking on a result sends the correct referrer.
985 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { 986 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) {
986 ASSERT_TRUE(test_server()->Start()); 987 ASSERT_TRUE(embedded_test_server()->Start());
987 GURL result_url = 988 GURL result_url = embedded_test_server()->GetURL(
988 test_server()->GetURL("files/referrer_policy/referrer-policy-log.html"); 989 "/referrer_policy/referrer-policy-log.html");
989 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 990 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
990 FocusOmnibox(); 991 FocusOmnibox();
991 992
992 // Type a query and press enter to get results. 993 // Type a query and press enter to get results.
993 SetOmniboxText("query"); 994 SetOmniboxText("query");
994 PressEnterAndWaitForFrameLoad(); 995 PressEnterAndWaitForFrameLoad();
995 996
996 // Simulate going to a result. 997 // Simulate going to a result.
997 content::WebContents* contents = 998 content::WebContents* contents =
998 browser()->tab_strip_model()->GetActiveWebContents(); 999 browser()->tab_strip_model()->GetActiveWebContents();
999 std::ostringstream stream; 1000 std::ostringstream stream;
1000 stream << "var link = document.createElement('a');"; 1001 stream << "var link = document.createElement('a');";
1001 stream << "link.href = \"" << result_url.spec() << "\";"; 1002 stream << "link.href = \"" << result_url.spec() << "\";";
1002 stream << "document.body.appendChild(link);"; 1003 stream << "document.body.appendChild(link);";
1003 stream << "link.click();"; 1004 stream << "link.click();";
1004 EXPECT_TRUE(content::ExecuteScript(contents, stream.str())); 1005 EXPECT_TRUE(content::ExecuteScript(contents, stream.str()));
1005 1006
1006 content::WaitForLoadStop(contents); 1007 content::WaitForLoadStop(contents);
1007 std::string expected_title = 1008 std::string expected_title =
1008 "Referrer is " + instant_url().GetWithEmptyPath().spec(); 1009 "Referrer is " + instant_url().GetWithEmptyPath().spec();
1009 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle()); 1010 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle());
1010 } 1011 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/find_bar/find_bar_host_interactive_uitest.cc ('k') | chrome/browser/ui/search/instant_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698