| 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/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
| 14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.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/base/net_util.h" |
| 18 #include "net/test/test_server.h" | 18 #include "net/test/test_server.h" |
| 19 | 19 |
| 20 using content::WebContents; |
| 21 |
| 20 class RenderViewHostTest : public InProcessBrowserTest { | 22 class RenderViewHostTest : public InProcessBrowserTest { |
| 21 public: | 23 public: |
| 22 RenderViewHostTest() {} | 24 RenderViewHostTest() {} |
| 23 }; | 25 }; |
| 24 | 26 |
| 25 | 27 |
| 26 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, | 28 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, |
| 27 ExecuteJavascriptAndGetValue) { | 29 ExecuteJavascriptAndGetValue) { |
| 28 ASSERT_TRUE(test_server()->Start()); | 30 ASSERT_TRUE(test_server()->Start()); |
| 29 GURL empty_url(test_server()->GetURL("files/empty.html")); | 31 GURL empty_url(test_server()->GetURL("files/empty.html")); |
| 30 ui_test_utils::NavigateToURL(browser(), empty_url); | 32 ui_test_utils::NavigateToURL(browser(), empty_url); |
| 31 | 33 |
| 32 RenderViewHost* rvh = | 34 RenderViewHost* rvh = |
| 33 browser()->GetSelectedTabContents()->GetRenderViewHost(); | 35 browser()->GetSelectedWebContents()->GetRenderViewHost(); |
| 34 | 36 |
| 35 { | 37 { |
| 36 Value* value = rvh->ExecuteJavascriptAndGetValue(string16(), | 38 Value* value = rvh->ExecuteJavascriptAndGetValue(string16(), |
| 37 ASCIIToUTF16("!false;")); | 39 ASCIIToUTF16("!false;")); |
| 38 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 40 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); |
| 39 bool bool_value; | 41 bool bool_value; |
| 40 EXPECT_TRUE(value->GetAsBoolean(&bool_value)); | 42 EXPECT_TRUE(value->GetAsBoolean(&bool_value)); |
| 41 EXPECT_TRUE(bool_value); | 43 EXPECT_TRUE(bool_value); |
| 42 } | 44 } |
| 43 | 45 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 EXPECT_TRUE(list_value->Get(1, &element_value)); | 159 EXPECT_TRUE(list_value->Get(1, &element_value)); |
| 158 EXPECT_EQ(Value::TYPE_INTEGER, element_value->GetType()); | 160 EXPECT_EQ(Value::TYPE_INTEGER, element_value->GetType()); |
| 159 EXPECT_TRUE(list_value->Get(2, &element_value)); | 161 EXPECT_TRUE(list_value->Get(2, &element_value)); |
| 160 EXPECT_EQ(Value::TYPE_BOOLEAN, element_value->GetType()); | 162 EXPECT_EQ(Value::TYPE_BOOLEAN, element_value->GetType()); |
| 161 } | 163 } |
| 162 } | 164 } |
| 163 | 165 |
| 164 class RenderViewHostTestWebContentsObserver | 166 class RenderViewHostTestWebContentsObserver |
| 165 : public content::WebContentsObserver { | 167 : public content::WebContentsObserver { |
| 166 public: | 168 public: |
| 167 explicit RenderViewHostTestWebContentsObserver(TabContents* tab_contents) | 169 explicit RenderViewHostTestWebContentsObserver(WebContents* web_contents) |
| 168 : content::WebContentsObserver(tab_contents), | 170 : content::WebContentsObserver(web_contents), |
| 169 navigation_count_(0) {} | 171 navigation_count_(0) {} |
| 170 virtual ~RenderViewHostTestWebContentsObserver() {} | 172 virtual ~RenderViewHostTestWebContentsObserver() {} |
| 171 | 173 |
| 172 virtual void DidNavigateMainFrame( | 174 virtual void DidNavigateMainFrame( |
| 173 const content::LoadCommittedDetails& details, | 175 const content::LoadCommittedDetails& details, |
| 174 const content::FrameNavigateParams& params) OVERRIDE { | 176 const content::FrameNavigateParams& params) OVERRIDE { |
| 175 observed_socket_address_ = params.socket_address; | 177 observed_socket_address_ = params.socket_address; |
| 176 base_url_ = params.base_url; | 178 base_url_ = params.base_url; |
| 177 ++navigation_count_; | 179 ++navigation_count_; |
| 178 } | 180 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 191 net::HostPortPair observed_socket_address_; | 193 net::HostPortPair observed_socket_address_; |
| 192 GURL base_url_; | 194 GURL base_url_; |
| 193 int navigation_count_; | 195 int navigation_count_; |
| 194 | 196 |
| 195 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestWebContentsObserver); | 197 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestWebContentsObserver); |
| 196 }; | 198 }; |
| 197 | 199 |
| 198 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, FrameNavigateSocketAddress) { | 200 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, FrameNavigateSocketAddress) { |
| 199 ASSERT_TRUE(test_server()->Start()); | 201 ASSERT_TRUE(test_server()->Start()); |
| 200 RenderViewHostTestWebContentsObserver observer( | 202 RenderViewHostTestWebContentsObserver observer( |
| 201 browser()->GetSelectedTabContents()); | 203 browser()->GetSelectedWebContents()); |
| 202 | 204 |
| 203 GURL test_url = test_server()->GetURL("files/simple.html"); | 205 GURL test_url = test_server()->GetURL("files/simple.html"); |
| 204 ui_test_utils::NavigateToURL(browser(), test_url); | 206 ui_test_utils::NavigateToURL(browser(), test_url); |
| 205 | 207 |
| 206 EXPECT_EQ(test_server()->host_port_pair().ToString(), | 208 EXPECT_EQ(test_server()->host_port_pair().ToString(), |
| 207 observer.observed_socket_address().ToString()); | 209 observer.observed_socket_address().ToString()); |
| 208 EXPECT_EQ(1, observer.navigation_count()); | 210 EXPECT_EQ(1, observer.navigation_count()); |
| 209 } | 211 } |
| 210 | 212 |
| 211 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, BaseURLParam) { | 213 IN_PROC_BROWSER_TEST_F(RenderViewHostTest, BaseURLParam) { |
| 212 ASSERT_TRUE(test_server()->Start()); | 214 ASSERT_TRUE(test_server()->Start()); |
| 213 RenderViewHostTestWebContentsObserver observer( | 215 RenderViewHostTestWebContentsObserver observer( |
| 214 browser()->GetSelectedTabContents()); | 216 browser()->GetSelectedWebContents()); |
| 215 | 217 |
| 216 // Base URL is not set if it is the same as the URL. | 218 // Base URL is not set if it is the same as the URL. |
| 217 GURL test_url = test_server()->GetURL("files/simple.html"); | 219 GURL test_url = test_server()->GetURL("files/simple.html"); |
| 218 ui_test_utils::NavigateToURL(browser(), test_url); | 220 ui_test_utils::NavigateToURL(browser(), test_url); |
| 219 EXPECT_TRUE(observer.base_url().is_empty()); | 221 EXPECT_TRUE(observer.base_url().is_empty()); |
| 220 EXPECT_EQ(1, observer.navigation_count()); | 222 EXPECT_EQ(1, observer.navigation_count()); |
| 221 | 223 |
| 222 // But should be set to the original page when reading MHTML. | 224 // But should be set to the original page when reading MHTML. |
| 223 test_url = net::FilePathToFileURL(test_server()->document_root().Append( | 225 test_url = net::FilePathToFileURL(test_server()->document_root().Append( |
| 224 FILE_PATH_LITERAL("google.mht"))); | 226 FILE_PATH_LITERAL("google.mht"))); |
| 225 ui_test_utils::NavigateToURL(browser(), test_url); | 227 ui_test_utils::NavigateToURL(browser(), test_url); |
| 226 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); | 228 EXPECT_EQ("http://www.google.com/", observer.base_url().spec()); |
| 227 } | 229 } |
| OLD | NEW |