OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" | 5 #include "base/time.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/browser/renderer_host/render_view_host.h" | 11 #include "content/browser/renderer_host/render_view_host.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "content/browser/tab_contents/tab_contents_observer.h" | 13 #include "content/browser/tab_contents/tab_contents_observer.h" |
14 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
| 17 #include "net/base/net_util.h" |
17 #include "net/test/test_server.h" | 18 #include "net/test/test_server.h" |
18 | 19 |
19 class RenderViewHostTest : public InProcessBrowserTest { | 20 class RenderViewHostTest : public InProcessBrowserTest { |
20 public: | 21 public: |
21 RenderViewHostTest() {} | 22 RenderViewHostTest() {} |
22 }; | 23 }; |
23 | 24 |
24 | 25 |
25 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, | 26 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, |
26 ExecuteJavascriptAndGetValue) { | 27 ExecuteJavascriptAndGetValue) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 public: | 165 public: |
165 explicit RenderViewHostTestTabContentsObserver(TabContents* tab_contents) | 166 explicit RenderViewHostTestTabContentsObserver(TabContents* tab_contents) |
166 : TabContentsObserver(tab_contents), | 167 : TabContentsObserver(tab_contents), |
167 navigation_count_(0) {} | 168 navigation_count_(0) {} |
168 virtual ~RenderViewHostTestTabContentsObserver() {} | 169 virtual ~RenderViewHostTestTabContentsObserver() {} |
169 | 170 |
170 virtual void DidNavigateMainFrame( | 171 virtual void DidNavigateMainFrame( |
171 const content::LoadCommittedDetails& details, | 172 const content::LoadCommittedDetails& details, |
172 const content::FrameNavigateParams& params) OVERRIDE { | 173 const content::FrameNavigateParams& params) OVERRIDE { |
173 observed_socket_address_ = params.socket_address; | 174 observed_socket_address_ = params.socket_address; |
| 175 base_url_ = params.base_url; |
174 ++navigation_count_; | 176 ++navigation_count_; |
175 } | 177 } |
176 | 178 |
177 const net::HostPortPair& observed_socket_address() const { | 179 const net::HostPortPair& observed_socket_address() const { |
178 return observed_socket_address_; | 180 return observed_socket_address_; |
179 } | 181 } |
180 | 182 |
| 183 GURL base_url() const { |
| 184 return base_url_; |
| 185 } |
| 186 |
181 int navigation_count() const { return navigation_count_; } | 187 int navigation_count() const { return navigation_count_; } |
182 | 188 |
183 private: | 189 private: |
184 net::HostPortPair observed_socket_address_; | 190 net::HostPortPair observed_socket_address_; |
| 191 GURL base_url_; |
185 int navigation_count_; | 192 int navigation_count_; |
186 | 193 |
187 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestTabContentsObserver); | 194 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestTabContentsObserver); |
188 }; | 195 }; |
189 | 196 |
190 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, FrameNavigateSocketAddress) { | 197 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, FrameNavigateSocketAddress) { |
191 ASSERT_TRUE(test_server()->Start()); | 198 ASSERT_TRUE(test_server()->Start()); |
192 RenderViewHostTestTabContentsObserver observer( | 199 RenderViewHostTestTabContentsObserver observer( |
193 browser()->GetSelectedTabContents()); | 200 browser()->GetSelectedTabContents()); |
194 | 201 |
195 GURL test_url = test_server()->GetURL("files/simple.html"); | 202 GURL test_url = test_server()->GetURL("files/simple.html"); |
196 ui_test_utils::NavigateToURL(browser(), test_url); | 203 ui_test_utils::NavigateToURL(browser(), test_url); |
197 | 204 |
198 EXPECT_EQ(test_server()->host_port_pair().ToString(), | 205 EXPECT_EQ(test_server()->host_port_pair().ToString(), |
199 observer.observed_socket_address().ToString()); | 206 observer.observed_socket_address().ToString()); |
200 EXPECT_EQ(1, observer.navigation_count()); | 207 EXPECT_EQ(1, observer.navigation_count()); |
201 } | 208 } |
| 209 |
| 210 // TODO(jcivelli): temporarily disabled while I figure-out why the EOL is |
| 211 // getting messed-up in google.mht (causing it to fail to load). |
| 212 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, DISABLED_BaseURLParam) { |
| 213 ASSERT_TRUE(test_server()->Start()); |
| 214 RenderViewHostTestTabContentsObserver observer( |
| 215 browser()->GetSelectedTabContents()); |
| 216 |
| 217 // Base URL is not set if it is the same as the URL. |
| 218 GURL test_url = test_server()->GetURL("files/simple.html"); |
| 219 ui_test_utils::NavigateToURL(browser(), test_url); |
| 220 EXPECT_TRUE(observer.base_url().is_empty()); |
| 221 EXPECT_EQ(1, observer.navigation_count()); |
| 222 |
| 223 // But should be set to the original page when reading MHTML. |
| 224 test_url = net::FilePathToFileURL(test_server()->document_root().Append( |
| 225 FILE_PATH_LITERAL("google.mht"))); |
| 226 ui_test_utils::NavigateToURL(browser(), test_url); |
| 227 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); |
| 228 } |
OLD | NEW |