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/path_service.h" |
5 #include "base/time.h" | 6 #include "base/time.h" |
6 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
11 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
12 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/common/content_paths.h" |
13 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
14 #include "content/shell/shell.h" | 16 #include "content/shell/shell.h" |
15 #include "content/test/content_browser_test.h" | 17 #include "content/test/content_browser_test.h" |
16 #include "content/test/content_browser_test_utils.h" | 18 #include "content/test/content_browser_test_utils.h" |
17 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
18 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
19 #include "net/test/spawned_test_server/spawned_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 | 24 |
23 class RenderViewHostTest : public ContentBrowserTest { | 25 class RenderViewHostTest : public ContentBrowserTest { |
24 public: | 26 public: |
25 RenderViewHostTest() {} | 27 RenderViewHostTest() {} |
26 }; | 28 }; |
27 | 29 |
28 class RenderViewHostTestWebContentsObserver : public WebContentsObserver { | 30 class RenderViewHostTestWebContentsObserver : public WebContentsObserver { |
29 public: | 31 public: |
(...skipping 22 matching lines...) Expand all Loading... |
52 | 54 |
53 private: | 55 private: |
54 net::HostPortPair observed_socket_address_; | 56 net::HostPortPair observed_socket_address_; |
55 GURL base_url_; | 57 GURL base_url_; |
56 int navigation_count_; | 58 int navigation_count_; |
57 | 59 |
58 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestWebContentsObserver); | 60 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestWebContentsObserver); |
59 }; | 61 }; |
60 | 62 |
61 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, FrameNavigateSocketAddress) { | 63 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, FrameNavigateSocketAddress) { |
62 ASSERT_TRUE(test_server()->Start()); | 64 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
63 RenderViewHostTestWebContentsObserver observer(shell()->web_contents()); | 65 RenderViewHostTestWebContentsObserver observer(shell()->web_contents()); |
64 | 66 |
65 GURL test_url = test_server()->GetURL("files/simple_page.html"); | 67 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
66 NavigateToURL(shell(), test_url); | 68 NavigateToURL(shell(), test_url); |
67 | 69 |
68 EXPECT_EQ(test_server()->host_port_pair().ToString(), | 70 EXPECT_EQ(net::HostPortPair::FromURL( |
| 71 embedded_test_server()->base_url()).ToString(), |
69 observer.observed_socket_address().ToString()); | 72 observer.observed_socket_address().ToString()); |
70 EXPECT_EQ(1, observer.navigation_count()); | 73 EXPECT_EQ(1, observer.navigation_count()); |
71 } | 74 } |
72 | 75 |
73 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, BaseURLParam) { | 76 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, BaseURLParam) { |
74 ASSERT_TRUE(test_server()->Start()); | 77 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
75 RenderViewHostTestWebContentsObserver observer(shell()->web_contents()); | 78 RenderViewHostTestWebContentsObserver observer(shell()->web_contents()); |
76 | 79 |
77 // Base URL is not set if it is the same as the URL. | 80 // Base URL is not set if it is the same as the URL. |
78 GURL test_url = test_server()->GetURL("files/simple_page.tml"); | 81 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
79 NavigateToURL(shell(), test_url); | 82 NavigateToURL(shell(), test_url); |
80 EXPECT_TRUE(observer.base_url().is_empty()); | 83 EXPECT_TRUE(observer.base_url().is_empty()); |
81 EXPECT_EQ(1, observer.navigation_count()); | 84 EXPECT_EQ(1, observer.navigation_count()); |
82 | 85 |
83 // But should be set to the original page when reading MHTML. | 86 // But should be set to the original page when reading MHTML. |
84 test_url = net::FilePathToFileURL(test_server()->document_root().Append( | 87 base::FilePath content_test_data_dir; |
85 FILE_PATH_LITERAL("google.mht"))); | 88 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &content_test_data_dir)); |
| 89 test_url = net::FilePathToFileURL( |
| 90 content_test_data_dir.AppendASCII("google.mht")); |
86 NavigateToURL(shell(), test_url); | 91 NavigateToURL(shell(), test_url); |
87 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); | 92 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); |
88 } | 93 } |
89 | 94 |
90 } // namespace content | 95 } // namespace content |
OLD | NEW |