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