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 "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/test_browser_context.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/aura/test/aura_test_helper.h" |
| 14 #include "ui/base/ime/text_input_focus_manager.h" |
| 15 #include "ui/base/ui_base_switches.h" |
| 16 #include "ui/compositor/test/context_factories_for_test.h" |
| 17 #include "ui/views/test/webview_test_helper.h" |
| 18 #include "ui/views/widget/widget.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 class WebViewTest : public testing::Test { |
| 23 public: |
| 24 WebViewTest() : widget_(NULL), webview_(NULL) {} |
| 25 |
| 26 virtual void SetUp() { |
| 27 testing::Test::SetUp(); |
| 28 |
| 29 ui::InitializeContextFactoryForTests(false); |
| 30 |
| 31 aura_test_helper_.reset( |
| 32 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
| 33 aura_test_helper_->SetUp(); |
| 34 |
| 35 InitWebView(); |
| 36 } |
| 37 |
| 38 virtual void TearDown() { |
| 39 if (widget_) |
| 40 widget_->Close(); |
| 41 |
| 42 aura_test_helper_->TearDown(); |
| 43 |
| 44 ui::TerminateContextFactoryForTests(); |
| 45 |
| 46 testing::Test::TearDown(); |
| 47 } |
| 48 |
| 49 protected: |
| 50 views::WebView* webview() { return webview_; } |
| 51 content::BrowserContext* browser_context() { return &browser_context_; } |
| 52 |
| 53 private: |
| 54 void InitWebView() { |
| 55 // WebViewTest.TextInputClientIsUpToDate needs kEnableTextInputFocusManager |
| 56 // flag to be enabled. |
| 57 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 58 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); |
| 59 |
| 60 widget_ = new views::Widget(); |
| 61 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 62 params.context = aura_test_helper_->root_window(); |
| 63 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 64 widget_->Init(params); |
| 65 |
| 66 webview_ = new views::WebView(browser_context()); |
| 67 widget_->SetContentsView(webview_); |
| 68 |
| 69 widget_->Activate(); |
| 70 widget_->Show(); |
| 71 } |
| 72 |
| 73 views::Widget* widget_; |
| 74 views::WebView* webview_; |
| 75 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 76 content::TestBrowserContext browser_context_; |
| 77 views::WebViewTestHelper webview_test_helper_; |
| 78 content::TestBrowserThreadBundle browser_thread_bundle_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(WebViewTest); |
| 81 }; |
| 82 |
| 83 TEST_F(WebViewTest, TextInputClientIsUpToDate) { |
| 84 webview()->SetEmbedFullscreenWidgetMode(true); |
| 85 |
| 86 ui::TextInputFocusManager* text_input_focus_manager = |
| 87 ui::TextInputFocusManager::GetInstance(); |
| 88 const ui::TextInputClient* null_text_input_client = NULL; |
| 89 |
| 90 EXPECT_EQ(null_text_input_client, webview()->GetTextInputClient()); |
| 91 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), |
| 92 webview()->GetTextInputClient()); |
| 93 |
| 94 // Case 1: Creates a new WebContents. |
| 95 webview()->GetWebContents(); |
| 96 webview()->RequestFocus(); |
| 97 ui::TextInputClient* client1 = webview()->GetTextInputClient(); |
| 98 EXPECT_NE(null_text_input_client, client1); |
| 99 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client1); |
| 100 |
| 101 // Case 2: Replaces a WebContents by SetWebContents(). |
| 102 content::WebContents::CreateParams params(browser_context()); |
| 103 scoped_ptr<content::WebContents> web_contents( |
| 104 content::WebContents::Create(params)); |
| 105 webview()->SetWebContents(web_contents.get()); |
| 106 ui::TextInputClient* client2 = webview()->GetTextInputClient(); |
| 107 EXPECT_NE(null_text_input_client, client2); |
| 108 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client2); |
| 109 EXPECT_NE(client1, client2); |
| 110 } |
| 111 |
| 112 } // namespace |
OLD | NEW |