Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile gdi. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" 12 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
17 #include "ui/base/gtk/gtk_hig_constants.h" 17 #include "ui/base/gtk/gtk_hig_constants.h"
18 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
20 20
21 namespace { 21 namespace {
22 class OmniboxEditControllerMock : public OmniboxEditController { 22 class OmniboxEditControllerMock : public OmniboxEditController {
23 public: 23 public:
24 MOCK_METHOD4(OnAutocompleteAccept, void(const GURL& url, 24 MOCK_METHOD4(OnAutocompleteAccept, void(const GURL& url,
(...skipping 10 matching lines...) Expand all
35 MOCK_METHOD0(GetInstant, InstantController*()); 35 MOCK_METHOD0(GetInstant, InstantController*());
36 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); 36 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*());
37 MOCK_CONST_METHOD0(GetOmniboxBounds, gfx::Rect()); 37 MOCK_CONST_METHOD0(GetOmniboxBounds, gfx::Rect());
38 38
39 virtual ~OmniboxEditControllerMock() {} 39 virtual ~OmniboxEditControllerMock() {}
40 }; 40 };
41 } // namespace 41 } // namespace
42 42
43 class OmniboxViewGtkTest : public PlatformTest { 43 class OmniboxViewGtkTest : public PlatformTest {
44 public: 44 public:
45 OmniboxViewGtkTest() : file_thread_(content::BrowserThread::UI) {}
46
47 virtual void SetUp() { 45 virtual void SetUp() {
48 PlatformTest::SetUp(); 46 PlatformTest::SetUp();
49 profile_.reset(new TestingProfile); 47 profile_.reset(new TestingProfile());
50 window_ = gtk_window_new(GTK_WINDOW_POPUP); 48 window_ = gtk_window_new(GTK_WINDOW_POPUP);
51 controller_.reset(new OmniboxEditControllerMock); 49 controller_.reset(new OmniboxEditControllerMock);
52 view_.reset(new OmniboxViewGtk(controller_.get(), NULL, 50 view_.reset(new OmniboxViewGtk(controller_.get(), NULL,
53 NULL, 51 NULL,
54 profile_.get(), 52 profile_.get(),
55 NULL, false, window_)); 53 NULL, false, window_));
56 view_->Init(); 54 view_->Init();
57 text_buffer_ = view_->text_buffer_; 55 text_buffer_ = view_->text_buffer_;
58 } 56 }
59 57
60 virtual void TearDown() { 58 virtual void TearDown() {
61 gtk_widget_destroy(window_); 59 gtk_widget_destroy(window_);
62 PlatformTest::TearDown(); 60 PlatformTest::TearDown();
63 } 61 }
64 62
65 void SetPasteClipboardRequested(bool b) { 63 void SetPasteClipboardRequested(bool b) {
66 view_->paste_clipboard_requested_ = b; 64 view_->paste_clipboard_requested_ = b;
67 } 65 }
68 66
67 content::TestBrowserThreadBundle thread_bundle_;
69 scoped_ptr<OmniboxEditControllerMock> controller_; 68 scoped_ptr<OmniboxEditControllerMock> controller_;
70 scoped_ptr<TestingProfile> profile_; 69 scoped_ptr<TestingProfile> profile_;
71 GtkTextBuffer* text_buffer_; 70 GtkTextBuffer* text_buffer_;
72 scoped_ptr<OmniboxViewGtk> view_; 71 scoped_ptr<OmniboxViewGtk> view_;
73 GtkWidget* window_; 72 GtkWidget* window_;
74 content::TestBrowserThread file_thread_;
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtkTest);
78 }; 73 };
79 74
80 TEST_F(OmniboxViewGtkTest, InsertText) { 75 TEST_F(OmniboxViewGtkTest, InsertText) {
81 GtkTextIter i; 76 GtkTextIter i;
82 const char input[] = " hello, world "; 77 const char input[] = " hello, world ";
83 const std::string expected = input; 78 const std::string expected = input;
84 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0); 79 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0);
85 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input)); 80 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input));
86 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText())); 81 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText()));
87 } 82 }
88 83
89 TEST_F(OmniboxViewGtkTest, PasteText) { 84 TEST_F(OmniboxViewGtkTest, PasteText) {
90 GtkTextIter i; 85 GtkTextIter i;
91 const char input[] = " hello, world "; 86 const char input[] = " hello, world ";
92 const std::string expected = "hello, world"; 87 const std::string expected = "hello, world";
93 SetPasteClipboardRequested(true); 88 SetPasteClipboardRequested(true);
94 view_->OnBeforePossibleChange(); 89 view_->OnBeforePossibleChange();
95 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0); 90 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0);
96 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input)); 91 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input));
97 92
98 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText())); 93 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText()));
99 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698