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

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: fix silly compile error 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 19
20 namespace { 20 namespace {
21 class OmniboxEditControllerMock : public OmniboxEditController { 21 class OmniboxEditControllerMock : public OmniboxEditController {
22 public: 22 public:
23 MOCK_METHOD4(OnAutocompleteAccept, void(const GURL& url, 23 MOCK_METHOD4(OnAutocompleteAccept, void(const GURL& url,
24 WindowOpenDisposition disposition, 24 WindowOpenDisposition disposition,
25 content::PageTransition transition, 25 content::PageTransition transition,
26 const GURL& alternate_nav_url)); 26 const GURL& alternate_nav_url));
27 MOCK_METHOD0(OnChanged, void()); 27 MOCK_METHOD0(OnChanged, void());
28 MOCK_METHOD0(OnSelectionBoundsChanged, void()); 28 MOCK_METHOD0(OnSelectionBoundsChanged, void());
29 MOCK_METHOD1(OnInputInProgress, void(bool in_progress)); 29 MOCK_METHOD1(OnInputInProgress, void(bool in_progress));
30 MOCK_METHOD0(OnKillFocus, void()); 30 MOCK_METHOD0(OnKillFocus, void());
31 MOCK_METHOD0(OnSetFocus, void()); 31 MOCK_METHOD0(OnSetFocus, void());
32 MOCK_CONST_METHOD0(GetFavicon, gfx::Image()); 32 MOCK_CONST_METHOD0(GetFavicon, gfx::Image());
33 MOCK_CONST_METHOD0(GetTitle, string16()); 33 MOCK_CONST_METHOD0(GetTitle, string16());
34 MOCK_METHOD0(GetInstant, InstantController*()); 34 MOCK_METHOD0(GetInstant, InstantController*());
35 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*()); 35 MOCK_CONST_METHOD0(GetWebContents, content::WebContents*());
36 36
37 virtual ~OmniboxEditControllerMock() {} 37 virtual ~OmniboxEditControllerMock() {}
38 }; 38 };
39 } // namespace 39 } // namespace
40 40
41 class OmniboxViewGtkTest : public PlatformTest { 41 class OmniboxViewGtkTest : public PlatformTest {
42 public: 42 public:
43 OmniboxViewGtkTest() : file_thread_(content::BrowserThread::UI) {}
44
45 virtual void SetUp() { 43 virtual void SetUp() {
46 PlatformTest::SetUp(); 44 PlatformTest::SetUp();
47 profile_.reset(new TestingProfile); 45 profile_.reset(new TestingProfile());
48 window_ = gtk_window_new(GTK_WINDOW_POPUP); 46 window_ = gtk_window_new(GTK_WINDOW_POPUP);
49 controller_.reset(new OmniboxEditControllerMock); 47 controller_.reset(new OmniboxEditControllerMock);
50 view_.reset(new OmniboxViewGtk(controller_.get(), NULL, 48 view_.reset(new OmniboxViewGtk(controller_.get(), NULL,
51 NULL, 49 NULL,
52 profile_.get(), 50 profile_.get(),
53 NULL, false, window_)); 51 NULL, false, window_));
54 view_->Init(); 52 view_->Init();
55 text_buffer_ = view_->text_buffer_; 53 text_buffer_ = view_->text_buffer_;
56 } 54 }
57 55
58 virtual void TearDown() { 56 virtual void TearDown() {
59 gtk_widget_destroy(window_); 57 gtk_widget_destroy(window_);
60 PlatformTest::TearDown(); 58 PlatformTest::TearDown();
61 } 59 }
62 60
63 void SetPasteClipboardRequested(bool b) { 61 void SetPasteClipboardRequested(bool b) {
64 view_->paste_clipboard_requested_ = b; 62 view_->paste_clipboard_requested_ = b;
65 } 63 }
66 64
65 content::TestBrowserThreadBundle thread_bundle_;
67 scoped_ptr<OmniboxEditControllerMock> controller_; 66 scoped_ptr<OmniboxEditControllerMock> controller_;
68 scoped_ptr<TestingProfile> profile_; 67 scoped_ptr<TestingProfile> profile_;
69 GtkTextBuffer* text_buffer_; 68 GtkTextBuffer* text_buffer_;
70 scoped_ptr<OmniboxViewGtk> view_; 69 scoped_ptr<OmniboxViewGtk> view_;
71 GtkWidget* window_; 70 GtkWidget* window_;
72 content::TestBrowserThread file_thread_;
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtkTest);
76 }; 71 };
77 72
78 TEST_F(OmniboxViewGtkTest, InsertText) { 73 TEST_F(OmniboxViewGtkTest, InsertText) {
79 GtkTextIter i; 74 GtkTextIter i;
80 const char input[] = " hello, world "; 75 const char input[] = " hello, world ";
81 const std::string expected = input; 76 const std::string expected = input;
82 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0); 77 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0);
83 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input)); 78 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input));
84 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText())); 79 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText()));
85 } 80 }
86 81
87 TEST_F(OmniboxViewGtkTest, PasteText) { 82 TEST_F(OmniboxViewGtkTest, PasteText) {
88 GtkTextIter i; 83 GtkTextIter i;
89 const char input[] = " hello, world "; 84 const char input[] = " hello, world ";
90 const std::string expected = "hello, world"; 85 const std::string expected = "hello, world";
91 SetPasteClipboardRequested(true); 86 SetPasteClipboardRequested(true);
92 view_->OnBeforePossibleChange(); 87 view_->OnBeforePossibleChange();
93 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0); 88 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0);
94 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input)); 89 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input));
95 90
96 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText())); 91 ASSERT_EQ(expected, UTF16ToUTF8(view_->GetText()));
97 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698