Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/controls/webview/webview.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 #include "content/public/test/test_browser_context.h" | |
| 12 #include "ui/base/ime/text_input_focus_manager.h" | |
| 13 #include "ui/base/resource/resource_bundle.h" | |
| 14 #include "ui/base/ui_base_switches.h" | |
| 15 #include "ui/gl/gl_surface.h" | |
| 16 #include "ui/views/test/webview_test_helper.h" | |
| 17 #include "ui/views/test/widget_test.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class WebViewInteractiveUiTest : public views::test::WidgetTest { | |
| 22 public: | |
| 23 virtual void SetUp() OVERRIDE { | |
| 24 gfx::GLSurface::InitializeOneOffForTests(); | |
| 25 base::FilePath pak_dir; | |
| 26 PathService::Get(base::DIR_MODULE, &pak_dir); | |
| 27 base::FilePath pak_file; | |
| 28 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); | |
| 29 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | |
| 30 WidgetTest::SetUp(); | |
| 31 } | |
| 32 | |
| 33 protected: | |
| 34 content::BrowserContext* browser_context() { return &browser_context_; } | |
| 35 | |
| 36 private: | |
| 37 content::TestBrowserContext browser_context_; | |
| 38 views::WebViewTestHelper webview_test_helper_; | |
| 39 }; | |
|
sky
2014/05/01 15:21:19
DISALLOW_...
Yuki
2014/05/02 06:38:11
Done.
| |
| 40 | |
| 41 #if defined(USE_AURA) | |
|
sky
2014/05/01 15:21:19
You shouldn't need this ifdef anymore.
Yuki
2014/05/02 06:38:11
Done.
| |
| 42 TEST_F(WebViewInteractiveUiTest, TextInputClientIsUpToDate) { | |
| 43 // WebViewInteractiveUiTest.TextInputClientIsUpToDate needs | |
| 44 // kEnableTextInputFocusManager flag to be enabled. | |
| 45 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
| 46 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); | |
| 47 | |
| 48 // Create a top level widget and a webview as its content. | |
| 49 views::Widget* widget = CreateTopLevelFramelessPlatformWidget(); | |
| 50 views::WebView* webview = new views::WebView(browser_context()); | |
| 51 widget->SetContentsView(webview); | |
| 52 widget->Show(); | |
| 53 webview->RequestFocus(); | |
| 54 | |
| 55 ui::TextInputFocusManager* text_input_focus_manager = | |
| 56 ui::TextInputFocusManager::GetInstance(); | |
| 57 const ui::TextInputClient* null_text_input_client = NULL; | |
| 58 EXPECT_EQ(null_text_input_client, webview->GetTextInputClient()); | |
| 59 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), | |
| 60 webview->GetTextInputClient()); | |
| 61 | |
| 62 // Case 1: Creates a new WebContents. | |
| 63 webview->GetWebContents(); | |
| 64 webview->RequestFocus(); | |
| 65 ui::TextInputClient* client1 = webview->GetTextInputClient(); | |
| 66 EXPECT_NE(null_text_input_client, client1); | |
| 67 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client1); | |
| 68 | |
| 69 // Case 2: Replaces a WebContents by SetWebContents(). | |
| 70 content::WebContents::CreateParams params(browser_context()); | |
| 71 scoped_ptr<content::WebContents> web_contents( | |
| 72 content::WebContents::Create(params)); | |
| 73 webview->SetWebContents(web_contents.get()); | |
| 74 ui::TextInputClient* client2 = webview->GetTextInputClient(); | |
| 75 EXPECT_NE(null_text_input_client, client2); | |
| 76 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client2); | |
| 77 EXPECT_NE(client1, client2); | |
| 78 | |
| 79 widget->Close(); | |
| 80 RunPendingMessages(); | |
| 81 } | |
| 82 #endif // defined(USE_AURA) | |
| 83 | |
| 84 } // namespace | |
| OLD | NEW |