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" |
11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
12 #include "content/public/browser/native_web_keyboard_event.h" | 12 #include "content/public/browser/native_web_keyboard_event.h" |
| 13 #include "content/public/browser/web_ui_controller_factory.h" |
13 #include "content/public/common/bindings_policy.h" | 14 #include "content/public/common/bindings_policy.h" |
| 15 #include "content/public/common/url_constants.h" |
14 #include "content/public/test/render_view_test.h" | 16 #include "content/public/test/render_view_test.h" |
15 #include "content/renderer/render_view_impl.h" | 17 #include "content/renderer/render_view_impl.h" |
| 18 #include "content/shell/shell_content_client.h" |
| 19 #include "content/shell/shell_content_browser_client.h" |
| 20 #include "content/shell/shell_main_delegate.h" |
16 #include "content/test/mock_keyboard.h" | 21 #include "content/test/mock_keyboard.h" |
17 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.
h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.
h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
24 #include "ui/base/keycodes/keyboard_codes.h" | 29 #include "ui/base/keycodes/keyboard_codes.h" |
25 #include "ui/base/range/range.h" | 30 #include "ui/base/range/range.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 }; | 71 }; |
67 int flags = 0; | 72 int flags = 0; |
68 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kModifierMap); ++i) { | 73 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kModifierMap); ++i) { |
69 if (kModifierMap[i].src & modifiers) { | 74 if (kModifierMap[i].src & modifiers) { |
70 flags |= kModifierMap[i].dst; | 75 flags |= kModifierMap[i].dst; |
71 } | 76 } |
72 } | 77 } |
73 return flags; | 78 return flags; |
74 } | 79 } |
75 #endif | 80 #endif |
| 81 |
| 82 class WebUITestWebUIControllerFactory : public content::WebUIControllerFactory { |
| 83 public: |
| 84 virtual content::WebUIController* CreateWebUIControllerForURL( |
| 85 content::WebUI* web_ui, const GURL& url) const OVERRIDE { |
| 86 return NULL; |
| 87 } |
| 88 virtual content::WebUI::TypeID GetWebUIType( |
| 89 content::BrowserContext* browser_context, |
| 90 const GURL& url) const OVERRIDE { |
| 91 return content::WebUI::kNoWebUI; |
| 92 } |
| 93 virtual bool UseWebUIForURL(content::BrowserContext* browser_context, |
| 94 const GURL& url) const OVERRIDE { |
| 95 return content::GetContentClient()->HasWebUIScheme(url); |
| 96 } |
| 97 virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, |
| 98 const GURL& url) const OVERRIDE { |
| 99 return content::GetContentClient()->HasWebUIScheme(url); |
| 100 } |
| 101 virtual bool IsURLAcceptableForWebUI( |
| 102 content::BrowserContext* browser_context, |
| 103 const GURL& url, |
| 104 bool data_urls_allowed) const OVERRIDE { |
| 105 return false; |
| 106 } |
| 107 }; |
| 108 |
| 109 class WebUITestClient : public content::ShellContentClient { |
| 110 public: |
| 111 WebUITestClient() { |
| 112 } |
| 113 |
| 114 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { |
| 115 return url.SchemeIs(chrome::kChromeUIScheme); |
| 116 } |
| 117 }; |
| 118 |
| 119 class WebUITestBrowserClient : public content::ShellContentBrowserClient { |
| 120 public: |
| 121 WebUITestBrowserClient() {} |
| 122 |
| 123 virtual content::WebUIControllerFactory* |
| 124 GetWebUIControllerFactory() OVERRIDE { |
| 125 return &factory_; |
| 126 } |
| 127 |
| 128 private: |
| 129 WebUITestWebUIControllerFactory factory_; |
| 130 }; |
| 131 |
76 } | 132 } |
77 | 133 |
78 class RenderViewImplTest : public content::RenderViewTest { | 134 class RenderViewImplTest : public content::RenderViewTest { |
79 public: | 135 public: |
80 RenderViewImplTest() { | 136 RenderViewImplTest() { |
81 // Attach a pseudo keyboard device to this object. | 137 // Attach a pseudo keyboard device to this object. |
82 mock_keyboard_.reset(new MockKeyboard()); | 138 mock_keyboard_.reset(new MockKeyboard()); |
83 } | 139 } |
84 | 140 |
| 141 virtual void SetUp() OVERRIDE { |
| 142 content::RenderViewTest::SetUp(); |
| 143 content::ShellMainDelegate::InitializeResourceBundle(); |
| 144 } |
| 145 |
85 RenderViewImpl* view() { | 146 RenderViewImpl* view() { |
86 return static_cast<RenderViewImpl*>(view_); | 147 return static_cast<RenderViewImpl*>(view_); |
87 } | 148 } |
88 | 149 |
89 // Sends IPC messages that emulates a key-press event. | 150 // Sends IPC messages that emulates a key-press event. |
90 int SendKeyEvent(MockKeyboard::Layout layout, | 151 int SendKeyEvent(MockKeyboard::Layout layout, |
91 int key_code, | 152 int key_code, |
92 MockKeyboard::Modifiers modifiers, | 153 MockKeyboard::Modifiers modifiers, |
93 string16* output) { | 154 string16* output) { |
94 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 294 |
234 // Change the value of the input. We should have gotten an update state | 295 // Change the value of the input. We should have gotten an update state |
235 // notification. We need to spin the message loop to catch this update. | 296 // notification. We need to spin the message loop to catch this update. |
236 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); | 297 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); |
237 ProcessPendingMessages(); | 298 ProcessPendingMessages(); |
238 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( | 299 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( |
239 ViewHostMsg_UpdateState::ID)); | 300 ViewHostMsg_UpdateState::ID)); |
240 } | 301 } |
241 | 302 |
242 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 303 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
| 304 WebUITestClient client; |
| 305 WebUITestBrowserClient browser_client; |
| 306 content::ContentClient* old_client = content::GetContentClient(); |
| 307 content::ContentBrowserClient* old_browser_client = |
| 308 content::GetContentClient()->browser(); |
| 309 |
| 310 content::SetContentClient(&client); |
| 311 content::GetContentClient()->set_browser_for_testing(&browser_client); |
| 312 client.set_renderer_for_testing(old_client->renderer()); |
| 313 |
243 // Navigations to normal HTTP URLs can be handled locally. | 314 // Navigations to normal HTTP URLs can be handled locally. |
244 WebKit::WebURLRequest request(GURL("http://foo.com")); | 315 WebKit::WebURLRequest request(GURL("http://foo.com")); |
245 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 316 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
246 GetMainFrame(), | 317 GetMainFrame(), |
247 request, | 318 request, |
248 WebKit::WebNavigationTypeLinkClicked, | 319 WebKit::WebNavigationTypeLinkClicked, |
249 WebKit::WebNode(), | 320 WebKit::WebNode(), |
250 WebKit::WebNavigationPolicyCurrentTab, | 321 WebKit::WebNavigationPolicyCurrentTab, |
251 false); | 322 false); |
252 EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy); | 323 EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy); |
(...skipping 13 matching lines...) Expand all Loading... |
266 // Verify that popup links to WebUI URLs also are sent to browser. | 337 // Verify that popup links to WebUI URLs also are sent to browser. |
267 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); | 338 WebKit::WebURLRequest popup_request(GURL("chrome://foo")); |
268 policy = view()->decidePolicyForNavigation( | 339 policy = view()->decidePolicyForNavigation( |
269 GetMainFrame(), | 340 GetMainFrame(), |
270 popup_request, | 341 popup_request, |
271 WebKit::WebNavigationTypeLinkClicked, | 342 WebKit::WebNavigationTypeLinkClicked, |
272 WebKit::WebNode(), | 343 WebKit::WebNode(), |
273 WebKit::WebNavigationPolicyNewForegroundTab, | 344 WebKit::WebNavigationPolicyNewForegroundTab, |
274 false); | 345 false); |
275 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); | 346 EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy); |
| 347 |
| 348 content::GetContentClient()->set_browser_for_testing(old_browser_client); |
| 349 content::SetContentClient(old_client); |
276 } | 350 } |
277 | 351 |
278 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { | 352 TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) { |
279 // Enable bindings to simulate a WebUI view. | 353 // Enable bindings to simulate a WebUI view. |
280 view()->OnAllowBindings(content::BINDINGS_POLICY_WEB_UI); | 354 view()->OnAllowBindings(content::BINDINGS_POLICY_WEB_UI); |
281 | 355 |
282 // Navigations to normal HTTP URLs will be sent to browser process. | 356 // Navigations to normal HTTP URLs will be sent to browser process. |
283 WebKit::WebURLRequest request(GURL("http://foo.com")); | 357 WebKit::WebURLRequest request(GURL("http://foo.com")); |
284 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( | 358 WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation( |
285 GetMainFrame(), | 359 GetMainFrame(), |
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 ASSERT_EQ(utf16_length, bounds.size()); | 1645 ASSERT_EQ(utf16_length, bounds.size()); |
1572 for (size_t i = 0; i < utf16_length; ++i) { | 1646 for (size_t i = 0; i < utf16_length; ++i) { |
1573 if (is_surrogate_pair_empty_rect[i]) { | 1647 if (is_surrogate_pair_empty_rect[i]) { |
1574 EXPECT_EQ(0, bounds[i].width()); | 1648 EXPECT_EQ(0, bounds[i].width()); |
1575 } else { | 1649 } else { |
1576 EXPECT_LT(0, bounds[i].width()); | 1650 EXPECT_LT(0, bounds[i].width()); |
1577 } | 1651 } |
1578 } | 1652 } |
1579 view()->OnImeConfirmComposition(empty_string, ui::Range::InvalidRange()); | 1653 view()->OnImeConfirmComposition(empty_string, ui::Range::InvalidRange()); |
1580 } | 1654 } |
OLD | NEW |