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

Side by Side Diff: content/browser/session_history_browsertest.cc

Issue 15505003: GTTF: Convert most tests in content to use EmbeddedTestServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang Created 7 years, 7 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 (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/stringprintf.h"
5 #include "base/string_util.h" 6 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
7 #include "content/public/browser/navigation_controller.h" 8 #include "content/public/browser/navigation_controller.h"
8 #include "content/public/browser/notification_service.h" 9 #include "content/public/browser/notification_service.h"
9 #include "content/public/browser/notification_types.h" 10 #include "content/public/browser/notification_types.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
12 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
14 #include "content/shell/shell.h" 15 #include "content/shell/shell.h"
15 #include "content/test/content_browser_test.h" 16 #include "content/test/content_browser_test.h"
16 #include "content/test/content_browser_test_utils.h" 17 #include "content/test/content_browser_test_utils.h"
17 #include "net/test/spawned_test_server/spawned_test_server.h" 18 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "net/test/embedded_test_server/http_response.h"
20 #include "net/test/embedded_test_server/http_request.h"
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
19 22
20 namespace content { 23 namespace content {
21 24
25 namespace {
26
27 // Handles |request| by serving a response with title set to request contents.
28 scoped_ptr<net::test_server::HttpResponse> HandleEchoTitleRequest(
29 const std::string& echotitle_path,
30 const net::test_server::HttpRequest& request) {
31 if (!StartsWithASCII(request.relative_url, echotitle_path, true))
32 return scoped_ptr<net::test_server::HttpResponse>(NULL);
33
34 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
35 new net::test_server::BasicHttpResponse);
36 http_response->set_code(net::test_server::SUCCESS);
37 http_response->set_content(
38 base::StringPrintf(
39 "<html><head><title>%s</title></head></html>",
40 request.content.c_str()));
41 return http_response.PassAs<net::test_server::HttpResponse>();
42 }
43
44 } // namespace
45
22 class SessionHistoryTest : public ContentBrowserTest { 46 class SessionHistoryTest : public ContentBrowserTest {
23 protected: 47 protected:
24 SessionHistoryTest() {} 48 SessionHistoryTest() {}
25 49
26 virtual void SetUpOnMainThread() OVERRIDE { 50 virtual void SetUpOnMainThread() OVERRIDE {
27 ASSERT_TRUE(test_server()->Start()); 51 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
52 embedded_test_server()->RegisterRequestHandler(
53 base::Bind(&HandleEchoTitleRequest, "/echotitle"));
54
28 NavigateToURL(shell(), GURL(kAboutBlankURL)); 55 NavigateToURL(shell(), GURL(kAboutBlankURL));
29 } 56 }
30 57
31 // Simulate clicking a link. Only works on the frames.html testserver page. 58 // Simulate clicking a link. Only works on the frames.html testserver page.
32 void ClickLink(std::string node_id) { 59 void ClickLink(std::string node_id) {
33 GURL url("javascript:clickLink('" + node_id + "')"); 60 GURL url("javascript:clickLink('" + node_id + "')");
34 NavigateToURL(shell(), url); 61 NavigateToURL(shell(), url);
35 } 62 }
36 63
37 // Simulate filling in form data. Only works on the frames.html page with 64 // Simulate filling in form data. Only works on the frames.html page with
(...skipping 21 matching lines...) Expand all
59 86
60 std::string GetTabTitle() { 87 std::string GetTabTitle() {
61 return UTF16ToASCII(shell()->web_contents()->GetTitle()); 88 return UTF16ToASCII(shell()->web_contents()->GetTitle());
62 } 89 }
63 90
64 GURL GetTabURL() { 91 GURL GetTabURL() {
65 return shell()->web_contents()->GetURL(); 92 return shell()->web_contents()->GetURL();
66 } 93 }
67 94
68 GURL GetURL(const std::string file) { 95 GURL GetURL(const std::string file) {
69 return test_server()->GetURL(std::string("files/session_history/") + file); 96 return embedded_test_server()->GetURL(
97 std::string("/session_history/") + file);
70 } 98 }
71 99
72 void NavigateAndCheckTitle(const char* filename, 100 void NavigateAndCheckTitle(const char* filename,
73 const std::string& expected_title) { 101 const std::string& expected_title) {
74 string16 expected_title16(ASCIIToUTF16(expected_title)); 102 string16 expected_title16(ASCIIToUTF16(expected_title));
75 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); 103 TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
76 NavigateToURL(shell(), GetURL(filename)); 104 NavigateToURL(shell(), GetURL(filename));
77 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); 105 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
78 } 106 }
79 107
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 318
291 SubmitForm("isubmit"); 319 SubmitForm("isubmit");
292 EXPECT_EQ("text=&select=a", GetTabTitle()); 320 EXPECT_EQ("text=&select=a", GetTabTitle());
293 EXPECT_EQ(frames, GetTabURL()); 321 EXPECT_EQ(frames, GetTabURL());
294 } 322 }
295 323
296 // Test that back/forward entries are created for reference fragment 324 // Test that back/forward entries are created for reference fragment
297 // navigations. Bug 730379. 325 // navigations. Bug 730379.
298 // If this flakes use http://crbug.com/61619. 326 // If this flakes use http://crbug.com/61619.
299 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) { 327 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) {
328 embedded_test_server()->RegisterRequestHandler(
329 base::Bind(&HandleEchoTitleRequest, "/echotitle"));
330
300 ASSERT_FALSE(CanGoBack()); 331 ASSERT_FALSE(CanGoBack());
301 332
302 GURL fragment(GetURL("fragment.html")); 333 GURL fragment(GetURL("fragment.html"));
303 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment")); 334 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment"));
304 335
305 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#a", "fragment")); 336 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#a", "fragment"));
306 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#b", "fragment")); 337 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#b", "fragment"));
307 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#c", "fragment")); 338 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#c", "fragment"));
308 339
309 // history is [blank, fragment, fragment#a, fragment#b, *fragment#c] 340 // history is [blank, fragment, fragment#a, fragment#b, *fragment#c]
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 NavigateToURL(shell(), GetURL("title2.html")); 490 NavigateToURL(shell(), GetURL("title2.html"));
460 491
461 ASSERT_TRUE(ExecuteScriptAndExtractInt( 492 ASSERT_TRUE(ExecuteScriptAndExtractInt(
462 shell()->web_contents(), 493 shell()->web_contents(),
463 "domAutomationController.send(history.length)", 494 "domAutomationController.send(history.length)",
464 &length)); 495 &length));
465 EXPECT_EQ(2, length); 496 EXPECT_EQ(2, length);
466 } 497 }
467 498
468 } // namespace content 499 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698