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/basictypes.h" | 5 #include "base/basictypes.h" |
6 | 6 |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/common/intents_messages.h" | 10 #include "content/common/intents_messages.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 virtual WebUIController* CreateWebUIControllerForURL( | 89 virtual WebUIController* CreateWebUIControllerForURL( |
90 WebUI* web_ui, const GURL& url) const OVERRIDE { | 90 WebUI* web_ui, const GURL& url) const OVERRIDE { |
91 return NULL; | 91 return NULL; |
92 } | 92 } |
93 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 93 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
94 const GURL& url) const OVERRIDE { | 94 const GURL& url) const OVERRIDE { |
95 return WebUI::kNoWebUI; | 95 return WebUI::kNoWebUI; |
96 } | 96 } |
97 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 97 virtual bool UseWebUIForURL(BrowserContext* browser_context, |
98 const GURL& url) const OVERRIDE { | 98 const GURL& url) const OVERRIDE { |
99 return GetContentClient()->HasWebUIScheme(url); | 99 return HasWebUIScheme(url); |
100 } | 100 } |
101 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 101 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
102 const GURL& url) const OVERRIDE { | 102 const GURL& url) const OVERRIDE { |
103 return GetContentClient()->HasWebUIScheme(url); | 103 return HasWebUIScheme(url); |
104 } | 104 } |
105 virtual bool IsURLAcceptableForWebUI( | 105 virtual bool IsURLAcceptableForWebUI( |
106 BrowserContext* browser_context, | 106 BrowserContext* browser_context, |
107 const GURL& url, | 107 const GURL& url, |
108 bool data_urls_allowed) const OVERRIDE { | 108 bool data_urls_allowed) const OVERRIDE { |
109 return false; | 109 return false; |
110 } | 110 } |
111 }; | 111 }; |
112 | 112 |
113 class WebUITestClient : public ShellContentClient { | |
114 public: | |
115 WebUITestClient() { | |
116 } | |
117 | |
118 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { | |
119 return url.SchemeIs(chrome::kChromeUIScheme); | |
120 } | |
121 }; | |
122 | |
123 class WebUITestBrowserClient : public ShellContentBrowserClient { | |
124 public: | |
125 WebUITestBrowserClient() {} | |
126 | |
127 virtual WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE { | |
128 return &factory_; | |
129 } | |
130 | |
131 private: | |
132 WebUITestWebUIControllerFactory factory_; | |
133 }; | |
134 | |
135 } // namespace | 113 } // namespace |
136 | 114 |
137 class RenderViewImplTest : public RenderViewTest { | 115 class RenderViewImplTest : public RenderViewTest { |
138 public: | 116 public: |
139 RenderViewImplTest() { | 117 RenderViewImplTest() { |
140 // Attach a pseudo keyboard device to this object. | 118 // Attach a pseudo keyboard device to this object. |
141 mock_keyboard_.reset(new MockKeyboard()); | 119 mock_keyboard_.reset(new MockKeyboard()); |
142 } | 120 } |
143 | 121 |
144 RenderViewImpl* view() { | 122 RenderViewImpl* view() { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 WebKit::WebHTTPBody body = item.httpBody(); | 313 WebKit::WebHTTPBody body = item.httpBody(); |
336 WebKit::WebHTTPBody::Element element; | 314 WebKit::WebHTTPBody::Element element; |
337 bool successful = body.elementAt(0, element); | 315 bool successful = body.elementAt(0, element); |
338 EXPECT_TRUE(successful); | 316 EXPECT_TRUE(successful); |
339 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); | 317 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); |
340 EXPECT_EQ(length, element.data.size()); | 318 EXPECT_EQ(length, element.data.size()); |
341 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); | 319 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); |
342 } | 320 } |
343 | 321 |
344 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 322 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
345 WebUITestClient client; | 323 WebUITestWebUIControllerFactory factory; |
346 WebUITestBrowserClient browser_client; | 324 WebUIControllerFactory::RegisterFactory(&factory); |
347 ContentClient* old_client = GetContentClient(); | |
348 ContentBrowserClient* old_browser_client = GetContentClient()->browser(); | |
349 | |
350 SetContentClient(&client); | |
351 GetContentClient()->set_browser_for_testing(&browser_client); | |
352 client.set_renderer_for_testing(old_client->renderer()); | |
353 | 325 |
354 // Navigations to normal HTTP URLs can be handled locally. | 326 // Navigations to normal HTTP URLs can be handled locally. |
355 WebKit::WebURLRequest request(GURL("http://foo.com")); | 327 WebKit::WebURLRequest request(GURL("http://foo.com")); |
356 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 328 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
357 GetMainFrame(), | 329 GetMainFrame(), |
358 request, | 330 request, |
359 WebKit::WebNavigationTypeLinkClicked, | 331 WebKit::WebNavigationTypeLinkClicked, |
360 WebKit::WebNode(), | 332 WebKit::WebNode(), |
361 WebKit::WebNavigationPolicyCurrentTab, | 333 WebKit::WebNavigationPolicyCurrentTab, |
362 false); | 334 false); |
(...skipping 14 matching lines...) Expand all Loading... |
377 // Verify that popup links to WebUI URLs also are sent to browser. | 349 // Verify that popup links to WebUI URLs also are sent to browser. |
378 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); | 350 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); |
379 policy = view()->decidePolicyForNavigation( | 351 policy = view()->decidePolicyForNavigation( |
380 GetMainFrame(), | 352 GetMainFrame(), |
381 popup_request, | 353 popup_request, |
382 WebKit::WebNavigationTypeLinkClicked, | 354 WebKit::WebNavigationTypeLinkClicked, |
383 WebKit::WebNode(), | 355 WebKit::WebNode(), |
384 WebKit::WebNavigationPolicyNewForegroundTab, | 356 WebKit::WebNavigationPolicyNewForegroundTab, |
385 false); | 357 false); |
386 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 358 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
387 | |
388 GetContentClient()->set_browser_for_testing(old_browser_client); | |
389 SetContentClient(old_client); | |
390 } | 359 } |
391 | 360 |
392 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { | 361 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { |
393 // Enable bindings to simulate a WebUI view. | 362 // Enable bindings to simulate a WebUI view. |
394 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); | 363 view()->OnAllowBindings(BINDINGS_POLICY_WEB_UI); |
395 | 364 |
396 // Navigations to normal HTTP URLs will be sent to browser process. | 365 // Navigations to normal HTTP URLs will be sent to browser process. |
397 WebKit::WebURLRequest request(GURL("http://foo.com")); | 366 WebKit::WebURLRequest request(GURL("http://foo.com")); |
398 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 367 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
399 GetMainFrame(), | 368 GetMainFrame(), |
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 | 1848 |
1880 // Copy the document content to std::wstring and compare with the | 1849 // Copy the document content to std::wstring and compare with the |
1881 // expected result. | 1850 // expected result. |
1882 const int kMaxOutputCharacters = 256; | 1851 const int kMaxOutputCharacters = 256; |
1883 std::wstring output = UTF16ToWideHack( | 1852 std::wstring output = UTF16ToWideHack( |
1884 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 1853 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
1885 EXPECT_EQ(output, L"hello \n\nworld"); | 1854 EXPECT_EQ(output, L"hello \n\nworld"); |
1886 } | 1855 } |
1887 | 1856 |
1888 } // namespace content | 1857 } // namespace content |
OLD | NEW |